Skip to content

Commit

Permalink
feature: with pm2 plus command ask to install modules
Browse files Browse the repository at this point in the history
  • Loading branch information
wallet77 committed Jul 10, 2018
1 parent 8692a1d commit 28c6171
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 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 @@ -103,20 +105,22 @@ module.exports = function(CLI) {
printMotd();

promptly.confirm(chalk.bold('Do you have a pm2.io account? (y/n)'), (err, answer) => {
if (answer == true) {
return this.loginToKM();
}
CLIAuthStrategy.registerViaCLI((err, data) => {
console.log('[-] Creating Bucket...')

io.bucket.create({
name: 'Node.JS Monitoring'
}).then(res => {
const bucket = res.data.bucket
console.log(chalk.bold.green('[+] Bucket created!'))
linkOpenExit(bucket)
})
})

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, () => {
return KMConnection(answer)
});
} else {
return KMConnection(answer)
}
});
});
}

Expand Down Expand Up @@ -242,4 +246,21 @@ module.exports = function(CLI) {
var dt = fs.readFileSync(path.join(__dirname, 'motd'));
console.log(dt.toString());
}

function KMConnection(answer) {
if (answer == true) {
return CLI.prototype.loginToKM();
}
CLIAuthStrategy.registerViaCLI((err, data) => {
console.log('[-] Creating Bucket...')

io.bucket.create({
name: 'Node.JS Monitoring'
}).then(res => {
const bucket = res.data.bucket
console.log(chalk.bold.green('[+] Bucket created!'))
linkOpenExit(bucket)
})
})
}
};

0 comments on commit 28c6171

Please sign in to comment.