Add cmd-line help and reduce node error output by default

Added nopt package dependency - npm update required!

Added -v cmdline option to show node module load errors, which are otherwise hidden by default with only a summary shown
This commit is contained in:
Nick O'Leary
2014-03-06 22:32:23 +00:00
parent 68d5ebf388
commit f7792c66b4
4 changed files with 95 additions and 45 deletions

View File

@@ -273,6 +273,7 @@ module.exports.load = function(settings) {
}
function loadNodes(dir) {
var errors = [];
fs.readdirSync(dir).sort().filter(function(fn){
var stats = fs.statSync(path.join(dir,fn));
if (stats.isFile()) {
@@ -280,26 +281,30 @@ module.exports.load = function(settings) {
try {
require(path.join(dir,fn));
} catch(err) {
util.log("["+fn+"] "+err);
errors.push({fn:fn, err:err});
//util.log("["+fn+"] "+err);
//console.log(err.stack);
}
}
} else if (stats.isDirectory()) {
// Ignore /.dirs/, /lib/ /node_modules/
if (!/^(\..*|lib|icons|node_modules)$/.test(fn)) {
loadNodes(path.join(dir,fn));
errors = errors.concat(loadNodes(path.join(dir,fn)));
} else if (fn === "icons") {
events.emit("node-icon-dir",path.join(dir,fn));
}
}
});
return errors;
}
loadNodes(__dirname+"/../nodes");
var errors = loadNodes(__dirname+"/../nodes");
scanForNodes(__dirname+"/../nodes");
if (settings.nodesDir) {
loadNodes(settings.nodesDir);
errors = errors.concat(loadNodes(settings.nodesDir));
scanForNodes(settings.nodesDir);
}
//console.log(errors);
return errors;
//events.emit("nodes-loaded");
}

View File

@@ -16,6 +16,8 @@
var express = require('express');
var util = require('util');
var when = require('when');
var createUI = require("./ui");
var redNodes = require("./nodes");
@@ -71,20 +73,25 @@ function createServer(_server,_settings) {
}
function start() {
var defer = when.defer();
storage.init(settings).then(function() {
console.log("\nWelcome to Node-RED\n===================\n");
util.log("[red] Loading palette nodes");
util.log("------------------------------------------");
redNodes.load(settings);
util.log("");
util.log('You may ignore any errors above here if they are for');
util.log('nodes you are not using. The nodes indicated will not');
util.log('be available in the main palette until any missing');
util.log('modules are installed, typically by running:');
util.log(' npm install {the module name}');
util.log('or any other errors are resolved');
util.log("------------------------------------------");
var nodeErrors = redNodes.load(settings);
if (nodeErrors.length > 0) {
util.log("------------------------------------------");
if (settings.verbose) {
for (var i=0;i<nodeErrors.length;i+=1) {
util.log("["+nodeErrors[i].fn+"] "+nodeErrors[i].err);
}
} else {
util.log("[red] Failed to register "+nodeErrors.length+" node type"+(nodeErrors.length==1?"":"s"));
util.log("[red] Run with -v for details");
}
util.log("------------------------------------------");
}
defer.resolve();
storage.getFlows().then(function(flows) {
if (flows.length > 0) {
redNodes.setConfig(flows);
@@ -93,6 +100,8 @@ function start() {
util.log("[red] Error loading flows : "+err);
});
});
return defer.promise;
}
function stop() {