forked from ccd0/4chan-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
366 lines (276 loc) · 10.2 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
ifdef ComSpec
BIN := $(subst /,\,node_modules/.bin/)
RMDIR := -rmdir /s /q
RM := -del
CAT = type $(subst /,\,$1) > $(subst /,\,$2) 2>NUL
MKDIR = -mkdir $(subst /,\,$@)
QUOTE = $(patsubst %,"%",$1)
else
BIN := node_modules/.bin/
RMDIR := rm -rf
RM := rm -rf
CAT = cat $1 > $2
MKDIR = mkdir -p $@
QUOTE = $(patsubst %,'%',$1)
endif
CP = $(call CAT,$<,$@)
npgoals := clean cleanrel cleanweb cleanfull withtests wrapped archives $(foreach i,1 2 3 4,bump$(i)) tag tagcommit beta stable web update updatehard
ifneq "$(filter $(npgoals),$(MAKECMDGOALS))" ""
.NOTPARALLEL :
endif
coffee := $(BIN)coffee -c --no-header
coffee_deps := node_modules/coffee-script/package.json
template := node tools/template.js
template_deps := package.json tools/template.js node_modules/lodash.template/package.json node_modules/esprima/package.json
# read name meta_name meta_distBranch meta_uploadPath
$(eval $(shell node tools/pkgvars.js))
# must be read in when needed to prevent out-of-date version
version = $(shell node -p "JSON.parse(require('fs').readFileSync('version.json')).version")
source_directories := \
globals config css platform classes \
Archive Filtering General Images Linkification \
Menu Miscellaneous Monitoring Posting Quotelinks \
main
# remove extension when sorting so X.coffee comes before X.Y.coffee
sort_directory = \
$(subst !c,.coffee,$(subst !j,.js,$(sort $(subst .coffee,!c,$(subst .js,!j, \
$(wildcard src/$1/*.coffee src/$1/*.js))))))
sources := $(foreach d,$(source_directories),$(call sort_directory,$(d)))
uses_tests_enabled := \
src/classes/Post.coffee \
src/General/Build.Test.coffee \
src/Linkification/Linkify.coffee \
src/Miscellaneous/Keybinds.coffee \
src/Monitoring/Unread.coffee \
src/main/Main.coffee
imports_src/globals/globals.js := \
version.json
imports_src/css/CSS.js := \
node_modules/font-awesome/package.json
imports_src/Monitoring/Favicon.coffee := \
src/meta/icon128.png
imports = \
$(filter-out %.coffee %.js,$(wildcard $(dir $1)*.*)) \
$(wildcard $(basename $1)/*.*) \
$(if $(filter $(uses_tests_enabled),$1),.tests_enabled) \
$(imports_$1)
dests_platform = $(addprefix tmp/,$(subst /,-,$(patsubst src/%,%.js,$(subst platform,platform_$2,$1))))
dests_of = $(sort $(call dests_platform,$1,crx) $(call dests_platform,$1,userscript))
dests := $(foreach s,$(sources),$(call dests_of,$(s)))
updates := $(subst tmp/,.events/,$(dests))
pieces = \
tmp/LICENSE \
tmp/meta-newline.js \
tmp/meta-fbegin.js \
tmp/meta-newline.js \
tmp/declaration.js \
tmp/meta-newline.js \
$(foreach s,$(sources),$(call dests_platform,$(s),$1)) \
tmp/meta-fend.js
crx_contents := script.js eventPage.js icon16.png icon48.png icon128.png manifest.json
release := \
$(foreach f, \
$(foreach c,. -beta.,$(name)$(c)crx updates$(c)xml $(name)$(c)user.js $(name)$(c)meta.js) \
$(name)-noupdate.crx \
$(name)-noupdate.user.js \
$(name).zip \
,builds/$(f))
script := $(foreach f,$(filter-out %.crx %.zip,$(release)),test$(f)) $(foreach t,crx crx-beta crx-noupdate,$(foreach f,$(crx_contents),testbuilds/$(t)/$(f)))
crx := $(foreach f,$(filter %.crx %.zip,$(release)),test$(f))
default : script jshint install
all : default release
.events .events2 tmp testbuilds builds :
$(MKDIR)
ifneq "$(wildcard npm-shrinkwrap.json)" ""
.events/npm : npm-shrinkwrap.json | .events
npm install
echo -> $@
node_modules/%/package.json : .events/npm
$(if $(wildcard $@),,npm install && echo -> $<)
else
node_modules/%/package.json : package.json
npm install $(call QUOTE,$*@$(version_$*))
endif
.tests_enabled :
echo false> .tests_enabled
.events/declare : $(wildcard src/*/*.coffee) tools/declare.js | .events tmp
node tools/declare.js
echo -> $@
tmp/declaration.js : .events/declare
$(if $(wildcard $@),,node tools/declare.js && echo -> $<)
define check_source
$$(subst tmp/,.events/,$(call dests_of,$1)) : $1 $$(call imports,$1) | .events
echo -> $$(call QUOTE,$$@)
endef
$(foreach s,$(sources),$(eval $(call check_source,$(subst $$,$$$$,$(s)))))
.events/compile : $(updates) $(template_deps) $(coffee_deps) tools/chain.js
node tools/chain.js $(call QUOTE, \
$(subst .events/,tmp/, \
$(if $(filter-out $(updates),$?), \
$(updates), \
$(filter $(updates),$?) \
) \
) \
)
echo -> $@
$(dests) : .events/compile
$(if $(wildcard $@),, \
node tools/chain.js $(filter-out $(wildcard $(dests)),$(dests)) \
&& echo -> $< \
)
tmp/eventPage.js : src/meta/eventPage.coffee $(coffee_deps) | tmp
$(coffee) -o tmp src/meta/eventPage.coffee
tmp/LICENSE : LICENSE tools/newlinefix.js | tmp
node tools/newlinefix.js $< $@
tmp/meta-%.js : src/meta/%.js tools/newlinefix.js | tmp
node tools/newlinefix.js $< $@
define rules_channel
testbuilds/crx$1 :
$$(MKDIR)
testbuilds/crx$1/script.js : $$(call pieces,crx) | testbuilds/crx$1 .events/compile
@echo Concatenating: $$@
@$$(call CAT,$$(call QUOTE,$$(call pieces,crx)),$$@)
testbuilds/crx$1/eventPage.js : tmp/eventPage.js | testbuilds/crx$1
$$(CP)
testbuilds/crx$1/icon%.png : src/meta/icon%.png | testbuilds/crx$1
$$(CP)
testbuilds/crx$1/manifest.json : src/meta/manifest.json version.json $(template_deps) | testbuilds/crx$1
$(template) $$< $$@ type=crx channel=$1
testbuilds/updates$1.xml : src/meta/updates.xml version.json $(template_deps) | testbuilds/crx$1
$(template) $$< $$@ type=crx channel=$1
testbuilds/$(name)$1.crx.zip : \
$(foreach f,$(crx_contents),testbuilds/crx$1/$(f)) \
package.json version.json tools/zip-crx.js node_modules/jszip/package.json
node tools/zip-crx.js $1
testbuilds/$(name)$1.crx : testbuilds/$(name)$1.crx.zip package.json tools/sign.js node_modules/node-rsa/package.json
node tools/sign.js $1
testbuilds/$(name)$1.meta.js : src/meta/metadata.js src/meta/icon48.png version.json $(template_deps) | testbuilds
$(template) $$< $$@ type=userscript channel=$1
testbuilds/$(name)$1.user.js : testbuilds/$(name)$1.meta.js tmp/meta-newline.js $$(call pieces,userscript) | .events/compile
@echo Concatenating: $$@
@$$(call CAT,testbuilds/$(name)$1.meta.js tmp/meta-newline.js $$(call QUOTE,$$(call pieces,userscript)),$$@)
endef
$(eval $(call rules_channel,))
$(eval $(call rules_channel,-beta))
$(eval $(call rules_channel,-noupdate))
testbuilds/$(name).zip : testbuilds/$(name)-noupdate.crx.zip
$(CP)
builds/% : testbuilds/% | builds
$(CP)
test.html : README.md template.jst tools/markdown.js node_modules/markdown-it/package.json node_modules/markdown-it-anchor/package.json node_modules/lodash.template/package.json
node tools/markdown.js
index.html : test.html
$(CP)
tmp/.jshintrc : src/meta/jshint.json tmp/declaration.js src/globals/globals.js $(template_deps) | tmp
$(template) $< $@
.events/jshint : $(dests) tmp/.jshintrc node_modules/jshint/package.json
$(BIN)jshint $(call QUOTE, \
$(if $(filter-out $(dests),$?), \
$(dests), \
$(filter $(dests),$?) \
) \
)
echo -> $@
install.json :
echo {}> $@
.events/install : $(script) install.json tools/install.js | .events
node tools/install.js
echo -> $@
.events/CHANGELOG : version.json | .events
node tools/updcl.js
echo -> $@
dist :
git worktree add $@ $(meta_distBranch)
$(wildcard dist/* dist/*/*) : dist
@
distready : dist $(wildcard dist/* dist/*/*)
cd dist && git checkout $(meta_distBranch)
cd dist && git pull
.events2/push-git : .git/refs/heads .git/refs/tags $(wildcard .git/refs/heads/* .git/refs/tags/*) | .events2 distready
git push origin --tags -f
git push origin --all
echo -> $@
.events2/push-web : .git/refs/heads/$(meta_distBranch) | .events2 distready
git push web --tags -f
git push web $(meta_distBranch)
echo -> $@
.events2/push-store : .git/refs/tags/stable | .events2 distready node_modules/webstore-upload/package.json node_modules/request/package.json
node tools/webstore.js
echo -> $@
.SECONDARY :
.PHONY: default all distready script crx release jshint install push captchas $(npgoals)
script : $(script)
crx : $(crx)
release : $(release)
jshint : .events/jshint
install : .events/install
push : .events2/push-git .events2/push-web .events2/push-store
captchas : redirect.html $(template_deps)
$(template) redirect.html captchas.html url="$(url)"
scp captchas.html $(meta_uploadPath)
clean :
$(RMDIR) tmp testbuilds .events
$(RM) .tests_enabled
cleanrel : clean
$(RMDIR) builds
cleanweb :
$(RM) test.html captchas.html
cleanfull : clean cleanweb
$(RMDIR) .events2 dist node_modules
$(RM) npm-shrinkwrap.json
git worktree prune
withtests :
echo true> .tests_enabled
-$(MAKE)
echo false> .tests_enabled
wrapped : src/meta/npm-shrinkwrap.json
$(call CAT,$<,npm-shrinkwrap.json)
npm install
archives :
git fetch -n archives
git merge --no-commit -s ours archives/gh-pages
git show archives/gh-pages:archives.json > src/Archive/archives.json
-git commit -am 'Update archive list.'
$(foreach i,1 2 3 4,bump$(i)) :
$(MAKE) archives
node tools/bump.js $(subst bump,,$@)
$(MAKE) .events/CHANGELOG
$(MAKE) all
tag :
git add builds
$(MAKE) cleanrel
$(MAKE) wrapped
$(MAKE) all
git diff --quiet -- builds
$(MAKE) tagcommit
tagcommit :
git commit -am "Release $(meta_name) v$(version)."
git tag -a $(version) -m "$(meta_name) v$(version)."
beta : distready
git tag -af beta -m "$(meta_name) v$(version)."
cd dist && git merge --no-commit -s ours beta
cd dist && git checkout beta "builds/*-beta.*" img .gitignore .gitattributes
cd dist && git commit -am "Move $(meta_name) v$(version) to beta channel."
stable : distready
git push . HEAD:bstable
git tag -af stable -m "$(meta_name) v$(version)."
cd dist && git merge --no-commit -s ours stable
cd dist && git checkout stable "builds/$(name).*" builds/updates.xml
cd dist && git commit -am "Move $(meta_name) v$(version) to stable channel."
web : index.html distready
-git commit -am "Build web page."
cd dist && git merge --no-commit -s ours master
cd dist && git checkout master README.md index.html web.css img .gitignore .gitattributes
cd dist && git commit -am "Update web page."
update :
$(RM) npm-shrinkwrap.json
npm install --save-dev $(shell node tools/unpinned.js)
npm install
npm shrinkwrap --dev
$(call CAT,npm-shrinkwrap.json,src/meta/npm-shrinkwrap.json)
updatehard :
$(RM) npm-shrinkwrap.json
npm install --save-dev $(shell node tools/unpinned.js latest)
npm install
npm shrinkwrap --dev
$(call CAT,npm-shrinkwrap.json,src/meta/npm-shrinkwrap.json)