mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
76 lines
1.8 KiB
JavaScript
Executable File
76 lines
1.8 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
'use strict';
|
|
|
|
var commander = require('commander');
|
|
|
|
var debug = require('debug')('pm2:cli');
|
|
var PM2 = require('../lib/CLI.js');
|
|
var CLI = require('../lib/CLI');
|
|
var Log = require('../lib/CLI/Log');
|
|
var cst = require('../constants.js');
|
|
var pkg = require('../package.json');
|
|
var platform = require('os').platform();
|
|
var moment = require('moment');
|
|
var Common = require('../lib/Common');
|
|
var chalk = require('chalk');
|
|
var path = require('path');
|
|
|
|
process.env.PM2_SILENT = 'true';
|
|
|
|
commander.version(pkg.version)
|
|
.option('--raw', 'raw log output')
|
|
.option('--timestamp [format]', 'add timestamps to logs')
|
|
.usage('[cmd] app');
|
|
|
|
var pm2 = new PM2({
|
|
pm2_home : path.join(process.env.HOME, '.pm2-dev')
|
|
});
|
|
|
|
pm2.connect(function() {
|
|
commander.parse(process.argv);
|
|
});
|
|
|
|
function run(cmd, opts) {
|
|
commander.watch = true;
|
|
commander.autorestart = false;
|
|
|
|
var needRaw = opts.parent.rawArgs.indexOf('--raw') > -1 || false;
|
|
var timestamp = opts.parent.timestamp;
|
|
|
|
if (timestamp === true)
|
|
timestamp = 'YYYY-MM-DD-HH:mm:ss';
|
|
|
|
pm2.start(cmd, commander, function(err, obj) {
|
|
Log.stream(pm2.Client, 'all', needRaw, timestamp, false);
|
|
|
|
process.on('SIGINT', function() {
|
|
console.log('>>>>> [PM2 DEV] Stopping current development session');
|
|
pm2.delete('all', function() {
|
|
pm2.destroy(function() {
|
|
process.exit(0);
|
|
});
|
|
});
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
commander.command('*')
|
|
.description('run <file|json_file> in development mode')
|
|
.action(function(cmd, opts){
|
|
run(cmd, opts);
|
|
});
|
|
|
|
commander.command('run <file|json_file>')
|
|
.alias('start')
|
|
.description('run <file|json_file> in development mode')
|
|
.action(function(cmd, opts) {
|
|
run(cmd, opts);
|
|
});
|
|
|
|
if (process.argv.length == 2) {
|
|
commander.outputHelp();
|
|
process.exit(1);
|
|
}
|