-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
130 lines (90 loc) · 4.34 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
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
NODE?=node
ARTICLES_SOURCES=$(wildcard private/articles/*.yaml)
ARTICLES_HTML=$(patsubst private/articles/%.yaml,public/articles/%.html,$(ARTICLES_SOURCES))
ARTICLES_HTML_TOUCH=$(patsubst private/articles/%.yaml,public/articles/%.html.touch,$(ARTICLES_SOURCES))
ARTICLES_PRIVATE_JSON=$(patsubst private/articles/%.yaml,private/json/%.json,$(ARTICLES_SOURCES))
ARTICLES_PRIVATE_JSON_TOUCH=$(patsubst private/articles/%.yaml,private/json/%.json.touch,$(ARTICLES_SOURCES))
ARTICLES_JSON=$(patsubst private/articles/%.yaml,public/json/%.json,$(ARTICLES_SOURCES))
ARTICLES_JSON_TOUCH=$(patsubst private/articles/%.yaml,public/json/%.json.touch,$(ARTICLES_SOURCES))
CSS_SOURCES=$(wildcard private/css/[!_]*.css)
CSS_OBJ=$(patsubst private/css/%.css,public/css/%.css,$(CSS_SOURCES))
RENDERER_SOURCES=$(wildcard renderer/*) private/Config.ts
NODE_SOURCES=$(wildcard node/*)
STATIC_SOURCES=$(RENDERER_SOURCES) $(NODE_SOURCES) package-lock.json
DYNAMIC_SOURCES=$(RENDERER_SOURCES) package-lock.json
DIST_DEPS=render.mjs schema.json
all: dist articles articles_json
dist: css js $(DIST_DEPS)
schema.json: tsconfig.static.json renderer/Article.ts
@printf SCHEMA\\t$@\\n
@$(NODE) generate-schema.js $< Article $@
render.mjs: rollup.static.config.mjs $(STATIC_SOURCES)
@printf JSS\\t$@\\n
@./node_modules/.bin/rollup -c $<
.SUFFIXES:
# html
# all targeted html files should be newer than this file to allow for cleaning up non-targeted files
public/articles/.guard:
@touch $@
public/articles/%.html: private/articles/%.yaml $(DIST_DEPS) | public/articles/.guard
@printf HTML\\t$@\\n
@$(NODE) render.mjs $< $@
# this forced static pattern ensures that all targeted html files are newer than guard
$(ARTICLES_HTML_TOUCH): public/articles/%.html.touch: private/articles/%.yaml $(DIST_DEPS) | public/articles/.guard
@$(NODE) render.mjs --touch --no-validate $(patsubst public/articles/%.html.touch,private/articles/%.yaml,$@) $(patsubst public/articles/%.html.touch,public/articles/%.html,$@)
@touch -c -r $(patsubst public/articles/%.html.touch,public/articles/%.html,$@) $(patsubst public/articles/%.html.touch,public/%.html,$@) 2>/dev/null || true
public/%.html: public/articles/%.html
@printf INDEX\\t$@\\n
@cp -f $< $@
# cleanup non-targeted files
articles: $(ARTICLES_HTML) $(ARTICLES_HTML_TOUCH) public/index.html public/404.html
@find public/articles/ -type f -name '*.html' \! -newer public/articles/.guard -printf 'DELETE\t%p\n' -delete
@$(RM) public/articles/.guard public/articles/*.touch
# json
private/json/.guard:
@touch $@
private/json/%.json: private/articles/%.yaml $(DIST_DEPS) | private/json/.guard
@printf JSON\\t$@\\n
@$(NODE) render.mjs --format json --private $< $@
$(ARTICLES_PRIVATE_JSON_TOUCH): private/json/%.json.touch: | private/json/.guard
@touch -c $(patsubst private/json/%.json.touch,private/json/%.json,$@)
public/json/.guard:
@touch $@
public/json/%.json: private/articles/%.yaml $(DIST_DEPS) | public/json/.guard
@printf JSON\\t$@\\n
@$(NODE) render.mjs --format json $< $@
$(ARTICLES_JSON_TOUCH): public/json/%.json.touch: | public/json/.guard
@touch -c $(patsubst public/json/%.json.touch,public/json/%.json,$@)
articles_json: $(ARTICLES_PRIVATE_JSON) $(ARTICLES_PRIVATE_JSON_TOUCH) $(ARTICLES_JSON) $(ARTICLES_JSON_TOUCH)
@find private/json/ -type f -name '*.json' \! -newer private/json/.guard -printf 'DELETE\t%p\n' -delete
@$(RM) private/json/.guard private/json/*.touch
@find public/json/ -type f -name '*.json' \! -newer public/json/.guard -printf 'DELETE\t%p\n' -delete
@$(RM) public/json/.guard public/json/*.touch
# css/js
public/css/%.css: private/css/%.css
@printf CSS\\t$@\\n
@$(NODE) cleancss.js $< -o $@
css: $(CSS_OBJ)
public/js/dynamic.js: rollup.dynamic.config.mjs $(DYNAMIC_SOURCES)
@printf JSD\\t$@\\n
@./node_modules/.bin/rollup -c $<
@./node_modules/.bin/terser -o $@ -c -m -- $@
js: public/js/dynamic.js
# referenced deps
rollup.static.config.mjs: tsconfig.static.json
@touch $@
tsconfig.static.json: tsconfig.base.json
@touch $@
rollup.dynamic.config.mjs: tsconfig.dynamic.json
@touch $@
tsconfig.dynamic.json: tsconfig.base.json
@touch $@
# clean
clean:
$(RM) $(ARTICLES_HTML) $(ARTICLES_JSON)
distclean:
$(RM) $(CSS_OBJ) public/js/dynamic.js $(DIST_DEPS)
cleanall: clean distclean
$(RM) public/articles/*.html public/css/*.css public/js/*.js public/json/*.json
.PHONY: clean distclean cleanall
-include private/Makefile.*