Skip to content

Instantly share code, notes, and snippets.

@ndmitchell
Created April 7, 2014 08:36
Show Gist options
  • Save ndmitchell/10016729 to your computer and use it in GitHub Desktop.
Save ndmitchell/10016729 to your computer and use it in GitHub Desktop.
Shake .min.js build system
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
module Temp where
import Development.Shake
import Development.Shake.Classes
import Development.Shake.FilePath
import Data.Char
newtype JsFiles = JsFiles () deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
main = shakeArgs shakeOptions $ do
want ["tester/bundle.jsz"]
"//*.min.js" *> \out -> do
putNormal "Running minimizer"
let src = dropExtension out -<.> "js"
writeFile' out . filter (not . isSpace) =<< readFile' src
jsFiles <- addOracle $ \(JsFiles _) ->
fmap (filter $ \x -> takeExtensions x == ".js") $ getDirectoryFiles "" ["tester//*.js"]
"//*.jsz" *> \out -> do
putNormal "Running compressor"
js <- jsFiles $ JsFiles ()
let mjs = map (-<.> "min.js") js
need mjs
writeFile' out . unlines =<< mapM readFile' mjs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment