This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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 popup = manifest.action?.default_popup;
|
||||
|
||||
if (manifest.manifest_version !== 3) {
|
||||
fail("dist/manifest.json must be a Manifest V3 extension manifest.");
|
||||
}
|
||||
|
||||
if (!popup) {
|
||||
fail("dist/manifest.json is missing action.default_popup.");
|
||||
} else if (!existsSync(join(distDir, popup))) {
|
||||
fail(`dist/${popup} does not exist.`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!process.exitCode) {
|
||||
console.log("dist/ is ready to load as an unpacked Chrome extension.");
|
||||
}
|
||||
Reference in New Issue
Block a user