-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
139 lines (105 loc) · 3.63 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
#
# Directories
#
ROOT_SLASH := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
ROOT := $(patsubst %/,%,$(ROOT_SLASH))
LIB := $(ROOT)/lib
TEST := $(ROOT)/test
TOOLS := $(ROOT)/tools
GITHOOKS_SRC := $(TOOLS)/githooks
GITHOOKS_DEST := $(ROOT)/.git/hooks
#
# Generated Files & Directories
#
NODE_MODULES := $(ROOT)/node_modules
NODE_BIN := $(NODE_MODULES)/.bin
COVERAGE := $(ROOT)/.nyc_output
COVERAGE_RES := $(ROOT)/coverage
YARN_LOCK := $(ROOT)/yarn.lock
PACKAGE_LOCK := $(ROOT)/package-lock.json
#
# Tools and binaries
#
NPM := npm
YARN := yarn
ESLINT := $(NODE_BIN)/eslint
MOCHA := $(NODE_BIN)/mocha
NYC := $(NODE_BIN)/nyc
PRETTIER := $(NODE_BIN)/prettier
UNLEASH := $(NODE_BIN)/unleash
CONVENTIONAL_RECOMMENDED_BUMP := $(NODE_BIN)/conventional-recommended-bump
COVERALLS := $(NODE_BIN)/coveralls
#
# Files and globs
#
PACKAGE_JSON := $(ROOT)/package.json
API_MD := $(ROOT)/api.md
GITHOOKS := $(wildcard $(GITHOOKS_SRC)/*)
LCOV := $(COVERAGE)/lcov.info
ALL_FILES := $(shell find $(ROOT) \
-not \( -path $(NODE_MODULES) -prune \) \
-not \( -path $(COVERAGE) -prune \) \
-not \( -path $(COVERAGE_RES) -prune \) \
-name '*.js' -type f)
TEST_FILES := $(shell find $(TEST) -name '*.js' -type f)
#
# Targets
#
$(NODE_MODULES): $(PACKAGE_JSON) ## Install node_modules
@$(YARN)
@touch $(NODE_MODULES)
.PHONY: help
help:
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) \
| sort | awk 'BEGIN {FS = ":.*?## "}; \
{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: githooks
githooks: $(GITHOOKS) ## Symlink githooks
@$(foreach hook,\
$(GITHOOKS),\
ln -sf $(hook) $(GITHOOKS_DEST)/$(hook##*/);\
)
.PHONY: release-dry
release-dry: $(NODE_MODULES) ## Dry run of `release` target
@$(UNLEASH) -d --type=$(shell $(CONVENTIONAL_RECOMMENDED_BUMP) -p angular)
.PHONY: release
release: $(NODE_MODULES) security ## Versions, tags, and updates changelog based on commit messages
@$(UNLEASH) --type=$(shell $(CONVENTIONAL_RECOMMENDED_BUMP) -p angular) --no-publish
@$(NPM) publish
.PHONY: lint
lint: $(NODE_MODULES) $(ESLINT) $(ALL_FILES) ## Run lint checker (eslint).
@$(ESLINT) $(ALL_FILES)
.PHONY: lint-fix
lint-fix: $(NODE_MODULES) $(PRETTIER) $(ALL_FILES) ## Reprint code (prettier, eslint).
@$(PRETTIER) --write $(ALL_FILES)
@$(ESLINT) --fix $(ALL_FILES)
.PHONY: security
security: $(NODE_MODULES) ## Check for dependency vulnerabilities.
@# remove lockfile, reinstall to get latest deps and regen lockfile
@rm $(YARN_LOCK) || true
@$(YARN)
@$(YARN) audit || EXIT_CODE=$$?; \
if [ $$EXIT_CODE -gt 15 ] ; then \
echo "'yarn audit' exited with error code $$EXIT_CODE, critical vulnerabilities found!"; \
exit 1; \
else \
echo "'yarn audit' exited with error code $$EXIT_CODE, no critical vulnerabilities found."; \
fi
.PHONY: prepush
prepush: $(NODE_MODULES) lint coverage ## Git pre-push hook task. Run before committing and pushing.
.PHONY: test
test: $(NODE_MODULES) $(MOCHA) ## Run unit tests.
@$(MOCHA) -R spec --full-trace --no-timeouts $(TEST_FILES)
.PHONY: coverage
coverage: $(NODE_MODULES) $(NYC) ## Run unit tests with coverage reporting. Generates reports into /coverage.
@$(NYC) --reporter=html --reporter=text make test
.PHONY: report-coverage ## Report unit test coverage to coveralls
report-coverage: $(NODE_MODULES) $(NYC) ## Run unit tests with coverage reporting. Generates reports into /coverage.
@$(NYC) report --reporter=text-lcov | $(COVERALLS)
.PHONY: clean
clean: ## Cleans unit test coverage files and node_modules.
@rm -rf $(NODE_MODULES) $(COVERAGE) $(COVERAGE_RES) $(YARN_LOCK) $(PACKAGE_LOCK)
#
## Debug -- print out a a variable via `make print-FOO`
#
print-% : ; @echo $* = $($*)