-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
license-gen.js
45 lines (37 loc) · 1.04 KB
/
license-gen.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
// Running: node license-gen.js > licenses.json
const checker = require('license-checker');
const packageJson = require('./package.json');
const dependencies = packageJson.dependencies;
const devDependencies = packageJson.devDependencies;
function filterProperties(pkg) {
const allowed = ['licenses', 'repository', 'url', 'publisher'];
Object.keys(pkg).forEach((key) => {
if (!allowed.includes(key)) {
delete pkg[key];
}
});
return pkg;
}
checker.init({
start: '.',
}, function (err, packages) {
const output = {
dependencies: {},
devDependencies: {},
};
if (err) {
console.error(err);
process.exit(1);
} else {
Object.keys(packages).forEach((pkg) => {
const pkgName = pkg.replace(/@[^@]+$/, '');
if (dependencies[pkgName]) {
output.dependencies[pkgName] = filterProperties(packages[pkg]);
}
if (devDependencies[pkgName]) {
output.devDependencies[pkgName] = filterProperties(packages[pkg]);
}
});
console.log(JSON.stringify(output, null, 2));
}
});