Skip to content

Instantly share code, notes, and snippets.

@brianium
Created July 12, 2012 14:46
Show Gist options
  • Save brianium/3098580 to your computer and use it in GitHub Desktop.
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)
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