-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
189 lines (138 loc) · 4.72 KB
/
Copy pathMakefile
File metadata and controls
189 lines (138 loc) · 4.72 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# This Makefile is meant to be exported by Patternslib or Mockup packages.
# .evn include, mainly for a GITHUB_TOKEN.
-include .env
export
# If you want to release on GitHub, make sure to have a .env file with a GITHUB_TOKEN.
# Also see:
# https://github.com/settings/tokens
# and https://github.com/release-it/release-it/blob/master/docs/github-releases.md#automated
ESLINT ?= npx eslint
PRETTIER ?= npx prettier
YARN ?= npx yarn
BUILDABLE := $(shell node -p "Boolean(require('./package.json').scripts?.build)")
PACKAGE_NAME := $(shell node -p "require('./package.json').name")
BUNDLE_NAME := $(subst @patternslib/,,$(subst @plone/,,$(PACKAGE_NAME)))
.PHONY: install
yarn.lock install: .git/hooks/commit-msg
$(YARN) install
.git/hooks/commit-msg:
echo "npx commitlint --edit" > .git/hooks/commit-msg
chmod u+x .git/hooks/commit-msg
.PHONY: clean-dist
clean-dist:
rm -Rf dist/
.PHONY: clean
clean: clean-dist
rm -Rf node_modules/
.PHONY: eslint
eslint: install
$(ESLINT) ./src
.PHONY: prettier
prettier: install
$(PRETTIER) --write .
.PHONY: check
check: install eslint
$(YARN) run test
.PHONY: bundle-pre
bundle-pre::
@# Override this in your project to add some tasks before the bundle is built.
@# Please use double-colons `::` so that the base bundle-pre is also run.
@# Example: Unlink any linked dependencies.
@# bundle-pre::
@# -yarn unlink @patternslib/patternslib
@# yarn install --force
npx update-browserslist-db@latest
# Compile the bundle.
# NOTE: When using the normal workflow - e.g. `make release-minor`, the
# relase-it config runs `make bundle` after the version bump.
.PHONY: bundle
bundle: clean-dist bundle-pre install
ifeq ($(BUILDABLE),true)
$(YARN) run build
endif
# Create a ZIP file from the bundle which is uploaded to the GitHub release tag.
# NOTE: When using the normal workflow - e.g. `make release-minor`, the
# relase-it config runs `make release-zip` after the version bump and `make bundle`.
.PHONY: release-zip
release-zip:
ifeq ($(BUILDABLE),true)
$(eval PACKAGE_VERSION := $(shell node -p "require('./package.json').version"))
@echo Creating $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
mkdir -p $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
cp -R dist/. $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
zip -r $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)/
rm -Rf $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
endif
# Prepare some necessary variables.
.PHONY: prepare-release
prepare-release:
$(eval RELEASE_IT_GITHUB_OPTIONS :=)
ifeq ($(LEVEL),$(filter $(LEVEL), alpha beta))
@# case alpha or beta pre-release
@# Set level argument for release-it.
$(eval RELEASE_IT_LEVEL := "--preRelease=$(LEVEL)")
else
@# case normal major/minor/patch release
@# Set level argument for release-it.
$(eval RELEASE_IT_LEVEL := $(LEVEL))
endif
# Note release-zip is run via the `after:bump` hook from .release-it.js, so
# that the build contains the correct version bump.
.PHONY: release
release: clean install check prepare-release
@# Note: The consuming package must include dist/ in its package.json files list.
$(eval PACKAGE_VERSION := $(shell npx release-it $(RELEASE_IT_LEVEL) --release-version))
ifeq ($(BUILDABLE),true)
$(eval RELEASE_IT_GITHUB_OPTIONS += --github.assets=$(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip)
endif
npx release-it \
$(RELEASE_IT_LEVEL) \
--github.release \
--no-github.update \
--no-github.draft \
$(RELEASE_IT_GITHUB_OPTIONS)
@# Remove the bundle from release-zip again.
@# But don't break if it doesn't exist.
-rm $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
.PHONY: release-major
release-major:
$(MAKE) LEVEL=major release
.PHONY: release-minor
release-minor:
$(MAKE) LEVEL=minor release
.PHONY: release-patch
release-patch:
$(MAKE) LEVEL=patch release
.PHONY: prerelease-alpha
prerelease-alpha:
$(MAKE) LEVEL=alpha release
.PHONY: prerelease-beta
prerelease-beta:
$(MAKE) LEVEL=beta release
.PHONY: serve
serve: install
$(YARN) run start
upgrade:\
.git/hooks/commit-msg\
upgrade-remove-husky\
upgrade-eslint
@# Upgrade target, depends on other upgrades
upgrade-remove-husky:
test -d .husky\
&& rm -R .husky\
&& git add .husky\
&& git commit -m"maint: @patternslib/dev upgrade - remove .husky directory in favor of git hooks."\
|| :
-git config --unset core.hooksPath
eslint.config.js upgrade-eslint:
test -f "eslint.config.js"\
|| (\
echo 'module.exports = require("@patternslib/dev/eslint.config.js");' > eslint.config.js\
&& git add eslint.config.js\
&& git commit -m"maint: @patternslib/dev upgrade - create eslint.config.js."\
)
test -f ".eslintrc.js"\
&& rm .eslintrc.js\
&& git add .eslintrc.js\
&& git commit -m"maint: @patternslib/dev upgrade - remove old .eslintrc.js."\
|| :