Move initPM2 to CLI.js #712

This commit is contained in:
tknew2 2014-10-10 11:03:34 +02:00
parent 02d47e8e60
commit 13c66ab2a0
2 changed files with 25 additions and 30 deletions

32
bin/pm2
View File

@ -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);
});
}

View File

@ -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