command line data overrides
This commit is contained in:
parent
1be33ad3f0
commit
21df671d15
40
tibia
40
tibia
@ -2,37 +2,56 @@
|
|||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
console.log("Usage:");
|
console.log("Usage:");
|
||||||
console.log(" tibia file1.json,file2.json,...filen.json template outDirectory");
|
console.log(" tibia file1.json,file2.json,...filen.json template outDirectory [override1=value1] [override2=value2] ...");
|
||||||
console.log(" tibia --common template outDirectory");
|
console.log(" tibia --common template outDirectory [override1=value1] [override2=value2] ...");
|
||||||
console.log(" tibia --data file1.json,file2.json,...filen.json template outDirectory");
|
console.log(" tibia --data file1.json,file2.json,...filen.json template outDirectory [override1=value1] [override2=value2] ...");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonFiles, template, outputDir, outputCommon, outputData;
|
var jsonFiles, template, outputDir, outputCommon, outputData, i;
|
||||||
if (process.argv[2] == "--common") {
|
if (process.argv[2] == "--common") {
|
||||||
if (process.argv.length != 5)
|
if (process.argv.length < 5)
|
||||||
usage();
|
usage();
|
||||||
jsonFiles = [];
|
jsonFiles = [];
|
||||||
template = process.argv[3];
|
template = process.argv[3];
|
||||||
outputDir = process.argv[4];
|
outputDir = process.argv[4];
|
||||||
outputCommon = true;
|
outputCommon = true;
|
||||||
outputData = false;
|
outputData = false;
|
||||||
|
i = 5;
|
||||||
} else if (process.argv[2] == "--data") {
|
} else if (process.argv[2] == "--data") {
|
||||||
if (process.argv.length != 6)
|
if (process.argv.length < 6)
|
||||||
usage();
|
usage();
|
||||||
jsonFiles = process.argv[3].split(",");
|
jsonFiles = process.argv[3].split(",");
|
||||||
template = process.argv[4];
|
template = process.argv[4];
|
||||||
outputDir = process.argv[5];
|
outputDir = process.argv[5];
|
||||||
outputCommon = false;
|
outputCommon = false;
|
||||||
outputData = true;
|
outputData = true;
|
||||||
|
i = 6;
|
||||||
} else {
|
} else {
|
||||||
if (process.argv.length != 5)
|
if (process.argv.length < 5)
|
||||||
usage();
|
usage();
|
||||||
jsonFiles = process.argv[2].split(",");
|
jsonFiles = process.argv[2].split(",");
|
||||||
template = process.argv[3];
|
template = process.argv[3];
|
||||||
outputDir = process.argv[4];
|
outputDir = process.argv[4];
|
||||||
outputCommon = true;
|
outputCommon = true;
|
||||||
outputData = true;
|
outputData = true;
|
||||||
|
i = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
var overrides = [];
|
||||||
|
for (; i < process.argv.length; i++) {
|
||||||
|
var o = process.argv[i];
|
||||||
|
var r = o.match(/^([_a-zA-Z][_a-zA-Z0-9]*(\.[_a-zA-Z][_a-zA-Z0-9]*)*)=/);
|
||||||
|
if (!r)
|
||||||
|
usage();
|
||||||
|
var p = r[1].split(".");
|
||||||
|
var v = o.substring(r[0].length);
|
||||||
|
try {
|
||||||
|
v = JSON.parse(v);
|
||||||
|
} catch (e) {
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
overrides.push({ property: p, value: v });
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
@ -54,6 +73,13 @@ for (var i = 0; i < jsonFiles.length; i++) {
|
|||||||
for (var k in d)
|
for (var k in d)
|
||||||
data[k] = d[k];
|
data[k] = d[k];
|
||||||
}
|
}
|
||||||
|
for (var i = 0; i < overrides.length; i++) {
|
||||||
|
var p = data;
|
||||||
|
var o = overrides[i];
|
||||||
|
for (var j = 0; j < o.property.length - 1; j++)
|
||||||
|
p = p[o.property[j]];
|
||||||
|
p[o.property[o.property.length - 1]] = o.value;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (outputData) {
|
if (outputData) {
|
||||||
|
Loading…
Reference in New Issue
Block a user