forked from elpete/gitlab-npm-audit-parser
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathparse.js
executable file
·43 lines (35 loc) · 929 Bytes
/
parse.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
#!/usr/bin/env node
const { stdin } = process;
const fs = require("fs");
const program = require("commander");
const { version } = require("./package.json");
const convert = require("./lib/convert");
const chunks = [];
program
.version(version)
.option(
"-o, --out <path>",
"output filename, defaults to gl-dependency-scanning-report.json"
)
.parse(process.argv);
const filename = program.opts().out || "gl-dependency-scanning-report.json";
stdin.setEncoding("utf8");
stdin.on("data", (chunk) => {
chunks.push(chunk);
});
stdin.on("end", () => {
const inputJSON = chunks.join("");
try {
const outputJSON = convert(inputJSON);
fs.writeFile(filename, `${outputJSON}\n`, (err) => {
if (err) {
console.log(err);
return;
}
console.log(`The file was saved as ${filename}!`);
});
} catch (error) {
console.error(error);
process.exitCode = 1;
}
});