forked from babashka/nbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bb.edn
81 lines (71 loc) · 3.35 KB
/
bb.edn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{:paths ["script"]
:tasks
{:requires ([babashka.fs :as fs]
[cheshire.core :as json]
[clojure.string :as str])
:init (do (def ^:dynamic *test* (= "true" (System/getenv "NBB_TESTS")))
(def windows? (-> (System/getProperty "os.name")
str/lower-case
(str/starts-with? "win")))
(when *test* (println "Tests are enabled.."))
(defn wrap-cmd [cmd]
(let [cmd (if *test*
(str (str/replace cmd
"-M" "-M:test")
" --config-merge shadow-tests.edn")
cmd)]
cmd)))
clean (fs/delete-tree "out")
compile (clojure (wrap-cmd "-M -m shadow.cljs.devtools.cli --force-spawn compile modules"))
dev {:doc "Run shadow in watch mode with tests enabled."
:task
(binding [*test* true]
(println "Starting shadow-cljs in watch mode.")
(println "Run node out/nbb_main.js to test nbb")
(println "Run bb run-tests to run the tests")
(apply clojure {:extra-env {"PATH" (str "script" fs/path-separator (System/getenv "PATH"))}}
(wrap-cmd "-M -m shadow.cljs.devtools.cli --force-spawn watch modules")
*command-line-args*))}
run-tests (shell "node out/nbb_tests.js")
release {:depends [clean]
:doc "Compiles release build."
:task
(do (apply clojure (wrap-cmd "-M -m shadow.cljs.devtools.cli --force-spawn release modules")
*command-line-args*)
(spit "out/nbb_core.js"
(clojure.string/replace (slurp "out/nbb_core.js") (re-pattern "self") "globalThis"))
(spit "out/nbb_main.js"
(str "#!/usr/bin/env node\n\n" (slurp "out/nbb_main.js")))
(shell "chmod +x out/nbb_main.js")
(run! fs/delete (fs/glob "out" "**.map")))}
run-integration-tests nbb-tests/main
publish {:doc "Bumps version, pushes tag and lets CI publish to npm."
:task
(do (shell "npm version patch")
(shell "git push --atomic origin main"
(str "v" (:version (json/parse-string (slurp "package.json") true)))))}
current-tag (->> (shell {:out :string} "git describe")
:out
str/trim
(re-matches (re-pattern "^v\\d+\\.\\d+\\.\\d+$")))
current-branch (->> (shell {:out :string} "git rev-parse --abbrev-ref HEAD")
:out
str/trim)
ci:is-release {:depends [current-tag current-branch]
:task (and current-tag (= "main" current-branch))}
ci:test {:doc "Runs all tests in CI."
:task (binding [*test* true]
(println "Testing optimizations :advanced")
(run 'clean)
(run 'release)
(run 'run-tests)
(run 'run-integration-tests))}
ci:publish {:doc "Publishes release build to npm"
:depends [ci:is-release]
:task
(if ci:is-release
(do (println "Releasing")
(binding [*test* false]
(run 'release)
(shell "npm publish")))
(println "Skipping release."))}}}