-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
182 lines (147 loc) · 5.52 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
# Include all env variables from .env.local
# Just create such file with a content of config override variables like
# SERVER_PORT=5000
-include .env.local
# And make them available for an application
export
DOCKER_IMAGE_PATH=ghcr.io/artem-malko/react-ssr-template/node-app
CYAN=`tput bold && tput setaf 6`
RESET=`tput sgr0`
TEST_FILES ?= src/**/__tests__/*.ts \
src/**/__tests__/**/*.ts \
src/**/__tests__/*.tsx \
src/**/__tests__/**/*.tsx --reporter spec
### Main tasks
# Development mode
.PHONY: development
development dev d: prebuild
$(MAKE) --jobs build-dev-client build-dev-server watch-ts-errors start-dev-server
# Production mode
.PHONY: production
production prod p: prebuild
$(MAKE) --jobs build-prod-client build-prod-server
# Fetch info about new versions of used npm-packages
.PHONY: npm-check-update
npm-check-update:
npm-check --skip-unused
# Start all tests with coverage
.PHONY: tests
tests test t: lint prettier tsc unit-coverage
# Start simple nodeJS server
.PHONY: start
start:
NODE_ENV=DEBUG node ./build/server
# Start nodeJS server in prod mode
.PHONY: start-prod
start-prod:
NODE_ENV=production node --max-old-space-size=512 ./build/server
### Tasks
# Prebuild phase
.PHONY: prebuild
prebuild: clean prepare-build-dir
### Subtasks
# Clean last build
.PHONY: clean
clean:
rm -rf ./build
# Create dir for new build
# Create empty server.js file for nodemon
# Copy public files to build dir
.PHONY: prepare-build-dir
prepare-build-dir:
mkdir build && touch ./build/server.js && cp -r public build
# Start nodemon
.PHONY: start-dev-server
start-dev-server:
node_modules/.bin/nodemon --delay 0.1 --inspect -e js,json --ignore ./build/public -w ./build/ ./build/server.js
# Make dev build for client with changes watching
.PHONY: build-dev-client
build-dev-client:
NODE_ENV=development node_modules/.bin/webpack-cli --config ./webpack/client.ts --watch
# Make dev build for client with changes watching
.PHONY: build-client-stats
build-client-stats:
NODE_ENV=production node_modules/.bin/webpack --config ./webpack/client.ts --json > build/stats_full.json
# Make dev build for server with changes watching
.PHONY: build-dev-server
build-dev-server:
NODE_ENV=development node_modules/.bin/webpack-cli --config ./webpack/server.ts --watch
# Separate process to watch typescript errors
.PHONY: watch-ts-errors
watch-ts-errors:
NODE_ENV=development node_modules/.bin/tsc --incremental --outDir ./.tsc_incremental_output -w | sed -e "s/\(error.*\)/`tput setaf 9`\1`tput op`/g"
# Make production build for client
.PHONY: build-prod-client
build-prod-client:
NODE_ENV=production node_modules/.bin/webpack-cli --config webpack/client.ts
# Make production build for server
.PHONY: build-prod-server
build-prod-server:
NODE_ENV=production node_modules/.bin/webpack-cli --config webpack/server.ts
## Tests, checks on push
# pass paths as env var
# Start unit and dom tests without coverage
.PHONY: unit
unit:
@echo "\n${CYAN}Start unit and dom tests without coverage ${RESET}\n" && RTL_SKIP_AUTO_CLEANUP=true TS_NODE_TRANSPILE_ONLY=true NODE_ENV=test NODE_PATH=./src \
node_modules/.bin/mocha \
--require ts-node/register \
--require ./tools/setupChaiDomAsserions.js \
--require ./src/framework/infrastructure/tests/hooks/beforeAndAfterEach.ts \
--require source-map-support/register \
--bail \
--recursive \
${TEST_FILES} \
--enable-source-maps \
--reporter nyan
# Start unit and dom tests with coverage
.PHONY: unit-coverage
unit-coverage:
@echo "\n${CYAN}Start unit and dom tests with coverage ${RESET}\n" && RTL_SKIP_AUTO_CLEANUP=true TS_NODE_TRANSPILE_ONLY=true NODE_ENV=test NODE_PATH=./src \
node_modules/.bin/nyc \
node_modules/.bin/mocha \
--require ts-node/register \
--require ./tools/setupChaiDomAsserions.js \
--require ./src/framework/infrastructure/tests/hooks/beforeAndAfterEach.ts \
--require source-map-support/register \
--bail \
--recursive \
${TEST_FILES} \
--reporter progress
# Start integration tests (services —» actions —» reducers)
.PHONY: integration
integration:
@echo "\n${CYAN}Start integration tests${RESET}\n" && TS_NODE_TRANSPILE_ONLY=true NODE_ENV=test NODE_PATH=./src node_modules/.bin/mocha --opts src/tests/integration/mocha.opts --reporter nyan
# Start eslint
.PHONY: lint
lint:
@echo "\n${CYAN}Start eslint${RESET}\n" && node_modules/.bin/eslint "./src/**/*.ts" "./src/**/*.tsx" --cache --cache-location ".cache"
# Start eslint-without-cache
.PHONY: lint-without-cache
lint-without-cache:
@echo "\n${CYAN}Start eslint without cache${RESET}\n" && node_modules/.bin/eslint "./src/**/*.ts" "./src/**/*.tsx"
# Start prettier with only error logs
.PHONY: prettier
prettier:
@echo "\n${CYAN}Start prettier${RESET}\n" && node_modules/.bin/prettier --cache --list-different "src/**/*.tsx" "src/**/*.ts"
# Start tsc checks (typings and etc)
.PHONY: tsc
tsc:
@echo "\n${CYAN}Start typescript checker${RESET}\n" && node_modules/.bin/tsc --incremental --outDir ./.tsc_incremental_output
## Docker
# Build a docker image with NodeJS App inside
.PHONY: build-nodejs-app-image
build-nodejs-app-image:
docker buildx build \
--load \
--platform=linux/amd64 \
--build-arg GITHUB_SHA=$$(git rev-parse --verify HEAD) \
--build-arg DOCKER_IMAGE_WITH_EXISTS_BUILD=${DOCKER_IMAGE_PATH}:latest \
-t ${DOCKER_IMAGE_PATH}:latest .
# Push a docker image with NodeJS App inside
.PHONY: push-nodejs-app-image
push-nodejs-app-image:
docker push ${DOCKER_IMAGE_PATH}:latest
# Build and push a docker image with NodeJS App inside
.PHONY: dockerize-nodejs-app
dockerize-nodejs-app: build-nodejs-app-image push-nodejs-app-image