2020-10-28 01:29:44 +03:00
|
|
|
import Development.Shake
|
|
|
|
import Development.Shake.Command
|
|
|
|
import Development.Shake.FilePath
|
|
|
|
import Development.Shake.Util
|
|
|
|
|
|
|
|
main :: IO ()
|
2020-10-28 13:49:28 +03:00
|
|
|
main =
|
2020-10-29 06:34:44 +03:00
|
|
|
shakeArgs
|
|
|
|
shakeOptions
|
|
|
|
{ shakeFiles = "_build",
|
2020-10-29 17:09:03 +03:00
|
|
|
shakeThreads = 0,
|
|
|
|
shakeChange = ChangeModtimeAndDigest,
|
|
|
|
-- we ignore a lot of generated/downloaded dependency files so
|
|
|
|
-- that the output of `shake --lint-fsatrace` is usable. There
|
|
|
|
-- are probably a few untracked dependencies due to these ignores
|
|
|
|
-- (in particular relying on scripts in `node_modules`) but the
|
|
|
|
-- additional benefits are marginal compared to the effort required
|
|
|
|
-- to get everything 100% buttoned down. Long term, it'd be better to
|
|
|
|
-- move node dependencies into nix (either by using proper packages
|
|
|
|
-- where available or npm2nix where not.)
|
2020-10-29 07:46:36 +03:00
|
|
|
shakeLintIgnore =
|
|
|
|
[ "node_modules/**/*",
|
|
|
|
"elm-stuff/**/*",
|
|
|
|
"styleguide-app/elm-stuff/**/*"
|
2020-10-29 17:09:03 +03:00
|
|
|
]
|
2020-10-29 06:34:44 +03:00
|
|
|
}
|
|
|
|
$ do
|
2020-10-29 07:51:48 +03:00
|
|
|
-- phonies. These provide a nice public API for using shake (`shake
|
|
|
|
-- clean`, `shake test`, etc.)
|
|
|
|
phony "clean" $ do
|
|
|
|
removeFilesAfter "elm-stuff" ["//*"]
|
|
|
|
removeFilesAfter "log" ["//*"]
|
|
|
|
removeFilesAfter "node_modules" ["//*"]
|
|
|
|
removeFilesAfter "public" ["//*"]
|
|
|
|
removeFilesAfter "styleguide-app" ["elm.js", "bundle.js", "elm-stuff"]
|
|
|
|
|
2020-10-29 08:02:20 +03:00
|
|
|
phony "public" $ need ["log/public.txt"]
|
|
|
|
|
2020-10-29 07:58:47 +03:00
|
|
|
phony "test" $ do
|
|
|
|
need
|
|
|
|
[ "log/npm-install.txt",
|
|
|
|
"tests/elm-verify-examples.json",
|
|
|
|
"log/elm-verify-examples.txt",
|
|
|
|
"log/elm-test.txt",
|
|
|
|
"log/axe-report.txt",
|
|
|
|
"log/percy-tests.txt",
|
2020-10-29 08:03:59 +03:00
|
|
|
"log/deprecated-imports-report.txt",
|
|
|
|
"log/check-exposed.txt",
|
|
|
|
"log/format.txt",
|
|
|
|
"log/documentation.json"
|
2020-10-29 07:58:47 +03:00
|
|
|
]
|
|
|
|
|
2020-10-29 08:03:59 +03:00
|
|
|
phony "ci" $ do need ["test", "public"]
|
|
|
|
|
2020-10-29 06:34:44 +03:00
|
|
|
-- things that should be kept under version control
|
|
|
|
"tests/elm-verify-examples.json" %> \out -> do
|
|
|
|
need ["elm.json"]
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "jq" "--indent" "4" ["{ root: \"../src\", tests: .[\"exposed-modules\"] }"] "elm.json")
|
2020-10-29 06:34:44 +03:00
|
|
|
|
2020-10-29 07:13:24 +03:00
|
|
|
"script/deprecated-imports.csv" %> \out -> do
|
|
|
|
elmFiles <- getDirectoryFiles "." ["src/**/*.elm", "tests/**/*.elm"]
|
|
|
|
need (["elm.json", "script/deprecated-imports.py"] ++ elmFiles)
|
|
|
|
cmd_ "script/deprecated-imports.py" "--imports-file" out "update"
|
|
|
|
|
2020-10-29 06:34:44 +03:00
|
|
|
-- temporary files, used to produce CI reports
|
2020-10-29 07:58:47 +03:00
|
|
|
"log/elm-test.txt" %> \out -> do
|
|
|
|
elmFiles <- getDirectoryFiles "." ["tests/**/*.elm"]
|
|
|
|
-- I'm not sure why elm-test needs package.json, but fsatracing it
|
|
|
|
-- reveals the dep, so in it goes!
|
|
|
|
need (["package.json", "elm.json"] ++ elmFiles)
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "elm-test")
|
2020-10-29 07:58:47 +03:00
|
|
|
|
|
|
|
"log/elm-verify-examples.txt" %> \out -> do
|
|
|
|
elmFiles <- getDirectoryFiles "." ["src/**/*.elm"]
|
|
|
|
need (["tests/elm-verify-examples.json"] ++ elmFiles)
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "elm-verify-examples")
|
2020-10-29 07:58:47 +03:00
|
|
|
|
2020-10-29 06:34:44 +03:00
|
|
|
"log/format.txt" %> \out -> do
|
|
|
|
let placesToLook = ["src", "tests", "styleguide-app"]
|
|
|
|
elmFiles <- getDirectoryFiles "." (map (\place -> place </> "**" </> "*.elm") placesToLook)
|
|
|
|
need elmFiles
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "elm-format" "--validate" placesToLook)
|
2020-10-29 06:34:44 +03:00
|
|
|
|
|
|
|
"log/percy-tests.txt" %> \out -> do
|
|
|
|
percyToken <- getEnv "PERCY_TOKEN"
|
|
|
|
case percyToken of
|
|
|
|
Nothing -> do
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "echo" "Skipped running Percy tests, PERCY_TOKEN not set.")
|
2020-10-29 06:34:44 +03:00
|
|
|
Just _ -> do
|
|
|
|
need ["log/npm-install.txt"]
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "script/percy-tests.js")
|
2020-10-29 06:34:44 +03:00
|
|
|
|
|
|
|
"log/axe-report.json" %> \out -> do
|
|
|
|
need ["log/npm-install.txt", "script/run-axe.sh", "script/axe-puppeteer.js"]
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "script/run-axe.sh")
|
2020-10-29 06:34:44 +03:00
|
|
|
|
|
|
|
"log/axe-report.txt" %> \out -> do
|
|
|
|
need ["log/axe-report.json", "script/format-axe-report.sh", "script/axe-report.jq"]
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "script/format-axe-report.sh" "log/axe-report.json")
|
2020-10-29 06:34:44 +03:00
|
|
|
|
2020-10-29 07:11:06 +03:00
|
|
|
"log/deprecated-imports-report.txt" %> \out -> do
|
|
|
|
elmFiles <- getDirectoryFiles "." ["src/**/*.elm", "tests/**/*.elm"]
|
|
|
|
need (["elm.json", "script/deprecated-imports.py"] ++ elmFiles)
|
|
|
|
-- still need to do something when this fails (e.g. run "check" instead of "report")
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "script/deprecated-imports.py" "report")
|
2020-10-29 07:11:06 +03:00
|
|
|
|
2020-10-29 07:12:26 +03:00
|
|
|
"log/check-exposed.txt" %> \out -> do
|
|
|
|
elmFiles <- getDirectoryFiles "." ["src/**/*.elm"]
|
|
|
|
need (["elm.json", "script/check-exposed.py"] ++ elmFiles)
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "script/check-exposed.py")
|
2020-10-29 07:12:26 +03:00
|
|
|
|
2020-10-29 07:32:28 +03:00
|
|
|
"log/documentation.json" %> \out -> do
|
|
|
|
elmFiles <- getDirectoryFiles "." ["src/**/*.elm"]
|
|
|
|
need elmFiles
|
|
|
|
cmd_ "elm" "make" "--docs" out
|
|
|
|
|
2020-10-29 07:49:57 +03:00
|
|
|
"public/bundle.js" %> \out -> do
|
2020-10-29 07:35:50 +03:00
|
|
|
libJsFiles <- getDirectoryFiles "." ["lib/**/*.js"]
|
|
|
|
need (["package.json", "lib/index.js", "styleguide-app/manifest.js", "log/npm-install.txt"] ++ libJsFiles)
|
|
|
|
cmd_ "./node_modules/.bin/browserify" "--entry" "styleguide-app/manifest.js" "--outfile" out
|
|
|
|
|
2020-10-29 07:49:57 +03:00
|
|
|
"public/elm.js" %> \out -> do
|
2020-10-29 07:46:36 +03:00
|
|
|
elmSources <- getDirectoryFiles "." ["styleguide-app/**/*.elm", "src/**/*.elm"]
|
|
|
|
need elmSources
|
|
|
|
cmd_ (Cwd "styleguide-app") "elm" "make" "Main.elm" "--output" (".." </> out)
|
|
|
|
|
2020-10-29 07:49:57 +03:00
|
|
|
"public/**/*" %> \out ->
|
|
|
|
copyFileChanged (replaceDirectory1 out "styleguide-app") out
|
|
|
|
|
|
|
|
"log/public.txt" %> \out -> do
|
|
|
|
styleguideAssets <- getDirectoryFiles ("styleguide-app" </> "assets") ["**/*"]
|
|
|
|
need
|
|
|
|
( ["public/index.html", "public/elm.js", "public/bundle.js"]
|
|
|
|
++ map (("public" </> "assets") </>) styleguideAssets
|
|
|
|
)
|
|
|
|
writeFileChanged out "build styleguide app successfully"
|
|
|
|
|
2020-10-29 06:34:44 +03:00
|
|
|
-- dev deps we get dynamically instead of from Nix (frowny face)
|
|
|
|
"log/npm-install.txt" %> \out -> do
|
2020-10-29 07:10:55 +03:00
|
|
|
-- npm looks in some unrelated files for whatever reason. We mark
|
|
|
|
-- them as used here to avoid getting linter errors.
|
2020-10-29 17:04:00 +03:00
|
|
|
gitHeads <- getDirectoryFiles "." [".git/refs/heads/*"]
|
|
|
|
needed (["README.md", ".git/HEAD"] ++ gitHeads)
|
2020-10-29 07:10:55 +03:00
|
|
|
|
|
|
|
-- now that we've satisfied the linter, let's build.
|
2020-10-29 06:34:44 +03:00
|
|
|
need ["package.json", "package-lock.json"]
|
2020-10-30 18:03:54 +03:00
|
|
|
writeStdoutIfChanged out (cmd "npm" "install")
|
|
|
|
|
|
|
|
writeStdoutIfChanged :: FilePath -> Action (Stdout String) -> Action ()
|
|
|
|
writeStdoutIfChanged out action = do
|
|
|
|
(Stdout stdout) <- action
|
|
|
|
writeFileChanged out stdout
|