shake.hs 1.64 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 13
import           Development.Shake.FilePath
import           Control.Monad

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

Valentin Reis's avatar
Valentin Reis committed
21
main = shakeArgs shakeOptions $ do
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  phony "clean" $ removeFilesAfter "." ["README.md"]

  phony "ghcid"
    $  cmd_ Shell
    $  "while true; do "
    <> "nix-shell "
    <> "--run 'ghcid "
    <> "--command \"cabal repl --ghc-options=-fno-code "
    <> "--ghc-options=-fno-break-on-exception "
    <> "--ghc-options=-fno-break-on-error "
    <> "--ghc-options=-v1 --ghc-options=-ferror-spans "
    <> "--ghc-options=-j\" "
    <> "--restart=argotk.cabal "
    <> "--restart=default.nix"
    <> "--restart=shell.nix'"
    <> "; done"

  phony "ht-refact" htRefactAll

  phony "brittany" brittany

Valentin Reis's avatar
Valentin Reis committed
43
  phony "codequality" $  htRefactAll >> brittany
Valentin Reis's avatar
Valentin Reis committed
44

45
  want ["README.md"]
Valentin Reis's avatar
Valentin Reis committed
46 47 48

  "README.md" %> \out -> do
    let template = ".README.md"
49
    need [template, "src/argotk.hs", "src/Argo/Stack.hs"]
Valentin Reis's avatar
Valentin Reis committed
50 51 52
    (Stdout panpipe) <- cmd "which panpipe"
    cmd_ "pandoc --filter"
         [take (length panpipe - 1) panpipe, template, "-o", out]
53 54 55 56 57 58 59 60 61 62 63 64 65
 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"