Skip to content

Commit

Permalink
added post_install to ecosystem.json
Browse files Browse the repository at this point in the history
  • Loading branch information
imarakho committed Jul 25, 2018
1 parent 992a045 commit 991ef5b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
33 changes: 23 additions & 10 deletions lib/API/Modules/Modularizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var cst = require('../../../constants.js');
var Common = require('../../Common');
var Utility = require('../../Utility.js');
var ModularizerV1 = require('./Modularizerv1.js');


var Modularizer = module.exports = {};

var MODULE_CONF_PREFIX = 'module-db-v2';
Expand Down Expand Up @@ -59,19 +61,17 @@ Modularizer.install = function (CLI, moduleName, opts, cb) {
Common.printError(cst.PREFIX_MSG_ERR + 'File ' + file + ' not found');
return cb(Common.retErr(e));
}

try {
var config = Common.parseConfig(data, file);
} catch (e) {
Common.printError(cst.PREFIX_MSG_ERR + 'File ' + file + ' malformated');
console.error(e);
return cb(Common.retErr(e));
}

Modularizer.installMultipleModules(config.dependencies, cb);
Modularizer.installMultipleModules(config.dependencies, cb, config.post_install);
return;
}

Common.printOut(cst.PREFIX_MSG_MOD + 'Installing module ' + moduleName);

var canonicModuleName = Utility.getCanonicModuleName(moduleName);
Expand All @@ -84,7 +84,6 @@ Modularizer.install = function (CLI, moduleName, opts, cb) {
} else {
installModuleByName(currentModule, cb);
}

return false;
}

Expand All @@ -109,7 +108,7 @@ Modularizer.install = function (CLI, moduleName, opts, cb) {
});
};

Modularizer.installMultipleModules = function (modules, cb) {
Modularizer.installMultipleModules = function (modules, cb, post_install) {
var functionList = [];
for (var i = 0; i < modules.length; i++) {
functionList.push((function (index) {
Expand All @@ -118,9 +117,22 @@ Modularizer.installMultipleModules = function (modules, cb) {
if (typeof modules[index] === 'string') {
module = {name: modules[index]};
}

installModuleByName(module, function (err) {
callback(null, {module: module, err: err});
installModuleByName(module, function ($post_install, err, $index, $modules) {
try
{
var install_instance = spawn(post_install[modules[index]], {
stdio : 'inherit',
env: process.env,
shell : true,
cwd : process.cwd()
});
Common.printOut(cst.PREFIX_MSG_MOD + 'Running configuraton script.');
}
catch(e)
{
Common.printOut(cst.PREFIX_MSG_MOD + 'No configuraton script found.');
}
callback(null, { module: module, err: err });
}, false);
};
})(i));
Expand Down Expand Up @@ -583,6 +595,7 @@ Modularizer.generateSample = function(app_name, cb) {
};

function installModuleByName (module, cb, verbose) {
//console.log(module.version);
if (!module || !module.name || module.name.length === 0) {
return cb(new Error('No module name !'));
}
Expand Down Expand Up @@ -619,7 +632,7 @@ function installLangModule(module_name, cb) {
return cb(new Error('Module install failed'));
return cb(null);
});

install_instance.on('error', function (err) {
console.error(err.stack || err);
});
Expand Down
15 changes: 15 additions & 0 deletions test/programmatic/modules.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ describe('Modules programmatic testing', function() {
});
});

it('should run post install command', function(done)
{
var fs = require('fs');
var ec = {};
ec.dependencies = new Array();
ec.dependencies.push('pm2-server-monit');
ec.post_install = {};
ec.post_install['pm2-server-monit'] = 'echo "test passed!"';
fs.appendFileSync('test.json', JSON.stringify(ec));
pm2.install('test.json', function() {
fs.unlinkSync('test.json');
done();
});
});

it('should list one module', function(done) {
pm2.list(function(err, apps) {
should(err).eql(null);
Expand Down

0 comments on commit 991ef5b

Please sign in to comment.