generated from napi-rs/package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
84 lines (69 loc) · 2.95 KB
/
Makefile
File metadata and controls
84 lines (69 loc) · 2.95 KB
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
all: index.js index.d.ts asn1-napi-rs.node
# Print some usage information
help:
@echo 'Usage:'
@echo ' make [all] - Build the N-API module'
@echo ' make test - Run automated tests'
@echo ' make do-test-cargo-only - Run just the Cargo tests'
@echo ' make do-test-no-dep-build - Run the automated tests without rebuilding dependencies'
@echo ' make do-lint - Run linters'
@echo ' make do-bench - Run automated benchmarks'
@echo ' make do-npm-publish - Publish NPM package'
@echo ' make clean - Remove generated files'
@echo ' make distclean - Remove generated and downloaded/cached files'
@echo ' make help - Print this usage information'
# Install "node_modules"
node_modules/.done: package.json package-lock.json
rm -rf node_modules
npm clean-install
@touch node_modules/.done
node_modules: node_modules/.done
@touch node_modules
# Build the local NAPI module
index.js: Cargo.toml Cargo.lock package.json package-lock.json tsconfig.json node_modules $(shell find src -type f) build.rs utils/helpers.ts
rm -rf __TMP__
npm run napi -- build --platform --release __TMP__ $(NAPI_LOCAL_BUILD_ARGS)
npm run prettier -- __TMP__/index.* --write --loglevel error
rm -f index.js index.d.ts
mv __TMP__/index.* __TMP__/asn1-napi-rs.*.node ./
rmdir __TMP__
echo 'export type ASN1AnyJS = ASN1AnyJS[] | bigint | number | Date | Buffer | ASN1OID | ASN1Set | ASN1ContextTag | ASN1BitString | ASN1Date | ASN1String | ASN1Struct | string | boolean | null | undefined;' >> index.d.ts
# "index.d.ts" is generated by the rule that generates "index.js", but Make
# lacks a way to express this outcome
index.d.ts: index.js
@touch index.d.ts
asn1-napi-rs.node: index.js
rm -f asn1-napi-rs.node
ln -s $(shell echo ./asn1-napi-rs.*.node | sed 's@^\./@./@') asn1-napi-rs.node
touch asn1-napi-rs.node
# Run automated tests
test: node_modules index.js index.d.ts asn1-napi-rs.node
cargo test
npm run ava
# Run just the Cargo tests, which does not require the NAPI module to be built
do-test-cargo-only:
cargo test
# Run the automated tests, but do not rebuild the dependencies
# This is because the dependencies are already built during the CI process
# and we do not want to rebuild them just because they are technically out
# of date
do-test-no-dep-build: node_modules
npm run ava
do-lint: node_modules
npm run eslint -- -c ./.eslintrc.yml .
rustfmt --check $(shell find src -type f)
# Run automated benchmarks
do-bench: node_modules index.js index.d.ts asn1-napi-rs.node
node -r @swc-node/register benchmark/bench.ts
# Create an npm package
do-npm-publish: node_modules
npm publish
# Remove generated files
clean:
rm -rf __TMP__
rm -f asn1-napi-rs*.node index.js index.d.ts
# Remove generated and downloaded files
distclean: clean
rm -rf target
rm -rf node_modules
.PHONY: all help test do-test-no-dep-build do-test-cargo-only do-lint do-bench do-npm-publish clean distclean