-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
122 lines (89 loc) · 3.01 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
COMMITID=$(shell git rev-parse HEAD)
ROOT=cmsocial-web-build
DEST=$(ROOT)/$(COMMITID)
MAKEROOT=$(shell pwd)
SHELL := /bin/bash
PROD ?= 0
ONLINE ?= $(PROD)
ifeq ($(ONLINE), 1)
CDNFLAGS=
else
CDNFLAGS=--use-local
endif
ifeq ($(PROD), 1)
STRIPDEBUG=sed '/<!-- *start *debug *-->/,/<!-- *end *debug *-->/d'
UGLIFY=node_modules/.bin/uglifyjs
BABEL=npx babel --
else
STRIPDEBUG=cat
UGLIFY=cat
BABEL=npx babel --
endif
WEBDIRS=$(shell find cmsocial-web -type d)
TMPDIRS=$(patsubst cmsocial-web%,tmp%,$(WEBDIRS))
DESTDIRS=$(patsubst cmsocial-web%,$(DEST)%,$(WEBDIRS))
JS=$(shell echo cmsocial-web/scripts/app.js; find cmsocial-web -type f -name '*.js' -and -not -name 'app.js' | sort)
LESS=$(shell find cmsocial-web -type f -name '*.less')
HTML=$(shell find cmsocial-web -type f -name '*.html')
DESTHTML=$(patsubst cmsocial-web/%,$(DEST)/%,$(HTML))
CSS=$(patsubst cmsocial-web/%.less,tmp/%.css,$(LESS))
TMPJS=$(patsubst cmsocial-web/%.js,tmp/%.js,$(JS))
.PHONY: all dirs other-files config-files js-deps clean distclean jshint bsync
all: $(DESTHTML) $(ROOT)/index.html $(DEST)/styles/main.css $(DEST)/scripts/app.js js-deps other-files config-files | dirs
other-files: $(DEST)/robots.txt $(DEST)/images/loader.gif $(ROOT)/__init__.py
config-files: $(ROOT)/custom_images $(ROOT)/favicon.ico $(DEST)/views/footer.html $(DEST)/views/homepage-training.html $(DEST)/views/homepage-digit.html
ifeq ($(ONLINE), 1)
js-deps:
else
js-deps: $(ROOT)/node_modules
endif
config/%: | config/%.sample
cp $| $@
node_modules: package.json
npm install
touch node_modules
dirs: $(DEST) tmp $(ROOT)/__init__.py
$(DEST): cmsocial-web
mkdir -p $(DESTDIRS)
touch $(DEST)
$(ROOT)/__init__.py: cmsocial-web/__init__.py
cp cmsocial-web/__init__.py $@
tmp: cmsocial-web
mkdir -p $(TMPDIRS)
cp cmsocial-web/.babelrc tmp
touch tmp
$(ROOT)/custom_images: config/custom_images | $(DEST)
cp -r $^ $@
$(ROOT)/favicon.ico: config/favicon.ico | $(DEST)
cp $^ $@
$(DEST)/views/footer.html: config/footer.html | $(DEST)
cp $< $@
$(DEST)/views/homepage-training.html: config/homepage-training.html | $(DEST)
cp $< $@
$(DEST)/views/homepage-digit.html: config/homepage-digit.html | $(DEST)
cp $< $@
$(DEST)/%.html: cmsocial-web/%.html | $(DEST)
cat $< | $(STRIPDEBUG) > $@
$(ROOT)/index.html: cmsocial-web/index.html node_modules | $(DEST)
node_modules/.bin/cdnify $(CDNFLAGS) $< | $(STRIPDEBUG) > $@
sed "s/COMMIT_ID_HERE/$(COMMITID)/" -i $@
rm $(DEST)/index.html
$(DEST)/styles/main.css: $(CSS)
cat $^ > $@
tmp/%.css: cmsocial-web/%.less node_modules | tmp
node_modules/.bin/lessc $< $@
$(DEST)/scripts/app.js: $(TMPJS) | node_modules
${BABEL} $^ | sed "s/COMMIT_ID_HERE/$(COMMITID)/" | ${UGLIFY} > $@
tmp/%.js: cmsocial-web/%.js | tmp
cat $< | $(STRIPDEBUG) > $@
$(ROOT)/node_modules: node_modules
ln -s ../node_modules $@
touch $(ROOT)/node_modules
$(DEST)/%: cmsocial-web/%
cp $^ $@
clean:
rm -rf tmp/ $(ROOT)/ build/ cmsocial.egg-info/ dist/
distclean: clean
rm -rf node_modules
jshint:
./node_modules/.bin/jshint --reporter=node_modules/jshint-stylish $(JS)