Skip to content

Commit

Permalink
fix #20 Create executable cli.js for global PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Nov 26, 2018
1 parent 7503387 commit 8d6f2b5
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
frog-*.log

# Editor directories and files
.idea
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Duplicate the file `.SAMPLE.npmfrogrc.json` and rename it to `.npmfrogrc.json` (
## Usage

```bash
npm start
npmfrog
```

Browse to npmFrog instance [http://localhost:8000](http://localhost:8000).
Expand Down
36 changes: 36 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env node

const exec = require("child_process").exec;
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),
};
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}`);
}
}
);
28 changes: 7 additions & 21 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"compile": "npm run lint && cd server && tsc",
"build": "npm run compile && npm run copy && vue-cli-service build --dest dist/webui",
"zip": "bestzip tmp/webui.zip dist/*",
"logs": "pm2 logs",
"logs": "pm2 logs /frog-.*/",
"stop": "pm2 stop /frog-.*/",
"pre-release": "release-it --preRelease=alpha",
"rc": "release-it --preRelease=rc --npm.tag=next"
},
"bin": "./cli.js",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
Expand Down Expand Up @@ -68,7 +69,8 @@
"ecosystem.config.js",
".sample.npmfrogrc.json",
"pm2.config.js",
"pm2.prod.config.js"
"pm2.prod.config.js",
"cli.js"
],
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions pm2.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const env_local = {
MOCK: true
};

const log_date_format = "DD-MM-YYYY HH:mm:ss";

module.exports = {
watchUI: {
name: "frog-ui",
Expand All @@ -27,11 +29,14 @@ module.exports = {
name: "frog-server",
script: "index.js",
cwd: "dist/server/",
log: '../../frog-server.log',
env_local
},
serveUIStatic: {
name: "frog-ui-static",
script: "serve",
log: './frog-ui.log',
log_date_format,
env: {
PM2_SERVE_PATH: "dist/webui",
PM2_SERVE_PORT: 8000
Expand Down

0 comments on commit 8d6f2b5

Please sign in to comment.