-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
138 lines (119 loc) · 4.01 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
GULP := $(PWD)/node_modules/.bin/gulp
WPCLI := $(PWD)/bin/dwp
THEME_NAME := md-starter
THEME_DIR := app/wp-content/themes/$(THEME_NAME)
.PHONY: deps
deps: node_modules $(THEME_DIR)/vendor
node_modules: package.json yarn.lock
@yarn install
@touch $@
app/index.php:
@$(WPCLI) core download --locale=en_US --version=5.3.2
app/wp-config.php:
@$(WPCLI) core config --dbname=wordpress --dbuser=root --dbpass=password --dbhost=mysqldb --locale=en_US
@$(WPCLI) core install --url=localhost:3010 --title=md-starter --admin_user=admin --admin_password=password [email protected] --skip-email
$(THEME_DIR)/vendor: $(THEME_DIR)/composer.json $(THEME_DIR)/composer.lock
@cd $(THEME_DIR); composer install
.PHONY: create-theme
## Run an interactive prompt to create a new theme
create-theme: node_modules
@bin/create-theme
## Get everything ready (Docker containers, WordPress download
## and configuration)
.PHONY: setup
setup: up-docker deps app/index.php app/wp-config.php
@$(WPCLI) theme activate md-starter
@$(WPCLI) menu create "navbar"
@$(WPCLI) menu create "nav_footer"
@# Display the home page in navbar and nav_footer
@$(WPCLI) menu item add-custom navbar Home http://localhost:3010
@$(WPCLI) menu item add-custom nav_footer Home http://localhost:3010
@# Display the sample page in navbar and nav_footer
@$(WPCLI) menu item add-post navbar 2
@$(WPCLI) menu item add-post nav_footer 2
@# Publish and display the privacy policy page in nav_footer
@$(WPCLI) post update 3 --post_status=publish
@$(WPCLI) menu item add-post nav_footer 3
@$(WPCLI) rewrite structure '/%year%/%monthnum%/%day%/%postname%/' --hard
.PHONY: build-docker
build-docker: .build-docker.mk
.build-docker.mk: Dockerfile docker-compose.yml
@sudo HOST_UID=$(shell id -u) HOST_USER=$(shell whoami) docker-compose build
@touch $@
.PHONY: up-docker
up-docker: build-docker
@HOST_UID=$(shell id -u) HOST_USER=$(shell whoami) docker-compose up -d
.DEFAULT_GOAL := serve
## Serve:
## - WordPress front-office at http://localhost:3000 with live reloading
## - WordPress back-office at http://localhost:3010/wp-admin
## (username: admin, password: password)
## - phpMyAdmin at http://localhost:3011
.PHONY: serve
serve: check-setup deps up-docker
@$(GULP) --continue
.PHONY: check-setup
check-setup:
ifeq (,$(wildcard ./app/index.php))
$(error ❌ WordPress doesn't seem to be installed. You should run make setup first.)
endif
## Build WordPress theme for production use
.PHONY: build
build: deps
@NODE_ENV=production $(GULP)
.PHONY: install-wpcs
install-wpcs: $(THEME_DIR)/vendor
@cd $(THEME_DIR); composer create-project wp-coding-standards/wpcs:dev-master --no-dev
.PHONY: clean
clean:
@docker-compose down
@sudo git clean -fdX
define primary
\033[38;2;166;204;112;1m$(1)\033[0m
endef
define title
\033[38;2;255;204;102m$(1)\033[0m\n
endef
## List available commands
.PHONY: help
help:
@printf "$(call primary,wordpress-starter)\n"
@printf "A starter template for WordPress websites using Make\n\n"
@printf "$(call title,USAGE)"
@printf " make <SUBCOMMAND>\n\n"
@printf "$(call title,SUBCOMMANDS)"
@awk '{ \
line = $$0; \
while((n = index(line, "http")) > 0) { \
if (match(line, "https?://[^ ]+")) { \
url = substr(line, RSTART, RLENGTH); \
sub(url, "\033[38;2;119;168;217m"url"\033[0m", $$0); \
line = substr(line, n + RLENGTH); \
} else {\
break; \
} \
}\
\
if ($$0 ~ /^.PHONY: [a-zA-Z0-9]+$$/) { \
helpCommand = substr($$0, index($$0, ":") + 2); \
if (helpMessage) { \
printf " $(call primary,%-15s)%s\n", \
helpCommand, helpMessage; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \
helpCommand = substr($$0, 0, index($$0, ":")); \
if (helpMessage) { \
printf " $(call primary,%-15s)%s\n", \
helpCommand, helpMessage; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^##/) { \
if (helpMessage) { \
helpMessage = helpMessage "\n " substr($$0, 3); \
} else { \
helpMessage = substr($$0, 3); \
} \
} \
}' \
$(MAKEFILE_LIST)