Skip to content

Instantly share code, notes, and snippets.

@maciejhirsz
Created October 9, 2014 11:23
Show Gist options
  • Save maciejhirsz/6b9dcb41e4a5d8f8cecf to your computer and use it in GitHub Desktop.
Save maciejhirsz/6b9dcb41e4a5d8f8cecf to your computer and use it in GitHub Desktop.
autogrunt
sys = require 'sys'
{exec} = require 'child_process'
fsevents = require 'fsevents'
###################################
compiling = false
compiler = null
notify = (message, type = 'info') ->
console.log(message)
exec "osx-notifier --title \"Grunt\" --type \"#{type}\" --message #{JSON.stringify(message)}"
compile = ->
if compiling and compiler?
compiler.kill("SIGKILL")
compiler.on 'close', (code, signal) -> compile()
notify("Killing previous compile", "fail")
return
compiling = true
start = Date.now()
notify('Starting Grunt')
compiler = exec "cd amazine; grunt scripts", (error, stdout, stderr) ->
message = "Done in #{Date.now() - start}ms"
type = "pass"
type = "fail" if error?
notify(message, type)
compiling = false
compiler.stdout.pipe process.stdout
watcher = fsevents('./amazine/scripts')
watcher.on 'change', (path) ->
extension = path.split('.').pop()
if extension in ['coffee', 'tmpl', 'scss']
console.log path
compile()
watcher.start()
compile()
@maciejhirsz
Copy link
Author

Install with npm:

osx-notifier -g
fsevents

Mac only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment