PowerShell Script to Compile-on-Modify

Source Code on GitHub 

A script, directly modified from this StackOverflow response, to watch a source code folder and then run a compiler on on modified files. To successfully modify this script, I needed to understand the .NET object IO.FileSystemWatcher, PowerShell’s Register-ObjectEvent, and PowerShell’s ScriptBlock concept, which are akin to anonymous functions or closures.

The script is written to compile Sass files for web design, but could work with any language’s command line compiler. The reason needed this script is because the –watch feature of Sass wasn’t behaving properly on Windows 10, and none of the solutions I found fixed the issues, so I scripted a solution to watch it myself. It’s better to create a solution than to give up!