ivan-94_obsidian-plugin-man.../scripts/verify-release.mjs
2026-07-18 13:17:11 +08:00

57 lines
2.4 KiB
JavaScript

import { access, readFile, stat } from "node:fs/promises";
const requiredArtifacts = ["main.js", "manifest.json", "styles.css"];
const requiredRepositoryFiles = [
"README.md",
"LICENSE",
"CHANGELOG.md",
"SECURITY.md",
"THIRD_PARTY_NOTICES.md",
"versions.json",
];
const parseJson = async (path) => JSON.parse(await readFile(path, "utf8"));
const manifest = await parseJson("manifest.json");
const packageJson = await parseJson("package.json");
const versions = await parseJson("versions.json");
const failures = [];
const expect = (condition, message) => {
if (!condition) failures.push(message);
};
expect(manifest.id === "manushelf", "manifest.id must remain 'manushelf'");
expect(manifest.name === "Manushelf", "manifest.name must remain 'Manushelf'");
expect(/^[a-z][a-z-]*$/.test(manifest.id), "manifest.id must contain lowercase letters and hyphens only");
expect(!manifest.id.includes("obsidian"), "manifest.id must not contain 'obsidian'");
expect(!manifest.id.endsWith("plugin"), "manifest.id must not end with 'plugin'");
expect(manifest.version === packageJson.version, "manifest.json and package.json versions must match");
expect(/^\d+\.\d+\.\d+$/.test(manifest.version), "version must use x.y.z format");
expect(typeof manifest.minAppVersion === "string", "manifest.minAppVersion is required");
expect(versions[manifest.version] === manifest.minAppVersion, "versions.json must map the current version to minAppVersion");
expect(manifest.isDesktopOnly === false, "Manushelf is intended to remain mobile-installable");
expect(typeof manifest.description === "string" && manifest.description.length > 0, "manifest.description is required");
expect(typeof manifest.author === "string" && manifest.author.length > 0, "manifest.author is required");
expect(/^https:\/\//.test(manifest.authorUrl ?? ""), "manifest.authorUrl must be an HTTPS URL");
for (const path of [...requiredArtifacts, ...requiredRepositoryFiles]) {
try {
await access(path);
} catch {
failures.push(`missing required file: ${path}`);
}
}
try {
const { size } = await stat("main.js");
expect(size > 0, "main.js must not be empty");
expect(size <= 15 * 1024 * 1024, "main.js exceeds the 15 MiB self-contained budget");
} catch {
// The missing file is reported above.
}
if (failures.length > 0) {
throw new Error(`Release verification failed:\n- ${failures.join("\n- ")}`);
}
console.log(`Release verified: Manushelf ${manifest.version}`);