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AO,KAAP,IAAgB,IAApB,EAA0B;AACxB,cAAM,KAAI,wCAAJ,EAA8B,qLAAqL,OAAO,KAAK,EAA/N,EAAmO,sBAAnO,CAAN;AACD,OAFD,MAGK,IAAI,OAAO,KAAP,IAAgB,IAApB,EAA0B;AAC7B,aAAK,MAAM,QAAX,IAAuB,OAAO,KAA9B,EAAqC;AACnC,gBAAM,YAAY,KAAK,IAAL,CAAU,MAAV,EAAkB,SAAS,IAA3B,CAAlB;;AACA,gBAAM,uBAAuB,MAAK,kCAAL,CAAwC,QAAxC,EAAkD,SAAlD,EAA6D,MAA7D,CAA7B,CAFmC,CAGnC;;;AACA,gBAAK,QAAL,CAAc,IAAd,CAAmB,uBAAnB,CAA2C,oBAA3C;AACD;AACF;AA1C6E;AA2C/E;;AAEO,qCAAmC,QAAnC,EAA2D,SAA3D,EAA8E,MAA9E,EAA4F;AAClG,UAAM,SAAS,SAAS,MAAxB,CADkG,CAElG;;AACA,WAAA,OAAA,MAAA,CAAA,EAAA,EACK,QADL,EACa;AACX,YAAM,SADK;AAEX,cAAQ,UAAU,IAAV,GAAiB,IAAjB,GAAwB,IAAI,UAAJ,CAAe,MAAf,EAAuB,MAAvB,EAAgC,KAAK,QAAL,CAAc,MAAd,CAA6B,MAA7B,CAAhC,CAFrB;AAGX,gBAAU,KAAK;AAHJ,KADb,CAAA;AAMD;;AA7FG;;;;AAgGN,MAAA,UAAA,SAAyB,cAAzB,CAA+B;AAC7B,cAAY,IAAZ,EAAmC,MAAnC,EAA4D,OAA5D,EAA6G;AAC3G,UAAM,IAAN;AADiC,SAAA,MAAA,GAAA,MAAA;AAAyB,SAAA,OAAA,GAAA,OAAA;AAE3D;;AAEK,OAAN,CAAY,SAAZ,EAA+B,IAA/B,EAAyC,CACvC;;AADuC;AAExC;;AAP4B,C","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { Arch, isEnvTrue, log, executeAppBuilderAsJson, InvalidConfigurationError } from \"builder-util\"\nimport * as path from \"path\"\nimport { UploadTask } from \"electron-publish/out/publisher\"\nimport { Target, TargetSpecificOptions } from \"../core\"\nimport { ArtifactCreated } from \"../packagerApi\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { ProjectInfoManager } from \"./ProjectInfoManager\"\n\ninterface TargetInfo {\n name: string\n arch: string\n unpackedDirectory: string\n outDir: string\n}\n\nexport class RemoteBuilder {\n private readonly toBuild = new Map<Arch, Array<TargetInfo>>()\n private buildStarted = false\n\n constructor(readonly packager: PlatformPackager<any>) {\n }\n\n scheduleBuild(target: Target, arch: Arch, unpackedDirectory: string) {\n if (!isEnvTrue(process.env._REMOTE_BUILD) && this.packager.config.remoteBuild === false) {\n throw new Error(\"Target is not supported on your OS and using of Electron Build Service is disabled (\\\"remoteBuild\\\" option)\")\n }\n\n let list = this.toBuild.get(arch)\n if (list == null) {\n list = []\n this.toBuild.set(arch, list)\n }\n\n list.push({\n name: target.name,\n arch: Arch[arch],\n unpackedDirectory,\n outDir: target.outDir,\n })\n }\n\n build(): Promise<any> {\n if (this.buildStarted) {\n return Promise.resolve()\n }\n\n this.buildStarted = true\n\n return BluebirdPromise.mapSeries(Array.from(this.toBuild.keys()), (arch: Arch) => {\n return this._build(this.toBuild.get(arch)!!, this.packager)\n })\n }\n\n // noinspection JSMethodCanBeStatic\n private async _build(targets: Array<TargetInfo>, packager: PlatformPackager<any>): Promise<void> {\n if (log.isDebugEnabled) {\n log.debug({remoteTargets: JSON.stringify(targets, null, 2)}, \"remote building\")\n }\n\n const projectInfoManager = new ProjectInfoManager(packager.info)\n\n // let result: RemoteBuilderResponse | null = null\n const req = Buffer.from(JSON.stringify({\n targets: targets.map(it => {\n return {\n name: it.name,\n arch: it.arch,\n unpackedDirName: path.basename(it.unpackedDirectory),\n }\n }),\n platform: packager.platform.buildConfigurationKey,\n })).toString(\"base64\")\n const outDir = targets[0].outDir\n const args = [\"remote-build\", \"--request\", req, \"--output\", outDir]\n\n args.push(\"--file\", targets[0].unpackedDirectory)\n args.push(\"--file\", await projectInfoManager.infoFile.value)\n\n const buildResourcesDir = packager.buildResourcesDir\n if (buildResourcesDir === packager.projectDir) {\n throw new InvalidConfigurationError(`Build resources dir equals to project dir and so, not sent to remote build agent. It will lead to incorrect results.\\nPlease set \"directories.buildResources\" to separate dir or leave default (\"build\" directory in the project root)`)\n }\n\n args.push(\"--file\", buildResourcesDir)\n\n const result: any = await executeAppBuilderAsJson(args)\n if (result.error != null) {\n throw new InvalidConfigurationError(`Remote builder error (if you think that it is not your application misconfiguration issue, please file issue to https://github.com/electron-userland/electron-builder/issues):\\n\\n${result.error}`, \"REMOTE_BUILDER_ERROR\")\n }\n else if (result.files != null) {\n for (const artifact of result.files) {\n const localFile = path.join(outDir, artifact.file)\n const artifactCreatedEvent = this.artifactInfoToArtifactCreatedEvent(artifact, localFile, outDir)\n // PublishManager uses outDir and options, real (the same as for local build) values must be used\n this.packager.info.dispatchArtifactCreated(artifactCreatedEvent)\n }\n }\n }\n\n private artifactInfoToArtifactCreatedEvent(artifact: ArtifactInfo, localFile: string, outDir: string): ArtifactCreated {\n const target = artifact.target\n // noinspection SpellCheckingInspection\n return {\n ...artifact,\n file: localFile,\n target: target == null ? null : new FakeTarget(target, outDir, (this.packager.config as any)[target]),\n packager: this.packager,\n }\n }\n}\n\nclass FakeTarget extends Target {\n constructor(name: string, readonly outDir: string, readonly options: TargetSpecificOptions | null | undefined) {\n super(name)\n }\n\n async build(appOutDir: string, arch: Arch) {\n // no build\n }\n}\n\ninterface ArtifactInfo extends UploadTask {\n target: string | null\n\n readonly isWriteUpdateInfo?: boolean\n readonly updateInfo?: any\n}\n\nexport interface RemoteBuilderResponse {\n files: Array<ArtifactInfo> | null\n error: string | null\n}"],"sourceRoot":""}