diff --git a/README.md b/README.md index be7c383..0e0f0da 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ It's free and open source. :) ## Prerequisites -* [Node.js >= 8.x](https://nodejs.org/en/download/) -* JFrog Artifactory is running somewhere in your company's network +- [Node.js >= 8.x](https://nodejs.org/en/download/) +- JFrog Artifactory is running somewhere in your company's network ## Installation @@ -32,10 +32,24 @@ npm i -g npmfrog ## Usage +### Start + ```bash npmfrog ``` +### Stop + +```bash +npmfrog stop +``` + +### Show logs + +```bash +npmfrog logs +``` + At the first start up, npmFrog will create a configuration file in your home directory under `~/.npmfrog/config.json`. Please fill this file with with your artifactory properties. Browse to npmFrog instance [http://localhost:8000](http://localhost:8000). diff --git a/bin/cli.ts b/bin/cli.ts index c5bf050..4a5750b 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -2,8 +2,9 @@ // ============================================================= import * as childProcess from 'child_process'; -const exec = childProcess.exec; import * as path from 'path'; +const exec = childProcess.spawn; + // tslint:disable-next-line:no-var-requires const pm2Config = require('../pm2.config'); const port = pm2Config.serveUIStatic.env.PM2_SERVE_PORT; @@ -11,22 +12,32 @@ const logFiles = { ui: path.join(__dirname, '..', pm2Config.serveUIStatic.cwd || '', pm2Config.serveUIStatic.log), server: path.join(__dirname, '..', pm2Config.runServer.cwd || '', pm2Config.runServer.log), }; -const startCommand = 'run prod'; + +const startCommand = ['run', 'prod']; const programm = 'npmfrog'; const firstArg = process.argv[2]; -const command = firstArg === 'stop' ? 'stop' : startCommand; - -exec(`npm ${command}`, { cwd: __dirname }, (error, stdout, stderr) => { - console.log(`${stdout}`); - console.error(`${stderr}`); - 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 === 'stop') { - console.log(`Stopped npmFrog.`); - } - if (error !== null) { - console.error(`npmFrog error: ${error}`); - } +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.`); +} + +run.stdout.on('data', data => { + console.log(data.toString()); +}); + +run.stderr.on('data', data => { + console.error(data.toString()); +}); + +run.on('exit', code => { + console.log(`npmFrog exited with code ${code.toString()}.`); });