Skip to content

Commit

Permalink
Merge pull request #3821 from imarakho/post_install
Browse files Browse the repository at this point in the history
added post_install to ecosystem.json
  • Loading branch information
wallet77 authored Aug 17, 2018
2 parents cc68dc1 + 61e32a4 commit 4217b15
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lib/API/Modules/Modularizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 @@ -61,19 +63,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.installMultipleInternalModules(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 @@ -86,7 +86,6 @@ Modularizer.install = function (CLI, moduleName, opts, cb) {
} else {
installModuleByName(currentModule, cb);
}

return false;
}

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

Modularizer.installMultipleInternalModules = 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 @@ -120,9 +119,22 @@ Modularizer.installMultipleInternalModules = 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 @@ -621,7 +633,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 4217b15

Please sign in to comment.