publisher.js
3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getCiTag = getCiTag;
Object.defineProperty(exports, "ProgressCallback", {
enumerable: true,
get: function () {
return _progress().ProgressCallback;
}
});
exports.HttpPublisher = exports.Publisher = void 0;
function _builderUtil() {
const data = require("builder-util");
_builderUtil = function () {
return data;
};
return data;
}
function _builderUtilRuntime() {
const data = require("builder-util-runtime");
_builderUtilRuntime = function () {
return data;
};
return data;
}
function _log() {
const data = require("builder-util/out/log");
_log = function () {
return data;
};
return data;
}
function _chalk() {
const data = _interopRequireDefault(require("chalk"));
_chalk = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = require("fs-extra");
_fsExtra = function () {
return data;
};
return data;
}
var _path = require("path");
function _progress() {
const data = require("./progress");
_progress = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const progressBarOptions = {
incomplete: " ",
width: 20
};
class Publisher {
constructor(context) {
this.context = context;
}
createProgressBar(fileName, size) {
_builderUtil().log.info({
file: fileName,
provider: this.providerName
}, "uploading");
if (this.context.progress == null || size < 512 * 1024) {
return null;
}
return this.context.progress.createBar(`${" ".repeat(_log().PADDING + 2)}[:bar] :percent :etas | ${_chalk().default.green(fileName)} to ${this.providerName}`, {
total: size,
...progressBarOptions
});
}
createReadStreamAndProgressBar(file, fileStat, progressBar, reject) {
const fileInputStream = (0, _fsExtra().createReadStream)(file);
fileInputStream.on("error", reject);
if (progressBar == null) {
return fileInputStream;
} else {
const progressStream = new (_builderUtilRuntime().ProgressCallbackTransform)(fileStat.size, this.context.cancellationToken, it => progressBar.tick(it.delta));
progressStream.on("error", reject);
return fileInputStream.pipe(progressStream);
}
}
}
exports.Publisher = Publisher;
class HttpPublisher extends Publisher {
constructor(context, useSafeArtifactName = false) {
super(context);
this.context = context;
this.useSafeArtifactName = useSafeArtifactName;
}
async upload(task) {
const fileName = (this.useSafeArtifactName ? task.safeArtifactName : null) || (0, _path.basename)(task.file);
if (task.fileContent != null) {
await this.doUpload(fileName, task.arch || _builderUtil().Arch.x64, task.fileContent.length, it => it.end(task.fileContent));
return;
}
const fileStat = await (0, _fsExtra().stat)(task.file);
const progressBar = this.createProgressBar(fileName, fileStat.size);
await this.doUpload(fileName, task.arch || _builderUtil().Arch.x64, fileStat.size, (request, reject) => {
if (progressBar != null) {
// reset (because can be called several times (several attempts)
progressBar.update(0);
}
return this.createReadStreamAndProgressBar(task.file, fileStat, progressBar, reject).pipe(request);
}, task.file);
}
}
exports.HttpPublisher = HttpPublisher;
function getCiTag() {
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;
return tag != null && tag.length > 0 ? tag : null;
}
// __ts-babel@6.0.4
//# sourceMappingURL=publisher.js.map