-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Makefile
216 lines (173 loc) · 6.29 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
PACKAGE := $(shell node -e "x=`cat package.json`; console.log(x.name)")
VERSION := $(shell node -e "x=`cat assets/manifest.json`; console.log(x.version)")
COMMIT := $(shell git rev-parse --short HEAD)
DEV_TAG := $(if $(shell git tag --points-at=HEAD),,-dev)
DIRTY_TAG := $(if $(shell git status --porcelain),-dirty,)
FULL_VERSION := $(VERSION)$(DEV_TAG)-$(COMMIT)$(DIRTY_TAG)
ifeq ($(VERSION),)
$(error Unable to determine the current version number)
endif
ifeq ($(COMMIT),)
$(error Unable to determine the HEAD commit)
endif
RELEASE_DIR = releases
SRCPKG_DIR = $(PACKAGE)-src-$(FULL_VERSION)
SRC_PKG = $(RELEASE_DIR)/$(SRCPKG_DIR).tar.gz
DIST_PKG = $(RELEASE_DIR)/$(PACKAGE)-$(FULL_VERSION).zip
# Primary (user-facing) targets.
# The default target. This is unrolled so that the things that are most likely
# to fail and are fastest to fail, fail first, and so that style issues can be
# automatically fixed.
debug:
$(MAKE) check-types
$(MAKE) build-dbg build-chrome-dbg
$(MAKE) check-tests
$(MAKE) check-style || ( $(MAKE) fix-style && $(MAKE) debug )
.PHONY: debug
check: check-types check-tests check-style
.PHONY: check
check-types: node_modules
./node_modules/.bin/vue-tsc --noEmit
.PHONY: check-types
check-tests: node_modules
./node_modules/.bin/c8 ./node_modules/.bin/mocha
.PHONY: check-tests
check-style: node_modules
./node_modules/.bin/prettier --ignore-path .gitignore --check .
.PHONY: check-style
fix-style: node_modules
./node_modules/.bin/prettier --ignore-path .gitignore --write .
.PHONY: fix-style
rel:
$(MAKE) distclean release-tag
$(MAKE) rel-inner
.PHONY: rel
# rel-inner is separate from rel since the version-number variables at the top
# of this file will change after the release tag is created.
rel-inner:
$(MAKE) pkg-webext pkg-source
$(MAKE) -C $(RELEASE_DIR)/$(SRCPKG_DIR) release-tag pkg-webext pkg-source
@if [ ! -z "$$(diff -Nru dist $(RELEASE_DIR)/$(SRCPKG_DIR)/dist)" ]; then \
diff -Nru dist $(RELEASE_DIR)/$(SRCPKG_DIR)/dist; \
echo "!!!" >&2; \
echo "!!! Build did not reproduce correctly; check diff output above" >&2; \
echo "!!!" >&2; \
exit 1; \
fi
rm -rf $(RELEASE_DIR)/$(SRCPKG_DIR)
@echo ""
@echo "Ready for release $(VERSION)!"
@echo
@echo "Git tag: v$(VERSION)"
@echo "Release package: $(DIST_PKG)"
@echo "Source package: $(SRC_PKG)"
@echo
@echo "If everything looks good, run \"git push && git push --tags\", and"
@echo "upload to AMO."
@echo ""
.PHONY: rel-inner
# My version of `npm update`, since `npm update` seems to leave stale stuff
# lying around in package-lock.json. :/
up:
rm -rf package-lock.json node_modules
$(MAKE)
.PHONY: up
##
## Intermediate targets.
##
## Packaging and Release
pkg-webext: clean-working-tree build-rel
mkdir -p $(RELEASE_DIR)
cd dist && zip -9rvo ../$(DIST_PKG) `find . -type f`
.PHONY: pkg-webext
pkg-source: clean-working-tree
mkdir -p $(RELEASE_DIR)
rm -rf $(RELEASE_DIR)/$(SRCPKG_DIR) $(SRC_PKG)
git clone -b v$(VERSION) . $(RELEASE_DIR)/$(SRCPKG_DIR)
git -C $(RELEASE_DIR)/$(SRCPKG_DIR) fetch -f origin
git -C $(RELEASE_DIR)/$(SRCPKG_DIR) gc --aggressive
tar -C $(RELEASE_DIR) -czf $(SRC_PKG) $(SRCPKG_DIR)
.PHONY: pkg-source
release-tag: clean-working-tree
[ `git name-rev --tags --name-only HEAD` = "v$(VERSION)" ] || \
git tag v$(VERSION) HEAD
.PHONY: release-tag
.NOTPARALLEL: release-tag
clean-working-tree:
[ -z "$$(git status --porcelain)" ] # Working tree must be clean.
.PHONY: clean-working-tree
.NOTPARALLEL: clean-working-tree
## Build
build-chrome-dbg: build-dbg
rsync -aHvx --delete --force dist/ dist-chrome/
cp assets/manifest.json dist-chrome/
patch --no-backup-if-mismatch dist-chrome/manifest.json chrome-manifest.patch
.PHONY: build-chrome-dbg
build-dbg: node_modules icons dist/tab-stash.css
NODE_ENV=development ./node_modules/.bin/vite build -c vite.config.html.ts -m development
NODE_ENV=development ./node_modules/.bin/vite build -c vite.config.lib.ts -m development
./node_modules/.bin/copyfiles -u 1 'assets/**/*' dist
.PHONY: build-dbg
build-rel:
$(MAKE) clean
$(MAKE) node_modules icons dist/tab-stash.css
$(MAKE) check
NODE_ENV=production ./node_modules/.bin/vite build -c vite.config.html.ts -m production
NODE_ENV=production ./node_modules/.bin/vite build -c vite.config.lib.ts -m production
./node_modules/.bin/copyfiles -u 1 'assets/**/*' dist
./node_modules/.bin/web-ext lint -s dist -i 'test.*'
.PHONY: build-rel
node_modules: package-lock.json
node_modules package-lock.json: package.json
npm install
touch node_modules package-lock.json
dist/tab-stash.css: node_modules $(wildcard styles/*.less) $(wildcard styles/*/*.less)
@mkdir -p dist
./node_modules/.bin/lessc --math=strict styles/index.less dist/tab-stash.css
## Build Icons
DARK_ICONS = $(patsubst icons/%,dist/icons/dark/%,$(wildcard icons/*.svg))
LIGHT_ICONS = $(patsubst icons/%,dist/icons/light/%,$(wildcard icons/*.svg))
LOGO_ICONS = dist/icons/logo.svg \
dist/icons/warning.svg \
$(foreach size,16 32 48 64 96 128,dist/icons/logo-$(size).png)
TOOLBAR_ICONS = dist/icons/stash-one.svg \
$(foreach size,16 32 64,dist/icons/logo-$(size).png) \
$(foreach theme,dark light,$(foreach size,16 32 64,dist/icons/$(theme)/logo-$(size).png))
icons: $(DARK_ICONS) $(LIGHT_ICONS) $(LOGO_ICONS) $(TOOLBAR_ICONS)
.PHONY: icons
dist/icons/dark/%.svg: icons/%.svg
@mkdir -p $(dir $@)
sed 's%style="[^"]*"%style="fill:#fbfbfe"%g' <$< >$@
dist/icons/%.svg: icons/%.svg
@mkdir -p $(dir $@)
sed 's%style="[^"]*"%style="fill:#808080"%g' <$< >$@
dist/icons/light/%.svg: icons/%.svg
@mkdir -p $(dir $@)
sed 's%style="[^"]*"%style="fill:#222426"%g' <$< >$@
%-16.png: %.svg
inkscape "$<" -o "$@" -D -w 16 -h 16
%-32.png: %.svg
inkscape "$<" -o "$@" -D -w 32 -h 32
%-48.png: %.svg
inkscape "$<" -o "$@" -D -w 48 -h 48
%-64.png: %.svg
inkscape "$<" -o "$@" -D -w 64 -h 64
%-96.png: %.svg
inkscape "$<" -o "$@" -D -w 96 -h 96
%-128.png: %.svg
inkscape "$<" -o "$@" -D -w 128 -h 128
## Website
BUNDLE = $(if $(shell type /opt/homebrew/opt/ruby/bin/bundle),/opt/homebrew/opt/ruby/bin/bundle,bundle)
site:
cd docs; $(BUNDLE) install
cd docs; $(BUNDLE) exec jekyll serve -H 0.0.0.0
.PHONY: site
## Cleanup
distclean: clean
rm -rf node_modules docs/vendor \
$(RELEASE_DIR)/$(SRCPKG_DIR) $(SRC_PKG) $(DIST_PKG) \
releases/*-dirty* releases/*-dev*
.PHONY: distclean
clean:
rm -rf build.test dist dist-chrome docs/_site coverage
.PHONY: clean