Skip to content

Instantly share code, notes, and snippets.

@jbgutierrez jbgutierrez/watch
Last active Aug 29, 2015

What would you like to do?
Hire/fire a webpack watcher after detecting new files in the file system
#!/usr/bin/env coffee
os = require 'os'
chokidar = require './nosync/node_modules/chokidar'
spawn = require('child_process').spawn
watcher = null
debounce = (fn, delay=100) ->
timer = null
context = this
args = arguments
clearTimeout timer
timer = setTimeout((->
fn.apply context, args
), delay)
start = ->
console.log "hiring new watcher"
cmd = 'webpack'
cmd += '.cmd' if ~['win32', 'win64'].indexOf os.platform()
watcher = spawn cmd, ['--watch', '--watch-polling'], stdio: 'inherit'
watcher.on 'close', (code, signal) ->
console.log "child process terminated due to receipt of signal #{signal}"
restart =
debounce ->
if watcher
console.log "firing #{}"
start()'modules/versions').on 'add', (path) ->
console.log "file #{path} has been added."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.