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AnC,EAAoE,IAApE,CAAyE,SAAzE,CAAT,GAA+F,GAAtG;AACD,C","sourcesContent":["import { exec } from \"builder-util\"\nimport { PlatformPackager } from \"app-builder-lib\"\nimport { AsyncTaskManager } from \"builder-util/out/asyncTaskManager\"\nimport { exists } from \"builder-util/out/fs\"\nimport { executeFinally } from \"builder-util/out/promise\"\nimport { outputFile, readFile } from \"fs-extra-p\"\nimport * as path from \"path\"\nimport { TmpDir } from \"temp-file\"\n\nexport { DmgTarget } from \"./dmg\"\n\nconst root = path.join(__dirname, \"..\")\n\nexport function getDmgTemplatePath() {\n return path.join(root, \"templates\")\n}\n\nexport function getDmgVendorPath() {\n return path.join(root, \"vendor\")\n}\n\nexport async function attachAndExecute(dmgPath: string, readWrite: boolean, task: () => Promise<any>) {\n //noinspection SpellCheckingInspection\n const args = [\"attach\", \"-noverify\", \"-noautoopen\"]\n if (readWrite) {\n args.push(\"-readwrite\")\n }\n\n args.push(dmgPath)\n const attachResult = await exec(\"hdiutil\", args)\n const deviceResult = attachResult == null ? null : /^(\\/dev\\/\\w+)/.exec(attachResult)\n const device = deviceResult == null || deviceResult.length !== 2 ? null : deviceResult[1]\n if (device == null) {\n throw new Error(`Cannot mount: ${attachResult}`)\n }\n\n return await executeFinally(task(), () => detach(device))\n}\n\nexport async function detach(name: string) {\n try {\n await exec(\"hdiutil\", [\"detach\", \"-quiet\", name])\n }\n catch (e) {\n await new Promise((resolve, reject) => {\n setTimeout(() => {\n exec(\"hdiutil\", [\"detach\", \"-force\", name])\n .then(resolve)\n .catch(reject)\n }, 1000)\n })\n }\n}\n\nexport function computeBackgroundColor(rawValue: string) {\n return require(\"parse-color\")(rawValue).hex\n}\n\nexport async function computeBackground(packager: PlatformPackager<any>): Promise<string> {\n const resourceList = await packager.resourceList\n if (resourceList.includes(\"background.tiff\")) {\n return path.join(packager.buildResourcesDir, \"background.tiff\")\n }\n else if (resourceList.includes(\"background.png\")) {\n return path.join(packager.buildResourcesDir, \"background.png\")\n }\n else {\n return path.join(getDmgTemplatePath(), \"background.tiff\")\n }\n}\n\nexport async function applyProperties(entries: any, env: any, asyncTaskManager: AsyncTaskManager, packager: PlatformPackager<any>) {\n const dmgPropertiesFile = await packager.getTempFile(\"dmgProperties.pl\")\n asyncTaskManager.addTask(outputFile(dmgPropertiesFile, (await readFile(path.join(getDmgTemplatePath(), \"dmgProperties.pl\"), \"utf-8\")).replace(\"$ENTRIES\", entries)))\n await asyncTaskManager.awaitTasks()\n\n await exec(\"/usr/bin/perl\", [dmgPropertiesFile], {\n cwd: getDmgVendorPath(),\n env\n })\n}\n\nexport async function transformBackgroundFileIfNeed(file: string, tmpDir: TmpDir): Promise<string> {\n if (file.endsWith(\".tiff\") || file.endsWith(\".TIFF\")) {\n return file\n }\n\n const retinaFile = file.replace(/\\.([a-z]+)$/, \"@2x.$1\")\n if (await exists(retinaFile)) {\n const tiffFile = await tmpDir.getTempFile({suffix: \".tiff\"})\n await exec(\"tiffutil\", [\"-cathidpicheck\", file, retinaFile, \"-out\", tiffFile])\n return tiffFile\n }\n\n return file\n}\n\n/** @internal */\nexport function serializeString(data: string) {\n return ' $\"' + data.match(/.{1,32}/g)!!.map(it => it.match(/.{1,4}/g)!!.join(\" \")).join('\"\\n $\"') + '\"'\n}"],"sourceRoot":""}