forked from babashka/nbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb.edn
104 lines (92 loc) · 4.22 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
{:paths ["script"]
:tasks
{:requires ([babashka.fs :as fs]
[cheshire.core :as json]
[clojure.edn :as edn]
[clojure.pprint :as pp]
[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")))
(def features (some-> (System/getenv "NBB_FEATURES")
(str/split (re-pattern ","))))
(when *test* (println "Tests are enabled.."))
(defn wrap-cmd [cmd]
(let [cmd (if features
(format "-Sdeps '%s' %s"
{:deps
(into {}
(map (fn [f]
[(symbol (str f "/deps"))
{:local/root (str "features/" f)}])
features))}
cmd)
cmd)
cmd (if *test*
(str (str/replace cmd
"-M" "-M:test")
" --config-merge shadow-tests.edn")
cmd)]
(if features
(apply str cmd
(map (fn [f] (format " --config-merge features/%s/shadow-cljs.edn" f))
features))
cmd))))
clean (fs/delete-tree "lib")
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 lib/nbb_main.js to test nbb")
(println "Run bb run-tests to run the tests")
(apply clojure (wrap-cmd "-M -m shadow.cljs.devtools.cli --force-spawn watch modules")
*command-line-args*))}
run-tests (shell "node lib/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 "lib/nbb_core.js"
(clojure.string/replace (slurp "lib/nbb_core.js") (re-pattern "self") "globalThis"))
(spit "lib/nbb_main.js"
(str "#!/usr/bin/env node\n\n" (slurp "lib/nbb_main.js")))
(shell "chmod +x lib/nbb_main.js")
(run! fs/delete (fs/glob "lib" "**.map")))}
run-integration-tests nbb-tests/main
run-feature-integration-tests nbb-feature-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)
(when features
(run 'run-feature-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."))}}}