Skip to content

Commit

Permalink
reformat cli.js to run under node
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Nov 26, 2018
1 parent 978d1a8 commit 548cadf
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,24 @@ const path = require('path');
const pm2Config = require('./pm2.config');
const port = pm2Config.serveUIStatic.env.PM2_SERVE_PORT;
const logFiles = {
ui: path.join(
__dirname,
pm2Config.runServer.cwd || '',
pm2Config.runServer.log,
),
server: path.join(
__dirname,
pm2Config.serveUIStatic.cwd || '',
pm2Config.serveUIStatic.log,
),
ui: path.join(__dirname, pm2Config.runServer.cwd || '', pm2Config.runServer.log),
server: path.join(__dirname, pm2Config.serveUIStatic.cwd || '', pm2Config.serveUIStatic.log),
};
const programm = 'npmfrog';
const firstArg = process.argv[2];
const command = firstArg === 'stop' ? 'stop' : 'start';

exec(
`npm ${command}`,
{
cwd: __dirname,
},
(error, stdout, stderr) => {
console.log(`${stdout}`);
console.error(`${stderr}`);
if (command === 'start') {
console.log(`Running npmFrog in background on http://localhost:${port}`);
console.log(`To stop npmFrog, run \`${programm} stop\``);
console.log(
`Logs can be found in ${logFiles.server} and ${logFiles.ui} .`,
);
} else if (command === 'stop') {
console.log(`Stopped npmFrog.`);
}
if (error !== null) {
console.error(`npmFrog error: ${error}`);
}
},
);
exec(`npm ${command}`, { cwd: __dirname }, (error, stdout, stderr) => {
console.log(`${stdout}`);
console.error(`${stderr}`);
if (command === 'start') {
console.log(`Running npmFrog in background on http://localhost:${port}`);
console.log(`To stop npmFrog, run \`${programm} stop\``);
console.log(`Logs can be found in ${logFiles.server} and ${logFiles.ui} .`);
} else if (command === 'stop') {
console.log(`Stopped npmFrog.`);
}
if (error !== null) {
console.error(`npmFrog error: ${error}`);
}
});

0 comments on commit 548cadf

Please sign in to comment.