/* eslint-disable */ import { spawnSync } from "child_process"; import { writeFileSync, copyFileSync } from "fs"; import esbuild from "esbuild"; let res = spawnSync("git", ["rev-list", "--count", "HEAD"]); let rev = +res.stdout; const domains = [ "https://*.4chan.org/*", "https://*.4channel.org/*", "https://sys.4chan.org/*", ]; const manif3 = { manifest_version: 3, name: "Joshi Koukousei Captcha Service", description: "The captcha solver made by and for japanese high school girls", version: "0." + rev, icons: { 64: "1449696017588.png", }, permissions: [], web_accessible_resources: [ { resources: ["*.html", "*.js", "*.json", "*.bin", "*.wasm"], matches: [""], }, ], content_scripts: [ { matches: domains, css: [], run_at: "document_end", js: ["dist/main.js"], }, ], }; (async () => { let res; const lmanif = manif3; res = await esbuild.build({ entryPoints: ["src/main.ts"], bundle: true, treeShaking: true, outdir: "./chrome/dist", // outfile: "./chrome/dist/main.js", define: { global: "window", execution_mode: '"chrome_api"', manifest: lmanif.version, isBackground: "false", BUILD_VERSION: JSON.stringify([0, rev]), }, // inject: ["./esbuild.inject.js"], plugins: [], loader: { ".bin": "binary", ".wasm": "binary" }, // Hacky solution for loading model.weights.bin but it works for now. 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/main.js"], bundle: true, treeShaking: true, outfile: "./chrome/dist/background.js", define: { global: "window", execution_mode: '"chrome_api"', manifest: lmanif.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("./chrome/manifest.json", JSON.stringify(lmanif, null, 2)); copyFileSync("./logo.png", "./chrome/1449696017588.png"); copyFileSync("./src/group1-shard1of1.bin", "./chrome/group1-shard1of1.bin"); copyFileSync( "./src/tfjs-backend-wasm-threaded-simd.wasm", "./chrome/tfjs-backend-wasm-threaded-simd.wasm" ); copyFileSync( "./src/tfjs-backend-wasm-simd.wasm", "./chrome/tfjs-backend-wasm-simd.wasm" ); copyFileSync( "./src/tfjs-backend-wasm.wasm", "./chrome/tfjs-backend-wasm.wasm" ); //const ext = await crx.load('./chrome'); //const crxBuffer = await ext.pack(); //const updateXML = crx.generateUpdateXML(); //writeFileSync('./chrome_update.xml', updateXML); //writeFileSync('./PEE-chrome.crx', crxBuffer); })();