Disable palette editor if npm not found

This commit is contained in:
Nick O'Leary
2016-10-12 22:30:32 +01:00
parent a76674032d
commit 49f72881f4
11 changed files with 108 additions and 30 deletions

View File

@@ -98,7 +98,6 @@ function start() {
}
log.info(log._("runtime.version",{component:"Node.js ",version:process.version}));
log.info(os.type()+" "+os.release()+" "+os.arch()+" "+os.endianness());
log.info(log._("server.loading"));
return redNodes.load().then(function() {
var i;

View File

@@ -9,6 +9,10 @@
"server": {
"loading": "Loading palette nodes",
"palette-editor": {
"disabled": "Palette editor disabled : user settings",
"npm-not-found": "Palette editor disabled : npm command not found"
},
"errors": "Failed to register __count__ node type",
"errors_plural": "Failed to register __count__ node types",
"errors-help": "Run with -v for details",

View File

@@ -110,6 +110,7 @@ module.exports = {
getNode: flows.get,
eachNode: flows.eachNode,
paletteEditorEnabled: registry.paletteEditorEnabled,
installModule: registry.installModule,
uninstallModule: uninstallModule,

View File

@@ -34,7 +34,7 @@ function init(runtime) {
function load() {
registry.load();
return loader.load();
return installer.checkPrereq().then(loader.load);
}
function addModule(module) {
@@ -80,5 +80,7 @@ module.exports = {
installModule: installer.installModule,
uninstallModule: installer.uninstallModule,
cleanModuleList: registry.cleanModuleList
cleanModuleList: registry.cleanModuleList,
paletteEditorEnabled: installer.paletteEditorEnabled
};

View File

@@ -25,6 +25,8 @@ var log = require("../../log");
var events = require("../../events");
var child_process = require('child_process');
var npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
var paletteEditorEnabled = false;
var settings;
@@ -86,7 +88,7 @@ function installModule(module) {
log.info(log._("server.install.installing",{name: module}));
var installDir = settings.userDir || process.env.NODE_RED_HOME || ".";
var child = child_process.execFile('npm',['install','--production',installName],
var child = child_process.execFile(npmCommand,['install','--production',installName],
{
cwd: installDir
},
@@ -160,7 +162,7 @@ function uninstallModule(module) {
var list = registry.removeModule(module);
log.info(log._("server.install.uninstalling",{name:module}));
var child = child_process.execFile('npm',['remove',module],
var child = child_process.execFile(npmCommand,['remove',module],
{
cwd: installDir
},
@@ -183,9 +185,35 @@ function uninstallModule(module) {
});
}
function checkPrereq() {
if (settings.hasOwnProperty('editorTheme') &&
settings.editorTheme.hasOwnProperty('palette') &&
settings.editorTheme.palette.hasOwnProperty('editable') &&
settings.editorTheme.palette.editable === false
) {
log.info(log._("server.palette-editor.disabled"));
paletteEditorEnabled = false;
return when.resolve();
} else {
return when.promise(function(resolve) {
child_process.execFile(npmCommand,['-v'],function(err) {
if (err) {
log.info(log._("server.palette-editor.npm-not-found"));
paletteEditorEnabled = false;
} else {
paletteEditorEnabled = true;
}
resolve();
});
})
}
}
module.exports = {
init: init,
checkPrereq: checkPrereq,
installModule: installModule,
uninstallModule: uninstallModule
uninstallModule: uninstallModule,
paletteEditorEnabled: function() {
return paletteEditorEnabled
}
}

View File

@@ -36,6 +36,7 @@ function load(defaultNodesDir,disableNodePathScan) {
// We should expose that as an option at some point, although the
// performance gains are minimal.
//return loadNodeFiles(registry.getModuleList());
runtime.log.info(runtime.log._("server.loading"));
var nodeFiles = localfilesystem.getNodeFiles(defaultNodesDir,disableNodePathScan);
return loadNodeFiles(nodeFiles);