shake.hs 1.87 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 15 16 17 18 19 20 21 22 23 24 25 26 27
refactCommands =
  [ "OrganizeExtensions Argo.Args"
  , "OrganizeExtensions Argo.Utils"
  , "OrganizeExtensions Argo.Types"
  , "OrganizeImports Argo.Stack"
  , "OrganizeImports Argo.Args"
  , "OrganizeImports Argo.Utils"
  , "OrganizeImports Argo.Types"
  , "GenerateExports Argo.Stack"
  , "GenerateExports Argo.Args"
  , "GenerateExports Argo.Utils"
  , "GenerateExports Argo.Types"
  ]

Valentin Reis's avatar
Valentin Reis committed
28
main = shakeArgs shakeOptions $ do
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  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

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

52
  want ["README.md"]
Valentin Reis's avatar
Valentin Reis committed
53 54 55

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