mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Modify format of -D settings file
This commit is contained in:
parent
666822cf51
commit
215aab0fe4
47
packages/node_modules/node-red/red.js
vendored
47
packages/node_modules/node-red/red.js
vendored
@ -59,32 +59,6 @@ nopt.invalidHandler = function(k,v,t) {
|
|||||||
|
|
||||||
var parsedArgs = nopt(knownOpts,shortHands,process.argv,2)
|
var parsedArgs = nopt(knownOpts,shortHands,process.argv,2)
|
||||||
|
|
||||||
/**
|
|
||||||
* Marge values in second object into first object.
|
|
||||||
*
|
|
||||||
* @param {Object} obj0 - target object
|
|
||||||
* @param {Object} obj1 - object to be merged
|
|
||||||
*/
|
|
||||||
function mergeObject(obj0, obj1) {
|
|
||||||
function isObject(o) {
|
|
||||||
function typeOf(o) {
|
|
||||||
var toString = Object.prototype.toString;
|
|
||||||
return toString.call(o).slice(8, -1);
|
|
||||||
}
|
|
||||||
return (typeOf(o) == "Object");
|
|
||||||
}
|
|
||||||
Object.entries(obj1).forEach(([key, val]) => {
|
|
||||||
if (obj0.hasOwnProperty(key) && isObject(obj0[key]) && isObject(val)) {
|
|
||||||
mergeObject(obj0[key], val);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
obj0[key] = val;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return obj0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (parsedArgs.help) {
|
if (parsedArgs.help) {
|
||||||
console.log("Node-RED v"+RED.version());
|
console.log("Node-RED v"+RED.version());
|
||||||
console.log("Usage: node-red [-v] [-?] [--settings settings.js] [--userDir DIR]");
|
console.log("Usage: node-red [-v] [-?] [--settings settings.js] [--userDir DIR]");
|
||||||
@ -161,29 +135,32 @@ try {
|
|||||||
|
|
||||||
if (parsedArgs.define) {
|
if (parsedArgs.define) {
|
||||||
var defs = parsedArgs.define;
|
var defs = parsedArgs.define;
|
||||||
defs.forEach(function (def) {
|
|
||||||
try {
|
try {
|
||||||
|
while (defs.length > 0) {
|
||||||
|
var def = defs.shift();
|
||||||
var match = /^(([^=]+)=(.+)|@(.*))$/.exec(def);
|
var match = /^(([^=]+)=(.+)|@(.*))$/.exec(def);
|
||||||
if (match) {
|
if (match) {
|
||||||
if (!match[4]) {
|
if (!match[4]) {
|
||||||
var val = JSON.parse(match[3]);
|
var val = JSON.parse(match[3]);
|
||||||
RED.util.setObjectProperty(settings, match[2], val, true);
|
RED.util.setObjectProperty(settings, match[2], val, true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
var obj = fs.readJsonSync(match[4]);
|
var obj = fs.readJsonSync(match[4]);
|
||||||
mergeObject(settings, obj);
|
for (var k in obj) {
|
||||||
|
if (obj.hasOwnProperty(k)) {
|
||||||
|
RED.util.setObjectProperty(settings, k, obj[k], true)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Error("unexpected syntax");
|
throw new Error("Invalid syntax: '"+def+"'");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
} catch (e) {
|
||||||
console.log("Error processing option: "+def);
|
console.log("Error processing -D option: "+e.message);
|
||||||
console.log(e);
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedArgs.verbose) {
|
if (parsedArgs.verbose) {
|
||||||
|
Loading…
Reference in New Issue
Block a user