generated from NuclearRedeye/typescript-web-application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
97 lines (77 loc) · 3.23 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
PROJECT := $(notdir $(CURDIR))
NODE_VERSION ?= jod
PORT ?= 8080
# Build commands
DOCKER := docker run --rm -w=/$(PROJECT) -v $(CURDIR):/$(PROJECT):rw
# Files that when changed should trigger a rebuild.
TS := $(shell find ./src/ts -type f -name *.ts)
SASS := $(shell find ./src/scss -type f -name *.scss)
HTML := $(shell find ./src/html -type f -name *.html)
ASSETS := $(shell find ./src/assets -type f)
# Targets that don't result in output of the same name.
.PHONY: clean \
distclean \
lint \
format \
debug \
release \
start
# When no target is specified, the default target to run.
.DEFAULT_GOAL := start
# Target that cleans build output and local dependencies.
distclean: clean
@rm -rf node_modules
# Target that cleans build output
clean:
@rm -rf out
# Target to install Node.js dependencies.
node_modules: package.json
@echo "Installing dependencies..."
@$(DOCKER) node:$(NODE_VERSION) npm install
@-touch node_modules
# Target to create the output directories.
out/debug out/release:
@echo "Creating $@..."
@mkdir -p $(CURDIR)/$@
# Target that creates the specified HTML file by copying it from the src directory.
out/debug/index.html out/release/index.html: $(HTML)
@echo "Creating $@..."
@cp $(CURDIR)/src/html/$(@F) $@
# Target that creates the assets by copying them from the src directory.
out/debug/assets out/release/assets: $(ASSETS)
@echo "Creating $@..."
@cp -r $(CURDIR)/src/assets/ $@
@touch $@
# Target that compiles TypeScript to JavaScript.
out/debug/index.js: node_modules out/debug tsconfig.json $(TS)
@echo "Creating $@..."
@$(DOCKER) node:$(NODE_VERSION) npx tsc
# Target that compiles SCSS to CSS.
out/debug/index.css: node_modules out/debug $(SASS)
@echo "Creating $@..."
@$(DOCKER) node:$(NODE_VERSION) npx sass ./src/scss/index.scss $@
# Target that bundles, treeshakes and minifies the JavaScript.
out/release/index.js: out/release out/debug/index.js
@echo "Creating $@..."
@$(DOCKER) node:$(NODE_VERSION) npx rollup ./out/debug/index.js --file $@
@$(DOCKER) node:$(NODE_VERSION) npx terser -c -m -o $@ $@
# Target that compiles SCSS to CSS.
out/release/index.css: node_modules out/release $(SASS)
@echo "Creating $@..."
@$(DOCKER) node:$(NODE_VERSION) npx sass --no-source-map ./src/scss/index.scss $@
# Target that checks the code for style/formating issues.
format: node_modules
@echo "Running style checks..."
@$(DOCKER) node:$(NODE_VERSION) npx prettier --check .
# Target that lints the code for errors.
lint: node_modules
@echo "Running linter..."
@$(DOCKER) node:$(NODE_VERSION) npx eslint ./src --ext .js,.ts
# Target that builds a debug/development version of the app
debug: out/debug out/debug/index.html out/debug/index.css out/debug/index.js out/debug/assets
# Target that builds a release version of the app
release: out/release out/release/index.html out/release/index.css out/release/index.js out/release/assets
# Target that builds and runs a debug instance of the project.
start: debug
@echo "Starting '$(PROJECT)' on 'http://localhost:$(PORT)'..."
@docker run --rm --name $(PROJECT) -p $(PORT):80 -e NGINX_ENTRYPOINT_QUIET_LOGS=1 -v '$(CURDIR)/.nginx/nginx.conf:/etc/nginx/nginx.conf:ro' -v $(CURDIR)/out/debug:/usr/share/nginx/html/:ro nginx:alpine