-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
175 lines (132 loc) · 4.78 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
INNER_PACKAGES_DIR := $(CURDIR)/packages
MAIN_PKG := $(INNER_PACKAGES_DIR)/option-t
API_TEST_PKG := $(INNER_PACKAGES_DIR)/api_tests
TYPE_IMPORT_TEST_UNDER_MODULE_RESOLUTION_NODE16_PKG := $(INNER_PACKAGES_DIR)/test_module_resolution_node16
TYPE_IMPORT_TEST_UNDER_MODULE_RESOLUTION_BUNDLER_PKG := $(INNER_PACKAGES_DIR)/test_module_resolution_bundler
DIST_DIR := $(MAIN_PKG)/__dist
NODE_BIN := node
NPM_MOD_DIR := $(CURDIR)/node_modules
NPM_BIN := $(NPM_MOD_DIR)/.bin
NPM_CMD := npm
PNPM_CMD := pnpm
PROJECT_NPMRC := $(DIST_DIR)/.npmrc
all: help
help:
@echo "Specify the task"
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@exit 1
###########################
# Setup
###########################
.PHONY: install
install: ## Install dependencies.
$(PNPM_CMD) install
###########################
# Clean
###########################
CLEAN_TARGETS := \
repo_root \
main_pkg \
.PHONY: clean
clean: $(addprefix clean_, $(CLEAN_TARGETS)) ## Clean up generated items.
.PHONY: clean_main_pkg
clean_main_pkg:
$(MAKE) clean -C $(MAIN_PKG)
.PHONY: clean_repo_root
clean_repo_root: clean_npmrc
.PHONY: clean_npmrc
clean_npmrc:
$(NPM_BIN)/del $(PROJECT_NPMRC)
###########################
# Build
###########################
.PHONY: build
build:
$(MAKE) $@ -C $(MAIN_PKG)
###########################
# Lint
###########################
.PHONY: lint
lint: eslint ## Run all lints
.PHONY: eslint
eslint:
$(NPM_BIN)/eslint $(CURDIR)/
.PHONY: eslint_fix
eslint_fix: ## Apply ESLint's `--fix` mode
$(NPM_BIN)/eslint --fix $(CURDIR)/
.PHONY: typecheck
typecheck: ## Check static types.
$(MAKE) $@ -C $(MAIN_PKG)
###########################
# Test
###########################
.PHONY: test_unittest
test_unittest: build ## Build and run unit tests
$(MAKE) run_test_unittest -C $(CURDIR)
.PHONY: test_import_types
test_import_types: build ## Build and run type import tests
$(MAKE) run_test_import_types -C $(CURDIR)
MODULE_RESOLUTION_TEST_TARGETS := \
node16 \
bundler
.PHONY: run_test_import_types
run_test_import_types: $(addprefix __run_test_import_types_under_module_resolution_, $(MODULE_RESOLUTION_TEST_TARGETS)) ## Run type import tests
.PHONY: __run_test_import_types_under_module_resolution_node16
__run_test_import_types_under_module_resolution_node16:
$(MAKE) test -C $(TYPE_IMPORT_TEST_UNDER_MODULE_RESOLUTION_NODE16_PKG)
.PHONY: __run_test_import_types_under_module_resolution_bundler
__run_test_import_types_under_module_resolution_bundler:
$(MAKE) test -C $(TYPE_IMPORT_TEST_UNDER_MODULE_RESOLUTION_BUNDLER_PKG)
.PHONY: run_test_unittest
run_test_unittest: ## Run unit tests only.
$(MAKE) test -C $(API_TEST_PKG)
.PHONY: run_test_unittest_with_update_snapshots
run_test_unittest_with_update_snapshots: ## Run unit tests only with updating snapshots.
$(MAKE) test_with_update_snapshots -C $(API_TEST_PKG)
.PHONY: test_package_json_exports_field_format
test_package_json_exports_field_format:
$(MAKE) $@ -C $(MAIN_PKG)
.PHONY: test_distribution_contain_all
test_distribution_contain_all:
$(MAKE) $@ -C $(MAIN_PKG)
.PHONY: run_test_distribution_contain_all
run_test_distribution_contain_all: ## Run the test that check to contain expected items all.
$(MAKE) $@ -C $(MAIN_PKG)
.PHONY: run_test_distribution_contain_all
run_test_distribution_contain_all_with_update_snapshots: ## Run the test that check to contain expected items all with updating snapshots.
$(MAKE) $@ -C $(MAIN_PKG)
###########################
# Tools
###########################
.PHONY: generate_import_path_list_md
generate_import_path_list_md: ## Generate all public import paths to docs/import_path.md
$(MAKE) $@ -C $(MAIN_PKG)
.PHONY: format
format: ## Apply formatters
$(NPM_BIN)/prettier --write $(CURDIR)
.PHONY: format_check
format_check: ## Check code formatting
$(NPM_BIN)/prettier --check $(CURDIR)
.PHONY: prepublish
prepublish:
$(MAKE) $@ -C $(MAIN_PKG)
$(MAKE) run_test_unittest -C $(CURDIR)
$(MAKE) run_test_import_types -C $(CURDIR)
.PHONY: publish
publish: copy_npmrc_to_project_root ## Run some commands for 'npm publish'
$(MAKE) $@ -C $(MAIN_PKG)
.PHONY: copy_npmrc_to_project_root
copy_npmrc_to_project_root: clean_npmrc
cp $(CURDIR)/tools/publish/.npmrc $(PROJECT_NPMRC)
.PHONY: git_diff
git_diff: ## Test whether there is no committed changes.
git diff --exit-code
.PHONY: version_major
version_major: ## Alias to run `npm version major -ws`.
$(NPM_CMD) version major --no-git-tag-version --workspaces --no-workspaces-update
.PHONY: version_minor
version_minor: ## Alias to run `npm version minor -ws`.
$(NPM_CMD) version minor --no-git-tag-version --workspaces --no-workspaces-update
.PHONY: version_patch
version_patch: ## Alias to run `npm version patch -ws`.
$(NPM_CMD) version patch --no-git-tag-version --workspaces --no-workspaces-update