Skip to content

Commit

Permalink
CLI: fix spawn command for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Nov 19, 2018
1 parent ad4e479 commit 77a63e7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
29 changes: 15 additions & 14 deletions bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env node
// =============================================================

import * as childProcess from 'child_process';
import * as path from 'path';
const exec = childProcess.spawn;
import * as execute from 'cross-spawn';

// tslint:disable-next-line:no-var-requires
const pm2Config = require('../pm2.config');
import * as pm2Config from '../pm2.config';
const port = pm2Config.serveUIStatic.env.PM2_SERVE_PORT;
const logFiles = {
ui: path.join(__dirname, '..', pm2Config.serveUIStatic.cwd || '', pm2Config.serveUIStatic.log),
Expand All @@ -20,15 +18,7 @@ const allowedCliCommands = ['stop', 'logs'];
const command: string[] =
allowedCliCommands.indexOf(firstArg) > -1 ? ['run', firstArg] : startCommand;

const run = exec(`npm`, command);

if (command === startCommand) {
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[1] === 'stop') {
console.log(`Stopped npmFrog.`);
}
const run = execute(`npm`, command);

run.stdout.on('data', data => {
console.log(data.toString());
Expand All @@ -39,5 +29,16 @@ run.stderr.on('data', data => {
});

run.on('exit', code => {
console.log(`npmFrog exited with code ${code.toString()}.`);
if (code === 0) {
if (command === startCommand) {
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} .
Or run \`npmfrog logs\` to get all live logs.`,
);
} else if (command[1] === 'stop') {
console.log(`Stopped npmFrog.`);
}
}
});
19 changes: 12 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"cross-spawn": "^6.0.5",
"express": "^4.16.3",
"express-serve-static-core": "^0.1.1",
"fs-extra": "^7.0.0",
Expand All @@ -54,6 +55,7 @@
"vuetify": "^1.3.5"
},
"devDependencies": {
"@types/cross-spawn": "^6.0.0",
"@types/body-parser": "^1.17.0",
"@types/cors": "^2.8.4",
"@types/express": "^4.16.0",
Expand Down
2 changes: 2 additions & 0 deletions server/config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ export default {
`Creating default configuration in ${configPath} . Please fill it with life and restart the server. :)`,
);
const config = sampleConfig.toJSON().data;
// tslint:disable no-string-literal
return {
artifactory: config['artifactory'],
companyScope: config['companyScope'],
};
// tslint:enable no-string-literal
}
},
};

0 comments on commit 77a63e7

Please sign in to comment.