-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
102 lines (77 loc) · 2.38 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
node := node
eslint := tools/node_modules/.bin/eslint
flow := tools/node_modules/.bin/flow
babel := tools/node_modules/.bin/babel
babel-node := tools/node_modules/.bin/babel-node
mocha := tools/node_modules/.bin/mocha
_mocha := tools/node_modules/.bin/_mocha
babel-external-helpers := tools/node_modules/.bin/babel-external-helpers
istanbul := tools/node_modules/.bin/istanbul
MOCHA_OPTS := --ui=`pwd`/tools/mocha-interface.js
SCRIPT_FILES = $(wildcard scripts/*.js)
SCRIPTS = $(patsubst scripts/%.js,%,$(SCRIPT_FILES))
define SCRIPT
run.$(1):
@echo
@echo "Running \033[0;32mscripts/$(1).js\033[0m"
@echo
@$(babel-node) ./scripts/$(1).js
endef
all: clean flow lint test check-coverage compile
$(foreach i,$(SCRIPTS), $(eval $(call SCRIPT,$(i))))
lint:
$(eslint) src
flow:
$(flow) check --no-flowlib
compile:
@rm -rf src-compiled
$(babel) src --ignore __tests__ --out-dir src-compiled --copy-files
compile-test:
@rm -rf src-compiled-test
$(babel) src --out-dir src-compiled-test --copy-files
compile-cover:
@rm -rf src-compiled-cover
$(babel) src --out-dir src-compiled-cover --copy-files --plugins=`pwd`/tools/node_modules/babel-plugin-external-helpers-2
cover: compile-cover
@rm -rf cover
$(babel-external-helpers) > ./babel-helpers.js
$(istanbul) cover $(_mocha) -- --require ./babel-helpers.js src-compiled-cover/**/__tests__/**/*.js $(MOCHA_OPTS)
@rm babel-helpers.js
check-coverage: cover
$(istanbul) check-coverage
test: compile-test
$(mocha) src-compiled-test/**/__tests__/**/*.js $(MOCHA_OPTS)
clean:
@rm -rf src-compiled
@rm -rf src-compiled-test
@rm -rf src-compiled-cover
@rm -rf cover
# lib only
define PKG
var pkg = require('./package.json');
delete pkg.devDependencies;
delete pkg.scripts;
delete pkg.private; // private is used to prevent from publishing source
delete pkg.allowPublish;
console.log(JSON.stringify(pkg));
endef
export PKG
define CHECK
var pkg = require('./package.json');
if (!pkg.allowPublish) {
throw new Error('publishing is not allowed');
}
endef
export CHECK
dist: compile
@$(node) -e "$$CHECK"
@rm -rf dist
@mkdir -p dist
@cp -r src/ dist
@find dist/ -name '__tests__' | xargs rm -r
@find dist/ -name '*.js' | xargs -I {} mv {} {}.flow
@cp -r src-compiled/ dist
@$(node) -e "$$PKG" > dist/package.json
publish:
cd dist && npm publish
.PHONY: clean test lint flow compile compile-test compile-cover all cover run.% check-coverage dist publish