This repository has been archived by the owner on Feb 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
216 lines (177 loc) · 5.85 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
#!/bin/sh
SHELL=/bin/bash
BIN=./bin
LOAD_ENV=source bin/load-dotenv.sh && source bin/construct-additional-env.sh
WEBPACK=yarn webpack --bail
JEST=yarn jest
PRETTIER=yarn prettier --write --parser babel '{!(dist)/,!(dist)/**/}*.js'
PRETTIER_FAIL=yarn prettier --list-different --parser babel './**/*.js'
ESLINT=yarn eslint
SERVERLESS=cd services && ../node_modules/.bin/sls
WEBPACK_DEV_SERVER=yarn webpack-dev-server
NPM_CHECK_UPDATES=yarn ncu
# color output
NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m
OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)
ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)
WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)
AWK_CMD = awk '{ printf "%-30s %-10s\n",$$1, $$2; }'
PRINT_LINE = printf "%0.s*" {1..50} && printf "\n"
PRINT_ERROR = printf "$(ERROR_COLOR)$@ $(ERROR_STRING)\n" | $(AWK_CMD) && printf "$(CMD)\n$$LOG\n" && false && $(PRINT_LINE)
PRINT_WARNING = printf "$(WARN_COLOR)$@ $(WARN_STRING)\n" | $(AWK_CMD) && printf "$(CMD)\n$$LOG\n" && $(PRINT_LINE)
PRINT_OK = printf "$(OK_COLOR)$@ $(OK_STRING)\n" | $(AWK_CMD) && $(PRINT_LINE)
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
badger: ## Red Badger 4 lyfe!
npm run badger > /dev/null
clean: ## Remove compiled files
rm -rf dist
@$(PRINT_OK)
clean/services:
rm -rf dist/services
rm -f dist/services.zip
@$(PRINT_OK)
check-deps: ## Check deps for updates
$(NPM_CHECK_UPDATES)
@$(PRINT_OK)
dev: badger ## Run the frontend dev server
$(LOAD_ENV) && $(WEBPACK_DEV_SERVER) --color --hot --config webpack.dev.browser.config.js
@$(PRINT_OK)
fetch:
$(LOAD_ENV) && node dev/content-fetcher
generate-sitemap:
$(LOAD_ENV) && node dev/generate-sitemap
dev-static: dist/static-site dist/dev-static/index.js ## Compile the site to HTML locally and serve
ln -fs ../assets-honestly dist/static-site/assets-honestly
node dist/dev-static/index.js
./node_modules/.bin/http-server ./dist/static-site -p 8000
@$(PRINT_OK)
dev-commit: dist/static-site dist/dev-static/index.js ## Compile the site to HTML locally
node dist/dev-static/index.js
@$(PRINT_OK)
test: ## Run the tests
FORCE_COLOR=1 $(JEST)
@$(PRINT_OK)
flow: ## Run the type checker
yarn flow
@$(PRINT_OK)
prettier: ## Run the prettifier
$(PRETTIER)
@$(PRINT_OK)
prettier-fail: ## Run the prettifier, but fail if changes need to be made
$(PRETTIER_FAIL)
@$(PRINT_OK)
test-watch: ## Run the tests and watch for changes
$(JEST) --watch
@$(PRINT_OK)
test-coverage: ## Run the tests and coverage for changes
$(JEST) --coverage --runInBand
@$(PRINT_OK)
build: dist/services.zip ## Compile project used in CI deploy
@$(PRINT_OK)
build-all: dist/services.zip dist/dev-static/index.js ## Compile project
@$(PRINT_OK)
lint: ## Lint Javascript files
FORCE_COLOR=1 $(ESLINT) . --ext .js --ext .jsx --ignore-path .eslintignore --cache
@$(PRINT_OK)
services-info: ## Check serverless installed correctly and detects the correct service
$(LOAD_ENV) \
&& $(SERVERLESS) info
@$(PRINT_OK)
services-deploy: dist/services.zip ## Upload the publish service to AWS Lambda
$(LOAD_ENV) \
&& $(SERVERLESS) deploy
@$(PRINT_OK)
services-invoke-publish:
$(LOAD_ENV) \
&& $(SERVERLESS) invoke -f publish
@$(PRINT_OK)
publish-service-invoke: ## Invoke the publish service
$(LOAD_ENV) \
&& curl -XPOST --fail $$PUBLISH_ENDPOINT
@$(PRINT_OK)
keyrings: ## Initialize blackbox secrets in the keyrings folder (required to get .env file)
git clone [email protected]:redbadger/blackbox-secrets.git keyrings -b website-honestly
@echo ""
@echo "*************************************************************"
@echo "* Follow the instructions to get added to the blackbox admins:"
@echo "* https://github.com/redbadger/blackbox-secrets/blob/master/README.md"
@echo "*************************************************************"
@echo ""
@read -p "Press any key to continue."
@$(PRINT_OK)
update-secrets: keyrings ## Update .env file to latest version
cd keyrings \
&& git pull
blackbox_edit_start keyrings/files/.env
mv keyrings/files/.env .env
@$(PRINT_OK)
edit-secrets: keyrings update-secrets ## Edit .env file (get latest -> decrypt -> edit -> encrypt -> push)
blackbox_edit keyrings/files/.env
cd keyrings \
&& git commit -m "files/.env.gpg updated" "files/.env.gpg" \
&& git push origin website-honestly
blackbox_edit_start keyrings/files/.env
mv keyrings/files/.env .env
@$(PRINT_OK)
dist/services.zip: dist/services
cd dist/services \
&& zip -r ../services.zip *
@$(PRINT_OK)
dist/services:
export NODE_ENV=production \
&& $(LOAD_ENV) \
&& $(WEBPACK) --config webpack.lambda.config.js \
&& $(WEBPACK) --config webpack.browser.config.js \
&& rm -rf dist/services/assets-honestly
@$(PRINT_OK)
dist/dev-static/index.js:
export NODE_ENV=production \
&& $(LOAD_ENV) \
&& $(WEBPACK) --config webpack.dev.static.config.js
@$(PRINT_OK)
dist/static-site:
mkdir -p ./dist/static-site
@$(PRINT_OK)
scanner: ## Initialize git secrets in the scanner folder
git clone [email protected]:redbadger/secrets-scanner.git scanner
@echo ""
@echo "*************************************************************"
@echo "* Follow the instructions below to setup the scanner:"
@echo "* https://github.com/redbadger/secrets-scanner/blob/master/README.md"
@echo "*************************************************************"
@echo ""
@read -p "Press any key to continue."
setup-scanner: scanner ## Setup git secrets with stored configuration
@cd scanner && git pull
@cd scanner && $(MAKE) full-setup
@$(PRINT_OK)
scan-secrets: scanner ## Scan for secrets
@git secrets --scan
@$(PRINT_OK)
.PHONY: \
dev \
dev-static \
install \
check-deps \
flow \
prettier \
lint \
help \
clear \
build \
badger \
services-info \
services-deploy \
services-invoke \
fetch \
test \
test-watch \
sw \
update-secrets \
edit-secrets \
setup-scanner \
scan-secrets