module Development.Shake.Elm ( elmMake
                             ) where

import           Development.Shake

-- | Rules for calling @elm-make@.
elmMake :: [FilePath] -- ^ Elm source files
        -> [FilePath] -- ^ Extra source files to be tracked
        -> Bool -- ^ Toggle optimized build product
        -> FilePattern -- ^ Build output
        -> Rules ()
elmMake sources extras opt fp =
    fp %> \out -> do
        need ("elm.json" : (sources ++ extras))
        let go = if opt then ("--optimize":) else id
        command [] "elm" ("make" : go ("--output" : out : sources))