1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getCiTag = exports.HttpPublisher = exports.Publisher = exports.ProgressCallback = void 0;
|
4 | const builder_util_1 = require("builder-util");
|
5 | const builder_util_runtime_1 = require("builder-util-runtime");
|
6 | const log_1 = require("builder-util/out/log");
|
7 | const chalk = require("chalk");
|
8 | const fs_extra_1 = require("fs-extra");
|
9 | const path_1 = require("path");
|
10 | var progress_1 = require("./progress");
|
11 | Object.defineProperty(exports, "ProgressCallback", { enumerable: true, get: function () { return progress_1.ProgressCallback; } });
|
12 | const progressBarOptions = {
|
13 | incomplete: " ",
|
14 | width: 20,
|
15 | };
|
16 | class Publisher {
|
17 | constructor(context) {
|
18 | this.context = context;
|
19 | }
|
20 | createProgressBar(fileName, size) {
|
21 | builder_util_1.log.info({ file: fileName, provider: this.providerName }, "uploading");
|
22 | if (this.context.progress == null || size < 512 * 1024) {
|
23 | return null;
|
24 | }
|
25 | return this.context.progress.createBar(`${" ".repeat(log_1.PADDING + 2)}[:bar] :percent :etas | ${chalk.green(fileName)} to ${this.providerName}`, {
|
26 | total: size,
|
27 | ...progressBarOptions,
|
28 | });
|
29 | }
|
30 | createReadStreamAndProgressBar(file, fileStat, progressBar, reject) {
|
31 | const fileInputStream = fs_extra_1.createReadStream(file);
|
32 | fileInputStream.on("error", reject);
|
33 | if (progressBar == null) {
|
34 | return fileInputStream;
|
35 | }
|
36 | else {
|
37 | const progressStream = new builder_util_runtime_1.ProgressCallbackTransform(fileStat.size, this.context.cancellationToken, it => progressBar.tick(it.delta));
|
38 | progressStream.on("error", reject);
|
39 | return fileInputStream.pipe(progressStream);
|
40 | }
|
41 | }
|
42 | }
|
43 | exports.Publisher = Publisher;
|
44 | class HttpPublisher extends Publisher {
|
45 | constructor(context, useSafeArtifactName = false) {
|
46 | super(context);
|
47 | this.context = context;
|
48 | this.useSafeArtifactName = useSafeArtifactName;
|
49 | }
|
50 | async upload(task) {
|
51 | const fileName = (this.useSafeArtifactName ? task.safeArtifactName : null) || path_1.basename(task.file);
|
52 | if (task.fileContent != null) {
|
53 | await this.doUpload(fileName, task.arch || builder_util_1.Arch.x64, task.fileContent.length, it => it.end(task.fileContent), task.file);
|
54 | return;
|
55 | }
|
56 | const fileStat = await fs_extra_1.stat(task.file);
|
57 | const progressBar = this.createProgressBar(fileName, fileStat.size);
|
58 | return this.doUpload(fileName, task.arch || builder_util_1.Arch.x64, fileStat.size, (request, reject) => {
|
59 | if (progressBar != null) {
|
60 |
|
61 | progressBar.update(0);
|
62 | }
|
63 | return this.createReadStreamAndProgressBar(task.file, fileStat, progressBar, reject).pipe(request);
|
64 | }, task.file);
|
65 | }
|
66 | }
|
67 | exports.HttpPublisher = HttpPublisher;
|
68 | function getCiTag() {
|
69 | 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 || process.env.BITBUCKET_TAG;
|
70 | return tag != null && tag.length > 0 ? tag : null;
|
71 | }
|
72 | exports.getCiTag = getCiTag;
|
73 |
|
\ | No newline at end of file |