AutistMask/build.js
sneak 1c9d5a9f2d
All checks were successful
check / check (push) Successful in 13s
Implement EIP-1193 provider for dApp connectivity
Three-part architecture:
- inpage.js: creates window.ethereum in page context with
  request(), on(), send(), sendAsync(), enable() methods.
  Sets isMetaMask=true for compatibility.
- content/index.js: bridge between page and extension via
  postMessage (page<->content) and runtime.sendMessage
  (content<->background).
- background/index.js: handles RPC routing. Proxies read-only
  methods (eth_call, eth_getBalance, etc.) to configured RPC.
  Handles eth_requestAccounts (auto-connect for now),
  wallet_switchEthereumChain (mainnet only), and returns
  informative errors for unimplemented signing methods.

Manifests updated with web_accessible_resources for inpage.js.
Build updated to bundle inpage.js as a separate output file.
2026-02-25 18:36:27 +07:00

103 lines
3.3 KiB
JavaScript

const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
const esbuild = require("esbuild");
const DIST_CHROME = path.join(__dirname, "dist", "chrome");
const DIST_FIREFOX = path.join(__dirname, "dist", "firefox");
const SRC = path.join(__dirname, "src");
function ensureDir(dir) {
fs.mkdirSync(dir, { recursive: true });
}
async function build() {
console.log("Building AutistMask extension...");
// compile tailwind CSS
console.log("Compiling Tailwind CSS...");
const tailwindInput = path.join(SRC, "popup", "styles", "main.css");
const tailwindOutput = path.join(__dirname, "dist", "styles.css");
ensureDir(path.join(__dirname, "dist"));
execSync(
`npx @tailwindcss/cli -i ${tailwindInput} -o ${tailwindOutput} --minify`,
{ stdio: "inherit" },
);
for (const distDir of [DIST_CHROME, DIST_FIREFOX]) {
ensureDir(path.join(distDir, "src", "popup"));
ensureDir(path.join(distDir, "src", "background"));
ensureDir(path.join(distDir, "src", "content"));
// bundle popup JS with esbuild (inlines ethers, libsodium, etc.)
await esbuild.build({
entryPoints: [path.join(SRC, "popup", "index.js")],
bundle: true,
format: "iife",
outfile: path.join(distDir, "src", "popup", "index.js"),
platform: "browser",
target: ["chrome110", "firefox110"],
minify: true,
});
// bundle background script
await esbuild.build({
entryPoints: [path.join(SRC, "background", "index.js")],
bundle: true,
format: "iife",
outfile: path.join(distDir, "src", "background", "index.js"),
platform: "browser",
target: ["chrome110", "firefox110"],
minify: true,
});
// bundle content script
await esbuild.build({
entryPoints: [path.join(SRC, "content", "index.js")],
bundle: true,
format: "iife",
outfile: path.join(distDir, "src", "content", "index.js"),
platform: "browser",
target: ["chrome110", "firefox110"],
minify: true,
});
// bundle inpage script (injected into page context, separate file)
await esbuild.build({
entryPoints: [path.join(SRC, "content", "inpage.js")],
bundle: true,
format: "iife",
outfile: path.join(distDir, "src", "content", "inpage.js"),
platform: "browser",
target: ["chrome110", "firefox110"],
minify: true,
});
// copy popup HTML
fs.copyFileSync(
path.join(SRC, "popup", "index.html"),
path.join(distDir, "src", "popup", "index.html"),
);
// place compiled CSS next to popup HTML
fs.copyFileSync(
tailwindOutput,
path.join(distDir, "src", "popup", "styles.css"),
);
}
// copy manifests
fs.copyFileSync(
path.join(__dirname, "manifest", "chrome.json"),
path.join(DIST_CHROME, "manifest.json"),
);
fs.copyFileSync(
path.join(__dirname, "manifest", "firefox.json"),
path.join(DIST_FIREFOX, "manifest.json"),
);
console.log("Build complete: dist/chrome/ and dist/firefox/");
}
build();