Skip to content

Instantly share code, notes, and snippets.

@cbilson
Created October 24, 2011 18:45
Show Gist options
  • Save cbilson/1309783 to your computer and use it in GitHub Desktop.
Save cbilson/1309783 to your computer and use it in GitHub Desktop.
Was going to do this to recompile all our coffee scripts when they change, but found a better way
task Start-Coffee-Watcher -Description "when a coffee file changes recompile - for testing" {
Start-Job -Name "CoffeeWatcher" -ArgumentList "$srcDir\WebRole\scripts" -ScriptBlock {
param($scriptsFolder)
Write-Host "Watching $scriptsFolder"
$recompile = {
# TODO: Figure out how to recompile coffee scripts from command line with SassAndCoffee
}
$scriptsFileSystemWatcher = New-Object io.FileSystemWatcher -Property @{
Path = $scriptsFolder
Filter = '*.coffee'
IncludeSubdirectories = $true
NotifyFilter = [io.NotifyFilters]'FileName, LastWrite'
EnableRaisingEvents = $true
}
$onCreate = Register-ObjectEvent $scriptsFileSystemWatcher Created -SourceIdentifier FileCreated -Action {
& $recompile
}
$onChange = Register-ObjectEvent $scriptsFileSystemWatcher Changed -SourceIdentifier FileChanged -Action {
& $recompile
}
while ($true) { Sleep 100; Get-Event }
}
}
task Stop-Coffee-Watcher {
Stop-Job -Name "CoffeeWatcher"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment