Skip to content

Commit

Permalink
Implement termination
Browse files Browse the repository at this point in the history
  • Loading branch information
muusli committed Dec 28, 2020
1 parent 1e92bd4 commit 6f4c265
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 33 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const chokidar = require('chokidar');
const program = require('caporal');
const fs = require('fs');
const { spawn } = require('child_process');
const chalk = require('chalk');

program.version('0.0.1').argument('[filename]', 'Name of a file to execute').action(async ({ filename }) => {
const name = filename || 'index.js';
Expand All @@ -16,9 +17,14 @@ program.version('0.0.1').argument('[filename]', 'Name of a file to execute').act
} catch (err) {
throw new Error(`could not find the file ${name}`);
}
let proc;
const start = debounce(() => {
spawn('node', [ name ], { stdio: 'inherit' });
}, 500);
if (proc) {
proc.kill();
}
console.log(chalk.blue('>>> Starting process...'));
proc = spawn('node', [ name ], { stdio: 'inherit' });
}, 200);

chokidar.watch('.').on('add', start).on('change', start).on('unlink', start);
});
Expand Down
86 changes: 57 additions & 29 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
@@ -1,7 +1,6 @@
{
"name": "nodemon-watchit",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -22,7 +21,10 @@
"homepage": "https://github.com/jbeckmann1/nodemon-watchit#readme",
"dependencies": {
"caporal": "^1.4.0",
"chalk": "^4.1.0",
"chokidar": "^3.4.3",
"lodash.debounce": "^4.0.8"
}
},
"devDependencies": {},
"description": ""
}

0 comments on commit 6f4c265

Please sign in to comment.