Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: with pm2 plus command ask to install modules #3780

Merged
merged 3 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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