Skip to content

Commit

Permalink
update firefox build manifest to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ynshung committed Oct 1, 2023
1 parent ca779ad commit 52f6e48
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions firefox-build-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ const fs = require("fs");

const RELATIVE_PATH_TO_MANIFEST = "./dist/manifest.json";

const REPLACED_LINES = {
service_worker: '\t\t"scripts": ["service-worker-loader.js"],',
};

if (process.argv[2] && process.argv[2] === "--skip-build") {
buildFirefoxManifest();
} else {
Expand All @@ -24,23 +20,30 @@ if (process.argv[2] && process.argv[2] === "--skip-build") {

function buildFirefoxManifest() {
try {
const chromeManifest = fs.readFileSync(
const manifest = JSON.parse(
fs.readFileSync(RELATIVE_PATH_TO_MANIFEST, "utf8")
);

manifest.manifest_version = 2;
manifest.browser_action = manifest.action;
delete manifest.action;

manifest.background.scripts = [manifest.background.service_worker];
delete manifest.background.service_worker;

manifest.web_accessible_resources = manifest.web_accessible_resources.resources;

manifest.browser_specific_settings = {
gecko: {
id: "{ac34afe8-3a2e-4201-b745-346c0cf6ec7d}",
},
};

fs.writeFileSync(
RELATIVE_PATH_TO_MANIFEST,
"utf8"
JSON.stringify(manifest, null, 2)
);
const lines = chromeManifest.split("\n");
const newLines = [];

lines.forEach((line) => {
for (const key in REPLACED_LINES) {
if (line.includes(key)) {
line = REPLACED_LINES[key];
}
}
newLines.push(line);
});

fs.writeFileSync(RELATIVE_PATH_TO_MANIFEST, newLines.join("\n"));

console.log("Firefox manifest created successfully.");
} catch (error) {
console.error(
Expand Down

0 comments on commit 52f6e48

Please sign in to comment.