type Purpose = "debug" | "install" | "update" | "enterprise"; type Choice = { id: string; reason: string; }; const UPDATE_SOURCES = new Set(["zip", "squirrel", "appx", "snap", "flatpak"]); function chooseArtifact(purpose: Purpose): Choice { if (purpose === "debug") { return { id: "dir", reason: "本地验证,不分发" }; } if (purpose === "update") { return { id: "zip", reason: "Squirrel.Mac 只接受 zip 作为更新源" }; } if (purpose === "enterprise") { return { id: "pkg", reason: "企业分发与安装脚本" }; } return { id: "dmg", reason: "拖拽安装的用户体验" }; } function isUpdateSource(id: string): boolean { return UPDATE_SOURCES.has(id); } function layerOf(id: string): string[] { if (id === "dir") return ["package"]; if (isUpdateSource(id)) return ["make", "update"]; return ["make"]; } const debug = chooseArtifact("debug"); const install = chooseArtifact("install"); const update = chooseArtifact("update"); const enterprise = chooseArtifact("enterprise"); const ok = debug.id === "dir" && install.id === "dmg" && update.id === "zip" && enterprise.id === "pkg" && isUpdateSource("zip") && isUpdateSource("squirrel") && isUpdateSource("appx") && !isUpdateSource("dmg") && !isUpdateSource("nsis") && layerOf("dir").join() === "package" && layerOf("zip").join() === "make,update" && layerOf("dmg").join() === "make"; console.log( JSON.stringify({ evt: "smoke", ok, choices: { debug, install, update, enterprise }, updateSources: [...UPDATE_SOURCES], }), );