noredink-ui/Shakefile.hs

183 lines
8.1 KiB
Haskell
Raw Normal View History

2020-10-28 01:29:44 +03:00
import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util
import qualified GHC.IO.Encoding
import qualified System.IO
2020-10-28 01:29:44 +03:00
main :: IO ()
main = do
-- Work around `hGetContents: invalid argument (invalid byte sequence)` bug on
-- Nix: https://github.com/dhall-lang/dhall-haskell/issues/865
GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
2020-10-29 06:34:44 +03:00
shakeArgs
shakeOptions
{ shakeFiles = "_build",
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/**/*",
2023-02-14 01:33:45 +03:00
"component-catalog/elm-stuff/**/*"
]
2020-10-29 06:34:44 +03:00
}
$ do
2020-12-04 05:39:45 +03:00
want ["test"]
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" ["//*"]
2023-02-14 01:33:45 +03:00
removeFilesAfter "component-catalog" ["elm.js", "bundle.js", "elm-stuff"]
2020-10-29 07:51:48 +03:00
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",
2023-02-14 01:33:45 +03:00
"log/elm-test-component-catalog.txt",
2022-03-15 20:29:20 +03:00
"log/elm-review.txt",
2023-02-14 01:33:45 +03:00
"log/elm-review-component-catalog.txt",
2022-04-14 20:41:10 +03:00
"log/puppeteer-tests.txt",
2020-11-22 15:01:35 +03:00
"log/forbidden-imports-report.txt",
"log/check-exposed.txt",
"log/format.txt",
"log/documentation.json"
2020-10-29 07:58:47 +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:32:07 +03:00
cmd (WithStdout True) (FileStdout out) "jq" "--indent" "4" ["{ root: \"../src\", tests: .[\"exposed-modules\"] }"] "elm.json"
2020-10-29 06:34:44 +03:00
"deprecated-modules.csv" %> \out -> do
need ["elm.json", "script/deprecated-modules-csv.py"]
cmd (WithStdout True) (FileStdout out) "script/deprecated-modules-csv.py"
2020-11-22 15:01:35 +03:00
"forbidden-imports.toml" %> \out -> do
-- we always want to consume our own published deprecated modules list
-- so that we're not presenting outdated stuff in the Component Catalog! This
-- file can change separately from the CSV, but should always have at
-- least the deprecated modules in it.
need ["deprecated-modules.csv"]
cmd "elm-forbid-import" "forbid-from-csv" "deprecated-modules.csv"
2020-10-29 07:13:24 +03:00
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:32:07 +03:00
cmd (WithStdout True) (FileStdout out) "elm-test"
2020-10-29 07:58:47 +03:00
2023-02-14 01:33:45 +03:00
"log/elm-test-component-catalog.txt" %> \out -> do
elmFiles <- getDirectoryFiles "." ["component-catalog/tests/**/*.elm"]
need (["package.json", "component-catalog/elm.json"] ++ elmFiles)
cmd (Cwd "component-catalog") (WithStdout True) (FileStdout out) "elm-test"
2022-04-12 21:18:09 +03:00
2022-03-15 20:29:20 +03:00
"log/elm-review.txt" %> \out -> do
elmFiles <- getDirectoryFiles "." ["src/**/*.elm", "tests/**/*.elm"]
2022-03-15 20:29:20 +03:00
need (["package.json", "elm.json"] ++ elmFiles)
cmd (WithStdout True) (FileStdout out) "elm-review"
2023-02-14 01:33:45 +03:00
"log/elm-review-component-catalog.txt" %> \out -> do
elmFiles <- getDirectoryFiles "." ["component-catalog/**/*.elm"]
2023-02-14 01:33:45 +03:00
need (["package.json", "component-catalog/elm.json"] ++ elmFiles)
cmd (Cwd "component-catalog") (WithStdout True) (FileStdout out) "elm-review"
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:32:07 +03:00
cmd (WithStdout True) (FileStdout out) "elm-verify-examples"
2020-10-29 07:58:47 +03:00
2020-10-29 06:34:44 +03:00
"log/format.txt" %> \out -> do
need ["log/elm-format.txt", "log/prettier.txt"]
2022-05-26 17:37:20 +03:00
writeFileChanged out "formatting checks passed"
"log/elm-format.txt" %> \out -> do
let placesToLook = ["src", "tests", "component-catalog"]
2020-10-29 06:34:44 +03:00
elmFiles <- getDirectoryFiles "." (map (\place -> place </> "**" </> "*.elm") placesToLook)
need elmFiles
2020-10-30 18:32:07 +03:00
cmd (WithStdout True) (FileStdout out) "elm-format" "--validate" placesToLook
2020-10-29 06:34:44 +03:00
"log/prettier.txt" %> \out -> do
(Stdout trackedFilesOut) <- cmd "git" "ls-files"
let trackedFiles = lines trackedFilesOut
let jsFiles = filter (\name -> takeExtension name == ".js") trackedFiles
need ("log/npm-install.txt" : jsFiles)
cmd (WithStdout True) (FileStdout out) "./node_modules/.bin/prettier" "--check" jsFiles
2022-04-14 20:41:10 +03:00
"log/puppeteer-tests.txt" %> \out -> do
2023-05-03 22:25:39 +03:00
-- `getEnv` looks like a no-op, but it actually makes Shake pay
-- attention to this variable so that if it changes this command will be
-- re-run with the new token.
getEnv "PERCY_TOKEN"
need ["log/npm-install.txt", "log/public.txt"]
cmd (WithStdout True) (FileStdout out) "script/puppeteer-tests.sh"
2020-10-29 06:34:44 +03:00
2020-11-22 15:01:35 +03:00
"log/forbidden-imports-report.txt" %> \out -> do
need ["forbidden-imports.toml"]
2020-10-29 07:11:06 +03:00
elmFiles <- getDirectoryFiles "." ["src/**/*.elm", "tests/**/*.elm"]
2020-11-22 15:01:35 +03:00
need (["forbidden-imports.toml"] ++ elmFiles)
cmd (WithStdout True) (FileStdout out) "elm-forbid-import" "check"
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:32:07 +03:00
cmd (WithStdout True) (FileStdout out) "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"]
2023-02-14 01:33:45 +03:00
need (["package.json", "lib/index.js", "component-catalog/manifest.js", "log/npm-install.txt"] ++ libJsFiles)
cmd_ "./node_modules/.bin/browserify" "--entry" "component-catalog/manifest.js" "--outfile" out
2020-10-29 07:35:50 +03:00
2020-10-29 07:49:57 +03:00
"public/elm.js" %> \out -> do
elmSources <- getDirectoryFiles "." ["component-catalog/src/**/*.elm", "src/**/*.elm"]
2020-10-29 07:46:36 +03:00
need elmSources
cmd_ (Cwd "component-catalog") "elm" "make" "src/Main.elm" "--output" (".." </> out)
2020-10-29 07:46:36 +03:00
2022-03-29 00:34:52 +03:00
"public/package.json" %> \out -> do
copyFileChanged "elm.json" out
"public/application.json" %> \out -> do
2023-02-14 01:33:45 +03:00
copyFileChanged "component-catalog/elm.json" out
2022-03-29 00:34:52 +03:00
2020-10-29 07:49:57 +03:00
"public/**/*" %> \out ->
2023-02-14 01:33:45 +03:00
copyFileChanged (replaceDirectory1 out "component-catalog") out
2020-10-29 07:49:57 +03:00
"log/public.txt" %> \out -> do
2023-02-14 21:58:06 +03:00
need (["public/index.html", "public/favicon.svg", "public/elm.js", "public/bundle.js", "public/package.json", "public/application.json"])
2023-02-14 01:33:45 +03:00
writeFileChanged out "built component-catalog app successfully"
2020-10-29 07:49:57 +03:00
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.
gitHeads <- getDirectoryFiles "." [".git/refs/heads/*"]
2020-10-31 00:24:26 +03:00
trackRead (["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:32:07 +03:00
cmd (WithStdout True) (FileStdout out) (FileStderr out) "npm" "install"