OSDN Git Service

Regular updates
[twpd/master.git] / Makefile
1 npmbin := ./node_modules/.bin
2 PORT ?= 3000
3 HOST ?= 127.0.0.1
4
5 help:
6         @echo
7         @echo Makefile targets
8         @grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
9         @echo
10
11 # Builds intermediate files. Needs a _site built first though
12 update: _site critical
13
14 # Builds _site
15 _site:
16         bundle exec jekyll build --incremental
17
18 critical: _site ## Builds critical path CSS/JS
19         node _support/critical.js
20
21 # Ensure that bins are available.
22 ensure-bin:
23         @if [ ! -d $(npmbin) ]; then \
24                 echo "---"; \
25                 echo "Error: $(npmbin) not found, you may need to run '[docker-compose run --rm web] yarn install'."; \
26                 echo "---"; \
27                 exit 1; \
28                 fi
29         @if ! which jekyll &>/dev/null; then \
30                 echo "---"; \
31                 echo "Warning: Jekyll not found, you may need to run '[docker-compose run --rm web] bundle install'."; \
32                 echo "---"; \
33                 fi
34
35 dev: ensure-bin ## Starts development server
36         $(npmbin)/concurrently -k -p command -c "blue,green" \
37                 "make dev-webpack" \
38                 "make dev-jekyll"
39
40 dev-webpack: ensure-bin
41         $(npmbin)/webpack --watch --colors -p
42
43 dev-jekyll: ensure-bin
44         if [ -f _site ]; then \
45                 bundle exec jekyll serve --safe --trace --drafts --watch --incremental --host $(HOST) --port $(PORT); \
46                 else \
47                 bundle exec jekyll serve --safe --trace --drafts --watch --host $(HOST) --port $(PORT); \
48                 fi
49
50 test: _site ## Runs rudimentary tests
51         @test -f _site/vim.html
52         @test -f _site/react.html
53         @test -f _site/index.html
54         @grep "<script src" _site/index.html >/dev/null
55         @grep "<script src" _site/vim.html >/dev/null
56         @grep "<script src" _site/react.html >/dev/null
57
58 test-warning:
59         @echo "========="
60         @echo "If your build failed at this point, it means"
61         @echo "the site failed to generate. Check the project"
62         @echo "out locally and try to find out why."
63         @echo "========="