-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (41 loc) · 1.15 KB
/
Copy pathindex.js
File metadata and controls
47 lines (41 loc) · 1.15 KB
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
#!/usr/bin/env node
'use strict';
var opts = require("nomnom").parse();
var fs = require('fs');
var transformJson = require('./transform-json');
if(!opts.input) {
return console.log('--input has to be specified');
}
else if(!opts.output) {
return console.log('--output has to be specified');
}
else if(!opts.transform) {
return console.log('--transform has to be specified');
}
else {
var inputFile = opts.input;
var transformFile = opts.transform;
var outputFile = opts.output;
fs.readFile(inputFile, 'utf8', function (err,input) {
if (err) {
return console.log(err);
}
// input is there
var inputJSON = JSON.parse(input);
fs.readFile(transformFile, 'utf8', function (err,transform) {
if (err) {
return console.log(err);
}
// transform is there
var templateJSON = JSON.parse(transform);
var output = transformJson(inputJSON, templateJSON);
fs.writeFile(outputFile, JSON.stringify(output, null, 2), function(err) {
if(err) {
console.log(err);
} else {
console.log("File " + outputFile + " successfully saved.");
}
});
});
});
}