xcarve-proxy/cli
2016-11-27 14:29:14 +01:00

60 lines
1.1 KiB
JavaScript
Executable file

#!/usr/bin/env node
var pm2 = require('pm2'),
fs = require('fs'),
path = require('path'),
logo = fs.readFileSync(path.join(__dirname,'logo.txt'), 'utf8'),
cli = require('commander'),
package = require('./package.json');
function start() {
console.log(logo);
pm2.connect((err) => {
if(err) {
console.error(err);
process.exit(2);
}
pm2.start({
script: path.join(__dirname,'index.js'),
name: 'xcarve'
}, (err, apps) => {
pm2.disconnect();
if (err) throw err
console.log('starting proxy on port 1338...\n');
});
});
}
function stop() {
pm2.connect((err) => {
if(err) {
console.error(err);
process.exit(2);
}
pm2.stop('xcarve', (err) => {
if(err) throw err;
console.log('stopping proxy...');
process.exit();
});
});
}
cli.version(package.version);
cli.command('start').description('starts the local xcarve proxy').action(start);
cli.command('stop').description('stops the local xcarve proxy').action(stop);
cli.parse(process.argv);
if (!process.argv.slice(2).length) {
cli.outputHelp();
}