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AuB,GAAvB;AACD;AACF;;AAED,WAAK,IAAL,CAAU,iBAAV;AAEA,YAAM,yBAAK,UAAL,EAAiB,IAAjB,CAAN;AA5D4G;AA6D7G;;AApIkC;;;;AAuI/B,SAAA,uBAAA,CAAkC,QAAlC,EAA6D,QAA7D,EAAgG;AACpG,QAAM,OAAsB,EAA5B;;AACA,MAAI,YAAY,IAAhB,EAAsB;AACpB,SAAK,IAAL,CAAU,QAAV,EAAoB,SAAS,IAA7B;;AACA,QAAI,YAAY,IAAhB,EAAsB;AACpB,WAAK,IAAL,CAAU,YAAV,EAAwB,QAAxB;AACD;AACF;;AACD,SAAO,IAAP;AACD,C","sourcesContent":["import { Arch, debug, exec, use } from \"builder-util\"\nimport { statOrNull } from \"builder-util/out/fs\"\nimport { getNotLocalizedLicenseFile } from \"../util/license\"\nimport { readFile, unlink, writeFile } from \"fs-extra-p\"\nimport * as path from \"path\"\nimport { build as buildPlist, parse as parsePlist } from \"plist\"\nimport { PkgOptions } from \"..\"\nimport { filterCFBundleIdentifier } from \"../appInfo\"\nimport { findIdentity, Identity } from \"../codeSign\"\nimport { Target } from \"../core\"\nimport MacPackager from \"../macPackager\"\n\nconst certType = \"Developer ID Installer\"\n\n// http://www.shanekirk.com/2013/10/creating-flat-packages-in-osx/\n// to use --scripts, we must build .app bundle separately using pkgbuild\n// productbuild --scripts doesn't work (because scripts in this case not added to our package)\n// https://github.com/electron-userland/electron-osx-sign/issues/96#issuecomment-274986942\nexport class PkgTarget extends Target {\n readonly options: PkgOptions = {\n allowAnywhere: true,\n allowCurrentUserHome: true,\n allowRootDirectory: true,\n ...this.packager.config.pkg,\n }\n\n constructor(private readonly packager: MacPackager, readonly outDir: string) {\n super(\"pkg\")\n }\n\n async build(appPath: string, arch: Arch): Promise<any> {\n const packager = this.packager\n const options = this.options\n const appInfo = packager.appInfo\n\n const artifactName = packager.expandArtifactNamePattern(options, \"pkg\")\n const artifactPath = path.join(this.outDir, artifactName)\n\n this.logBuilding(\"pkg\", artifactPath, arch)\n\n const keychainName = (await packager.codeSigningInfo.value).keychainName\n\n const appOutDir = this.outDir\n // https://developer.apple.com/library/content/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html\n const distInfoFile = path.join(appOutDir, \"distribution.xml\")\n\n const innerPackageFile = path.join(appOutDir, `${filterCFBundleIdentifier(appInfo.id)}.pkg`)\n const componentPropertyListFile = path.join(appOutDir, `${filterCFBundleIdentifier(appInfo.id)}.plist`)\n const identity = (await Promise.all([\n findIdentity(certType, options.identity || packager.platformSpecificBuildOptions.identity, keychainName),\n this.customizeDistributionConfiguration(distInfoFile, appPath),\n this.buildComponentPackage(appPath, componentPropertyListFile, innerPackageFile),\n ]))[0]\n\n if (identity == null && packager.forceCodeSigning) {\n throw new Error(`Cannot find valid \"${certType}\" to sign standalone installer, please see https://electron.build/code-signing`)\n }\n\n const args = prepareProductBuildArgs(identity, keychainName)\n args.push(\"--distribution\", distInfoFile)\n args.push(artifactPath)\n use(options.productbuild, it => args.push(...it as any))\n await exec(\"productbuild\", args, {\n cwd: appOutDir,\n })\n await Promise.all([unlink(innerPackageFile), unlink(distInfoFile)])\n\n packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName(artifactName, \"pkg\", arch))\n }\n\n private async customizeDistributionConfiguration(distInfoFile: string, appPath: string) {\n await exec(\"productbuild\", [\"--synthesize\", \"--component\", appPath, distInfoFile], {\n cwd: this.outDir,\n })\n\n const options = this.options\n let distInfo = await readFile(distInfoFile, \"utf-8\")\n const insertIndex = distInfo.lastIndexOf(\"</installer-gui-script>\")\n distInfo = distInfo.substring(0, insertIndex) + ` <domains enable_anywhere=\"${options.allowAnywhere}\" enable_currentUserHome=\"${options.allowCurrentUserHome}\" enable_localSystem=\"${options.allowRootDirectory}\" />\\n` + distInfo.substring(insertIndex)\n\n const license = await getNotLocalizedLicenseFile(options.license, this.packager)\n if (license != null) {\n distInfo = distInfo.substring(0, insertIndex) + ` <license file=\"${license}\"/>\\n` + distInfo.substring(insertIndex)\n }\n\n debug(distInfo)\n await writeFile(distInfoFile, distInfo)\n }\n\n private async buildComponentPackage(appPath: string, propertyListOutputFile: string, packageOutputFile: string) {\n const options = this.options\n const rootPath = path.dirname(appPath)\n\n // first produce a component plist template\n await exec(\"pkgbuild\", [\n \"--analyze\",\n \"--root\", rootPath,\n propertyListOutputFile,\n ])\n\n // process the template plist\n const plistInfo = parsePlist(await readFile(propertyListOutputFile, \"utf8\"))\n if (plistInfo.length > 0) {\n const packageInfo = plistInfo[0]\n\n // ChildBundles lists all of electron binaries within the .app.\n // There is no particular reason for removing that key, except to be as close as possible to\n // the PackageInfo generated by previous versions of electron-builder.\n delete packageInfo.ChildBundles\n\n if (options.isRelocatable != null) {\n packageInfo.BundleIsRelocatable = options.isRelocatable\n }\n\n if (options.isVersionChecked != null) {\n packageInfo.BundleIsVersionChecked = options.isVersionChecked\n }\n\n if (options.hasStrictIdentifier != null) {\n packageInfo.BundleHasStrictIdentifier = options.hasStrictIdentifier\n }\n\n if (options.overwriteAction != null) {\n packageInfo.BundleOverwriteAction = options.overwriteAction\n }\n\n await writeFile(propertyListOutputFile, buildPlist(plistInfo))\n }\n\n // now build the package\n const args = [\n \"--root\", rootPath,\n \"--component-plist\", propertyListOutputFile,\n ]\n\n use(this.options.installLocation || \"/Applications\", it => args.push(\"--install-location\", it!))\n if (options.scripts != null) {\n args.push(\"--scripts\", path.resolve(this.packager.info.buildResourcesDir, options.scripts))\n }\n else if (options.scripts !== null) {\n const dir = path.join(this.packager.info.buildResourcesDir, \"pkg-scripts\")\n const stat = await statOrNull(dir)\n if (stat != null && stat.isDirectory()) {\n args.push(\"--scripts\", dir)\n }\n }\n\n args.push(packageOutputFile)\n\n await exec(\"pkgbuild\", args)\n }\n}\n\nexport function prepareProductBuildArgs(identity: Identity | null, keychain: string | null | undefined): Array<string> {\n const args: Array<string> = []\n if (identity != null) {\n args.push(\"--sign\", identity.hash)\n if (keychain != null) {\n args.push(\"--keychain\", keychain)\n }\n }\n return args\n}"],"sourceRoot":""}
|