diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index 075f50d85..1742322c3 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -59,32 +59,6 @@ nopt.invalidHandler = function(k,v,t) { 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) { console.log("Node-RED v"+RED.version()); console.log("Usage: node-red [-v] [-?] [--settings settings.js] [--userDir DIR]"); @@ -161,29 +135,32 @@ try { if (parsedArgs.define) { var defs = parsedArgs.define; - defs.forEach(function (def) { - try { + try { + while (defs.length > 0) { + var def = defs.shift(); var match = /^(([^=]+)=(.+)|@(.*))$/.exec(def); if (match) { if (!match[4]) { var val = JSON.parse(match[3]); RED.util.setObjectProperty(settings, match[2], val, true); - } - else { + } else { 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 { - throw new Error("unexpected syntax"); + throw new Error("Invalid syntax: '"+def+"'"); } + } - catch (e) { - console.log("Error processing option: "+def); - console.log(e); - process.exit(); - } - }); + } catch (e) { + console.log("Error processing -D option: "+e.message); + process.exit(); + } } if (parsedArgs.verbose) {