Skip to content

Commit

Permalink
Merge pull request #3780 from Unitech/plus_modules
Browse files Browse the repository at this point in the history
feature: with pm2 plus command ask to install modules
  • Loading branch information
Unitech committed Jul 11, 2018
2 parents 3a582b4 + 35a1ed2 commit 466d270
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/API/Modules/Modularizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Modularizer.installMultipleModules = function (modules, cb) {
}
}

cb(err);
if(cb) cb(err);
});
};

Expand Down
46 changes: 40 additions & 6 deletions lib/API/PM2/PM2IO.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const Table = require('cli-table-redemption');
const open = require('../../tools/open.js');
const pkg = require('../../../package.json')
const IOAPI = require('@pm2/js-api')
const semver = require('semver');
const Modularizer = require('../Modules/Modularizer.js');


// const CustomStrategy = require('./custom_auth')
Expand Down Expand Up @@ -43,7 +45,7 @@ module.exports = function(CLI) {
});
};

CLI.prototype.loginToKM = function() {
CLI.prototype.loginToKM = function(cb) {
var promptly = require('promptly')

return CLIAuthStrategy._retrieveTokens((err, tokens) => {
Expand Down Expand Up @@ -81,15 +83,16 @@ module.exports = function(CLI) {
}
});

if (target_bucket == null)
if (target_bucket == null) {
return retryInsertion();
linkOpenExit(target_bucket);
}
return linkOpenExit(target_bucket, cb);
});
})();
}
else {
var target_bucket = buckets[0];
linkOpenExit(target_bucket)
linkOpenExit(target_bucket, cb)
}
}).catch(err => {
console.error(chalk.bold.red(`Oups, a error happened : ${err}`))
Expand All @@ -102,9 +105,36 @@ module.exports = function(CLI) {
var promptly = require('promptly');
printMotd();

const self = this

promptly.confirm(chalk.bold('Do you have a pm2.io account? (y/n)'), (err, answer) => {

if (answer == true) {
return this.loginToKM();
return CLI.prototype.loginToKM(() => {
promptly.confirm(chalk.bold('Do you want to install monitoring modules (pm2-logrotate, pm2-server-monit, ...) ? (y/n)'), (errModule, answerModule) => {
if(!errModule && answerModule === true) {
const modules = ['pm2-logrotate', 'pm2-server-monit', 'event-loop-inspector']

if (semver.satisfies(process.version, '< 8.0.0')) {
modules.push('v8-profiler-node8')
}

Modularizer.installMultipleModules(modules, () => {
self.reload('all')
setTimeout(function() {
console.log(chalk.bold.green('[+] Exiting now.'))
process.exit(cst.SUCCESS_EXIT);
}, 100);
});
} else {
self.reload('all')
setTimeout(function() {
console.log(chalk.bold.green('[+] Exiting now.'))
process.exit(cst.SUCCESS_EXIT);
}, 100);
}
});
});
}
CLIAuthStrategy.registerViaCLI((err, data) => {
console.log('[-] Creating Bucket...')
Expand Down Expand Up @@ -214,7 +244,7 @@ module.exports = function(CLI) {
};


function linkOpenExit(target_bucket) {
function linkOpenExit(target_bucket, cb) {
console.log('[-] Linking local PM2 to newly created bucket...')
KMDaemon.launchAndInteract(cst, {
public_key : target_bucket.public_id,
Expand All @@ -227,6 +257,10 @@ module.exports = function(CLI) {

setTimeout(function() {
open('https://app.pm2.io/#/r/' + target_bucket.public_id);

if (cb) {
return cb()
}
console.log(chalk.bold.green('[+] Opened! Exiting now.'))
setTimeout(function() {
process.exit(cst.SUCCESS_EXIT);
Expand Down

0 comments on commit 466d270

Please sign in to comment.