mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #509 from anna2130/nr-cli-enhancements
nr-cli enhancements
This commit is contained in:
commit
8c5fab61e6
@ -68,9 +68,11 @@ var registry = (function() {
|
||||
for (var module in moduleConfigs) {
|
||||
if (moduleConfigs.hasOwnProperty(module)) {
|
||||
if (!moduleList[module]) {
|
||||
moduleList[module] = {};
|
||||
moduleList[module].name = module;
|
||||
moduleList[module].nodes = {};
|
||||
moduleList[module] = {
|
||||
name: module,
|
||||
version: moduleConfigs[module].version,
|
||||
nodes: {}
|
||||
};
|
||||
}
|
||||
var nodes = moduleConfigs[module].nodes;
|
||||
for(var node in nodes) {
|
||||
@ -87,7 +89,7 @@ var registry = (function() {
|
||||
}
|
||||
}
|
||||
if (settings.available()) {
|
||||
return settings.set("modules",moduleList);
|
||||
return settings.set("nodes",moduleList);
|
||||
} else {
|
||||
return when.reject("Settings unavailable");
|
||||
}
|
||||
@ -114,21 +116,21 @@ var registry = (function() {
|
||||
nodeSetName = nodeConfig.name.split(":")[1];
|
||||
} else {
|
||||
moduleName = "node-red";
|
||||
nodeSetName = nodeConfig.name.replace(/^\d+-/,"").replace(/\.js$/,"")
|
||||
nodeSetName = nodeConfig.name.replace(/^\d+-/,"").replace(/\.js$/,"");
|
||||
}
|
||||
|
||||
if (!newConfigs[moduleName]) {
|
||||
newConfigs[moduleName] = {
|
||||
name: moduleName,
|
||||
nodes:{}
|
||||
}
|
||||
};
|
||||
}
|
||||
newConfigs[moduleName].nodes[nodeSetName] = {
|
||||
name: nodeSetName,
|
||||
types: nodeConfig.types,
|
||||
enabled: nodeConfig.enabled,
|
||||
module: moduleName
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
settings.set("nodes",newConfigs);
|
||||
@ -532,7 +534,7 @@ function scanTreeForNodesModules(moduleName) {
|
||||
* @param moduleDir the root directory of the package
|
||||
* @param pkg the module's package.json object
|
||||
*/
|
||||
function loadNodesFromModule(moduleDir,pkg,version) {
|
||||
function loadNodesFromModule(moduleDir,pkg) {
|
||||
var nodes = pkg['node-red'].nodes||{};
|
||||
var results = [];
|
||||
var iconDirs = [];
|
||||
@ -540,7 +542,7 @@ function loadNodesFromModule(moduleDir,pkg,version) {
|
||||
if (nodes.hasOwnProperty(n)) {
|
||||
var file = path.join(moduleDir,nodes[n]);
|
||||
try {
|
||||
results.push(loadNodeConfig(file,pkg.name,n,version));
|
||||
results.push(loadNodeConfig(file,pkg.name,n,pkg.version));
|
||||
} catch(err) {
|
||||
}
|
||||
var iconDir = path.join(moduleDir,path.dirname(nodes[n]),"icons");
|
||||
@ -625,6 +627,7 @@ function loadNodeConfig(file,module,name,version) {
|
||||
node.err = err.toString();
|
||||
}
|
||||
}
|
||||
|
||||
registry.addNodeSet(id,node,version);
|
||||
return node;
|
||||
}
|
||||
@ -657,7 +660,7 @@ function load(defaultNodesDir,disableNodePathScan) {
|
||||
var nodes = [];
|
||||
nodeFiles.forEach(function(file) {
|
||||
try {
|
||||
nodes.push(loadNodeConfig(file,"node-red",path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,"")));
|
||||
nodes.push(loadNodeConfig(file,"node-red",path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,""),settings.version));
|
||||
} catch(err) {
|
||||
//
|
||||
}
|
||||
@ -763,14 +766,14 @@ function addNode(file) {
|
||||
}
|
||||
var nodes = [];
|
||||
try {
|
||||
nodes.push(loadNodeConfig(file,"node-red",path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,"")));
|
||||
nodes.push(loadNodeConfig(file,"node-red",path.basename(file).replace(/^\d+-/,"").replace(/\.js$/,""),settings.version));
|
||||
} catch(err) {
|
||||
return when.reject(err);
|
||||
}
|
||||
return loadNodeList(nodes);
|
||||
}
|
||||
|
||||
function addModule(module,version) {
|
||||
function addModule(module) {
|
||||
if (!settings.available()) {
|
||||
throw new Error("Settings unavailable");
|
||||
}
|
||||
@ -785,7 +788,7 @@ function addModule(module,version) {
|
||||
return when.reject(err);
|
||||
}
|
||||
moduleFiles.forEach(function(moduleFile) {
|
||||
nodes = nodes.concat(loadNodesFromModule(moduleFile.dir,moduleFile.package,version));
|
||||
nodes = nodes.concat(loadNodesFromModule(moduleFile.dir,moduleFile.package));
|
||||
});
|
||||
return loadNodeList(nodes);
|
||||
}
|
||||
|
@ -162,11 +162,8 @@ function installModule(module) {
|
||||
reject(new Error("Install failed"));
|
||||
}
|
||||
} else {
|
||||
var grandchild = child_process.exec('npm view '+module+' version', function(err, stdin, stdout) {
|
||||
var version = stdin.replace(/\s/g, "");
|
||||
util.log("[red] Installed module: "+module+":"+version);
|
||||
resolve(redNodes.addModule(module,version).then(reportAddedModules));
|
||||
});
|
||||
util.log("[red] Installed module: "+module);
|
||||
resolve(redNodes.addModule(module).then(reportAddedModules));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -301,7 +301,7 @@ describe('NodeRegistry', function() {
|
||||
moduleList.should.be.Array.and.have.length(1);
|
||||
|
||||
settingsSave.callCount.should.equal(1);
|
||||
settingsSave.firstCall.args[0].should.be.equal("modules");
|
||||
settingsSave.firstCall.args[0].should.be.equal("nodes");
|
||||
var savedList = settingsSave.firstCall.args[1];
|
||||
|
||||
savedList[moduleList[0].name].name.should.equal(moduleList[0].name);
|
||||
|
Loading…
Reference in New Issue
Block a user