mirror of
https://github.com/Dasemu/X-GeoBlock.git
synced 2026-11-26 15:26:09 +00:00
feat: add cross-browser X GeoBlock extension
This commit is contained in:
commit
0944faab3e
26 files changed
+803
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import { cpSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const dist = join(root, "dist");
|
||||
const baseManifest = JSON.parse(readFileSync(join(root, "manifest.json"), "utf8"));
|
||||
const version = baseManifest.version;
|
||||
const sharedFiles = [
|
||||
"background.js", "content.js", "content.css", "lib", "options", "popup"
|
||||
];
|
||||
|
||||
rmSync(dist, { recursive: true, force: true });
|
||||
mkdirSync(dist, { recursive: true });
|
||||
|
||||
function prepare(target, manifest, extraFiles = []) {
|
||||
const targetDirectory = join(dist, target);
|
||||
mkdirSync(targetDirectory, { recursive: true });
|
||||
for (const source of [...sharedFiles, ...extraFiles]) {
|
||||
cpSync(join(root, source), join(targetDirectory, source), { recursive: true });
|
||||
}
|
||||
writeFileSync(join(targetDirectory, "manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`);
|
||||
return targetDirectory;
|
||||
}
|
||||
|
||||
const chromeDirectory = prepare("chrome", baseManifest, ["offscreen"]);
|
||||
|
||||
const firefoxManifest = structuredClone(baseManifest);
|
||||
delete firefoxManifest.minimum_chrome_version;
|
||||
firefoxManifest.permissions = firefoxManifest.permissions.filter((permission) => permission !== "offscreen");
|
||||
firefoxManifest.background = {
|
||||
scripts: ["lib/config.js", "lib/parser.js", "background.js"]
|
||||
};
|
||||
firefoxManifest.browser_specific_settings = {
|
||||
gecko: {
|
||||
id: "x-geoblock@dasemu.github.io",
|
||||
strict_min_version: "109.0"
|
||||
}
|
||||
};
|
||||
const firefoxDirectory = prepare("firefox", firefoxManifest);
|
||||
|
||||
function archive(directory, filename) {
|
||||
const result = spawnSync("zip", ["-q", "-r", join(dist, filename), "."], {
|
||||
cwd: directory,
|
||||
stdio: "inherit"
|
||||
});
|
||||
if (result.status !== 0) throw new Error(`zip failed for ${filename}`);
|
||||
}
|
||||
|
||||
archive(chromeDirectory, `x-geoblock-chrome-v${version}.zip`);
|
||||
archive(firefoxDirectory, `x-geoblock-firefox-v${version}.xpi`);
|
||||
console.log(`Built Chromium ZIP and Firefox XPI for v${version}.`);
|
||||
@@ -0,0 +1,31 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const kind = process.argv[2];
|
||||
if (!new Set(["patch", "minor"]).has(kind)) {
|
||||
console.error("Usage: node scripts/bump-version.mjs <patch|minor>");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const manifestPath = resolve(root, "manifest.json");
|
||||
const packagePath = resolve(root, "package.json");
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
||||
const packageJson = JSON.parse(readFileSync(packagePath, "utf8"));
|
||||
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(manifest.version);
|
||||
if (!match) throw new Error(`Unsupported version: ${manifest.version}`);
|
||||
|
||||
let [, major, minor, patch] = match.map(Number);
|
||||
if (kind === "minor") {
|
||||
minor += 1;
|
||||
patch = 0;
|
||||
} else {
|
||||
patch += 1;
|
||||
}
|
||||
const version = `${major}.${minor}.${patch}`;
|
||||
manifest.version = version;
|
||||
packageJson.version = version;
|
||||
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
||||
writeFileSync(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
||||
console.log(version);
|
||||
Reference in new issue
Block a user