forked from Ripplemerich777/cw-sdk-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (83 loc) · 2.75 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
SHELL := /bin/bash
proto_module := src/websocket/modules/proto
version_file := src/version.ts
build: node_modules src/websocket/modules ## Build project
rm -rf build
npm run build
src/websocket/modules: proto-module version-file ## Generate typescript definition files
# Generate typescript definitions for our protobuf messages
proto-module: node_modules
mkdir -p ${proto_module}
# Generate static module
yarn run pbjs:static-module
echo "/* Generated by Makefile */" > ${proto_module}/index.js
echo "/* tslint:disable */" >> ${proto_module}/index.js
cat index.tmp.js >> ${proto_module}/index.js
rm index.tmp.js
# Generate definition files
yarn run pbjs:definitions
# Add some stuff to the top of the file and rename it
echo "/* Generated by Makefile */" > ${proto_module}/index.d.ts
echo "/* tslint:disable */" >> ${proto_module}/index.d.ts
cat proto.d.ts >> ${proto_module}/index.d.ts
rm proto.d.ts
# Copy pre-built d.ts files to build folder
yarn run copy-dts
# Generate a version.ts file that exports the current version of the app
version-file:
rm -rf ${version_file}
PACKAGE_VERSION=$$(node -p -e "require('./package.json').version") ; \
echo "/* This code was generated by Makefile: \"make set_version_file\" */" > ${version_file} ; \
echo "const version = \"$$PACKAGE_VERSION\";" >> ${version_file} ; \
echo "export default version;" >> ${version_file}
test: test-diff lint test-modules test-package ## Shortcut to run all tests
lint: node_modules ## Run linter
npm run lint
test-modules: node_modules ## Test package modules
timeout -k 5s 20s npm run test -- test src --ci
test-diff: clean build docs ## Tests if generated code was made properly
@TMP=$$(mktemp -t checkout-diff.XXXXXX) ; \
git diff ./ > $$TMP ; \
if [ -s "$$TMP" ]; then \
echo Found diffs in checkout:; git status -s; head -n 50 "$$TMP"; \
rm $$TMP; \
echo; \
echo 'Try running "make"'; \
echo; \
exit 1; \
fi; \
rm $$TMP;
test-package: build ## Tests packaged npm module
npm pack
@PACK=$$(find . -name cw-sdk-node* | xargs basename $1) ; \
TMP=$$(mktemp -d -t package-test.XXXXXX) ; \
echo $$TMP ; \
echo $$PACK ; \
echo mv $$PACK $$TMP ; \
mv $$PACK $$TMP ; \
cp __tests__/package/package.json $$TMP ; \
cp __tests__/package/index.js $$TMP ; \
cd $$TMP ; \
npm i $$PACK ; \
node . ; \
if ! node .; then \
rm -rf $$TMP ; \
exit 1; \
fi; \
rm -rf $$TMP
node_modules:
yarn
docs:
yarn run docs
clean: ## Remove generated files
rm -rf node_modules build
help: ## Show help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: build \
docs \
test \
lint \
test-diff \
test-modules \
test-package