This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
129 lines (96 loc) · 3.13 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
#
# Directories
#
ROOT_SLASH := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
ROOT := $(patsubst %/,%,$(ROOT_SLASH))
TEST := $(ROOT)/test
TOOLS := $(ROOT)/tools
GITHOOKS_SRC := $(TOOLS)/githooks
GITHOOKS_DEST := $(ROOT)/.git/hooks
#
# Generated Directories
#
NODE_MODULES := $(ROOT)/node_modules
NODE_BIN := $(NODE_MODULES)/.bin
COVERAGE := $(ROOT)/coverage
#
# Tools and binaries
#
NPM := npm
ESLINT := $(NODE_BIN)/eslint
JSCS := $(NODE_BIN)/jscs
MOCHA := $(NODE_BIN)/mocha
_MOCHA := $(NODE_BIN)/_mocha
ISTANBUL := $(NODE_BIN)/istanbul
NSP := $(NODE_BIN)/nsp
COVERALLS := $(NODE_BIN)/coveralls
NSP_BADGE := $(TOOLS)/nspBadge.js
#
# Files and globs
#
PACKAGE_JSON := $(ROOT)/package.json
SHRINKWRAP := $(ROOT)/npm-shrinkwrap.json
GITHOOKS := $(wildcard $(GITHOOKS_SRC)/*)
LCOV := $(COVERAGE)/lcov.info
ALL_FILES := $(shell find $(ROOT) \
-not \( -path $(NODE_MODULES) -prune \) \
-not \( -path $(COVERAGE) -prune \) \
-name '*.js' -type f)
TEST_FILES := $(shell find $(TEST) -name '*.js' -type f)
#
# Targets
#
.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}'
$(NODE_MODULES): $(PACKAGE_JSON) ## Install node_modules
@$(NPM) install
@touch $(NODE_MODULES)
.PHONY: githooks
githooks: $(GITHOOKS) ## Symlink githooks
@$(foreach hook,\
$(GITHOOKS),\
ln -sf $(hook) $(GITHOOKS_DEST)/$(hook##*/);\
)
.PHONY: lint
lint: $(NODE_MODULES) $(ESLINT) $(ALL_FILES) ## Run lint checker (eslint).
@$(ESLINT) $(ALL_FILES)
.PHONY: codestyle
codestyle: $(NODE_MODULES) $(JSCS) $(ALL_FILES) ## Run code style checker (jscs).
@$(JSCS) $(ALL_FILES)
.PHONY: codestyle-fix
codestyle-fix: $(NODE_MODULES) $(JSCS) $(ALL_FILES) ## Run code style checker with auto whitespace fixing (jscs).
@$(JSCS) $(ALL_FILES) --fix
.PHONY: nsp
nsp: $(NODE_MODULES) $(NSP) $(NSP_BADGE) ## Run nsp. Shrinkwraps dependencies, checks for vulnerabilities.
ifeq ($(wildcard $(SHRINKWRAP)),)
@$(NPM) shrinkwrap --dev
@($(NSP) check) | $(NSP_BADGE)
@rm $(SHRINKWRAP)
else
@($(NSP) check) | $(NSP_BADGE)
endif
.PHONY: prepush
prepush: $(NODE_MODULES) lint codestyle coverage nsp ## Git pre-push hook task. Run before committing and pushing.
.PHONY: test
test: $(NODE_MODULES) $(MOCHA) ## Run unit tests.
@$(MOCHA) -R spec --full-trace $(TEST_FILES)
.PHONY: coverage-html
coverage-html: $(NODE_MODULES) $(ISTANBUL) $(_MOCHA) $(COVERAGE_BADGE) ## Run unit tests with coverage reporting. Generates reports into /coverage.
@$(ISTANBUL) cover $(_MOCHA) --report html -- -R spec $(TEST_FILES)
.PHONY: coverage
coverage: $(NODE_MODULES) $(ISTANBUL) $(_MOCHA) $(COVERAGE_BADGE) ## Run unit tests with coverage reporting. Generates reports into /coverage.
@$(ISTANBUL) cover $(_MOCHA) --report lcovonly -- -R spec $(TEST_FILES)
.PHONY: report-coverage ## Report unit test coverage to coveralls
report-coverage: coverage
@cat $(LCOV) | $(COVERALLS)
.PHONY: clean
clean: ## Cleans unit test coverage files and node_modules.
@rm -rf $(NODE_MODULES)
@rm -rf $(COVERAGE)
#
## Debug -- print out a a variable via `make print-FOO`
#
print-% : ; @echo $* = $($*)