forked from quantifiedcode/quantifiedcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (94 loc) · 3.63 KB
/
Makefile
File metadata and controls
120 lines (94 loc) · 3.63 KB
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
BUILD_FINAL_DIR=build
BUILD_BACKUP_DIR=lastBuild
SOURCE_DIR=src
STATIC_FILES=
MAIN_FRONTEND_PATH=../../../frontend
ES6_SRC_FILES = $(shell find $(SOURCE_DIR) -name "*.es6")
ES6_FILES = $(subst $(SOURCE_DIR),$(BUILD_TMP_DIR)/static,$(ES6_SRC_FILES))
JS_FILES = $(subst .es6,.js,$(ES6_FILES))
export PATH := ./node_modules/.bin:$(MAIN_FRONTEND_PATH)/node_modules/.bin:$(PATH)
export NODE_PATH := $(MAIN_FRONTEND_PATH)/node_modules:$(NODE_PATH)
ifeq ($(ENVIRONMENT),development)
BUILD_TMP_DIR=build
BUILD_ENVIRONMENT=development
else
BUILD_TMP_DIR=newBuild
BUILD_ENVIRONMENT=production
endif
$(info Build dir: $(BUILD_TMP_DIR))
all: $(BUILD_ENVIRONMENT)
clean:
rm -rf $(BUILD_FINAL_DIR)
rm -rf $(BUILD_TMP_DIR)
rm -rf $(BUILD_BACKUP_DIR)
production: backup assets scripts bower babel static-files scss optimize-css optimize move
development: assets scripts babel static-files scss watch
optimize: copy-assets optimize-rjs
copy-assets:
mkdir -p $(BUILD_TMP_DIR)/optimized/static
cp -rf $(BUILD_TMP_DIR)/static/assets $(BUILD_TMP_DIR)/optimized/static
optimize-rjs:
r.js -o $(BUILD_TMP_DIR)/static/js/build.js
#we copy require.js (so that we can include it)
cp $(BUILD_TMP_DIR)/static/bower_components/requirejs/require.js \
$(BUILD_TMP_DIR)/optimized/static/js/require.min.js
scripts:
mkdir -p $(BUILD_TMP_DIR)/static/js;
rsync -rupE $(SOURCE_DIR)/js --include="*.js" $(BUILD_TMP_DIR)/static
bower:
mkdir -p $(BUILD_TMP_DIR)/static
bower install --config.directory=$(BUILD_TMP_DIR)/static/bower_components
#compiles all ES6 files to JS (this is faster than compiling each file individually)
babel:
babel $(SOURCE_DIR)/js -x ".es6" --out-dir $(BUILD_TMP_DIR)/static/js --source-maps inline
assets: $(BUILD_DIR)
mkdir -p $(BUILD_TMP_DIR)
rsync -rupE $(SOURCE_DIR)/assets $(BUILD_TMP_DIR)/static
#used in watch, as it is faster
es6-files: $(JS_FILES)
#compiles ES6 into JS files using babel (for es6-files rule)
%.js : %.es6
babel $< --out-file $@ --source-maps inline
scss: $(SOURCE_DIR)/scss/main.scss
mkdir -p $(BUILD_TMP_DIR)/static/css
scss $(SOURCE_DIR)/scss/main.scss $(BUILD_TMP_DIR)/static/css/main.css
optimize-css: $(BUILD_TMP_DIR)/static/css/main.css
mkdir -p $(BUILD_TMP_DIR)/optimized/static/css
#we generate the output in the same directory, as relative imports won't work otherwise...
cleancss -o $(BUILD_TMP_DIR)/static/css/main.min.css \
$(BUILD_TMP_DIR)/static/css/main.css
#we move the file to another directory afterwards...
mv $(BUILD_TMP_DIR)/static/css/main.min.css \
$(BUILD_TMP_DIR)/optimized/static/css/main.min.css
#we copy dependent resources (fonts) to the optimized directory
rsync -am --include="*.woff" --include="*.eot" --include="*.woff2" --include="*/" \
--exclude="*" -a $(BUILD_TMP_DIR)/static/bower_components \
$(BUILD_TMP_DIR)/optimized/static
static-files: $(STATIC_FILES)
$(STATIC_FILES):
cp -p $(SOURCE_DIR)/$@ $(BUILD_TMP_DIR)/static/$@
watch:
@which inotifywait || (echo "Please install inotifywait";exit 2)
@while true ; do \
inotifywait -r src -e create,delete,move,modify || break; \
$(MAKE) assets scripts es6-files static-files scss || break;\
done
backup:
@if [ ! -e $(BUILD_TMP_DIR) ]; then \
mkdir $(BUILD_TMP_DIR); \
fi;
move:
@if [ -e $(BUILD_BACKUP_DIR) ]; then \
rm -rf $(BUILD_BACKUP_DIR); \
fi;
if [ -e $(BUILD_FINAL_DIR) -a ! $(BUILD_TMP_DIR) = $(BUILD_FINAL_DIR) ]; then \
mv $(BUILD_FINAL_DIR) $(BUILD_BACKUP_DIR); \
fi;
if [ ! $(BUILD_TMP_DIR) = $(BUILD_FINAL_DIR) ]; then \
mv $(BUILD_TMP_DIR) $(BUILD_FINAL_DIR); \
fi;
rollback:
@if [ -e $(BUILD_BACKUP_DIR) ]; then \
rm -rf $(BUILD_FINAL_DIR); \
mv $(BUILD_BACKUP_DIR) $(BUILD_FINAL_DIR); \
fi;