-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
131 lines (112 loc) · 4.14 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
NAME=JobsFiltererForLinkedIn
#
# The first time this extension was uploaded to the Chrome Web Store the
# private key was included in it but it doesn't need to be after that and I
# don't want to keep it in the source tree both because it's a security issue
# and Chrome complains about unpacked extensions with private key files in
# their directories.
#
#PRIVATE_KEY=key.pem
GEN_JS_FILES=$(patsubst %.in,%,$(wildcard *.js.in)) button.js
TEST_FILES=$(GEN_JS_FILES) \
$(filter-out utils.js button.js $(GEN_JS_FILES),$(wildcard *.js)) \
$(wildcard *.html) manifest.json options.html \
icons/16.png icons/48.png icons/128.png $(PRIVATE_KEY)
SHIP_FILES=$(filter-out tests.js,$(TEST_FILES))
ESLINT=node_modules/.bin/eslint
all: $(GEN_JS_FILES) $(NAME).zip $(NAME)-test.zip $(NAME).xpi $(NAME)-test.xpi
$(NAME).zip: $(foreach f,$(SHIP_FILES),build/$(f))
@if grep 'utils\.debugging.*true' $(SHIP_FILES); then \
echo "Can't ship with debugging enabled" 1>&2; false; \
else true; fi
rm -f build/[email protected]
cd build && zip -r [email protected] $(SHIP_FILES)
mv -f build/[email protected] $@
$(NAME).crx: $(foreach f,$(SHIP_FILES),build/$(f))
@if grep 'utils\.debugging.*true' $(SHIP_FILES); then \
echo "Can't ship with debugging enabled" 1>&2; false; \
else true; fi
rm -f firefox/[email protected]
cd firefox && zip -r [email protected] $(SHIP_FILES)
mv -f firefox/[email protected] $@
$(NAME).xpi: $(foreach f,$(SHIP_FILES),firefox/$(f))
@if grep 'utils\.debugging.*true' $(SHIP_FILES); then \
echo "Can't ship with debugging enabled" 1>&2; false; \
else true; fi
rm -f firefox/[email protected]
cd firefox && zip -r [email protected] $(SHIP_FILES)
mv -f firefox/[email protected] $@
$(NAME)-test.xpi: $(foreach f,$(TEST_FILES),firefox/$(f))
rm -f firefox/[email protected]
cd firefox && zip -r [email protected] $(TEST_FILES)
mv -f firefox/[email protected] $@
$(NAME)-test.zip: $(foreach f,$(TEST_FILES),build/$(f))
rm -f build/[email protected]
cd build && zip -r [email protected] $(TEST_FILES)
mv -f build/[email protected] $@
firefox/manifest.json: manifest.json Makefile
@mkdir -p firefox
rm -f [email protected]
jq ".background.scripts = [.background.service_worker] | \
.browser_specific_settings.gecko.id = \"[email protected]\" | \
.browser_specific_settings.gecko.strict_min_version = \"109.0\" | \
.options_ui.page = \"options.html\" | \
.options_ui.open_in_tab = true | \
.action.default_area = \"navbar\" | \
del(.background.service_worker, .key, .options_page)" < $< > [email protected]
mv [email protected] $@
firefox/%: %
@mkdir -p $(dir $@)
cp -f $< $@
build/manifest.json: manifest.json
@mkdir -p build
rm -f [email protected]
grep -v '"key"' $< > [email protected]
mv [email protected] $@
build/%: %
@mkdir -p $(dir $@)
cp -f $< $@
lint: $(ESLINT) $(GEN_JS_FILES)
$(ESLINT) .
flake8 run-tests.py
test: test-config.yml $(NAME)-test.zip
./run-tests.py $(TEST_ARGS)
test-firefox: test-config.yml $(NAME)-test.xpi
./run-tests.py --firefox $(TEST_ARGS)
$(ESLINT):
npm install
clean:
rm -rf *.zip *.xpi *.crx build firefox $(GEN_JS_FILES)
# "Why isn't utils.js a JavaScript module that's imported into the other files
# that need its functions?" you ask? Because when it is, then whenever the
# extension is updated in a running Chrome instance, utils.js starts failing
# to import with the error "Failed to fetch dynamically imported module." I
# spent hours banging my head against this trying to figure out what's causing
# it and how to fix it and eventually gave up. The path of least resistence is
# to just embed a copy of the code in all the files that need it.
%.js: %.js.in utils.js
rm -f $@ [email protected]
cp /dev/null [email protected]
echo "// Included from utils.js" >> [email protected]
cat utils.js >> [email protected]
echo "// Original [email protected]" >> [email protected]
chmod a-w [email protected]
mv [email protected] $@
content-script.js: content-script.js.in utils.js button.js
rm -f $@ [email protected]
cp /dev/null [email protected]
echo "// Included from utils.js" >> [email protected]
cat utils.js >> [email protected]
echo "// Included from button.js" >> [email protected]
cat button.js >> [email protected]
echo "// Original [email protected]" >> [email protected]
chmod a-w [email protected]
mv [email protected] $@
button.js: icons/16.png
rm -f $@ [email protected]
echo "var buttonIconURL = 'data:image/png;base64,$$(base64 < $< | tr -d '\n')';" > [email protected]
chmod a-w [email protected]
mv [email protected] $@
.NOTINTERMEDIATE: $(GEN_JS_FILES)