From 13c66ab2a022c9da12da95f8eab031e092f446c4 Mon Sep 17 00:00:00 2001 From: tknew2 Date: Fri, 10 Oct 2014 11:03:34 +0200 Subject: [PATCH] Move initPM2 to CLI.js #712 --- bin/pm2 | 32 ++------------------------------ lib/CLI.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/bin/pm2 b/bin/pm2 index eee2ac76..236fb6d2 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -16,34 +16,7 @@ var CLI = require('../lib/CLI'); var cst = require('../constants.js'); var pkg = require('../package.json'); -// -// Init -// -(function init() { - var exist = fs.existsSync(cst.DEFAULT_FILE_PATH); - - if (!exist) { - console.log('Initializing folder for pm2 on %s', cst.DEFAULT_FILE_PATH); - fs.mkdirSync(cst.DEFAULT_FILE_PATH); - fs.mkdirSync(cst.DEFAULT_LOG_PATH); - fs.mkdirSync(cst.DEFAULT_PID_PATH); - - /** - * Create configuration file if not present - */ - fs.exists(cst.PM2_CONF_FILE, function(exist) { - if (!exist) { - console.log('Creating PM2 configuration file in %s', cst.PM2_CONF_FILE); - fs - .createReadStream(path.join(__dirname, cst.SAMPLE_CONF_FILE)) - .pipe(fs.createWriteStream(cst.PM2_CONF_FILE)); - } - - }); - } - -})(); - +CLI.pm2Init(); commander.version(pkg.version) .option('-v --version', 'get version') @@ -132,8 +105,7 @@ function beginCommandProcessing() { console.log('Local PM2 version:', chalk.blue.bold(pkg.version)); console.log(''); } - commander.parse(process.argv); - + commander.parse(process.argv); }); } diff --git a/lib/CLI.js b/lib/CLI.js index 448bc148..1de14a68 100644 --- a/lib/CLI.js +++ b/lib/CLI.js @@ -26,6 +26,29 @@ var printOut = Common.printOut; var pm2 = require('..'); +CLI.pm2Init = function() { + var exist = fs.existsSync(cst.DEFAULT_FILE_PATH); + + if (!exist) { + console.log('Initializing PM2 configuration (%s)', cst.DEFAULT_FILE_PATH); + fs.mkdirSync(cst.DEFAULT_FILE_PATH); + fs.mkdirSync(cst.DEFAULT_LOG_PATH); + fs.mkdirSync(cst.DEFAULT_PID_PATH); + + /** + * Create configuration file if not present + */ + fs.exists(cst.PM2_CONF_FILE, function(exist) { + if (!exist) { + fs + .createReadStream(path.join(__dirname, cst.SAMPLE_CONF_FILE)) + .pipe(fs.createWriteStream(cst.PM2_CONF_FILE)); + } + + }); + } +}; + /** * Method to start a script * @method startFile