This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
200 lines (166 loc) · 5.2 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
################
# BEGIN Helper #
################
# Text transforms
# @see https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/
# Usage:
# echo "${REV}Foo${NC}"
BOLD := $(shell tput -Txterm bold)
REV := $(shell tput -Txterm rev)
# Colour
# @see https://gist.github.com/prwhite/8168133#gistcomment-2278355
# Usage:
# echo "Roses are ${RED}red${NC}, violets are ${BLUE}blue${NC}."
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
BLUE := $(shell tput -Txterm setaf 4)
MAGENTA := $(shell tput -Txterm setaf 5)
CYAN := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
# Reset text transoform or colour
# @see https://gist.github.com/prwhite/8168133#gistcomment-2278355
# Usage:
# echo "${YELLOW}Foo${NC}"
NC := $(shell tput -Txterm sgr0)
# The help function enables us to use a special comment syntax (##).
# If we place a comment with ## one line above a Makefile method,
# it will be listed in `$ make help`.
# Usage:
# ## This line will appear in `$ make help`
# foo:
# echo bar
# Max char num in help function
TARGET_MAX_CHAR_NUM=20
## Shows this help
help:
@echo ''
@echo ' ${REV}${BLUE}TASK${NC} Listing all available commands'
@echo ''
@echo 'usage:'
@echo ' ${YELLOW}make${NC} ${GREEN}<command>${NC}'
@echo ''
@echo 'commands:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${NC} ${GREEN}%s${NC}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
@echo ''
@echo ''
@echo ' ${REV}${GREEN}SUCCESS${NC} Done'
@echo ''
# Define ARGS so we can use arguments within a Makefile method: `$ make <method> args`
ARGS = $(filter-out $@,$(MAKECMDGOALS))
# Define PROJECT_NAME
FOLDER_NAME := $(notdir $(shell pwd))
MAKE_UP_FOLDER_NAME := $(notdir $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
# Use git project name if available
GIT_PROJECT_NAME := $(shell basename `git rev-parse --show-toplevel 2>/dev/null` 2>/dev/null)
ifdef GIT_PROJECT_NAME
PROJECT_NAME := $(GIT_PROJECT_NAME)
else
PROJECT_NAME := $(FOLDER_NAME)
endif
export PROJECT_NAME
# Define path to HELPER_SCRIPTS
HELPER_SCRIPTS="$(MAKE_UP_FOLDER_NAME)/scripts"
# Define path to ENV_FILE
ORIGINAL_ENV_FILE=.env
ENV_FILE=$(ORIGINAL_ENV_FILE) # this can be overwritten in my-project/.env
# Export each variable from ORIGINAL_ENV_FILE.
# You may use each exported variable within each file in HELPER_SCRIPTS.
# List all available variables with: `$ make test`
ifneq ("$(wildcard $(ORIGINAL_ENV_FILE))","")
include $(ORIGINAL_ENV_FILE)
VARS:=$(shell sed -ne 's/ *\#.*$$//; /./ s/=.*$$// p' $(ORIGINAL_ENV_FILE) )
$(foreach v,$(VARS),$(eval $(shell echo export $(v)='$($(v))')))
endif
# Overwrite path to ENV_FILE
# If your ENV_FILE is not in the root directory (e.g. "my-project"), insert the following into "my-project/.env":
# ENV_FILE=path-to/.env
# Export each variable from ENV_FILE (because ORIGINAL_ENV_FILE may not match ENV_FILE at this point).
# You may use each exported variable within each file in HELPER_SCRIPTS.
# List all available variables with: `$ make test`
ifneq ("$(wildcard $(ENV_FILE))","")
include $(ENV_FILE)
VARS:=$(shell sed -ne 's/ *\#.*$$//; /./ s/=.*$$// p' $(ENV_FILE) )
$(foreach v,$(VARS),$(eval $(shell echo export $(v)='$($(v))')))
endif
##############
# END Helper #
##############
#################
# BEGIN methods #
#################
# Install make-up in project
install-make-up:
@./scripts/install-make-up/install.bash
## Display project information
info:
@./$(HELPER_SCRIPTS)/info/info.bash
## Initial project setup or an alias for 'start' if the project was already set up
up:
@if [ ! -f ".env" ]; then \
touch .env; \
./$(HELPER_SCRIPTS)/start/start.bash; \
./$(HELPER_SCRIPTS)/env/create.bash; \
./$(HELPER_SCRIPTS)/uploads/create-dir.bash; \
make help; \
./$(HELPER_SCRIPTS)/frontend/node_modules.bash; \
else \
make start; \
fi
## Start developing
start:
@./$(HELPER_SCRIPTS)/start/start.bash
## Stop developing
stop:
@./$(HELPER_SCRIPTS)/stop/stop.bash
## Restart developing
restart:
@make stop
@make start
## Build
build:
@./$(HELPER_SCRIPTS)/build/build.bash
## Run composer (Example: '$ make composer require foo/bar')
composer:
@./$(HELPER_SCRIPTS)/composer/composer.bash $(ARGS)
## Enter shell
shell:
@./$(HELPER_SCRIPTS)/shell/enter.bash
## Enter database shell
db-shell:
@./$(HELPER_SCRIPTS)/db-shell/enter.bash
## Backup
backup:
@./$(HELPER_SCRIPTS)/backup/create.bash
## Restore
restore:
@./$(HELPER_SCRIPTS)/backup/restore.bash $(ARGS)
## Deploy
deploy:
@./$(HELPER_SCRIPTS)/deploy/deploy.bash
## Synchronize from environment 'staging' to 'dev'
staging-to-dev:
@./$(HELPER_SCRIPTS)/sync/staging-to-dev.bash
## Synchronize from environment 'production' to 'dev'
production-to-dev:
@./$(HELPER_SCRIPTS)/sync/production-to-dev.bash
## (Re-)build .env
env:
@./$(HELPER_SCRIPTS)/env/create.bash
## Run tests
test:
@./$(HELPER_SCRIPTS)/test/env.bash
###############
# END methods #
###############
# prevents arguments passed beeing evaluated as task names
%:
@: