forked from SharzyL/pastebin-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
68 lines (52 loc) · 1.94 KB
/
Makefile
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
CONF = config.json
BUILD_DIR = dist
JS_DIR = src
JS_LOCK = yarn.lock
target_html_files = index.html tos.html
# script path
html_renderer = scripts/render.js
md2html = scripts/md2html.sh
deploy_static = scripts/deploy-static.sh
# stub directories to record when files are uploaded
DEPLOY_DIR = dist/deploy
PREVIEW_DIR = dist/preview
source_js_files = $(wildcard $(JS_DIR)/*.js)
target_js_file = dist/worker.js
all_html = $(addprefix $(BUILD_DIR)/,$(target_html_files))
all_html_deploy = $(addprefix $(DEPLOY_DIR)/, $(target_html_files))
all_html_preview = $(addprefix $(PREVIEW_DIR)/, $(target_html_files))
js_deploy = $(addprefix $(DEPLOY_DIR)/, $(target_js_file))
js_preview = $(addprefix $(PREVIEW_DIR)/, $(target_js_file))
html: $(all_html)
test:
./test/test.sh
deploy: $(all_html_deploy) $(js_deploy)
preview: $(all_html_preview) $(js_preview)
clean:
rm -f $(all_html) $(all_html_deploy) $(all_html_preview) $(js_deploy) $(js_preview)
$(BUILD_DIR)/tos.html.liquid: frontend/tos.md $(md2html)
$(md2html) $< $@ "Terms and Conditions"
$(BUILD_DIR)/index.html.liquid: frontend/index.html frontend/index.js frontend/style.css
@# no generation needed, simply copy
cp $< $@
# convert liquid template to html file
$(all_html): $(BUILD_DIR)/%.html: $(BUILD_DIR)/%.html.liquid $(CONF) $(html_renderer)
node $(html_renderer) -c $(CONF) -o $@ $<
@# remove indents to reduce size
sed -E -i 's/^\s+//g' $@
# deploy html file to Cloudflare
$(all_html_deploy): $(DEPLOY_DIR)/%.html: $(BUILD_DIR)/%.html $(deploy_static)
$(deploy_static) $<
@mkdir -p $(dir $@)
@touch $@
# deploy html file to Cloudflare preview
$(all_html_preview): $(PREVIEW_DIR)/%.html: $(BUILD_DIR)/%.html $(deploy_static)
$(deploy_static) --preview $^
@mkdir -p $(dir $@)
@touch $@
# because wrangler will always build before publish, we cannot do cache here
$(js_deploy): $(source_js_files) $(JS_LOCK)
yarn wrangler publish
@mkdir -p $(dir $@)
@touch $@
.PHONY: html test deploy preview clean