Skip to content

Commit 95d24fa

Browse files
committed
Init
0 parents  commit 95d24fa

File tree

6 files changed

+2743
-0
lines changed

6 files changed

+2743
-0
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__tests__
2+
dist
3+
node_modules

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#! /usr/bin/env node
2+
require('./dist/main').default();

package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "pwatch",
3+
"version": "0.0.1",
4+
"description": "Process Watcher",
5+
"main": "./index.js",
6+
"bin": {
7+
"pwatch": "./index.js"
8+
},
9+
"scripts": {
10+
"prepublish": "babel src --out-dir dist",
11+
"watch": "babel -w src --out-dir dist",
12+
"dev": "babel-node index.js",
13+
"test": "jest"
14+
},
15+
"author": "Justin Krup",
16+
"license": "ISC",
17+
"devDependencies": {
18+
"babel-cli": "^6.23.0",
19+
"babel-preset-es2015": "^6.22.0",
20+
"jest": "^18.1.0"
21+
},
22+
"dependencies": {
23+
"node-notifier": "^5.0.2"
24+
}
25+
}

src/main.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import tty from 'tty';
2+
import { exec } from 'child_process';
3+
import notifier from 'node-notifier';
4+
5+
function checkPid(pid, cb = function() { notifier.notify(`Process ${pid}: Completed`) }) {
6+
exec(`ps ${pid}`, (error, stdout, stderr) => {
7+
if (error) {
8+
return cb();
9+
}
10+
setTimeout(checkPid.bind(this, pid, cb), 1000);
11+
});
12+
}
13+
14+
function handlePiped() {
15+
process.stdin.on('data', () => { }); // required so that readable is called on end
16+
process.stdin.on('end', () => {
17+
notifier.notify(`Process Completed`);
18+
});
19+
}
20+
21+
function handlePid(pid) {
22+
if (!pid) {
23+
console.error('No pid specified');
24+
process.exit(1);
25+
}
26+
checkPid(pid);
27+
}
28+
29+
30+
export default function main() {
31+
const isCalledViaPipe = !tty.isatty();
32+
if (isCalledViaPipe) {
33+
handlePiped();
34+
} else {
35+
handlePid(process.argv[2])
36+
}
37+
}
38+

0 commit comments

Comments
 (0)