2015-11-09 12:29:48 +01:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2015-11-09 12:29:48 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2020-12-27 13:49:17 +01:00
|
|
|
const path = require("path");
|
|
|
|
const os = require("os");
|
|
|
|
const fs = require("fs-extra");
|
|
|
|
const tar = require("tar");
|
2015-11-09 12:29:48 +01:00
|
|
|
|
2020-12-27 13:49:17 +01:00
|
|
|
const registry = require("./registry");
|
|
|
|
const registryUtil = require("./util");
|
|
|
|
const library = require("./library");
|
2020-12-02 10:25:10 +01:00
|
|
|
const {exec,log,events} = require("@node-red/util");
|
2020-12-27 13:49:17 +01:00
|
|
|
const child_process = require('child_process');
|
|
|
|
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
|
|
let installerEnabled = false;
|
2015-11-09 12:29:48 +01:00
|
|
|
|
2020-12-27 13:49:17 +01:00
|
|
|
let settings;
|
2020-08-13 16:54:54 +02:00
|
|
|
const moduleRe = /^(@[^/@]+?[/])?[^/@]+?$/;
|
|
|
|
const slashRe = process.platform === "win32" ? /\\|[/]/ : /[/]/;
|
|
|
|
const pkgurlRe = /^(https?|git(|\+https?|\+ssh|\+file)):\/\//;
|
2020-11-25 22:04:24 +01:00
|
|
|
const localtgzRe = /^([a-zA-Z]:|\/).+tgz$/;
|
2015-11-09 17:52:14 +01:00
|
|
|
|
2020-12-27 13:49:17 +01:00
|
|
|
// Default allow/deny lists
|
|
|
|
let installAllowList = ['*'];
|
|
|
|
let installDenyList = [];
|
2021-01-06 21:03:22 +01:00
|
|
|
let installAllAllowed = true;
|
|
|
|
let installVersionRestricted = false;
|
2020-12-27 13:49:17 +01:00
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
function init(_settings) {
|
|
|
|
settings = _settings;
|
2020-12-27 13:49:17 +01:00
|
|
|
// TODO: This is duplicated in localfilesystem.js
|
|
|
|
// Should it *all* be managed by util?
|
|
|
|
if (settings.externalModules && settings.externalModules.palette) {
|
|
|
|
if (settings.externalModules.palette.allowList || settings.externalModules.palette.denyList) {
|
|
|
|
installAllowList = settings.externalModules.palette.allowList;
|
|
|
|
installDenyList = settings.externalModules.palette.denyList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
installAllowList = registryUtil.parseModuleList(installAllowList);
|
|
|
|
installDenyList = registryUtil.parseModuleList(installDenyList);
|
2021-01-06 21:03:22 +01:00
|
|
|
installAllAllowed = installDenyList.length === 0;
|
|
|
|
if (!installAllAllowed) {
|
|
|
|
installAllowList.forEach(function(rule) {
|
|
|
|
installVersionRestricted = installVersionRestricted || (!!rule.version);
|
|
|
|
})
|
|
|
|
if (!installVersionRestricted) {
|
|
|
|
installDenyList.forEach(function(rule) {
|
|
|
|
installVersionRestricted = installVersionRestricted || (!!rule.version);
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2015-11-09 12:29:48 +01:00
|
|
|
}
|
|
|
|
|
2018-07-30 11:08:39 +02:00
|
|
|
var activePromise = Promise.resolve();
|
|
|
|
|
2015-11-09 17:52:14 +01:00
|
|
|
function checkModulePath(folder) {
|
|
|
|
var moduleName;
|
2020-08-13 16:54:54 +02:00
|
|
|
var moduleVersion;
|
2015-11-09 17:52:14 +01:00
|
|
|
var err;
|
|
|
|
var fullPath = path.resolve(folder);
|
|
|
|
var packageFile = path.join(fullPath,'package.json');
|
2015-11-16 12:31:55 +01:00
|
|
|
try {
|
2015-11-09 17:52:14 +01:00
|
|
|
var pkg = require(packageFile);
|
|
|
|
moduleName = pkg.name;
|
2020-08-13 16:54:54 +02:00
|
|
|
moduleVersion = pkg.version;
|
2015-11-09 17:52:14 +01:00
|
|
|
if (!pkg['node-red']) {
|
|
|
|
// TODO: nls
|
|
|
|
err = new Error("Invalid Node-RED module");
|
|
|
|
err.code = 'invalid_module';
|
|
|
|
throw err;
|
|
|
|
}
|
2015-11-16 12:31:55 +01:00
|
|
|
} catch(err2) {
|
2015-11-09 17:52:14 +01:00
|
|
|
err = new Error("Module not found");
|
|
|
|
err.code = 404;
|
|
|
|
throw err;
|
|
|
|
}
|
2020-08-13 16:54:54 +02:00
|
|
|
return {
|
|
|
|
name: moduleName,
|
|
|
|
version: moduleVersion
|
|
|
|
};
|
2015-11-09 17:52:14 +01:00
|
|
|
}
|
2021-01-06 21:03:22 +01:00
|
|
|
async function installModule(module,version,url) {
|
2020-08-13 16:54:54 +02:00
|
|
|
if (Buffer.isBuffer(module)) {
|
|
|
|
return installTarball(module)
|
|
|
|
}
|
2020-06-03 11:45:28 +02:00
|
|
|
module = module || "";
|
2021-01-06 21:03:22 +01:00
|
|
|
activePromise = activePromise.then(async function() {
|
2018-07-30 11:08:39 +02:00
|
|
|
//TODO: ensure module is 'safe'
|
2021-01-06 21:03:22 +01:00
|
|
|
var installName = module;
|
|
|
|
let isRegistryPackage = true;
|
|
|
|
var isUpgrade = false;
|
2020-11-25 20:07:30 +01:00
|
|
|
var isExisting = false;
|
2021-01-06 21:03:22 +01:00
|
|
|
if (url) {
|
|
|
|
if (pkgurlRe.test(url) || localtgzRe.test(url)) {
|
|
|
|
// Git remote url or Tarball url - check the valid package url
|
|
|
|
installName = url;
|
|
|
|
isRegistryPackage = false;
|
|
|
|
} else {
|
|
|
|
log.warn(log._("server.install.install-failed-url",{name:module,url:url}));
|
|
|
|
const e = new Error("Invalid url");
|
|
|
|
e.code = "invalid_module_url";
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
} else if (moduleRe.test(module)) {
|
|
|
|
// Simple module name - assume it can be npm installed
|
|
|
|
if (version) {
|
|
|
|
installName += "@"+version;
|
|
|
|
}
|
|
|
|
} else if (slashRe.test(module)) {
|
|
|
|
// A path - check if there's a valid package.json
|
|
|
|
installName = module;
|
|
|
|
let info = checkModulePath(module);
|
|
|
|
module = info.name;
|
|
|
|
isRegistryPackage = false;
|
|
|
|
} else {
|
|
|
|
log.warn(log._("server.install.install-failed-name",{name:module}));
|
|
|
|
const e = new Error("Invalid module name");
|
|
|
|
e.code = "invalid_module_name";
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
if (!installAllAllowed) {
|
|
|
|
let installVersion = version;
|
|
|
|
if (installVersionRestricted && isRegistryPackage) {
|
|
|
|
installVersion = await getModuleVersionFromNPM(module, version);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!registryUtil.checkModuleAllowed(module,installVersion,installAllowList,installDenyList)) {
|
|
|
|
const e = new Error("Install not allowed");
|
|
|
|
e.code = "install_not_allowed";
|
|
|
|
throw e;
|
2015-11-09 17:52:14 +01:00
|
|
|
}
|
2021-01-06 21:03:22 +01:00
|
|
|
}
|
2020-11-25 20:07:30 +01:00
|
|
|
|
|
|
|
var info = registry.getModuleInfo(module);
|
|
|
|
if (info) {
|
|
|
|
if (!info.user) {
|
|
|
|
log.debug(`Installing existing module: ${module}`)
|
|
|
|
isExisting = true;
|
|
|
|
} else if (!version || info.version === version) {
|
|
|
|
var err = new Error("Module already loaded");
|
|
|
|
err.code = "module_already_loaded";
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
isUpgrade = true;
|
|
|
|
} else {
|
|
|
|
isUpgrade = false;
|
|
|
|
}
|
2021-01-06 21:03:22 +01:00
|
|
|
|
|
|
|
if (!isUpgrade) {
|
|
|
|
log.info(log._("server.install.installing",{name: module,version: version||"latest"}));
|
|
|
|
} else {
|
|
|
|
log.info(log._("server.install.upgrading",{name: module,version: version||"latest"}));
|
|
|
|
}
|
|
|
|
|
|
|
|
var installDir = settings.userDir || process.env.NODE_RED_HOME || ".";
|
|
|
|
var args = ['install','--no-audit','--no-update-notifier','--no-fund','--save','--save-prefix=~','--production',installName];
|
|
|
|
log.trace(npmCommand + JSON.stringify(args));
|
|
|
|
return exec.run(npmCommand,args,{
|
|
|
|
cwd: installDir
|
|
|
|
}, true).then(result => {
|
2020-11-25 20:07:30 +01:00
|
|
|
if (isExisting) {
|
|
|
|
// This is a module we already have installed as a non-user module.
|
|
|
|
// That means it was discovered when loading, but was not listed
|
|
|
|
// in package.json and has been hidden from the editor.
|
|
|
|
// The user has requested to install this module. Having run
|
|
|
|
// the npm install above, it will now be listed in package.json.
|
|
|
|
// Update the registry to mark it as a user module so it will
|
|
|
|
// be available to the editor.
|
|
|
|
log.info(log._("server.install.installed",{name:module}));
|
|
|
|
return require("./registry").setUserInstalled(module,true).then(reportAddedModules);
|
|
|
|
} else if (!isUpgrade) {
|
2021-01-06 21:03:22 +01:00
|
|
|
log.info(log._("server.install.installed",{name:module}));
|
|
|
|
return require("./index").addModule(module).then(reportAddedModules);
|
2018-01-24 23:40:42 +01:00
|
|
|
} else {
|
2021-01-06 21:03:22 +01:00
|
|
|
log.info(log._("server.install.upgraded",{name:module, version:version}));
|
|
|
|
events.emit("runtime-event",{id:"restart-required",payload:{type:"warning",text:"notification.warnings.restartRequired"},retain:true});
|
|
|
|
return require("./registry").setModulePendingUpdated(module,version);
|
2018-07-30 11:08:39 +02:00
|
|
|
}
|
2021-01-06 21:03:22 +01:00
|
|
|
}).catch(result => {
|
|
|
|
var output = result.stderr;
|
|
|
|
var e;
|
|
|
|
var lookFor404 = new RegExp(" 404 .*"+module,"m");
|
|
|
|
var lookForVersionNotFound = new RegExp("version not found: "+module+"@"+version,"m");
|
|
|
|
if (lookFor404.test(output)) {
|
|
|
|
log.warn(log._("server.install.install-failed-not-found",{name:module}));
|
|
|
|
e = new Error("Module not found");
|
|
|
|
e.code = 404;
|
|
|
|
throw e;
|
|
|
|
} else if (isUpgrade && lookForVersionNotFound.test(output)) {
|
|
|
|
log.warn(log._("server.install.upgrade-failed-not-found",{name:module}));
|
|
|
|
e = new Error("Module not found");
|
|
|
|
e.code = 404;
|
|
|
|
throw e;
|
|
|
|
} else {
|
|
|
|
log.warn(log._("server.install.install-failed-long",{name:module}));
|
|
|
|
log.warn("------------------------------------------");
|
|
|
|
log.warn(output);
|
|
|
|
log.warn("------------------------------------------");
|
|
|
|
throw new Error(log._("server.install.install-failed"));
|
|
|
|
}
|
|
|
|
})
|
2018-07-30 11:08:39 +02:00
|
|
|
}).catch(err => {
|
|
|
|
// In case of error, reset activePromise to be resolvable
|
|
|
|
activePromise = Promise.resolve();
|
|
|
|
throw err;
|
2015-11-09 12:29:48 +01:00
|
|
|
});
|
2018-07-30 11:08:39 +02:00
|
|
|
return activePromise;
|
2015-11-09 12:29:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function reportAddedModules(info) {
|
|
|
|
if (info.nodes.length > 0) {
|
|
|
|
log.info(log._("server.added-types"));
|
|
|
|
for (var i=0;i<info.nodes.length;i++) {
|
|
|
|
for (var j=0;j<info.nodes[i].types.length;j++) {
|
|
|
|
log.info(" - "+
|
|
|
|
(info.nodes[i].module?info.nodes[i].module+":":"")+
|
|
|
|
info.nodes[i].types[j]+
|
|
|
|
(info.nodes[i].err?" : "+info.nodes[i].err:"")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
function reportRemovedModules(removedNodes) {
|
|
|
|
//comms.publish("node/removed",removedNodes,false);
|
|
|
|
log.info(log._("server.removed-types"));
|
|
|
|
for (var j=0;j<removedNodes.length;j++) {
|
|
|
|
for (var i=0;i<removedNodes[j].types.length;i++) {
|
|
|
|
log.info(" - "+(removedNodes[j].module?removedNodes[j].module+":":"")+removedNodes[j].types[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return removedNodes;
|
|
|
|
}
|
|
|
|
|
2020-08-13 16:54:54 +02:00
|
|
|
async function getExistingPackageVersion(moduleName) {
|
|
|
|
try {
|
|
|
|
const packageFilename = path.join(settings.userDir || process.env.NODE_RED_HOME || "." , "package.json");
|
|
|
|
const pkg = await fs.readJson(packageFilename);
|
|
|
|
if (pkg.dependencies) {
|
|
|
|
return pkg.dependencies[moduleName];
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-06 21:03:22 +01:00
|
|
|
async function getModuleVersionFromNPM(module, version) {
|
|
|
|
let installName = module;
|
|
|
|
if (version) {
|
|
|
|
installName += "@" + version;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
child_process.execFile(npmCommand,['info','--json',installName],function(err,stdout,stderr) {
|
|
|
|
try {
|
|
|
|
if (!stdout) {
|
|
|
|
log.warn(log._("server.install.install-failed-not-found",{name:module}));
|
|
|
|
e = new Error("Version not found");
|
|
|
|
e.code = 404;
|
|
|
|
reject(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const response = JSON.parse(stdout);
|
|
|
|
if (response.error) {
|
|
|
|
if (response.error.code === "E404") {
|
|
|
|
log.warn(log._("server.install.install-failed-not-found",{name:module}));
|
|
|
|
e = new Error("Module not found");
|
|
|
|
e.code = 404;
|
|
|
|
reject(e);
|
|
|
|
} else {
|
|
|
|
log.warn(log._("server.install.install-failed-long",{name:module}));
|
|
|
|
log.warn("------------------------------------------");
|
|
|
|
log.warn(response.error.summary);
|
|
|
|
log.warn("------------------------------------------");
|
|
|
|
reject(new Error(log._("server.install.install-failed")));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
resolve(response.version);
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
log.warn(log._("server.install.install-failed-long",{name:module}));
|
|
|
|
log.warn("------------------------------------------");
|
|
|
|
if (stdout) {
|
|
|
|
log.warn(stdout);
|
|
|
|
}
|
|
|
|
if (stderr) {
|
|
|
|
log.warn(stderr);
|
|
|
|
}
|
|
|
|
log.warn(err);
|
|
|
|
log.warn("------------------------------------------");
|
|
|
|
reject(new Error(log._("server.install.install-failed")));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-13 16:54:54 +02:00
|
|
|
async function installTarball(tarball) {
|
2020-12-27 13:49:17 +01:00
|
|
|
if (settings.externalModules && settings.externalModules.palette && settings.externalModules.palette.allowUpload === false) {
|
|
|
|
throw new Error("Module upload disabled")
|
|
|
|
}
|
|
|
|
|
2020-08-13 16:54:54 +02:00
|
|
|
// Check this tarball contains a valid node-red module.
|
|
|
|
// Get its module name/version
|
|
|
|
const moduleInfo = await getTarballModuleInfo(tarball);
|
|
|
|
|
|
|
|
// Write the tarball to <userDir>/nodes/<filename.tgz>
|
|
|
|
// where the filename is the normalised form based on module name/version
|
|
|
|
let normalisedModuleName = moduleInfo.name[0] === '@'
|
|
|
|
? moduleInfo.name.substr(1).replace(/\//g, '-')
|
|
|
|
: moduleInfo.name
|
|
|
|
const tarballFile = `${normalisedModuleName}-${moduleInfo.version}.tgz`;
|
|
|
|
let tarballPath = path.resolve(path.join(settings.userDir || process.env.NODE_RED_HOME || ".", "nodes", tarballFile));
|
|
|
|
|
|
|
|
// (from fs-extra - move to writeFile with promise once Node 8 dropped)
|
|
|
|
await fs.outputFile(tarballPath, tarball);
|
|
|
|
|
|
|
|
// Next, need to check to see if this module is listed in `<userDir>/package.json`
|
|
|
|
let existingVersion = await getExistingPackageVersion(moduleInfo.name);
|
|
|
|
let existingFile = null;
|
|
|
|
let isUpdate = false;
|
|
|
|
|
|
|
|
// If this is a known module, need to check if there will be an old tarball
|
|
|
|
// to remove after the install of this one
|
|
|
|
if (existingVersion) {
|
|
|
|
// - Known module
|
|
|
|
if (/^file:nodes\//.test(existingVersion)) {
|
|
|
|
existingFile = existingVersion.substring(11);
|
|
|
|
isUpdate = true;
|
|
|
|
if (tarballFile === existingFile) {
|
|
|
|
// Edge case: a tar with the same name has bee uploaded.
|
|
|
|
// Carry on with the install, but don't remove the 'old' file
|
|
|
|
// as it will have been overwritten by the new one
|
|
|
|
existingFile = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Install the tgz
|
|
|
|
return installModule(moduleInfo.name, moduleInfo.version, tarballPath).then(function(info) {
|
|
|
|
if (existingFile) {
|
|
|
|
// Remove the old file
|
|
|
|
return fs.remove(path.resolve(path.join(settings.userDir || process.env.NODE_RED_HOME || ".", "nodes",existingFile))).then(() => info).catch(() => info)
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getTarballModuleInfo(tarball) {
|
|
|
|
const tarballDir = fs.mkdtempSync(path.join(os.tmpdir(),"nr-tarball-"));
|
|
|
|
const removeExtractedTar = function(done) {
|
|
|
|
fs.remove(tarballDir, err => {
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return new Promise((resolve,reject) => {
|
|
|
|
var writeStream = tar.x({
|
|
|
|
cwd: tarballDir
|
|
|
|
}).on('error', err => {
|
|
|
|
reject(err);
|
|
|
|
}).on('finish', () => {
|
|
|
|
try {
|
|
|
|
let moduleInfo = checkModulePath(path.join(tarballDir,"package"));
|
|
|
|
removeExtractedTar(err => {
|
|
|
|
resolve(moduleInfo);
|
|
|
|
})
|
|
|
|
} catch(err) {
|
|
|
|
removeExtractedTar(() => {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
writeStream.end(tarball);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-09 12:29:48 +01:00
|
|
|
function uninstallModule(module) {
|
2018-07-30 11:08:39 +02:00
|
|
|
activePromise = activePromise.then(() => {
|
|
|
|
return new Promise((resolve,reject) => {
|
|
|
|
if (/[\s;]/.test(module)) {
|
|
|
|
reject(new Error(log._("server.install.invalid")));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var installDir = settings.userDir || process.env.NODE_RED_HOME || ".";
|
|
|
|
var moduleDir = path.join(installDir,"node_modules",module);
|
2015-11-16 12:31:55 +01:00
|
|
|
|
2018-07-30 11:08:39 +02:00
|
|
|
try {
|
|
|
|
fs.statSync(moduleDir);
|
|
|
|
} catch(err) {
|
|
|
|
return reject(new Error(log._("server.install.uninstall-failed",{name:module})));
|
|
|
|
}
|
2015-11-09 12:29:48 +01:00
|
|
|
|
2018-07-30 11:08:39 +02:00
|
|
|
var list = registry.removeModule(module);
|
|
|
|
log.info(log._("server.install.uninstalling",{name:module}));
|
2018-01-22 14:46:11 +01:00
|
|
|
|
2020-05-31 12:21:53 +02:00
|
|
|
var args = ['remove','--no-audit','--no-update-notifier','--no-fund','--save',module];
|
2018-07-30 11:08:39 +02:00
|
|
|
log.trace(npmCommand + JSON.stringify(args));
|
2018-01-22 14:46:11 +01:00
|
|
|
|
2018-10-19 00:49:47 +02:00
|
|
|
exec.run(npmCommand,args,{
|
|
|
|
cwd: installDir,
|
|
|
|
},true).then(result => {
|
|
|
|
log.info(log._("server.install.uninstalled",{name:module}));
|
|
|
|
reportRemovedModules(list);
|
|
|
|
library.removeExamplesDir(module);
|
|
|
|
resolve(list);
|
|
|
|
}).catch(result => {
|
|
|
|
var output = result.stderr;
|
|
|
|
log.warn(log._("server.install.uninstall-failed-long",{name:module}));
|
|
|
|
log.warn("------------------------------------------");
|
|
|
|
log.warn(output.toString());
|
|
|
|
log.warn("------------------------------------------");
|
|
|
|
reject(new Error(log._("server.install.uninstall-failed",{name:module})));
|
|
|
|
});
|
2018-07-30 11:08:39 +02:00
|
|
|
});
|
|
|
|
}).catch(err => {
|
|
|
|
// In case of error, reset activePromise to be resolvable
|
|
|
|
activePromise = Promise.resolve();
|
|
|
|
throw err;
|
2015-11-09 12:29:48 +01:00
|
|
|
});
|
2018-07-30 11:08:39 +02:00
|
|
|
return activePromise;
|
2015-11-09 12:29:48 +01:00
|
|
|
}
|
|
|
|
|
2020-12-24 00:29:07 +01:00
|
|
|
async function checkPrereq() {
|
2021-01-06 18:36:59 +01:00
|
|
|
if (settings.editorTheme && settings.editorTheme.palette) {
|
|
|
|
if (settings.editorTheme.palette.hasOwnProperty("editable")) {
|
|
|
|
log.warn(log._("server.deprecatedOption",{old:"editorTheme.palette.editable", new:"externalModules.palette.allowInstall"}));
|
|
|
|
}
|
|
|
|
if (settings.editorTheme.palette.hasOwnProperty("upload")) {
|
|
|
|
log.warn(log._("server.deprecatedOption",{old:"editorTheme.palette.upload", new:"externalModules.palette.allowUpload"}));
|
|
|
|
}
|
|
|
|
}
|
2020-12-24 00:29:07 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (settings.editorTheme.palette.editable === false) {
|
|
|
|
log.info(log._("server.palette-editor.disabled"));
|
|
|
|
installerEnabled = false;
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} catch(err) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (settings.externalModules.palette.allowInstall === false) {
|
|
|
|
log.info(log._("server.palette-editor.disabled"));
|
|
|
|
installerEnabled = false;
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} catch(err) {}
|
|
|
|
|
2016-10-12 23:30:32 +02:00
|
|
|
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"));
|
2020-12-02 14:14:39 +01:00
|
|
|
installerEnabled = false;
|
2016-10-12 23:30:32 +02:00
|
|
|
} else {
|
2018-07-30 11:08:39 +02:00
|
|
|
return new Promise(resolve => {
|
2018-11-14 19:29:27 +01:00
|
|
|
child_process.execFile(npmCommand,['-v'],function(err,stdout) {
|
2016-10-12 23:30:32 +02:00
|
|
|
if (err) {
|
|
|
|
log.info(log._("server.palette-editor.npm-not-found"));
|
2020-12-02 14:14:39 +01:00
|
|
|
installerEnabled = false;
|
2016-10-12 23:30:32 +02:00
|
|
|
} else {
|
2018-11-14 19:29:27 +01:00
|
|
|
if (parseInt(stdout.split(".")[0]) < 3) {
|
|
|
|
log.info(log._("server.palette-editor.npm-too-old"));
|
2020-12-02 14:14:39 +01:00
|
|
|
installerEnabled = false;
|
2018-11-14 19:29:27 +01:00
|
|
|
} else {
|
2020-12-02 14:14:39 +01:00
|
|
|
installerEnabled = true;
|
2018-11-14 19:29:27 +01:00
|
|
|
}
|
2016-10-12 23:30:32 +02:00
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 16:54:54 +02:00
|
|
|
|
2015-11-09 12:29:48 +01:00
|
|
|
module.exports = {
|
|
|
|
init: init,
|
2016-10-12 23:30:32 +02:00
|
|
|
checkPrereq: checkPrereq,
|
2015-11-09 12:29:48 +01:00
|
|
|
installModule: installModule,
|
2016-10-12 23:30:32 +02:00
|
|
|
uninstallModule: uninstallModule,
|
2020-12-02 14:14:39 +01:00
|
|
|
installerEnabled: function() {
|
|
|
|
return installerEnabled
|
2016-10-12 23:30:32 +02:00
|
|
|
}
|
2015-11-09 12:29:48 +01:00
|
|
|
}
|