Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thecodejunkie/1384038 to your computer and use it in GitHub Desktop.
Save thecodejunkie/1384038 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
# Wrapped Graeme's version up into a function so it can be installed with install-module
# Also changed so it invoked coffee.exe directly, you need Coffee for Windows in your PATH for it to work
# https://github.com/alisey/CoffeeScript-Compiler-for-Windows
function watch
{
$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.exe -c $file.FullName
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment