-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
387 lines (293 loc) · 13.3 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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
## ------------------------------------------------------------------------ ##
## Build Project ##
## ------------------------------------------------------------------------ ##
.SILENT:
.EXPORT_ALL_VARIABLES:
# .IGNORE:
.ONESHELL:
SHELL = /bin/sh
THIS_FILE = $(lastword $(MAKEFILE_LIST))
TO_NULL = 2>&1 >/dev/null
# $(info [THIS_FILE:$(THIS_FILE)])
## ------------------------------------------------------------------------ ##
$(shell [ -f NODE_ENV ] || cp -prfu config/.NODE_ENV ./NODE_ENV);
$(shell [ -f .bowerrc ] || cp -prfu config/.bowerrc ./);
$(shell [ -f .npmrc ] || cp -prfu config/.npmrc ./);
## ------------------------------------------------------------------------ ##
APP_NAME := mp3web
APP_PREF := mp3web_
APP_SLOG := MP3WEB
APP_LOGO := ./assets/BANNER
APP_REPO := $(shell git ls-remote --get-url)
$(shell [ -f ./VERSION ] || echo "0.0.0" > VERSION)
$(shell [ -f ./.env ] || echo "NODE_ENV=production" >> .env)
CODE_VERSION := $(strip $(shell cat ./VERSION))
GIT_BRANCH := $(shell git rev-list --remove-empty --max-count=1 --reverse --branches)
GIT_COMMIT := $(shell git rev-list --remove-empty --max-count=1 --reverse --remotes --date-order)
# DT = $(shell date +'%Y-%m-%dT%H:%M:%S.%s %Z')
DT = $(shell date +'%T')
TS = $(shell date +'%s')
DZ = $(shell date +'%Y%m%dT%H%M%S%:z')
WD := $(shell pwd -P)
BD := $(WD)/bin
DATE = $(shell date +'%Y%m%d%H%M%S')
BUILD_FILE = BUILD-$(CODE_VERSION)
BUILD_CNTR = $(strip $(shell [ -f "$(BUILD_FILE)" ] && cat $(BUILD_FILE) || echo 0))
BUILD_CNTR := $(shell echo $$(( $(BUILD_CNTR) + 1 )))
BUILD_FULL := $(shell date +'%Y-%m-%dT%H:%M:%S%:z')
BUILD_DATE := $(shell date +'%Y-%m-%d')
BUILD_TIME := $(shell date +'%H:%M:%S')
BUILD_YEAR := $(shell date +'%Y')
BUILD_HASH := $(shell echo "$(BUILD_FULL)" | md5sum | cut -b -4)
## ------------------------------------------------------------------------ ##
## Colors definition
## ------------------------------------------------------------------------ ##
include $(BD)/Colors
## ------------------------------------------------------------------------ ##
FMP := ffmpeg -hide_banner -y -loglevel "error" -stats
DAT = [$(Gray)$(DT)$(NC)]
BEGIN = $(Yellow)$(On_Blue)BEGIN TARGET$(NC)
DONE = $(Yellow)$(On_Blue)DONE TARGET$(NC)
FINE = $(Yellow)$(On_Green)COMPLETED GOAL$(NC)
TARG = [$(Orange) $@ $(NC)]
THIS = [$(Red) $(THIS_FILE) $(NC)]
OKAY = [$(White) OK $(NC)]
## ------------------------------------------------------------------------ ##
## BUILDs counter
## ------------------------------------------------------------------------ ##
$(file > $(BUILD_FILE),$(BUILD_CNTR))
$(info $(DAT) Created file [$(Yellow)$(BUILD_FILE)$(NC):$(Red)$(BUILD_CNTR)$(NC)])
## ------------------------------------------------------------------------ ##
## BUILD information
## ------------------------------------------------------------------------ ##
BUILD_SOURCE = config/build.tpl
BUILD_CONFIG = config/build.json
# BUILD_CONTENT = $(strip $(shell cat $(BUILD_SOURCE)))
BUILD_CONTENT = $(shell cat $(BUILD_SOURCE))
BUILD_CONTENT := $(subst BUILD_CNTR,$(BUILD_CNTR),$(BUILD_CONTENT))
BUILD_CONTENT := $(subst BUILD_FULL,$(BUILD_FULL),$(BUILD_CONTENT))
BUILD_CONTENT := $(subst BUILD_DATE,$(BUILD_DATE),$(BUILD_CONTENT))
BUILD_CONTENT := $(subst BUILD_TIME,$(BUILD_TIME),$(BUILD_CONTENT))
BUILD_CONTENT := $(subst BUILD_YEAR,$(BUILD_YEAR),$(BUILD_CONTENT))
BUILD_CONTENT := $(subst BUILD_HASH,$(BUILD_HASH),$(BUILD_CONTENT))
BUILD_CONTENT := $(subst GIT_COMMIT,$(GIT_COMMIT),$(BUILD_CONTENT))
BUILD_CONTENT := $(subst CODE_VERSION,$(CODE_VERSION),$(BUILD_CONTENT))
$(file > $(BUILD_CONFIG),$(BUILD_CONTENT))
$(info $(DAT) Created file [$(Yellow)BUILD_CONTENT$(NC):$(White)$(WD)/config/build.json$(NC)])
## ------------------------------------------------------------------------ ##
## COMMIT information
## ------------------------------------------------------------------------ ##
$(file > COMMIT,$(GIT_COMMIT));
$(info $(DAT) Created file [$(BYellow)COMMIT$(NC):$(White)$(GIT_COMMIT)$(NC)]);
## ------------------------------------------------------------------------ ##
## DIRECTORIES ##
## ------------------------------------------------------------------------ ##
ARC := arch
SRC := src
BLD := build-${CODE_VERSION}
DST := dist-${CODE_VERSION}
# WEB := web-${CODE_VERSION}-${BUILD_CNTR}
WEB := webroot
$(shell [ -d $(ARC) ] || mkdir $(ARC))
## ------------------------------------------------------------------------ ##
## PATHS ##
## ------------------------------------------------------------------------ ##
DIR_SRC := $(WD)/$(SRC)
DIR_BUILD := $(WD)/$(BLD)
DIR_DIST := $(WD)/$(DST)
DIR_WEB := $(WD)/$(WEB)
$(shell [ -d $(DIR_SRC) ] || mkdir $(DIR_SRC))
$(shell [ -d $(DIR_BUILD) ] || mkdir $(DIR_BUILD))
$(shell [ -d $(DIR_DIST) ] || mkdir $(DIR_DIST))
$(shell [ -d $(DIR_WEB) ] || mkdir $(DIR_WEB))
## ------------------------------------------------------------------------ ##
# APP_ENV := $(strip $(shell [ -f NODE_ENV ] && cat NODE_ENV || cat config/.NODE_ENV))
APP_ENV := $(strip $(shell grep NODE_ENV .env | cut -d "=" -f 2))
ifeq ($(APP_ENV),)
$(info $(DAT) $(Orange)APP_ENV$(NC) is $(Yellow)$(On_Red)NOT DETECTED$(NC)!)
endif
## ------------------------------------------------------------------------ ##
RC_FILE = ${WD}/src/.env.rc
RC_EXISTS := $(shell [ -f ${RC_FILE} ] && echo 1 || echo 0)
ifeq ($(RC_EXISTS),0)
$(info $(DAT) $(Red)Missing$(NC) $(Yellow)RC_FILE$(NC): [$(Red)$(RC_FILE)$(NC)]);
# exit
else
include $(RC_FILE)
$(info $(DAT) USE $(Yellow)RC_FILE$(NC): [$(Purple)$(RC_FILE)$(NC)]);
endif
RC_ENV = ${WD}/config/.env.rc.${APP_ENV}
ifeq ($(shell [ -f $(RC_ENV) ] && echo 1 || echo 0),0)
$(info $(DAT) [$(Red)NOT EXIST$(NC)] [$(Yellow)RC_ENV$(NC):$(White)$(RC_ENV)$(NC)]);
else
$(info $(DAT) USE $(Yellow)RC_ENV$(NC): [$(Purple)$(RC_ENV)$(NC)]);
include $(RC_ENV)
endif
RC_ENV = ${WD}/config/.env.rc.local
ifeq ($(shell [ -f ${RC_ENV} ] && echo 1 || echo 0),0)
$(info $(DAT) [$(Red)NOT EXIST$(NC)] [$(Yellow)RC_ENV$(NC):$(White)$(RC_ENV)$(NC)]);
else
include $(RC_ENV)
$(info $(DAT) USE $(Yellow)RC_ENV$(NC): [$(Purple)$(RC_ENV)$(NC)]);
endif
REPO_URL := $(REPO_HOST)/$(REPO_USER)/$(REPO_NAME).git
DIR_ENGINE := engine/$(ENGINE_NAME)-$(ENGINE_VERSION)
APP_DIRS := $(addprefix ${WD}/,build-* dist-* web-*)
## ------------------------------------------------------------------------ ##
## Query default goal
## ------------------------------------------------------------------------ ##
ifeq ($(.DEFAULT_GOAL),)
.DEFAULT_GOAL := default
endif
$(info $(DAT) $(Yellow)$(On_Purple)GOALS$(NC));
$(info $(DAT) \-- $(Orange)DEFAULT$(NC): [$(White)$(.DEFAULT_GOAL)$(NC)]);
$(info $(DAT) \-- $(Orange)CURRENT$(NC): [$(Blue)$(MAKECMDGOALS)$(NC)]);
## ------------------------------------------------------------------------ ##
## INCLUDES ##
## ------------------------------------------------------------------------ ##
include $(BD)/*.mk
## ------------------------------------------------------------------------ ##
PHONY := default run
default: run ;
@ echo $(DAT) $(FINE): $(TARG) ;
## ------------------------------------------------------------------------ ##
# APP_BANNER := $(shell cat ${APP_LOGO})
## ------------------------------------------------------------------------ ##
## ENVIRONMENT CONFIG
## ------------------------------------------------------------------------ ##
# include ./bin/Configure.mk
## ------------------------------------------------------------------------ ##
## INCLUDES ENVIRONMENT CONFIGURATION ##
## ------------------------------------------------------------------------ ##
# ifeq ($(shell [ -f ${RC_FILE} ] && echo 1 || echo 0),0)
# include $(RC_FILE)
# $(info $(DAT) USE ${BYellow}RC_FILE${NC}: [${BPurple}${RC_FILE}${NC}]);
# else
# $(info $(DAT) [${Red}NOT EXIST${NC}] [${BYellow}RC_FILE${NC}:${White}${RC_FILE}${NC}]);
# endif
## ------------------------------------------------------------------------ ##
PHONY += run
run: banner state help test;
@ echo $(DAT) ${Yellow}EXECUTING${NC} [${Blue}$(.DEFAULT_GOAL)${NC}] ${Yellow}GOAL${NC} ;
@ echo $(DAT) ${Yellow}FINISHED${NC} [${Blue}$(.DEFAULT_GOAL)${NC}] ${Yellow}GOAL${NC} ;
@ echo $(DAT) $(FINE): $(TARG)
## ------------------------------------------------------------------------ ##
PHONY += test test_rc
test: test_rc;
@ echo $(DAT) $(FINE): $(TARG)
## SOURCE VARIABLES
test_rc: ;
@ echo $(DAT) ${Yellow}EXECUTING${NC} [${Blue}TEST${NC}] ${Yellow}GOAL${NC} ;
@ echo $(DAT) ${Yellow}FINISHED${NC} [${Blue}TEST${NC}] ${Yellow}GOAL${NC} ;
@ echo $(DAT) $(DONE): $(TARG)
## ------------------------------------------------------------------------ ##
PHONY += deps deps-install
deps-install:;
npm i
bower i --production
@ echo $(DAT) $(DONE): $(TARG)
deps: deps-install;
@ echo $(DAT) $(FINE): $(TARG)
## ------------------------------------------------------------------------ ##
PHONY += ownership
ownership:;
mkdir -p ${DIR_WEB} ;
sudo chgrp -R ${WEB_USER} ${DIR_WEB} ;
@ echo $(DAT) $(DONE): $(TARG)
## ------------------------------------------------------------------------ ##
PHONY += setup engine build build-engine build-assets release deploy
setup: deps;
@ echo $(DAT) $(FINE): $(TARG)
engine: engine_check;
@ echo $(DAT) $(FINE): $(TARG)
build: build-engine build-assets;
@ echo $(DAT) $(FINE): $(TARG)
build-engine: engine_check ;
mkdir -p ${DIR_BUILD} ;
cp -prf ${DIR_ENGINE}/* ${DIR_BUILD}/ 2>&1 >/dev/null ;
-rm -rvf ${DIR_BUILD}/public/css 2>&1 >/dev/null ;
-rm -rvf ${DIR_BUILD}/public/js 2>&1 >/dev/null ;
-rm -rvf ${DIR_BUILD}/resources/assets/js 2>&1 >/dev/null ;
-rm -rvf ${DIR_BUILD}/*.md 2>&1 >/dev/null ;
cp -prf ${DIR_SRC}/* ${DIR_BUILD}/ 2>&1 >/dev/null ;
cp -pvu ${RC_FILE} ${DIR_BUILD}/.env 2>&1 >/dev/null ;
cp -pvf ${DIR_SRC}/composer.json ${DIR_BUILD}/ 2>&1 >/dev/null ;
cp -pvf ${DIR_SRC}/webpack.mix.js ${DIR_BUILD}/ 2>&1 >/dev/null ;
cd "${DIR_BUILD}" \
&& npm i \
&& composer -vv -n --profile update \
&& composer --version > __COMPOSER_VERSION \
&& php artisan --ansi -V > __ENGINE_VERSION \
&& php artisan --ansi inspire > __INSPIRATION \
&& cd - ;
@ echo $(DAT) $(DONE): $(TARG)
build-assets:
gulp --env=${APP_ENV} build ;
mkdir -p "${DIR_BUILD}/public/assets/font-awesome" ;
mkdir -p "${DIR_ENGINE}/storage/media" ;
cd "${DIR_BUILD}/public/assets/font-awesome" \
&& [ -L ./fonts ] || ln -bs ../fonts 2>&1 >/dev/null ;
cd "${DIR_BUILD}/public" \
&& [ -L "${WD}/${DIR_ENGINE}/storage/media/audio" ] || ln -bs "/data/media/audio" "${WD}/${DIR_ENGINE}/storage/media/audio" 2>&1 >/dev/null ;
@ echo $(DAT) $(DONE): $(TARG)
# && [ -L "${WD}/${DIR_ENGINE}/storage/media/audio" || -f "${WD}/${DIR_ENGINE}/storage/media/audio" ] || ln -bs "/data/media/audio" "${WD}/${DIR_ENGINE}/storage/media/" 2>&1 >/dev/null ;
# && ln -s ../fonts 2>&1 >/dev/null ;
# && ln -s ../storage/media/audio/ 2>&1 >/dev/null ;
release:
mkdir -p ${DIR_DIST} ;
cp -prf ${DIR_BUILD}/* ${DIR_DIST}/ ;
cp -pvf ${RC_FILE} ${DIR_DIST}/ ;
cd ${DIR_DIST} \
&& rm -rf node_modules/ ;
cd ${WD} ;
@$(MAKE) ownership ;
@ echo $(DAT) $(FINE): $(TARG)
deploy:
mkdir -p ${DIR_WEB} 2>&1 >/dev/null ;
[ -f "${DIR_WEB}/.env" ] && cp -prf ${DIR_WEB}/.env ${DIR_WEB}/.env.${DATE}.bak 2>&1 >/dev/null || echo "NO .env FILE";
cp -prf ${DIR_DIST}/* ${DIR_WEB}/ 2>&1 >/dev/null ;
# cp -pv ${RC_FILE} ${DIR_WEB}/.env 2>&1 >/dev/null ;
cd ${DIR_WEB} \
&& php artisan --ansi down \
&& composer -n -vv update \
&& php artisan --ansi up ;
# cd ${WD} && rm -vf webroot
# cd ${WD} && ln -s ${DIR_WEB} webroot
@ echo $(DAT) $(FINE): $(TARG)
## ------------------------------------------------------------------------ ##
PHONY += artisan
artisan:
@ cd ${DIR_WEB} \
&& php artisan --ansi -n down \
&& php artisan --ansi -n optimize 2>&1 >/dev/null \
&& php artisan --ansi -n route:cache 2>&1 >/dev/null \
&& php artisan --ansi -n config:cache 2>&1 >/dev/null \
&& php artisan --ansi -n route:list \
&& php artisan --ansi -n up ;
@ echo $(DAT) $(DONE): $(TARG)
# @ cd ${DIR_WEB} \
# && $(MAKE) rights ;
## ------------------------------------------------------------------------ ##
PHONY += rebuild redeploy
rebuild: build release deploy;
@ echo $(DAT) $(FINE): $(TARG)
redeploy: release deploy;
@ echo $(DAT) $(FINE): $(TARG)
## ------------------------------------------------------------------------ ##
PHONY += all b dev full
#* means the word "all" doesn't represent a file name in this Makefile;
#* means the Makefile has nothing to do with a file called "all" in the same directory.
# all: clean rights tree setup engine build release deploy;
all: clean setup engine build release deploy;
@ echo $(DAT) $(FINE): $(TARG)
b: build-assets release deploy;
@ echo $(DAT) $(FINE): $(TARG)
dev: clean-dev setup build release deploy;
@ echo $(DAT) $(FINE): $(TARG)
full: clean-all all;
@ echo $(DAT) $(FINE): $(TARG)
## ------------------------------------------------------------------------ ##
## Declare the contents of the .PHONY variable as phony. We keep that
## information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)
## ------------------------------------------------------------------------ ##