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