-
-
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
This file contains hidden or 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
# 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