forked from prism-break/prism-break
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
127 lines (92 loc) · 4.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
# make build the entire site (all languages)
# make init just install NPM dependencies
# make en build just the English edition (replace 'en' with 'fr' for French, etc.)
# make clean destroy built files
# make reset destroy built files and build all languages from scratch
# make watch_css watches for stylus (CSS) edits and compiles it
#----------------------------------------------------------------------
# CONFIGURATION
#----------------------------------------------------------------------
# Collect list of languages based on available locale files
LANGUAGES := $(notdir $(basename $(wildcard source/locales/*.json)))
# Collect list of static assets that get copied over
ASSETS := $(notdir $(wildcard source/assets/*))
# Mark all rules that don’t actually check whether they need building
.PHONY: default test init reset all $(LANGUAGES) assets css html html_% clean watch watch_css sync localize_%
# Turn on expansion so we can reference target patterns in our dependencies list
.SECONDEXPANSION:
# Don’t delete intermediary targets after building
.SECONDARY:
# Figure out the absolute path to the directory where this Makefile is
BASE := $(shell cd "$(shell dirname $(lastword $(MAKEFILE_LIST)))" && pwd)
# Prepend the local NPM bin dir to the path for the scope of this Makefile
export PATH := $(BASE)/node_modules/.bin:$(PATH)
# Use yarn if the system has it, otherwise npm
NPM_HANDLER ?= $(shell hash yarn && echo yarn || echo npm)
# This is a hack for the ‘watch’ targets later on. It has to be
# early to nullify any targets that might otherwise run, but in
# the end allows extra parameters to be passed on to the next make
ifeq (watch,$(firstword $(MAKECMDGOALS)))
WATCH_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(WATCH_ARGS):;@:)
endif
#----------------------------------------------------------------------
# COMMANDS
#----------------------------------------------------------------------
# Explicitly set the default target to do everything that isn’t already done
default: | init assets all public ;
# Run anything that needs doing post-checkout to make this buildable
init: node_modules ;
# Use building English language as a check to see if everything works
test: en ;
# Start fresh and rebuild everything
reset: | clean default ;
# Targets to build all the dynamically generated stuff for all languages
all: css html ;
# Targets for rebuilding only single language and only what isn’t already done
$(LANGUAGES): | init assets css html_$$@ public ;
#----------------------------------------------------------------------
# CONVENIENCE ALIASES
#----------------------------------------------------------------------
assets: $(foreach ASSET,$(ASSETS),public/assets/$(ASSET)) ;
css: public/assets/css/screen.css ;
html: $(foreach LANGUAGE,$(LANGUAGES),html_$(LANGUAGE)) ;
html_%: public/%/index.html ;
public: public/.htaccess ;
#----------------------------------------------------------------------
# FUNCTIONS
#----------------------------------------------------------------------
node_modules: package.json
$(NPM_HANDLER) install
touch node_modules
# Copy fixed assets from the source tree (if newer files exist)
public/assets/%: source/assets/% $$(shell find source/assets/$$* -type f)
mkdir -p $(dir $@)
rsync -r $</ $@/
# Rebuild stylesheet if any of the input templates change
public/assets/css/%.css: source/stylesheets/%.styl $(shell git ls-files *.styl)
mkdir -p $(dir $@)
stylus -c -u nib < $< > $@
# Use script to rebuild index if index is older than any files with this locale in the name
public/%/index.html: source/functions/build/site-%.ls $$(shell git ls-files | grep '\b$$*\b')
lsc $<
clean:
rm -rf public/*
public/.htaccess: source/dotfiles/.htaccess
mkdir -p $(dir $@)
cp $< $@
# Localizations
localize_%:
lsc ./source/functions/find-missing-localizations.ls $*
#----------------------------------------------------------------------
# CONVENIENCE FUNCTIONS
#----------------------------------------------------------------------
watch:
git ls-files | entr -p make $(WATCH_ARGS)
# Rebuild CSS live on input changes
watch_css:
stylus -c -w source/stylesheets/screen.styl -u nib -o public/assets/css/
# copy ./public to another repository and commit changes
sync:
rsync -azru --delete --stats public/ ../prism-break-static/public/
(cd ../prism-break-static; git add -A; git commit -m 'regenerate'; git push)