-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
314 lines (223 loc) · 7.36 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
#!/usr/bin/env make
#
# A Desinax theme.
# See organisation on GitHub: https://github.com/desinax
# ------------------------------------------------------------------------
#
# General stuff, reusable for all Makefiles.
#
# Detect OS
OS = $(shell uname -s)
# Defaults
ECHO = echo
# Make adjustments based on OS
ifneq (, $(findstring CYGWIN, $(OS)))
ECHO = /bin/echo -e
endif
# Colors and helptext
NO_COLOR = \033[0m
ACTION = \033[32;01m
OK_COLOR = \033[32;01m
ERROR_COLOR = \033[31;01m
WARN_COLOR = \033[33;01m
# Print out colored action message
ACTION_MESSAGE = $(ECHO) "$(ACTION)---> $(1)$(NO_COLOR)"
# Which makefile am I in?
WHERE-AM-I = "$(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))"
THIS_MAKEFILE := $(call WHERE-AM-I)
# Echo some nice helptext based on the target comment
HELPTEXT = $(call ACTION_MESSAGE, $(shell egrep "^\# target: $(1) " $(THIS_MAKEFILE) | sed "s/\# target: $(1)[ ]*-[ ]* / /g"))
# Check version and path to command and display on one line
CHECK_VERSION = printf "%-15s %-10s %s\n" "$(shell basename $(1))" "`$(1) --version $(2)`" "`which $(1)`"
# Get current working directory, it may not exist as environment variable.
PWD = $(shell pwd)
# target: help - Displays help.
.PHONY: help
help:
@$(call HELPTEXT,$@)
@sed '/^$$/q' $(THIS_MAKEFILE) | tail +3 | sed 's/#\s*//g'
@$(ECHO) "Usage:"
@$(ECHO) " make [target] ..."
@$(ECHO) "target:"
@egrep "^# target:" $(THIS_MAKEFILE) | sed 's/# target: / /g'
# target: tag-prepare - Prepare to tag new version.
.PHONY: tag-prepare
tag-prepare:
@$(call HELPTEXT,$@)
grep "^v." REVISION.md | head -1
[ ! -f package.json ] || grep version package.json
git tag
git status
#gps && gps --tags
#npm publish
# ------------------------------------------------------------------------
#
# Specifics for this project.
#
# Add local bin path for test tools
LESSC = node_modules/.bin/lessc
ESLINT = node_modules/.bin/eslint
BUILD = build
HTDOCS = htdocs
SOURCE = src
LESS_SOURCES = $(shell find $(SOURCE) -maxdepth 1 -name '*.less')
LESS_CSS = $(LESS_SOURCES:$(SOURCE)/%.less=$(BUILD)/less/css/%.css)
LESS_MIN_CSS = $(LESS_SOURCES:$(SOURCE)/%.less=$(BUILD)/less/css/%.min.css)
LESS_LINT = $(LESS_SOURCES:$(SOURCE)/%.less=$(BUILD)/less/lint/%.less)
LESS_MODULES = $(shell find $(SOURCE) -mindepth 2 -name '*.less')
#SCSS_SOURCES := $(shell find $(SOURCEDIR) -name '*.scss')
#SCSS_INCLUDE_PATH = $(SOURCEDIR)
DESINAX_MODULES = $(shell cd $(SOURCE) && find @desinax -mindepth 1 -maxdepth 1 -type d)
# ------------------------------------------------------------------------
#
# Basic rules.
#
# target: prepare - Prepare the build directory.
.PHONY: prepare
prepare:
@$(call HELPTEXT,$@)
@[ -d $(BUILD)/less/css ] || install -d $(BUILD)/less/css
@[ -d $(BUILD)/less/lint ] || install -d $(BUILD)/less/lint
# target: build - Build the stylesheets.
.PHONY: build
build: prepare less
@$(call HELPTEXT,$@)
# target: clean - Clean from generated build files.
.PHONY: clean
clean:
@$(call HELPTEXT,$@)
rm -rf $(BUILD)
# target: clean-all - Clean all installed utilities.
.PHONY: clean-all
clean-all: clean
@$(call HELPTEXT,$@)
rm -rf node_modules
# target: install - Install modules and dev environment.
.PHONY: install
install: npm-install
@$(call HELPTEXT,$@)
# target: check - Check versions of tools.
.PHONY: check
check:
@$(call HELPTEXT,$@)
@$(call CHECK_VERSION, $(LESSC))
@$(call CHECK_VERSION, $(ESLINT))
npm list --depth=0
# target: update - Update codebase.
.PHONY: update
update: npm-update modules-install styleguide-update
@$(call HELPTEXT,$@)
# target: upgrade - Upgrade codebase.
.PHONY: upgrade
upgrade: npm-upgrade modules-install styleguide-update
@$(call HELPTEXT,$@)
# target: test - Execute all tests.
.PHONY: test
test: less-lint
@$(call HELPTEXT,$@)
# ------------------------------------------------------------------------
#
# External modules install
#
# target: modules-desinax-install - Install Desinax modules into less/sass/js-dir.
.PHONY: modules-desinax-install
modules-desinax-install:
@$(call HELPTEXT,$@)
@cd node_modules; \
for module in $(DESINAX_MODULES) ; do \
$(call ACTION_MESSAGE, $$module); \
[ ! -d $$module ] \
&& $(ECHO) "Module not installed, skipping it." \
&& continue; \
install -d ../src/$$module; \
rsync -av $$module/src/ ../src/$$module/; \
rsync -a $$module/README.md ../src/$$module/; \
rsync -a $$module/REVISION.md ../src/$$module/; \
rsync -a $$module/LICENSE ../src/$$module/; \
done
# target: modules-install - Install external modules.
.PHONY: modules-install
modules-install: modules-desinax-install
@$(call HELPTEXT,$@)
# Normalize.css
npm install normalize.css
rsync -av --exclude package.json node_modules/normalize.css src/
rsync -av src/normalize.css/normalize.css src/normalize.css/normalize.less
# Font Awesome
npm install @fortawesome/fontawesome-free
rsync -av --exclude package.json node_modules/@fortawesome/fontawesome-free src/@fortawesome/
# ------------------------------------------------------------------------
#
# Validation according to CSS-styleguide.
# @TODO Clean up this rule, is it active?
#
# target: styleguide-update - Update styleguide validation files.
.PHONY: styleguide-update
styleguide-update:
@$(call HELPTEXT,$@)
rsync -av node_modules/@desinax/css-styleguide/.stylelintrc.json .
# ------------------------------------------------------------------------
#
# LESS.
#
# target: less - Compile the LESS stylesheet(s).
less: prepare less-css less-min-css
@$(call HELPTEXT,$@)
@rsync -a $(BUILD)/less/css htdocs/
less-css: $(LESS_CSS)
less-min-css: $(LESS_MIN_CSS)
less-lint: $(LESS_LINT)
$(BUILD)/less/css/%.css: $(SOURCE)/%.less
@$(call ACTION_MESSAGE,$< -> $@)
$(LESSC) $< $@
$(BUILD)/less/css/%.min.css: $(SOURCE)/%.less
@$(call ACTION_MESSAGE,$< -> $@)
$(LESSC) --clean-css $< $@
$(BUILD)/less/lint/%.less: $(SOURCE)/%.less
@$(call ACTION_MESSAGE,$< -> $@)
$(LESSC) --lint $< $@
$(LESS_SOURCES): $(LESS_MODULES)
touch $@
# ------------------------------------------------------------------------
#
# SCSS.
#
# ------------------------------------------------------------------------
#
# CSS.
#
# target: lint-css - Lint the CSS stylesheet(s).
.PHONY: lint-css
lint-css: less
@$(call HELPTEXT,$@)
$(LESSC) --include-path=$(LESS_INCLUDE_PATH) --lint $(LESS_SOURCE) > build/lint/style.less
- $(ESLINT) build/css/style.css > build/lint/style.css
ls -l build/lint/
# ------------------------------------------------------------------------
#
# JS.
#
# ------------------------------------------------------------------------
#
# NPM.
#
# target: npm-install - Install npm from package.json.
.PHONY: npm-install
npm-install:
@$(call HELPTEXT,$@)
npm install
# target: npm-update - Update npm using package.json.
.PHONY: npm-update
npm-update:
@$(call HELPTEXT,$@)
npm update
# target: npm-upgrade - Upgrade npm using package.json.
.PHONY: npm-upgrade
npm-upgrade:
@$(call HELPTEXT,$@)
npm upgrade
# target: npm-outdated - Check for outdated packages.
.PHONY: npm-outdated
npm-outdated:
@$(call HELPTEXT,$@)
npm outdated --depth=0