JKCS/build-ff.js

144 lines
3.5 KiB
JavaScript
Raw Normal View History

2022-08-03 02:20:38 +00:00
/* eslint-disable */
import { spawnSync } from "child_process";
import { writeFileSync, readFileSync, copyFileSync } from "fs";
import esbuild from "esbuild";
import webExt from "web-ext";
let res = spawnSync("git", ["rev-list", "--count", "HEAD"]);
let rev = +res.stdout;
const domains = [
"https://*.4chan.org/*",
"https://*.4channel.org/*",
"https://sys.4chan.org/*",
];
2022-08-03 02:20:38 +00:00
const manif = {
manifest_version: 2,
2022-08-04 00:47:06 +00:00
browser_specific_settings: {},
name: "Joshi Koukousei Captcha Service",
description: "The captcha solver made by and for japanese high school girls",
2022-08-03 02:20:38 +00:00
version: "0." + rev,
icons: {
64: "1449696017588.png",
},
permissions: [...domains],
content_scripts: [
{
matches: domains,
css: [],
run_at: "document_end",
2022-08-03 15:56:33 +00:00
js: ["polyfill.min.js", "dist/main.js"],
2022-08-03 02:20:38 +00:00
},
],
web_accessible_resources: ["*.html", "*.js", "*.json", "*.bin", "*.wasm"],
2022-08-03 02:20:38 +00:00
// "background": {
// persistent: true,
// "scripts": [
// "polyfill.min.js",
// "browser-polyfill.min.js",
// "dist/background.js"
// ]
// }
};
(async () => {
let res;
res = await esbuild.build({
2023-08-10 02:38:21 +00:00
entryPoints: ["src/main.ts"],
2022-08-03 02:20:38 +00:00
bundle: true,
treeShaking: true,
outdir: "./firefox/dist",
// outfile: "./firefox/dist/main.js",
define: {
global: "window",
execution_mode: '"ff_api"',
manifest: manif.version,
isBackground: "false",
BUILD_VERSION: JSON.stringify([0, rev]),
},
// inject: ["./esbuild.inject.js"],
plugins: [],
2023-08-10 02:38:21 +00:00
loader: { ".bin": "binary", ".wasm": "binary" },
2022-08-03 02:20:38 +00:00
metafile: true,
});
console.log(res.metafile.inputs);
console.log(
Object.entries(res.metafile.inputs)
.sort((a, b) => a[1].bytes - b[1].bytes)
.map((e) => `${e[0]} -> ${e[1].bytes}`)
.join("\n")
);
/*
res = await esbuild.build({
entryPoints: ["src/background.ts"],
bundle: true,
treeShaking: true,
outfile: "./firefox/dist/background.js",
define: {
global: "window",
execution_mode: '"ff_api"',
manifest: manif.version,
isBackground: "true",
BUILD_VERSION: JSON.stringify([0, rev]),
},
inject: ["./esbuild.inject.js"],
metafile: true,
});
console.log(res.metafile.inputs);
console.log(
Object.entries(res.metafile.inputs)
.sort((a, b) => a[1].bytes - b[1].bytes)
.map((e) => `${e[0]} -> ${e[1].bytes}`)
.join("\n")
);
*/
writeFileSync("./firefox/manifest.json", JSON.stringify(manif, null, 2));
copyFileSync("./logo.png", "./firefox/1449696017588.png");
2023-08-10 02:38:21 +00:00
copyFileSync("./src/group1-shard1of1.bin", "./firefox/group1-shard1of1.bin");
copyFileSync(
"./src/tfjs-backend-wasm-threaded-simd.wasm",
"./firefox/tfjs-backend-wasm-threaded-simd.wasm"
);
copyFileSync(
"./src/tfjs-backend-wasm-simd.wasm",
"./firefox/tfjs-backend-wasm-simd.wasm"
);
copyFileSync(
"./src/tfjs-backend-wasm.wasm",
"./firefox/tfjs-backend-wasm.wasm"
);
2022-08-03 02:20:38 +00:00
res = await webExt.cmd.build({
sourceDir: "./firefox/",
artifactsDir: ".",
2022-08-03 16:38:32 +00:00
filename: `jkcs-${manif.version}.xpi`,
2022-08-03 02:20:38 +00:00
overwriteDest: true,
});
console.log(res);
2022-08-04 06:17:35 +00:00
/*
2022-08-03 02:20:38 +00:00
writeFileSync(
"./firefox_update.json",
JSON.stringify({
addons: {
2022-08-03 16:50:06 +00:00
"{jkcs@coom.tech}": {
2022-08-03 02:20:38 +00:00
updates: [
{
version: manif.version,
2022-08-03 16:54:07 +00:00
update_link: `https://git.coom.tech/araragi/JKCS/raw/branch/master/jkcs-${manif.version}.xpi`,
2022-08-03 02:20:38 +00:00
},
],
},
},
})
);
2022-08-04 06:17:35 +00:00
*/
2022-08-03 02:20:38 +00:00
})();