44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
import { existsSync, readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
const distDir = "dist";
|
|
const manifestPath = join(distDir, "manifest.json");
|
|
|
|
function fail(message) {
|
|
console.error(message);
|
|
process.exitCode = 1;
|
|
}
|
|
|
|
if (!existsSync(distDir)) {
|
|
fail("Missing dist/ output directory. Run vite build first.");
|
|
} else if (!existsSync(manifestPath)) {
|
|
fail("Missing dist/manifest.json. The built folder is not loadable as a Chrome extension.");
|
|
} else {
|
|
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
const extensionEntry = manifest.side_panel?.default_path || manifest.action?.default_popup;
|
|
|
|
if (manifest.manifest_version !== 3) {
|
|
fail("dist/manifest.json must be a Manifest V3 extension manifest.");
|
|
}
|
|
|
|
if (!extensionEntry) {
|
|
fail("dist/manifest.json is missing side_panel.default_path or action.default_popup.");
|
|
} else if (!existsSync(join(distDir, extensionEntry))) {
|
|
fail(`dist/${extensionEntry} does not exist.`);
|
|
}
|
|
|
|
if (manifest.background?.service_worker && !existsSync(join(distDir, manifest.background.service_worker))) {
|
|
fail(`dist/${manifest.background.service_worker} does not exist.`);
|
|
}
|
|
|
|
for (const [size, iconPath] of Object.entries(manifest.icons || {})) {
|
|
if (!existsSync(join(distDir, iconPath))) {
|
|
fail(`dist/${iconPath} for ${size}px icon does not exist.`);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!process.exitCode) {
|
|
console.log("dist/ is ready to load as an unpacked Chrome extension.");
|
|
}
|