-
Notifications
You must be signed in to change notification settings - Fork 1
/
Justfile
229 lines (149 loc) · 5 KB
/
Justfile
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
export NODE_OPTIONS := "--no-warnings"
# Variables
# ---------
config := "default"
dist_dir := "./build"
fission_cmd := "fission"
node_bin := "./node_modules/.bin"
src_dir := "./src"
workbox_config := "workbox.config.cjs"
# Tasks
# -----
@default: dev-build
just dev-server & just watch
# ---
@apply-config: insert-variables
echo "🎛 Applying config \`config/{{config}}.json\`"
{{node_bin}}/mustache config/{{config}}.json {{dist_dir}}/index.html > {{dist_dir}}/index.applied.html
rm {{dist_dir}}/index.html
mv {{dist_dir}}/index.applied.html {{dist_dir}}/index.html
@clean:
rm -rf {{dist_dir}}
mkdir -p {{dist_dir}}
@dev-build: clean css-large translate-schemas elm html js images static apply-config service-worker
echo {{config}} &> /dev/null
@dev-server:
echo "🤵 Putting up a server for ya"
echo "http://localhost:8001"
simple-http-server --port 8001 --try-file build/index.html --cors --index --nocache --silent -- build
@html:
echo "📄 Copying static HTML files"
mkdir -p {{dist_dir}}/ipfs/
mkdir -p {{dist_dir}}/reset/
cp {{src_dir}}/Static/Html/Main.html {{dist_dir}}/index.html
cp {{src_dir}}/Static/Html/Exchange.html {{dist_dir}}/exchange.html
cp {{src_dir}}/Static/Html/Reset.html {{dist_dir}}/reset/index.html
@images:
echo "🌄 Copying images"
npx copy-fission-images {{dist_dir}}/images/
rsync -r {{src_dir}}/Static/Images/ {{dist_dir}}/images/
insert-variables:
#!/usr/bin/env node
console.log("🎛 Inserting variables")
const fs = require("fs")
// Version
const html = fs.readFileSync("{{dist_dir}}/index.html", { encoding: "utf8" })
const work = fs.readFileSync("{{workbox_config}}", { encoding: "utf8" })
const timestamp = Math.floor(Date.now() / 1000).toString()
fs.writeFileSync("{{dist_dir}}/index.html", html.replace("UNIX_TIMESTAMP", timestamp))
fs.writeFileSync("{{dist_dir}}/{{workbox_config}}", work.replace("UNIX_TIMESTAMP", timestamp))
@install-deps:
echo "🦕 Downloading dependencies"
npm install
@js:
echo "📄 Copying JS files"
{{node_bin}}/esbuild \
--bundle \
--format=esm \
--outfile={{dist_dir}}/index.min.js \
{{src_dir}}/Javascript/main.ts
{{node_bin}}/esbuild \
--bundle \
--format=esm \
--outfile={{dist_dir}}/reset.min.js \
{{src_dir}}/Javascript/reset.ts
@minify-js:
echo "⚙️ Minifying Javascript Files"
{{node_bin}}/terser-dir \
{{dist_dir}} \
--each --extension .js \
--pattern "*.js, !**/*.min.js" \
--pseparator ", " \
--output {{dist_dir}} \
-- --compress --mangle
@production-build:
just config=production build
@staging-build:
just config=default build
@build:
just config={{config}} clean css-large translate-schemas production-elm html css-small js images static minify-js
just config={{config}} apply-config production-service-worker
@static:
echo "⛰ Copying some more static files"
rsync -r {{src_dir}}/Static/Favicons/ {{dist_dir}}/
rsync -r {{src_dir}}/Static/Manifests/ {{dist_dir}}/
rsync -r {{src_dir}}/Static/Themes/ {{dist_dir}}/themes/
npx copy-fission-fonts {{dist_dir}}/fonts/ --woff2
@translate-schemas:
echo "🔮 Translating schemas into Elm code"
./node_modules/quicktype/dist/cli/index.js -s schema -o src/Library/Theme.elm --module Theme src/Schemas/Dawn/Theme.json
elm-format src/Library/Theme.elm --yes
# CSS
# ---
dist_css := dist_dir + "/stylesheet.css"
main_css := src_dir + "/Css/Main.css"
@css-large:
echo "⚙️ Compiling CSS"
npx etc {{main_css}} \
--config tailwind.config.js \
--elm-path src/Library/Tailwind.elm \
--output {{dist_css}} \
--post-plugin-before postcss-import
echo ""
@css-small:
echo "⚙️ Compiling Minified CSS"
NODE_ENV=production npx etc {{main_css}} \
--config tailwind.config.js \
--output {{dist_css}} \
--purge-content={{dist_elm}} \
--purge-content={{dist_dir}}/index.html \
--purge-content={{dist_dir}}/reset/index.html \
--post-plugin-before postcss-import
echo ""
# Elm
# ---
dist_elm := dist_dir + "/elm.js"
main_elm := src_dir + "/Application/Main.elm"
@elm:
echo "🌳 Compiling Elm"
elm make {{main_elm}} --output={{dist_elm}} --debug
@production-elm:
echo "🌳 Compiling Elm"
elm make {{main_elm}} --output={{dist_elm}} --optimize
# Service worker
# --------------
@service-worker:
echo "⚙️ Generating service worker"
NODE_ENV=development npx workbox generateSW {{dist_dir}}/{{workbox_config}}
@production-service-worker:
echo "⚙️ Generating service worker"
NODE_ENV=production npx workbox generateSW {{dist_dir}}/{{workbox_config}}
# Watch
# -----
@watch:
echo "👀 Watching for changes"
just watch-css & \
just watch-elm & \
just watch-html & \
just watch-js & \
just watch-schemas
@watch-css:
watchexec -p -w . -f "**/*.css" -f "*/tailwind.config.js" -i build -- just css-large
@watch-elm:
watchexec -p -w src -e elm -- just elm
@watch-html:
watchexec -p -w src -e html -- just html apply-config
@watch-js:
watchexec -p -w src -e js,ts -- just js
@watch-schemas:
watchexec -p -w src/Schemas -e json -- just translate-schemas