forked from jcalcaben/magento-openapi-transformer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
49 lines (40 loc) · 929 Bytes
/
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
const Transformer = require("./src/Transformer");
const fs = require("fs");
const commandLineArgs = require("command-line-args");
const { emitWarning } = require("process");
const optionDefinitions = [
{
name: "infile",
alias: "i",
type: String,
},
{
name: "outfile",
alias: "o",
type: String,
},
];
const options = commandLineArgs(optionDefinitions);
const { infile, outfile } = options;
if (!infile) {
throw new Error("Input file argument --infile or -i not specified");
}
fs.readFile(infile, "utf8", (err, data) => {
if (err) {
throw err;
}
var json = data.toString();
const result = Transformer.run(json);
if (outfile) {
fs.writeFile(outfile, result, (err) => {
if (err) {
throw err;
}
});
} else {
emitWarning(
"outfile argument --outfile or -o not specified, writing output to console"
);
console.log(result);
}
});