Created
July 11, 2012 20:42
-
-
Save mlrawlings/3093247 to your computer and use it in GitHub Desktop.
SS LiveReload onChange
This file contains 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
onChange = (path, event) -> | |
takeAction = (action) -> | |
if (Date.now() - lastRun[action]) > 1000 # Reload browser max once per second | |
console.log('✎'.green, consoleMessage[action].grey) | |
ss.publish.all('__ss:' + action) | |
lastRun[action] = Date.now() | |
action = if pathlib.extname(path) in cssExtensions then 'updateCSS' else 'reload' | |
if event is 'added' or event is 'changed' | |
fs.readFile path, (err, data) -> | |
if data.toString() != '' then takeAction(action) | |
else setTimeout (-> takeAction(action)), 300 | |
else takeAction(action) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment