Skip to content

Instantly share code, notes, and snippets.

@GraemeF
Forked from jfromaniello/continous-qunit.ps1
Created October 8, 2011 22:19
Show Gist options
  • Save GraemeF/1272979 to your computer and use it in GitHub Desktop.
Save GraemeF/1272979 to your computer and use it in GitHub Desktop.
Continuously watches for .coffee file changes in a folder (and subfolders), and runs the CoffeeScript compiler against them
# watch a file changes in the current directory,
# compile when a .coffee file is changed or renamed
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = get-location
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $false
$watcher.NotifyFilter = [System.IO.NotifyFilters]::LastWrite -bor [System.IO.NotifyFilters]::FileName
while($TRUE){
$result = $watcher.WaitForChanged([System.IO.WatcherChangeTypes]::Changed -bor [System.IO.WatcherChangeTypes]::Renamed -bOr [System.IO.WatcherChangeTypes]::Created, 1000);
if($result.TimedOut){
continue;
}
write-host "Modified" $result.Name
$file = Get-Item $result.Name
if($file.Extension -eq ".coffee"){
write-host "Compiling" $result.Name
coffee.cmd -c $file.FullName
}
}
@GraemeF
Copy link
Author

GraemeF commented Oct 8, 2011

Note: coffee.cmd runs https://github.com/alisey/CoffeeScript-Compiler-for-Windows on my box but this works equally well with Node.exe if you'd like to use it to run the CoffeeScript compiler.

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