Created
July 12, 2012 14:46
-
-
Save brianium/3098580 to your computer and use it in GitHub Desktop.
A simple F# program to concat js given an input and output file (provided sprockets exists on the system)
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
open System; | |
open System.IO; | |
open Microsoft.FSharp.Collections; | |
open System.Diagnostics; | |
let projectDirectory = Directory.GetCurrentDirectory() | |
let args = Environment.GetCommandLineArgs(); | |
let watcher = new FileSystemWatcher(projectDirectory) | |
let exec procName procArgs = | |
let procInfo = new ProcessStartInfo(procName, procArgs) | |
procInfo.CreateNoWindow <- true | |
procInfo.WindowStyle <- ProcessWindowStyle.Hidden | |
Process.Start(procInfo) | |
let path file = projectDirectory + (string)Path.DirectorySeparatorChar + file | |
let concat (fargs:FileSystemEventArgs) = | |
if fargs.FullPath <> path args.[1] && fargs.FullPath <> path args.[2] then | |
exec "sprocketize" ("-I " + projectDirectory + " " + path args.[1] + " > " + path args.[2]) |> ignore | |
watcher.Changed.Add(concat) | |
watcher.Filter <- "*.js" | |
//read from console | |
let readlines = Seq.initInfinite (fun _ -> Console.ReadLine()) | |
let readline line = if line = "q" then Some(line) else None | |
//run it | |
watcher.EnableRaisingEvents <- true; | |
Console.WriteLine(@"Press 'q' to quit listening") | |
Seq.pick readline readlines |> ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment