forked from davityavryan/yarn-audit-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·59 lines (49 loc) · 1.58 KB
/
index.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
#!/usr/bin/env node
const program = require('commander');
const reporter = require('./lib/reporter');
const pkg = require('./package.json');
program
.version(pkg.version)
.option('-o, --output [output]', 'output file')
.option('-t, --template [ejs file]', 'ejs template file')
.option('--no-unique', 'show all vulnerability entries');
const genReport = (stdin, output = 'yarn-audit.html', template, showUnique = true) => {
if (!stdin) {
console.log('No JSON');
return process.exit(1);
}
const data = stdin.split(/\n/).filter((line) => line !== '');
let json;
try {
json = data.map(JSON.parse);
} catch (err) {
console.error('Failed to parse NPM Audit JSON!\n', err);
return process.exit(1);
}
const templateFile = template || `${__dirname}/templates/template.ejs`;
reporter(json, templateFile, output, showUnique)
.then(() => {
console.log(`Vulnerability snapshot saved at ${output}`);
process.exit(0);
})
.catch((error) => {
console.log('An error occurred!');
console.error(error);
process.exit(1);
});
};
if (process.stdin.isTTY) {
program.parse(process.argv);
} else {
let stdin = '';
process.stdin.on('readable', function () {
const chunk = this.read();
if (chunk !== null) {
stdin += chunk;
}
});
process.stdin.on('end', function () {
program.parse(process.argv);
genReport(stdin, program.output, program.template, program.unique);
});
}