mirror of
https://github.com/Unitech/pm2.git
synced 2026-02-01 16:57:09 +00:00
refactor: delete all "if" condition when installing new module, create an object with all modules and a generic installation process
This commit is contained in:
parent
0d2b7172a0
commit
1b92a9c400
@ -23,10 +23,15 @@ var MODULE_CONF_PREFIX = 'module-db-v2';
|
||||
|
||||
var KNOWN_MODULES = {
|
||||
'deep-monitoring': {
|
||||
'dependencies': ['v8-profiler-node8', 'gc-stats', 'event-loop-inspector']
|
||||
dependencies: [{name: 'v8-profiler-node8'}, {name: 'gc-stats'}, {name: 'event-loop-inspector'}]
|
||||
},
|
||||
'gc-stats': {name: 'gc-stats'},
|
||||
'event-loop-inspector': {name: 'event-loop-inspector'}
|
||||
'event-loop-inspector': {name: 'event-loop-inspector'},
|
||||
'v8-profiler': {name: 'v8-profiler-node8'},
|
||||
'profiler': {name: 'v8-profiler-node8'},
|
||||
'typescript': {dependencies: [{name: 'typescript'}, {name: 'ts-node@latest'}]},
|
||||
'coffee-script': {name: 'coffee-script', message: 'Coffeescript v1 support'},
|
||||
'coffeescript': {name: 'coffeescript', message: 'Coffeescript v2 support'}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -62,59 +67,24 @@ Modularizer.install = function (CLI, moduleName, opts, cb) {
|
||||
|
||||
async.parallel(functionList, function (err, results) {
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
var display = results[i].module.message || results[i].module.name;
|
||||
if (results[i].err) {
|
||||
err = results[i].err;
|
||||
Common.printError(cst.PREFIX_MSG_MOD_ERR + chalk.bold.green(results[i].module + ' installation has FAILED (checkout previous logs)'));
|
||||
Common.printError(cst.PREFIX_MSG_MOD_ERR + chalk.bold.green(display + ' installation has FAILED (checkout previous logs)'));
|
||||
} else {
|
||||
Common.printOut(cst.PREFIX_MSG + chalk.bold.green(results[i].module + ' ENABLED'));
|
||||
Common.printOut(cst.PREFIX_MSG + chalk.bold.green(display + ' ENABLED'));
|
||||
}
|
||||
}
|
||||
|
||||
cb(err);
|
||||
});
|
||||
} else {
|
||||
installModuleByName(currentModule.name, cb);
|
||||
installModuleByName(currentModule, cb);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (moduleName === 'v8-profiler' || moduleName === 'profiler') {
|
||||
installModuleByName('v8-profiler-node8', cb);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (moduleName.indexOf('typescript') > -1) {
|
||||
// Special dependency install
|
||||
return installLangModule(moduleName, function (e) {
|
||||
installLangModule('ts-node@latest', function (e) {
|
||||
Common.printOut(cst.PREFIX_MSG + chalk.bold.green('Typescript support enabled'));
|
||||
return cb(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (moduleName === 'livescript') {
|
||||
return installLangModule('livescript', function (e) {
|
||||
Common.printOut(cst.PREFIX_MSG + chalk.bold.green('Livescript support enabled'));
|
||||
return cb(e);
|
||||
});
|
||||
}
|
||||
|
||||
if (moduleName.indexOf('coffee-script') > -1) {
|
||||
return installLangModule(moduleName, function (e) {
|
||||
Common.printOut(cst.PREFIX_MSG + chalk.bold.green('Coffeescript v1 support enabled'));
|
||||
return cb(e);
|
||||
});
|
||||
}
|
||||
|
||||
if (moduleName.indexOf('coffeescript') > -1) {
|
||||
return installLangModule(moduleName, function (e) {
|
||||
Common.printOut(cst.PREFIX_MSG + chalk.bold.green('Coffeescript v2 support enabled'));
|
||||
return cb(e);
|
||||
});
|
||||
}
|
||||
|
||||
moduleExist(CLI, canonicModuleName, function (exists) {
|
||||
if (exists) {
|
||||
// Update
|
||||
@ -577,8 +547,8 @@ Modularizer.generateSample = function(app_name, cb) {
|
||||
});
|
||||
};
|
||||
|
||||
function installModuleByName (moduleName, cb, verbose) {
|
||||
if (!moduleName || moduleName.length === 0) {
|
||||
function installModuleByName (module, cb, verbose) {
|
||||
if (!module || !module.name || module.name.length === 0) {
|
||||
return cb(new Error('No module name !'));
|
||||
}
|
||||
|
||||
@ -586,13 +556,14 @@ function installModuleByName (moduleName, cb, verbose) {
|
||||
verbose = true;
|
||||
}
|
||||
|
||||
installLangModule(moduleName, function (err) {
|
||||
installLangModule(module.name, function (err) {
|
||||
var display = module.message || module.name;
|
||||
if (err) {
|
||||
if (verbose) { Common.printError(cst.PREFIX_MSG_MOD_ERR + chalk.bold.green(moduleName + ' installation has FAILED (checkout previous logs)')); }
|
||||
if (verbose) { Common.printError(cst.PREFIX_MSG_MOD_ERR + chalk.bold.green(display + ' installation has FAILED (checkout previous logs)')); }
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
if (verbose) { Common.printOut(cst.PREFIX_MSG + chalk.bold.green(moduleName + ' ENABLED')); }
|
||||
if (verbose) { Common.printOut(cst.PREFIX_MSG + chalk.bold.green(display + ' ENABLED')); }
|
||||
return cb();
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user