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AAC,EAAE,CACnB,CAAA;AACH,CAAC;AAlDD,oDAkDC;AAED,2CAA2C;AAC3C,KAAK,UAAU,eAAe,CAC5B,aAAmC,EACnC,MAAc,EACd,GAAW,EACX,OAAe,EACf,YAAyB,EACzB,OAAe,EACf,QAA+B;IAE/B,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,KAAK,QAAQ,CAAA;IACpD,MAAM,cAAc,GAAG,QAAQ,IAAI,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,WAAW,CAAC,CAAA;IAC3I,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;QACrC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;QAChC,MAAM,IAAA,qBAAU,EACd,cAAc,EACd;YACE,OAAO;YACP,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACrC,GAAG,EAAE,IAAA,mCAAkB,EAAC,aAAa,EAAE,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;SACjG,EACD,EAAE,MAAM,EAAE,CAAC,EAAE,CACd,CAAA;QAED,QAAQ,CAAC,IAAI,CAAC,uBAAuB,CAAC;YACpC,IAAI,EAAE,cAAc;YACpB,IAAI,EAAE,IAAI;YACV,QAAQ;YACR,MAAM,EAAE,IAAI;YACZ,aAAa;SACd,CAAC,CAAA;KACH;AACH,CAAC","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { Arch, log, safeStringifyJson, serializeToYaml } from \"builder-util\"\nimport { GenericServerOptions, PublishConfiguration, UpdateInfo, WindowsUpdateInfo } from \"builder-util-runtime\"\nimport { outputFile, outputJson, readFile } from \"fs-extra\"\nimport { Lazy } from \"lazy-val\"\nimport * as path from \"path\"\nimport * as semver from \"semver\"\nimport { Platform } from \"../core\"\nimport { ReleaseInfo } from \"../options/PlatformSpecificBuildOptions\"\nimport { Packager } from \"../packager\"\nimport { ArtifactCreated } from \"../packagerApi\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { hashFile } from \"../util/hash\"\nimport { computeDownloadUrl, getPublishConfigsForUpdateInfo } from \"./PublishManager\"\n\nasync function getReleaseInfo(packager: PlatformPackager<any>) {\n const releaseInfo: ReleaseInfo = { ...(packager.platformSpecificBuildOptions.releaseInfo || packager.config.releaseInfo) }\n if (releaseInfo.releaseNotes == null) {\n const releaseNotesFile = await packager.getResource(\n releaseInfo.releaseNotesFile,\n `release-notes-${packager.platform.buildConfigurationKey}.md`,\n `release-notes-${packager.platform.name}.md`,\n `release-notes-${packager.platform.nodeName}.md`,\n \"release-notes.md\"\n )\n const releaseNotes = releaseNotesFile == null ? null : await readFile(releaseNotesFile, \"utf-8\")\n // to avoid undefined in the file, check for null\n if (releaseNotes != null) {\n releaseInfo.releaseNotes = releaseNotes\n }\n }\n delete releaseInfo.releaseNotesFile\n return releaseInfo\n}\n\nfunction isGenerateUpdatesFilesForAllChannels(packager: PlatformPackager<any>) {\n const value = packager.platformSpecificBuildOptions.generateUpdatesFilesForAllChannels\n return value == null ? packager.config.generateUpdatesFilesForAllChannels : value\n}\n\n/**\n if this is an \"alpha\" version, we need to generate only the \"alpha\" .yml file\n if this is a \"beta\" version, we need to generate both the \"alpha\" and \"beta\" .yml file\n if this is a \"stable\" version, we need to generate all the \"alpha\", \"beta\" and \"stable\" .yml file\n */\nfunction computeChannelNames(packager: PlatformPackager<any>, publishConfig: PublishConfiguration): Array<string> {\n const currentChannel: string = (publishConfig as GenericServerOptions).channel || \"latest\"\n // for GitHub should be pre-release way be used\n if (currentChannel === \"alpha\" || publishConfig.provider === \"github\" || !isGenerateUpdatesFilesForAllChannels(packager)) {\n return [currentChannel]\n }\n\n switch (currentChannel) {\n case \"beta\":\n return [currentChannel, \"alpha\"]\n\n case \"latest\":\n return [currentChannel, \"alpha\", \"beta\"]\n\n default:\n return [currentChannel]\n }\n}\n\nfunction getUpdateInfoFileName(channel: string, packager: PlatformPackager<any>, arch: Arch | null): string {\n const osSuffix = packager.platform === Platform.WINDOWS ? \"\" : `-${packager.platform.buildConfigurationKey}`\n return `${channel}${osSuffix}${getArchPrefixForUpdateFile(arch, packager)}.yml`\n}\n\nfunction getArchPrefixForUpdateFile(arch: Arch | null, packager: PlatformPackager<any>) {\n if (arch == null || arch === Arch.x64 || packager.platform !== Platform.LINUX) {\n return \"\"\n }\n return arch === Arch.armv7l ? \"-arm\" : `-${Arch[arch]}`\n}\n\nexport interface UpdateInfoFileTask {\n readonly file: string\n readonly info: UpdateInfo\n readonly publishConfiguration: PublishConfiguration\n\n readonly packager: PlatformPackager<any>\n}\n\nfunction computeIsisElectronUpdater1xCompatibility(updaterCompatibility: string | null, publishConfiguration: PublishConfiguration, packager: Packager) {\n if (updaterCompatibility != null) {\n return semver.satisfies(\"1.0.0\", updaterCompatibility)\n }\n\n // spaces is a new publish provider, no need to keep backward compatibility\n if (publishConfiguration.provider === \"spaces\") {\n return false\n }\n\n const updaterVersion = packager.metadata.dependencies == null ? null : packager.metadata.dependencies[\"electron-updater\"]\n return updaterVersion == null || semver.lt(updaterVersion, \"4.0.0\")\n}\n\n/** @internal */\nexport async function createUpdateInfoTasks(event: ArtifactCreated, _publishConfigs: Array<PublishConfiguration>): Promise<Array<UpdateInfoFileTask>> {\n const packager = event.packager\n const publishConfigs = await getPublishConfigsForUpdateInfo(packager, _publishConfigs, event.arch)\n if (publishConfigs == null || publishConfigs.length === 0) {\n return []\n }\n\n const outDir = event.target!.outDir\n const version = packager.appInfo.version\n const sha2 = new Lazy<string>(() => hashFile(event.file, \"sha256\", \"hex\"))\n const isMac = packager.platform === Platform.MAC\n const createdFiles = new Set<string>()\n const sharedInfo = await createUpdateInfo(version, event, await getReleaseInfo(packager))\n const tasks: Array<UpdateInfoFileTask> = []\n const electronUpdaterCompatibility = packager.platformSpecificBuildOptions.electronUpdaterCompatibility || packager.config.electronUpdaterCompatibility || \">=2.15\"\n for (const publishConfiguration of publishConfigs) {\n let dir = outDir\n if (publishConfigs.length > 1 && publishConfiguration !== publishConfigs[0]) {\n dir = path.join(outDir, publishConfiguration.provider)\n }\n\n let isElectronUpdater1xCompatibility = computeIsisElectronUpdater1xCompatibility(electronUpdaterCompatibility, publishConfiguration, packager.info)\n\n let info = sharedInfo\n // noinspection JSDeprecatedSymbols\n if (isElectronUpdater1xCompatibility && packager.platform === Platform.WINDOWS) {\n info = {\n ...info,\n }\n // noinspection JSDeprecatedSymbols\n ;(info as WindowsUpdateInfo).sha2 = await sha2.value\n }\n\n if (event.safeArtifactName != null && publishConfiguration.provider === \"github\") {\n const newFiles = info.files.slice()\n newFiles[0].url = event.safeArtifactName\n info = {\n ...info,\n files: newFiles,\n path: event.safeArtifactName,\n }\n }\n\n for (const channel of computeChannelNames(packager, publishConfiguration)) {\n if (isMac && isElectronUpdater1xCompatibility && event.file.endsWith(\".zip\")) {\n // write only for first channel (generateUpdatesFilesForAllChannels is a new functionality, no need to generate old mac update info file)\n isElectronUpdater1xCompatibility = false\n await writeOldMacInfo(publishConfiguration, outDir, dir, channel, createdFiles, version, packager)\n }\n\n const updateInfoFile = path.join(dir, getUpdateInfoFileName(channel, packager, event.arch))\n if (createdFiles.has(updateInfoFile)) {\n continue\n }\n\n createdFiles.add(updateInfoFile)\n\n // artifact should be uploaded only to designated publish provider\n tasks.push({\n file: updateInfoFile,\n info,\n publishConfiguration,\n packager,\n })\n }\n }\n return tasks\n}\n\nasync function createUpdateInfo(version: string, event: ArtifactCreated, releaseInfo: ReleaseInfo): Promise<UpdateInfo> {\n const customUpdateInfo = event.updateInfo\n const url = path.basename(event.file)\n const sha512 = (customUpdateInfo == null ? null : customUpdateInfo.sha512) || (await hashFile(event.file))\n const files = [{ url, sha512 }]\n const result: UpdateInfo = {\n // @ts-ignore\n version,\n // @ts-ignore\n files,\n // @ts-ignore\n path: url /* backward compatibility, electron-updater 1.x - electron-updater 2.15.0 */,\n // @ts-ignore\n sha512 /* backward compatibility, electron-updater 1.x - electron-updater 2.15.0 */,\n ...(releaseInfo as UpdateInfo),\n }\n\n if (customUpdateInfo != null) {\n // file info or nsis web installer packages info\n Object.assign(\"sha512\" in customUpdateInfo ? files[0] : result, customUpdateInfo)\n }\n return result\n}\n\nexport async function writeUpdateInfoFiles(updateInfoFileTasks: Array<UpdateInfoFileTask>, packager: Packager) {\n // zip must be first and zip info must be used for old path/sha512 properties in the update info\n updateInfoFileTasks.sort((a, b) => (a.info.files[0].url.endsWith(\".zip\") ? 0 : 100) - (b.info.files[0].url.endsWith(\".zip\") ? 0 : 100))\n\n const updateChannelFileToInfo = new Map<string, UpdateInfoFileTask>()\n for (const task of updateInfoFileTasks) {\n // https://github.com/electron-userland/electron-builder/pull/2994\n const key = `${task.file}@${safeStringifyJson(task.publishConfiguration, new Set([\"releaseType\"]))}`\n const existingTask = updateChannelFileToInfo.get(key)\n if (existingTask == null) {\n updateChannelFileToInfo.set(key, task)\n continue\n }\n\n existingTask.info.files.push(...task.info.files)\n }\n\n const releaseDate = new Date().toISOString()\n await BluebirdPromise.map(\n updateChannelFileToInfo.values(),\n async task => {\n const publishConfig = task.publishConfiguration\n if (publishConfig.publishAutoUpdate === false) {\n log.debug(\n {\n provider: publishConfig.provider,\n reason: \"publishAutoUpdate is set to false\",\n },\n \"auto update metadata file not published\"\n )\n return\n }\n\n if (task.info.releaseDate == null) {\n task.info.releaseDate = releaseDate\n }\n\n const fileContent = Buffer.from(serializeToYaml(task.info, false, true))\n await outputFile(task.file, fileContent)\n packager.dispatchArtifactCreated({\n file: task.file,\n fileContent,\n arch: null,\n packager: task.packager,\n target: null,\n publishConfig,\n })\n },\n { concurrency: 4 }\n )\n}\n\n// backward compatibility - write json file\nasync function writeOldMacInfo(\n publishConfig: PublishConfiguration,\n outDir: string,\n dir: string,\n channel: string,\n createdFiles: Set<string>,\n version: string,\n packager: PlatformPackager<any>\n) {\n const isGitHub = publishConfig.provider === \"github\"\n const updateInfoFile = isGitHub && outDir === dir ? path.join(dir, \"github\", `${channel}-mac.json`) : path.join(dir, `${channel}-mac.json`)\n if (!createdFiles.has(updateInfoFile)) {\n createdFiles.add(updateInfoFile)\n await outputJson(\n updateInfoFile,\n {\n version,\n releaseDate: new Date().toISOString(),\n url: computeDownloadUrl(publishConfig, packager.generateName2(\"zip\", \"mac\", isGitHub), packager),\n },\n { spaces: 2 }\n )\n\n packager.info.dispatchArtifactCreated({\n file: updateInfoFile,\n arch: null,\n packager,\n target: null,\n publishConfig,\n })\n }\n}\n"]}
|