Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzel committed Aug 8, 2022
0 parents commit 82cc2b3
Show file tree
Hide file tree
Showing 8 changed files with 1,503 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "standard",
"parserOptions": {
"sourceType": "script"
},
"env": {
"node": true,
"jest": true
},
"rules": {
"strict": ["error", "global"]
}
}
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.vs
.vscode

.DS_Store

.node_history
*.log
.cache

pids
*.pid
*.seed

node_modules
public
build
dist
lib
tmp

.env
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Alex Zelensky

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# `pm2-devmon`

PM2 development environment monitor using independent mode.

## Installation

```sh
yarn add pm2 pm2-devmon
```

or

```sh
npm install pm2 pm2-devmon
```

## Usage

Run server scripts

```sh
pm2-devmon start server.js
```

or run process config files

```sh
pm2-devmon --raw start process.json
```

## Options

```
Options:
-v, --version output the current version
--raw raw log output
--ignore [files] files list to ignore watching
--env [name] env_[name] env variables in process file
-h, --help output usage information
```
5 changes: 5 additions & 0 deletions bin/pm2-devmon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

'use strict'

require('../src/cli.js')
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "pm2-devmon",
"version": "0.0.0",
"description": "PM2 development environment monitor",
"keywords": [
"pm2",
"pm2-dev",
"dev",
"monitor",
"independent"
],
"repository": "https://github.com/alexzel/pm2-devmon.git",
"author": "Alex Zelensky",
"license": "MIT",
"scripts": {
"lint": "eslint ./src",
"test": "echo no tests implemented for this package",
"pretest": "yarn run lint",
"release": "yarn version",
"preversion": "yarn install && yarn test",
"postversion": "git push --tags && yarn publish . --new-version $npm_package_version && git push && echo Successfully released version $npm_package_version!",
"cleanup": "git tag -d $(git tag) && git fetch --all --tags && git clean --force -d -x && git reset --hard origin/main && git checkout main"
},
"files": [
"src"
],
"bin": {
"pm2-devmon": "bin/pm2-devmon"
},
"devDependencies": {
"eslint": "^8.21.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.2.4",
"eslint-plugin-promise": "^6.0.0"
},
"peerDependencies": {
"pm2": ">= 5.2.0 < 6"
}
}
61 changes: 61 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict'

process.env.PM2_NO_INTERACTION = 'true'
process.env.PM2_DISCRETE_MODE = true

const commander = require('commander')
const { custom: PM2 } = require('pm2')
const Log = require('pm2/lib/API/Log')
const { version } = require('../package.json')

const log = (...msg) =>
console.log('\x1b[32m%s\x1b[0m', ...msg)

commander.version(version, '-v, --version', 'output the current version')
.description('pm2-devmon development environment monitor using independent mode')
.option('--raw', 'raw log output')
.option('--ignore [files]', 'files list to ignore watching')
.option('--env [name]', 'env_[name] env variables in process file')
.usage('pm2-devmon start process.json')

commander.exitOverride(err => {
if (err.code === 'commander.unknownOption' || err.code === 'commander.missingArgument') {
commander.outputHelp()
}
})

const pm2 = new PM2({ independent: true })

commander.command('start <js|config.js|process.json>')
.description('start script or config or process file')
.action((cmd, opts) => {
commander.watch = true
commander.autorestart = true
commander.restart_delay = 2500

if (commander.ignore) {
commander.ignore_watch = commander.ignore.split(',')
commander.ignore_watch.push('node_modules')
}

pm2.connect(() => {
pm2.start(cmd, commander, (err, apps) => {
if (err) {
console.error(err)
pm2.destroy(() => process.exit(0))
} else {
log('Apps:', apps.map(app => app.pm2_env.name))
log('Processes:', apps.map(app => app.process.pid))

Log.devStream(pm2.Client, 'all', commander.raw, false, false)

process.on('SIGINT', () => {
log('Stopping...')
pm2.delete('all', () => pm2.destroy(() => process.exit(0)))
})
}
})
})
})

commander.parse(process.argv)
Loading

0 comments on commit 82cc2b3

Please sign in to comment.