shake.hs 1.74 KB
Newer Older
Valentin Reis's avatar
Valentin Reis committed
1 2 3 4 5
{-|
Module      : shake.hs
Description : dev tasks.
Copyright   : (c) Valentin Reis, 2018
License     : MIT
6 7
Maintainer  : fre@freux.fr
-}
Valentin Reis's avatar
Valentin Reis committed
8

Valentin Reis's avatar
Valentin Reis committed
9
import           Development.Shake
10
import           Protolude
Valentin Reis's avatar
Valentin Reis committed
11 12
import           Development.Shake.FilePath
import           Control.Monad
13
import           System.Process.Typed
Valentin Reis's avatar
Valentin Reis committed
14

15
refactCommands =
Valentin Reis's avatar
Valentin Reis committed
16
  [ "OrganizeImports Argo.Stack"
17 18 19 20 21
  , "OrganizeImports Argo.Args"
  , "OrganizeImports Argo.Utils"
  , "OrganizeImports Argo.Types"
  ]

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
main = getArgs >>= deal
 where
  deal args
    | "ghcid" `elem` args = void $ startProcess $ proc
      "ghcid"
      [ "--command"
      , "cabal new-repl "
      <> " --ghc-options=-fno-code"
      <> " --ghc-options=-fno-break-on-exception"
      <> " --ghc-options=-fno-break-on-error"
      <> " --ghc-options=-v1 --ghc-options=-ferror-spans"
      , "--restart"
      , "argonix.cabal"
      , "--restart"
      , "default.nix"
      , "--restart"
      , "shell.nix"
      ]
    | otherwise = runshake
41

42 43
runshake = shakeArgs shakeOptions $ do
  phony "clean" $ removeFilesAfter "." ["README.md"]
44 45

  phony "ht-refact" htRefactAll
46 47
  phony "brittany"  brittany
  phony "codequality" $ htRefactAll >> brittany
Valentin Reis's avatar
Valentin Reis committed
48

49
  want ["README.md"]
Valentin Reis's avatar
Valentin Reis committed
50 51 52

  "README.md" %> \out -> do
    let template = ".README.md"
53
    need [template, "src/argotk.hs", "src/Argo/Stack.hs"]
Valentin Reis's avatar
Valentin Reis committed
54 55 56
    (Stdout panpipe) <- cmd "which panpipe"
    cmd_ "pandoc --filter"
         [take (length panpipe - 1) panpipe, template, "-o", out]
57 58 59 60 61 62 63 64 65 66 67 68 69
 where
  brittany =
    cmd_ Shell $ "brittany --write-mode inplace" <> " src/*.hs src/Argo/*hs"
  htRefactAll = for_ refactCommands htRefact
  htRefact x =
    cmd_ Shell
      $  "ht-refact "
      <> "-w `which hfswatch` "
      <> "--project-type cabal "
      <> ". "
      <> "-e \""
      <> x
      <> "\" || true"