-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.janet
69 lines (60 loc) · 2.35 KB
/
project.janet
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
(import path)
(defn s. [& args] (string ;args))
(declare-project
:name "rumination"
:description "A PWA Bible app written in React, with a minimal Janet server."
:author "Andrew Owen <yumaikas94@gmail.com>"
:url "https://github.com/yumaikas/rumination"
:dependencies ["path"
"https://github.com/yumaikas/janet-errs"
"https://github.com/swlkr/osprey"])
(def react-path (path/abspath (path/join "js" "vendor" "react")))
(defn- swap-react [& args]
(def [react react-dom] args)
(def curr-path (os/cwd))
(defer (os/cd curr-path)
(os/cd react-path)
(spit "../react.js" (slurp react))
(spit "../react.dom.js" (slurp react-dom))))
(defn- adjust-react []
(match (os/getenv "DEPLOY_ENV")
"production" (swap-react "react.production.js" "react.dom.production.js")
_ (swap-react "react.development.js" "react.dom.development.js")))
# TODO: Copy sw.js from js/ to public/js, rather than leaving it in public/js
(phony "bundle" []
(adjust-react)
(def app-path (path/join "js" "app.jsx"))
(def out-path (path/join "public" "js" "bundle.js"))
(def app-path (path/join "js" "app.jsx"))
(def esbuild (match (os/which)
:windows "esbuild.cmd"
_ "esbuild"))
(def bundleProc
(os/spawn [esbuild app-path "--bundle" "--minify" (s. "--outfile=" out-path)] :p))
(:wait bundleProc))
(var bundle-proc nil)
(phony "watch-bundle" []
(adjust-react)
(def app-path (path/join "js" "app.jsx"))
(def app-out-path (path/join "public" "js" "bundle.js"))
(def esbuild (match (os/which)
:windows "esbuild.cmd"
_ "esbuild"))
(set bundle-proc (os/spawn
[esbuild app-path
"--bundle"
#"--minify"
"--sourcemap"
"--watch"
(s. "--outfile=" app-out-path)]
:p)))
(phony "server" ["watch-bundle"]
(def server-proc (os/spawn ["janet" "serve.janet"] :p))
(prompt :done
(forever
(print `enter "X" to exit.` )
(def input (:read stdin :line))
(match (string/trim input)
"X" (return :done))))
(:kill server-proc)
(:kill bundle-proc))