1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Get version from pkg

This commit is contained in:
Anna Thomas 2014-12-08 10:11:59 +00:00
parent 81e08e06e4
commit e7ccff5a4b
2 changed files with 9 additions and 19 deletions

View File

@ -68,16 +68,9 @@ 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]) {
var version;
if (module === "node-red") {
version = settings.version;
} else {
version = moduleConfigs[module].version;
}
moduleList[module] = { moduleList[module] = {
name: module, name: module,
version: version, version: moduleConfigs[module].version,
nodes: {} nodes: {}
}; };
} }
@ -541,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 = [];
@ -549,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");
@ -667,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) {
// //
} }
@ -773,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");
} }
@ -795,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);
} }

View File

@ -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));
});
} }
}); });
}); });