-
Notifications
You must be signed in to change notification settings - Fork 24
/
compile_licenses.js
65 lines (53 loc) · 1.79 KB
/
compile_licenses.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Checker from "license-checker";
import { promisify } from "util";
import fs from "fs";
import path from "path";
Checker.initp = promisify(Checker.init);
async function main() {
let prod = await Checker.initp({ start: ".", production: true });
let dev = await Checker.initp({ start: ".", development: true });
let compile = (packages) => {
let final = ``;
for (let name in packages) {
let info = packages[name];
let { licenseFile, publisher, licenses } = info;
let licenseInfo = `© ${publisher} - ${licenses}`;
if (licenseFile) {
licenseInfo = fs.readFileSync(licenseFile, "utf8");
}
final += `
${name}
${licenseInfo}
--
`.replace(/^ /gm, "");
}
return final;
};
let customText = ``;
let submoduleDir = path.join(".", "submodules");
let submodules = fs.readdirSync(submoduleDir);
for (let name of submodules) {
let modulePath = path.join(submoduleDir, name);
try {
let licenseFile = fs
.readdirSync(modulePath)
.filter((f) => f.toLowerCase().includes("license"))[0];
let licensePath = path.join(modulePath, licenseFile);
customText += `
${name}
${fs.readFileSync(licensePath, "utf8")}
---
`.replace(/^ /gm, "");
} catch (error) {
continue;
}
}
let prodText = compile(prod);
let devText = compile(dev);
let custom = [customText, prodText, devText];
fs.writeFileSync("./OSAcknowledgements.txt", custom.join("\n"));
}
main().catch((err) => {
console.error(err);
process.exit(-1);
});