-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
75 lines (62 loc) · 2.12 KB
/
build.js
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
const fs = require("fs");
const path = require("path");
const archiver = require("archiver");
function readBaseManifest() {
return JSON.parse(fs.readFileSync("manifest.json", "utf8"));
}
function writeManifest(manifest, browser) {
const outputPath = path.join("dist", browser, "manifest.json");
fs.mkdirSync(path.join("dist", browser), { recursive: true });
fs.writeFileSync(outputPath, JSON.stringify(manifest, null, 2));
console.log(`${browser} manifest created at: ${outputPath}`);
}
function createZip(browser, version) {
return new Promise((resolve, reject) => {
const output = fs.createWriteStream(
`dist/${browser}-extension-v${version}.zip`
);
const archive = archiver("zip", { zlib: { level: 9 } });
output.on("close", () => {
console.log(
`${browser} extension v${version} has been zipped successfully`
);
resolve();
});
archive.on("error", (err) => {
reject(err);
});
archive.pipe(output);
archive.file("README.md", { name: "README.md" });
archive.file("styles.css", { name: "styles.css" });
archive.file(`dist/${browser}/manifest.json`, { name: "manifest.json" });
archive.file("main.js", { name: "main.js" });
archive.directory("assets", "assets");
archive.finalize();
});
}
function buildChrome(baseManifest) {
const chromeManifest = { ...baseManifest };
// Chrome-specific modifications can be added here
writeManifest(chromeManifest, "chrome");
return createZip("chrome", chromeManifest.version);
}
function buildFirefox(baseManifest) {
const firefoxManifest = { ...baseManifest };
firefoxManifest.browser_specific_settings = {
gecko: {
id: "silencio-x@adidoes",
strict_min_version: "42.0",
},
};
writeManifest(firefoxManifest, "firefox");
return createZip("firefox", firefoxManifest.version);
}
async function build() {
const baseManifest = readBaseManifest();
await buildChrome(baseManifest);
await buildFirefox(baseManifest);
console.log("Build process completed successfully");
}
build().catch((error) => {
console.error("An error occurred during the build process:", error);
});