macos-update-manifest.mjs 1.2 KB

123456789101112131415161718192021222324
  1. import { readdir, readFile, writeFile } from "node:fs/promises";
  2. import { join } from "node:path";
  3. import { gte } from "semver";
  4. import { parseDocument } from "yaml";
  5. // electron-updater 比较 os.release();macOS 13 对应 Darwin 22,不能填营销版本 13。
  6. const MINIMUM_DARWIN_VERSION = "22.0.0";
  7. export async function stampMacosUpdateManifests({ outputDir, platform }) {
  8. if (platform !== "mac") return;
  9. const entries = await readdir(outputDir, { withFileTypes: true });
  10. for (const entry of entries) {
  11. // 仅匹配 -mac.yml 会漏掉架构后缀和 .yaml,导致 CI 收集后丢失系统下限;仍限定 macOS 清单,避免改写其他平台。
  12. if (!entry.isFile() || !/-mac(?:-(?:arm64|x64))?\.ya?ml$/.test(entry.name)) continue;
  13. const file = join(outputDir, entry.name);
  14. const document = parseDocument(await readFile(file, "utf8"));
  15. if (document.errors.length > 0) throw document.errors[0];
  16. if (typeof document.get("version") !== "string") continue;
  17. const current = document.get("minimumSystemVersion");
  18. if (typeof current === "string" && gte(current, MINIMUM_DARWIN_VERSION)) continue;
  19. document.set("minimumSystemVersion", MINIMUM_DARWIN_VERSION);
  20. await writeFile(file, document.toString(), "utf8");
  21. }
  22. }