Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit f84b707

Browse files
committed
Flatten built extension, improve build script
1 parent c7e8dc1 commit f84b707

File tree

6 files changed

+38
-20
lines changed

6 files changed

+38
-20
lines changed

extension/.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
node_modules
2-
out
3-
*.zip
1+
*.xpi
2+
*.zip
3+
node_modules/
4+
out/
5+
packed-extensions/
6+
web-ext-artifacts/

extension/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
"background": {
1717
"scripts": [
18-
"out/background.js"
18+
"background.js"
1919
],
2020
"persistent": false
2121
},
@@ -25,7 +25,7 @@
2525
"https://*/*"
2626
],
2727
"js": [
28-
"out/content.js"
28+
"content.js"
2929
]
3030
}
3131
],
@@ -38,7 +38,7 @@
3838
"icons": {
3939
"128": "logo128.png"
4040
},
41-
"options_page": "out/config.html",
41+
"options_page": "config.html",
4242
"icons": {
4343
"128": "logo128.png"
4444
},

extension/pack.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -e
44

5+
cd $(dirname "$0")
6+
7+
VERSION=$(jq -r ".version" ./manifest.json)
8+
SRC_DIR="./out"
9+
OUTPUT_DIR="./packed-extensions"
10+
11+
mkdir -p "$OUTPUT_DIR"
12+
513
# Firefox extension (done first because web-ext verifies manifest)
6-
if [ -z "$AMO_JWT_ISSUER" ]; then
7-
web-ext build -i "node_modules/**/*" -i "src/**/*" -i "package.json" -i "tsconfig.json" -i "webpack.config.js" -i "yarn.lock"
14+
if [ -z "$WEB_EXT_API_KEY" ]; then
15+
web-ext build --source-dir="$SRC_DIR" --artifacts-dir="$OUTPUT_DIR" --overwrite-dest
16+
mv "$OUTPUT_DIR/sail-$VERSION.zip" "$OUTPUT_DIR/sail-$VERSION.firefox.zip"
817
else
9-
web-ext sign --api-key="$AMO_JWT_ISSUER" --api-secret="$AMO_JWT_SECRET" -i "node_modules/**/*" -i "src/**/*" -i "package.json" -i "tsconfig.json" -i "webpack.config.js" -i "yarn.lock"
18+
# Requires $WEB_EXT_API_KEY and $WEB_EXT_API_SECRET from addons.mozilla.org.
19+
web-ext sign --source-dir="$SRC_DIR" --artifacts-dir="$OUTPUT_DIR" --overwrite-dest
20+
mv "$OUTPUT_DIR/sail-$VERSION.xpi" "$OUTPUT_DIR/sail-$VERSION.firefox.xpi"
1021
fi
1122

1223
# Chrome extension
13-
zip -R chrome-extension.zip manifest.json out/* logo128.png logo.svg
24+
rm "$OUTPUT_DIR/sail-$VERSION.chrome.zip" || true
25+
zip -R "$OUTPUT_DIR/sail-$VERSION.chrome.zip" "$SRC_DIR/*"

extension/src/background.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,6 @@ chrome.runtime.onConnect.addListener((port: chrome.runtime.Port): void => {
186186

187187
// Open the config page when the browser action is clicked.
188188
chrome.browserAction.onClicked.addListener(() => {
189-
const url = chrome.runtime.getURL("/out/config.html");
189+
const url = chrome.runtime.getURL("/config.html");
190190
chrome.tabs.create({ url });
191191
});

extension/src/config.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ <h3 style="margin-bottom: 8px;">Add an approved host:</h3>
9090
</div>
9191
</section>
9292

93-
<script src="/out/config.js"></script>
93+
<script src="/config.js"></script>
9494
</body>
9595
</html>

extension/webpack.config.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const path = require("path");
22
const HappyPack = require("happypack");
33
const os = require("os");
44
const CopyPlugin = require("copy-webpack-plugin");
5+
6+
const srcDir = path.join(__dirname, "src");
57
const outDir = path.join(__dirname, "out");
68

79
const mainConfig = (plugins = []) => ({
@@ -55,33 +57,34 @@ module.exports = [
5557
...mainConfig([
5658
new CopyPlugin(
5759
[
58-
{
59-
from: path.resolve(__dirname, "src/config.html"),
60-
to: path.resolve(process.cwd(), "out/config.html"),
61-
}
60+
{ from: path.join(srcDir, "config.html"), },
61+
{ from: path.join(__dirname, "logo128.png") },
62+
{ from: path.join(__dirname, "logo.svg") },
63+
{ from: path.join(__dirname, "manifest.json") },
64+
{ from: path.join(__dirname, "logo128.png") },
6265
],
6366
{
6467
copyUnmodified: true,
6568
}
6669
),
6770
]),
68-
entry: path.join(__dirname, "src", "background.ts"),
71+
entry: path.join(srcDir, "background.ts"),
6972
output: {
7073
path: outDir,
7174
filename: "background.js",
7275
},
7376
},
7477
{
7578
...mainConfig(),
76-
entry: path.join(__dirname, "src", "content.ts"),
79+
entry: path.join(srcDir, "content.ts"),
7780
output: {
7881
path: outDir,
7982
filename: "content.js",
8083
},
8184
},
8285
{
8386
...mainConfig(),
84-
entry: path.join(__dirname, "src", "config.ts"),
87+
entry: path.join(srcDir, "config.ts"),
8588
output: {
8689
path: outDir,
8790
filename: "config.js",

0 commit comments

Comments
 (0)