1
+ # This Makefile is meant to be exported by Patternslib or Mockup packages.
2
+
3
+ # .evn include, mainly for a GITHUB_TOKEN.
1
4
-include .env
2
5
export
3
6
7
+
8
+ # If you want to release on GitHub, make sure to have a .env file with a GITHUB_TOKEN.
9
+ # Also see:
10
+ # https://github.com/settings/tokens
11
+ # and https://github.com/release-it/release-it/blob/master/docs/github-releases.md#automated
12
+
13
+
4
14
ESLINT ?= npx eslint
5
15
YARN ?= npx yarn
6
16
7
17
PACKAGE_DEV =@patternslib/dev
8
18
PACKAGE_NAME := $(shell node -p "require('./package.json') .name")
19
+ BUNDLE_NAME := $(subst @patternslib/,,$(subst @plone/,,$(PACKAGE_NAME ) ) )
9
20
10
21
.PHONY : install
11
22
stamp-yarn install :
@@ -43,6 +54,7 @@ bundle-pre:
43
54
@# yarn install --force
44
55
45
56
57
+ # Compile the bundle.
46
58
.PHONY : bundle
47
59
bundle : bundle-pre stamp-yarn
48
60
ifneq "$(PACKAGE_NAME ) " "$(PACKAGE_DEV ) "
@@ -51,58 +63,104 @@ ifneq "$(PACKAGE_NAME)" "$(PACKAGE_DEV)"
51
63
endif
52
64
53
65
54
- # If you want to release on GitHub, make sure to have a .env file with a GITHUB_TOKEN.
55
- # Also see:
56
- # https://github.com/settings/tokens
57
- # and https://github.com/release-it/release-it/blob/master/docs/github-releases.md#automated
58
-
59
-
66
+ # Create a ZIP file from the bundle which is uploaded to the GitHub release tag.
60
67
release-zip : clean-dist bundle
61
68
ifneq "$(PACKAGE_NAME ) " "$(PACKAGE_DEV ) "
62
69
@# Do not create a zip release for @patternslib/dev
63
- $(eval BUNDLE_NAME := $(subst @patternslib/,,$(subst @plone/,,$(PACKAGE_NAME))))
64
70
$(eval PACKAGE_VERSION := $(shell node -p "require('./package.json').version"))
65
71
@echo Creating $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
66
- mkdir -p dist/$(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
67
- -mv dist/* dist/$(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
68
- cd dist/ && zip -r $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)/
72
+ mkdir -p $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
73
+ -cp -R dist/* $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
74
+ zip -r $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)/
75
+ rm -Rf $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
69
76
endif
70
77
71
78
79
+ # Update the package.json version with NEXT_VERSION
80
+ define write_package_json
81
+ const fs = require("fs"); \
82
+ const package_json = require("./package.json"); \
83
+ package_json.version = "$(NEXT_VERSION ) "; \
84
+ const data = JSON.stringify(package_json, null, 4); \
85
+ fs.writeFileSync("package.json", data);
86
+ endef
87
+
88
+ prepare-release :
89
+ @# Get the current package version.
90
+ $(eval CURRENT_VERSION := $(shell node -p "require('./package.json') .version") )
91
+ ifeq ($(LEVEL ) ,$(filter $(LEVEL ) , alpha beta) )
92
+ @# case alpha or beta pre-release
93
+
94
+ @# Set level argument for release-it.
95
+ $(eval RELEASE_IT_LEVEL := "--preRelease=$(LEVEL)")
96
+ @# Get the next version via semver.
97
+ $(eval NEXT_VERSION := $(shell npx semver --increment premajor --preid $(LEVEL) $(CURRENT_VERSION)))
98
+ else
99
+ @# case normal major/minor/patch release
100
+
101
+ @# Set level argument for release-it.
102
+ $(eval RELEASE_IT_LEVEL := $(LEVEL))
103
+ @# Get the next version via semver.
104
+ $(eval NEXT_VERSION := $(shell npx semver --increment $(LEVEL) $(CURRENT_VERSION)))
105
+ endif
106
+ @echo Next version is: $(NEXT_VERSION)
107
+
108
+ @# Temporarily write the NEXT_VERSION to package.json, so that the bundle
109
+ @# and release-zip generate correct version strings.
110
+ node -p '$(write_package_json)'
111
+
112
+
113
+ release : clean install check prepare-release release-zip
114
+ @# RELEASE_IT_LEVEL and NEXT_VERSION set by prepare-release
115
+
116
+ @# Note: If you want to include the compiled bundle in your npm package you
117
+ @# have to allow it in a .npmignore file.
118
+
119
+ @# Checkout package.json which was modified by prepare-release and read by
120
+ @# release-zip.
121
+ git checkout .
122
+
123
+ @# 1) Release on npm.
124
+ @# 2) When successful, update release on GitHub
125
+ @# 3) Checkout CHANGES.md, which was modified by step 2)
126
+ npx release-it $(RELEASE_IT_LEVEL) \
127
+ && npx release-it \
128
+ --github.release \
129
+ --github.update \
130
+ --github.assets=$(BUNDLE_NAME)-bundle-$(NEXT_VERSION).zip \
131
+ --no-github.draft \
132
+ --no-increment \
133
+ --no-git \
134
+ --no-npm
135
+ && git checkout CHANGES.md
136
+
137
+ @# Remove the bundle from release-zip again.
138
+ rm $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
139
+
140
+
72
141
.PHONY : release-major
73
- release-major : check
74
- npx release-it major && \
75
- make release-zip && \
76
- npx release-it --github.release --github.update --github.assets=dist/* .zip --no-github.draft --no-increment --no-git --no-npm && \
77
- git checkout CHANGES.md
142
+ release-major :
143
+ make LEVEL=major release
144
+
78
145
79
146
.PHONY : release-minor
80
- release-minor : check
81
- npx release-it minor && \
82
- make release-zip && \
83
- npx release-it --github.release --github.update --github.assets=dist/* .zip --no-github.draft --no-increment --no-git --no-npm && \
84
- git checkout CHANGES.md
147
+ release-minor :
148
+ make LEVEL=minor release
149
+
85
150
86
151
.PHONY : release-patch
87
- release-patch : check
88
- npx release-it patch && \
89
- make release-zip && \
90
- npx release-it --github.release --github.update --github.assets=dist/* .zip --no-github.draft --no-increment --no-git --no-npm && \
91
- git checkout CHANGES.md
152
+ release-patch :
153
+ make LEVEL=patch release
154
+
92
155
93
156
.PHONY : prerelease-alpha
94
- prerelease-alpha : clean install
95
- npx release-it --preRelease=alpha && \
96
- make release-zip && \
97
- npx release-it --github.release --github.update --github.assets=dist/* .zip --no-github.draft --no-increment --no-git --no-npm && \
98
- git checkout CHANGES.md
157
+ prerelease-alpha :
158
+ make LEVEL=alpha release
159
+
99
160
100
161
.PHONY : prerelease-beta
101
- prerelease-beta : clean install
102
- npx release-it --preRelease=beta && \
103
- make release-zip && \
104
- npx release-it --github.release --github.update --github.assets=dist/* .zip --no-github.draft --no-increment --no-git --no-npm && \
105
- git checkout CHANGES.md
162
+ prerelease-beta :
163
+ make LEVEL=beta release
106
164
107
165
108
166
.PHONY : serve
0 commit comments