Skip to content

Commit 82cc2b3

Browse files
committed
Init
0 parents  commit 82cc2b3

File tree

8 files changed

+1503
-0
lines changed

8 files changed

+1503
-0
lines changed

.eslintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "standard",
3+
"parserOptions": {
4+
"sourceType": "script"
5+
},
6+
"env": {
7+
"node": true,
8+
"jest": true
9+
},
10+
"rules": {
11+
"strict": ["error", "global"]
12+
}
13+
}

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.vs
2+
.vscode
3+
4+
.DS_Store
5+
6+
.node_history
7+
*.log
8+
.cache
9+
10+
pids
11+
*.pid
12+
*.seed
13+
14+
node_modules
15+
public
16+
build
17+
dist
18+
lib
19+
tmp
20+
21+
.env

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Alex Zelensky
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# `pm2-devmon`
2+
3+
PM2 development environment monitor using independent mode.
4+
5+
## Installation
6+
7+
```sh
8+
yarn add pm2 pm2-devmon
9+
```
10+
11+
or
12+
13+
```sh
14+
npm install pm2 pm2-devmon
15+
```
16+
17+
## Usage
18+
19+
Run server scripts
20+
21+
```sh
22+
pm2-devmon start server.js
23+
```
24+
25+
or run process config files
26+
27+
```sh
28+
pm2-devmon --raw start process.json
29+
```
30+
31+
## Options
32+
33+
```
34+
Options:
35+
-v, --version output the current version
36+
--raw raw log output
37+
--ignore [files] files list to ignore watching
38+
--env [name] env_[name] env variables in process file
39+
-h, --help output usage information
40+
```

bin/pm2-devmon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
'use strict'
4+
5+
require('../src/cli.js')

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "pm2-devmon",
3+
"version": "0.0.0",
4+
"description": "PM2 development environment monitor",
5+
"keywords": [
6+
"pm2",
7+
"pm2-dev",
8+
"dev",
9+
"monitor",
10+
"independent"
11+
],
12+
"repository": "https://github.com/alexzel/pm2-devmon.git",
13+
"author": "Alex Zelensky",
14+
"license": "MIT",
15+
"scripts": {
16+
"lint": "eslint ./src",
17+
"test": "echo no tests implemented for this package",
18+
"pretest": "yarn run lint",
19+
"release": "yarn version",
20+
"preversion": "yarn install && yarn test",
21+
"postversion": "git push --tags && yarn publish . --new-version $npm_package_version && git push && echo Successfully released version $npm_package_version!",
22+
"cleanup": "git tag -d $(git tag) && git fetch --all --tags && git clean --force -d -x && git reset --hard origin/main && git checkout main"
23+
},
24+
"files": [
25+
"src"
26+
],
27+
"bin": {
28+
"pm2-devmon": "bin/pm2-devmon"
29+
},
30+
"devDependencies": {
31+
"eslint": "^8.21.0",
32+
"eslint-config-standard": "^17.0.0",
33+
"eslint-plugin-import": "^2.26.0",
34+
"eslint-plugin-n": "^15.2.4",
35+
"eslint-plugin-promise": "^6.0.0"
36+
},
37+
"peerDependencies": {
38+
"pm2": ">= 5.2.0 < 6"
39+
}
40+
}

src/cli.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict'
2+
3+
process.env.PM2_NO_INTERACTION = 'true'
4+
process.env.PM2_DISCRETE_MODE = true
5+
6+
const commander = require('commander')
7+
const { custom: PM2 } = require('pm2')
8+
const Log = require('pm2/lib/API/Log')
9+
const { version } = require('../package.json')
10+
11+
const log = (...msg) =>
12+
console.log('\x1b[32m%s\x1b[0m', ...msg)
13+
14+
commander.version(version, '-v, --version', 'output the current version')
15+
.description('pm2-devmon development environment monitor using independent mode')
16+
.option('--raw', 'raw log output')
17+
.option('--ignore [files]', 'files list to ignore watching')
18+
.option('--env [name]', 'env_[name] env variables in process file')
19+
.usage('pm2-devmon start process.json')
20+
21+
commander.exitOverride(err => {
22+
if (err.code === 'commander.unknownOption' || err.code === 'commander.missingArgument') {
23+
commander.outputHelp()
24+
}
25+
})
26+
27+
const pm2 = new PM2({ independent: true })
28+
29+
commander.command('start <js|config.js|process.json>')
30+
.description('start script or config or process file')
31+
.action((cmd, opts) => {
32+
commander.watch = true
33+
commander.autorestart = true
34+
commander.restart_delay = 2500
35+
36+
if (commander.ignore) {
37+
commander.ignore_watch = commander.ignore.split(',')
38+
commander.ignore_watch.push('node_modules')
39+
}
40+
41+
pm2.connect(() => {
42+
pm2.start(cmd, commander, (err, apps) => {
43+
if (err) {
44+
console.error(err)
45+
pm2.destroy(() => process.exit(0))
46+
} else {
47+
log('Apps:', apps.map(app => app.pm2_env.name))
48+
log('Processes:', apps.map(app => app.process.pid))
49+
50+
Log.devStream(pm2.Client, 'all', commander.raw, false, false)
51+
52+
process.on('SIGINT', () => {
53+
log('Stopping...')
54+
pm2.delete('all', () => pm2.destroy(() => process.exit(0)))
55+
})
56+
}
57+
})
58+
})
59+
})
60+
61+
commander.parse(process.argv)

0 commit comments

Comments
 (0)