Created
June 23, 2017 20:02
-
-
Save quidmonkey/30c626db783282834067f90bfdd7f2a6 to your computer and use it in GitHub Desktop.
Sample NPM Run Script File for Watching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function ctrl_c() { | |
for process in "${PROCESSES[@]}"; do | |
local pid=$(get_pid $process) | |
if [ ! -z $pid ]; then | |
kill $pid | |
fi | |
done | |
exit 0 | |
} | |
function get_pid() { | |
local process=$@ | |
ps aux | grep "$process" | grep -v grep | awk '{ print $2 }' | |
} | |
function runner() { | |
local cmd=$@ | |
local pid=$(get_pid $cmd) | |
if [ -z $pid ]; then | |
$cmd & | |
fi | |
PROCESSES+=("$cmd") | |
} | |
function main() { | |
rm -rf dist | |
npm run levels | |
runner "node ./node_modules/livereload/bin/livereload.js ." | |
runner "python -m SimpleHTTPServer" | |
./node_modules/rollup/bin/rollup -w -c tools/rollup-config.js | |
} | |
PROCESSES=() | |
trap ctrl_c INT | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment