Skip to content

Commit

Permalink
improve CLI: add logs command, improve README
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Nov 19, 2018
1 parent 8ed35a5 commit 5138211
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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).
Expand Down
45 changes: 28 additions & 17 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,42 @@
// =============================================================

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;
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()}.`);
});

0 comments on commit 5138211

Please sign in to comment.