Skip to content

Commit

Permalink
Use browser-specific manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
nachtjasmin committed Jul 17, 2023
1 parent 9b0ba88 commit 5b473ba
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 43 deletions.
4 changes: 3 additions & 1 deletion scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as esbuild from "esbuild";
import { defaultBuildOptions } from "./shared.mjs";
import { defaultBuildOptions, writeManifest } from "./shared.mjs";

writeManifest();

await esbuild.build({
...defaultBuildOptions,
Expand Down
56 changes: 56 additions & 0 deletions scripts/manifest.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable */
const manifest = {
manifest_version: 3,
name: "ProToots",
version: "1.1.2",

icons: {
48: "icons/icon small_size/icon small_size.png",
96: "icons/icon small_size/icon small_size.png",
},

description: "puts pronouns next to usernames on mastodon",
homepage_url: "https://github.com/ItsVipra/ProToots",
permissions: ["storage", "activeTab", "https://en.pronouns.page/api/*"],

action: {
default_icon: "icons/icon small_size/icon small_size.png",
default_title: "Enable ProToots on this page",
},
content_scripts: [
{
matches: ["*://*/*"],
js: ["content_scripts/protoots.js"],
css: ["styles/proplate.css"],
run_at: "document_start",
},
],

options_ui: {
page: "options/options.html",
browser_style: false,
},

browser_specific_settings: {
gecko: {
id: "[email protected]",
},
},
};

const firefoxManifest = {
...manifest,
background: {
scripts: ["background/worker.js"],
},
};

const chromeManifest = {
...manifest,
background: {
service_worker: "background/worker.js",
type: "module",
},
};

export { firefoxManifest, chromeManifest };
20 changes: 20 additions & 0 deletions scripts/shared.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import copyPluginPkg from "@sprout2000/esbuild-copy-plugin";
import path from "path";
const { copyPlugin } = copyPluginPkg; // js and your fucking mess of imports, sigh.
import { firefoxManifest, chromeManifest } from "./manifest.mjs";
import fs from "fs";

/**
* This array contains all files that we want to handle with esbuild.
Expand Down Expand Up @@ -47,3 +49,21 @@ export const defaultBuildOptions = {
}),
],
};

/** Writes the manifest for the current browser to the dist folder. */
export const writeManifest = () => {
const allowedBrowsers = ["firefox", "chrome"];
const browser = process.env.TARGET ?? "firefox";

if (!allowedBrowsers.includes(browser)) {
throw new Error(
"The browser set via the TARGET environment is not valid. Only 'firefox' or 'chrome' are allowed.",
);
}

const { outdir } = defaultBuildOptions;
if (!fs.existsSync(outdir)) fs.mkdirSync(outdir);

const manifest = JSON.stringify(browser === "firefox" ? firefoxManifest : chromeManifest);
fs.writeFileSync(path.join(outdir, "manifest.json"), manifest, { flag: "w" });
};
5 changes: 4 additions & 1 deletion scripts/watch.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import * as esbuild from "esbuild";
import { defaultBuildOptions } from "./shared.mjs";
import { defaultBuildOptions, writeManifest } from "./shared.mjs";

writeManifest();

let ctx = await esbuild.context(defaultBuildOptions);
await ctx.watch();
41 changes: 0 additions & 41 deletions src/manifest.json

This file was deleted.

0 comments on commit 5b473ba

Please sign in to comment.