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AAC,IAA1C,CAApB;AACA,UAAM,KAAK,QAAL,CAAc,QAAd,EAAwB,IAAI,CAAC,IAAL,IAAa,oBAAK,GAA1C,EAA+C,QAAQ,CAAC,IAAxD,EAA8D,CAAC,OAAD,EAAU,MAAV,KAAoB;AACtF,UAAI,WAAW,IAAI,IAAnB,EAAyB;AACvB;AACA,QAAA,WAAW,CAAC,MAAZ,CAAmB,CAAnB;AACD;;AACD,aAAO,KAAK,8BAAL,CAAoC,IAAI,CAAC,IAAzC,EAA+C,QAA/C,EAAyD,WAAzD,EAAsE,MAAtE,EAA8E,IAA9E,CAAmF,OAAnF,CAAP;AACD,KANK,EAMH,IAAI,CAAC,IANF,CAAN;AAOD;;AAvBkD;;;;AA4B/C,SAAU,QAAV,GAAkB;AACtB,QAAM,GAAG,GAAG,OAAO,CAAC,GAAR,CAAY,UAAZ,IAA0B,OAAO,CAAC,GAAR,CAAY,sBAAtC,IAAgE,OAAO,CAAC,GAAR,CAAY,UAA5E,IAA0F,OAAO,CAAC,GAAR,CAAY,eAAtG,IAAyH,OAAO,CAAC,GAAR,CAAY,YAAjJ;AACA,SAAO,GAAG,IAAI,IAAP,IAAe,GAAG,CAAC,MAAJ,GAAa,CAA5B,GAAgC,GAAhC,GAAsC,IAA7C;AACD,C","sourcesContent":["import { Arch, log } from \"builder-util\"\nimport { CancellationToken, ProgressCallbackTransform } from \"builder-util-runtime\"\nimport { PADDING } from \"builder-util/out/log\"\nimport chalk from \"chalk\"\nimport { createReadStream, stat, Stats } from \"fs-extra\"\nimport { ClientRequest } from \"http\"\nimport { basename } from \"path\"\nimport { MultiProgress } from \"./multiProgress\"\nimport { ProgressBar } from \"./progress\"\n\nexport type PublishPolicy = \"onTag\" | \"onTagOrDraft\" | \"always\" | \"never\"\n\nexport { ProgressCallback } from \"./progress\"\n\nexport interface PublishOptions {\n publish?: PublishPolicy | null\n}\n\nexport interface PublishContext {\n readonly cancellationToken: CancellationToken\n readonly progress: MultiProgress | null\n}\n\nconst progressBarOptions = {\n incomplete: \" \",\n width: 20,\n}\n\nexport interface UploadTask {\n file: string\n fileContent?: Buffer | null\n\n arch: Arch | null\n safeArtifactName?: string | null\n}\n\nexport abstract class Publisher {\n protected constructor(protected readonly context: PublishContext) {\n }\n\n abstract get providerName(): string\n\n abstract upload(task: UploadTask): Promise<any>\n\n protected createProgressBar(fileName: string, size: number): ProgressBar | null {\n log.info({file: fileName, provider: this.providerName}, \"uploading\")\n if (this.context.progress == null || size < (512 * 1024)) {\n return null\n }\n return this.context.progress.createBar(`${\" \".repeat(PADDING + 2)}[:bar] :percent :etas | ${chalk.green(fileName)} to ${this.providerName}`, {total: size, ...progressBarOptions})\n }\n\n protected createReadStreamAndProgressBar(file: string, fileStat: Stats, progressBar: ProgressBar | null, reject: (error: Error) => void): NodeJS.ReadableStream {\n const fileInputStream = createReadStream(file)\n fileInputStream.on(\"error\", reject)\n\n if (progressBar == null) {\n return fileInputStream\n }\n else {\n const progressStream = new ProgressCallbackTransform(fileStat.size, this.context.cancellationToken, it => progressBar.tick(it.delta))\n progressStream.on(\"error\", reject)\n return fileInputStream.pipe(progressStream)\n }\n }\n\n abstract toString(): string\n}\n\nexport abstract class HttpPublisher extends Publisher {\n protected constructor(protected readonly context: PublishContext, private readonly useSafeArtifactName = false) {\n super(context)\n }\n\n async upload(task: UploadTask): Promise<any> {\n const fileName = (this.useSafeArtifactName ? task.safeArtifactName : null) || basename(task.file)\n\n if (task.fileContent != null) {\n await this.doUpload(fileName, task.arch || Arch.x64, task.fileContent.length, it => it.end(task.fileContent))\n return\n }\n\n const fileStat = await stat(task.file)\n\n const progressBar = this.createProgressBar(fileName, fileStat.size)\n await this.doUpload(fileName, task.arch || Arch.x64, fileStat.size, (request, reject) => {\n if (progressBar != null) {\n // reset (because can be called several times (several attempts)\n progressBar.update(0)\n }\n return this.createReadStreamAndProgressBar(task.file, fileStat, progressBar, reject).pipe(request)\n }, task.file)\n }\n\n protected abstract doUpload(fileName: string, arch: Arch, dataLength: number, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void, file?: string): Promise<any>\n}\n\nexport function getCiTag() {\n const tag = process.env.TRAVIS_TAG || process.env.APPVEYOR_REPO_TAG_NAME || process.env.CIRCLE_TAG || process.env.BITRISE_GIT_TAG || process.env.CI_BUILD_TAG\n return tag != null && tag.length > 0 ? tag : null\n}"],"sourceRoot":""}
|