Skip to content

Instantly share code, notes, and snippets.

@uu59
Last active December 25, 2015 21:49
Show Gist options
  • Save uu59/7045417 to your computer and use it in GitHub Desktop.
Save uu59/7045417 to your computer and use it in GitHub Desktop.
module.exports = (grunt) ->
fs = require('fs')
path = require('path')
spawn = require('child_process').spawn
_ = grunt.util._
grunt.initConfig
fswatch:
watchDir: "target"
firstTimeExecution = true
grunt.registerTask 'fswatch', 'fs.watch glue', ->
rerun = =>
grunt.task.clearQueue()
grunt.task.run(@name)
defaultOptions =
watchDir: "."
callback: (event, filename) ->
options = _.extend defaultOptions, grunt.config.get(@name)
if firstTimeExecution
fs.watch options.watchDir, (event, filename) ->
filepath = path.join(options.watchDir, filename)
options.callback(event, filepath)
# forever running hack
done = @async()
sleep = spawn('sleep', [600])
sleep.on 'close', =>
firstTimeExecution = false
done()
rerun()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment