Skip to content

Instantly share code, notes, and snippets.

@quidmonkey
Created June 23, 2017 20:02
Show Gist options
  • Save quidmonkey/30c626db783282834067f90bfdd7f2a6 to your computer and use it in GitHub Desktop.
Save quidmonkey/30c626db783282834067f90bfdd7f2a6 to your computer and use it in GitHub Desktop.
Sample NPM Run Script File for Watching
#!/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