-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgulpfile.js
More file actions
98 lines (84 loc) · 2.47 KB
/
gulpfile.js
File metadata and controls
98 lines (84 loc) · 2.47 KB
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
const gulp = require("gulp"),
gulpif = require("gulp-if"),
jeditor = require("gulp-json-editor"),
zip = require("gulp-zip"),
manifest = require("./apps/browser/src/manifest.json"),
package = require("./package.json");
function dist(browser, merge) {
return gulp
.src("./apps/browser/build/**/*")
.pipe(gulpif(/^manifest.json$/, jeditor(merge)))
.pipe(
zip(`${manifest.name.toLowerCase()}-${browser}-${package.version}.zip`)
)
.pipe(gulp.dest("./dist/"));
}
function distFirefox() {
return dist("firefox", (manifest) => {
manifest.version = package.version;
// Not supported in firefox
delete manifest.externally_connectable;
// Applications are required on firefox
manifest.applications = {};
manifest.commands["toggle_button"].suggested_key = {
default: "Ctrl+Alt+Y",
};
manifest.commands["toggle_sidebar"].suggested_key = {
default: "Ctrl+Alt+S",
};
return manifest;
});
}
function distOpera() {
return dist("opera", (manifest) => {
manifest.version = package.version;
manifest.externally_connectable.matches.pop();
return manifest;
});
}
function distChrome() {
return dist("chrome", (manifest) => {
manifest.version = package.version;
manifest.externally_connectable.matches.pop();
return toV3(manifest);
});
}
function distEdge() {
return dist("edge", (manifest) => {
manifest.version = package.version;
manifest.externally_connectable.matches.pop();
return manifest;
});
}
function toV3(manifest) {
manifest.manifest_version = 3;
manifest.background.service_worker = manifest.background.scripts[0];
manifest.action = manifest.browser_action;
manifest.host_permissions = ["*://*/*"];
manifest.web_accessible_resources = [
{
resources: manifest.web_accessible_resources,
matches: ["http://*/*", "https://*/*"],
},
];
manifest.permissions = manifest.permissions.filter(
(p) =>
![
"http://*/*",
"https://*/*",
"webRequest",
"webRequestBlocking",
"clipboardWrite",
].includes(p)
);
manifest.permissions.push("scripting");
delete manifest.background.scripts;
delete manifest.background.persistent;
delete manifest.browser_action;
return manifest;
}
exports["dist:firefox"] = distFirefox;
exports["dist:chrome"] = distChrome;
exports["dist:opera"] = distOpera;
exports["dist:edge"] = distEdge;
exports["dist"] = gulp.parallel(distFirefox, distChrome, distOpera, distEdge);