-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
157 lines (131 loc) · 4.93 KB
/
build.sh
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
#!/bin/bash
#
# Build script for building the packages
# for Firefox and Chromium
#######################################
# Run tests
#######################################
# Running the description check script
sh test.sh
# Capturing the exit status of the previous command
exit_status=$?
# Check if the exit status is not equal to 0 (which means an error occurred in the check_description.sh script)
if [ $exit_status -ne 0 ]; then
echo -e "\e[31mThe description check failed with status: $exit_status\e[0m"
# Exit this script with a non-zero status to indicate failure
exit $exit_status
fi
# Other test commands can go here
echo "All tests passed successfully."
#######################################
# General configuration
#######################################
alias json=./node_modules/.bin/json
alias addons-linter=./node_modules/.bin/addons-linter
#######################################
# Compile to TypeScript Code
#######################################
echo "> Running Webpack (production)..."
webpack --config webpack.prod.js
echo ""
#######################################
# Copy public & modify public
#######################################
cp -r public build
# Replace all references of '../build/popup.js' with '../popup.js' in the copied popup.html
sed -i 's/\.\.\/build\/popup.js/\.\.\/popup.js/g' build/public/popup.html
#######################################
# Copy the manifest file
# TODO: Manifest V2 is a firefox
# workaround
# https://github.com/cachho/reparchive-browser-extension/issues/32
#######################################
cp manifest.json temp-manifest.json
cp manifest-v2.json temp-manifest-v2.json
#######################################
# Modify Manifest
#######################################
## Replace all references of 'build/' with './' in the copied manifest file
json -I -f temp-manifest.json -e 'function replace(obj) {
for (var prop in obj) {
if (typeof obj[prop] === "string") {
obj[prop] = obj[prop].replace(/build\//g, "./");
} else if (typeof obj[prop] === "object") {
replace(obj[prop]);
}
}
}; replace(this);'
# Manifest V2
json -I -f temp-manifest-v2.json -e 'function replace(obj) {
for (var prop in obj) {
if (typeof obj[prop] === "string") {
obj[prop] = obj[prop].replace(/build\//g, "./");
} else if (typeof obj[prop] === "object") {
replace(obj[prop]);
}
}
}; replace(this);'
#######################################
# Create a modifyable manifest copy
# for each browser
#######################################
cp temp-manifest.json temp-manifest-chromium.json
cp temp-manifest-v2.json temp-manifest-firefox.json
#######################################
# For Chromium exclusively
#######################################
# Delete browser specific settings
json -I -f temp-manifest-chromium.json -e 'delete this.browser_specific_settings;'
#######################################
# For Firefox exclusively
#######################################
# Replace 'service_worker' with 'scripts'.
json -I -f temp-manifest-firefox.json -e 'this.background.scripts = ["./js/background.js"]; delete this.service_worker;'
json -I -f temp-manifest-firefox.json -e 'delete this.background.service_worker;'
#######################################
# Build package .zip
#######################################
# Create target dir
mkdir -p dist
# Cleanup
rm -f dist/chromium.zip dist/firefox.zip
# For Chromium
## Copy browser specific manifest
cp temp-manifest-chromium.json build/manifest.json
## Build zip
cd build && zip -r ../dist.zip * && cd ..
## Move temporary zip to distribution folder
mv dist.zip dist/chromium.zip
echo "> Built chromium package at 'dist/chromium.zip'"
# For Firefox
## Copy browser specific manifest
cp temp-manifest-firefox.json build/manifest.json
## Build zip
cd build && zip -r ../dist.zip * && cd ..
## Move temporary zip to distribution folder
mv dist.zip dist/firefox.zip
echo "> Built firefox package at 'dist/firefox.zip'"
#######################################
# Revert build directory to Chrome
# Since only Chrome can run live anyways
#######################################
cp temp-manifest-chromium.json build/manifest.json
#######################################
# Cleanup
#######################################
rm -f temp-manifest.json temp-manifest-v2.json
rm -f temp-manifest-chromium.json temp-manifest-firefox.json
#######################################
# Run Mozilla's Firefox Addons-Linter
#######################################
echo "\n> Running Firefox Addons-Linter..."
addons-linter dist/firefox.zip --min-manifest-version 2 --max-manifest-version 3
#######################################
# Report back
#######################################
echo "\nBuild finished"
echo "> build/"
echo "> dist/chromium.zip"
echo "> dist/firefox.zip"
find "dist" -type f -exec stat -c"%s %n" {} \; | awk '{size_in_kb = $1 / 1024; printf("%-10.2f KB %s\n", size_in_kb, $2)}'
# TODO: Validate build