1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.BintrayPublisher = undefined;
|
7 |
|
8 | var _bluebirdLstC;
|
9 |
|
10 | function _load_bluebirdLstC() {
|
11 | return _bluebirdLstC = require("bluebird-lst-c");
|
12 | }
|
13 |
|
14 | var _bluebirdLstC2;
|
15 |
|
16 | function _load_bluebirdLstC2() {
|
17 | return _bluebirdLstC2 = _interopRequireDefault(require("bluebird-lst-c"));
|
18 | }
|
19 |
|
20 | var _electronBuilderHttp;
|
21 |
|
22 | function _load_electronBuilderHttp() {
|
23 | return _electronBuilderHttp = require("electron-builder-http");
|
24 | }
|
25 |
|
26 | var _bintray;
|
27 |
|
28 | function _load_bintray() {
|
29 | return _bintray = require("electron-builder-http/out/bintray");
|
30 | }
|
31 |
|
32 | var _electronBuilderUtil;
|
33 |
|
34 | function _load_electronBuilderUtil() {
|
35 | return _electronBuilderUtil = require("electron-builder-util");
|
36 | }
|
37 |
|
38 | var _log;
|
39 |
|
40 | function _load_log() {
|
41 | return _log = require("electron-builder-util/out/log");
|
42 | }
|
43 |
|
44 | var _nodeHttpExecutor;
|
45 |
|
46 | function _load_nodeHttpExecutor() {
|
47 | return _nodeHttpExecutor = require("electron-builder-util/out/nodeHttpExecutor");
|
48 | }
|
49 |
|
50 | var _publisher;
|
51 |
|
52 | function _load_publisher() {
|
53 | return _publisher = require("./publisher");
|
54 | }
|
55 |
|
56 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
57 |
|
58 | class BintrayPublisher extends (_publisher || _load_publisher()).HttpPublisher {
|
59 | constructor(context, info, version) {
|
60 | let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
61 |
|
62 | super(context);
|
63 | this.version = version;
|
64 | this.options = options;
|
65 | this.providerName = "Bintray";
|
66 | let token = info.token;
|
67 | if ((0, (_electronBuilderUtil || _load_electronBuilderUtil()).isEmptyOrSpaces)(token)) {
|
68 | token = process.env.BT_TOKEN;
|
69 | if ((0, (_electronBuilderUtil || _load_electronBuilderUtil()).isEmptyOrSpaces)(token)) {
|
70 | throw new Error(`Bintray token is not set, neither programmatically, nor using env "BT_TOKEN"`);
|
71 | }
|
72 | }
|
73 | this.client = new (_bintray || _load_bintray()).BintrayClient(info, this.context.cancellationToken, token);
|
74 | this._versionPromise = this.init();
|
75 | }
|
76 | init() {
|
77 | var _this = this;
|
78 |
|
79 | return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () {
|
80 | try {
|
81 | return yield _this.client.getVersion(_this.version);
|
82 | } catch (e) {
|
83 | if (e instanceof (_electronBuilderHttp || _load_electronBuilderHttp()).HttpError && e.response.statusCode === 404) {
|
84 | if (_this.options.publish !== "onTagOrDraft") {
|
85 | (0, (_log || _load_log()).log)(`Version ${_this.version} doesn't exist, creating one`);
|
86 | return _this.client.createVersion(_this.version);
|
87 | } else {
|
88 | (0, (_log || _load_log()).log)(`Version ${_this.version} doesn't exist, artifacts will be not published`);
|
89 | }
|
90 | }
|
91 | throw e;
|
92 | }
|
93 | })();
|
94 | }
|
95 | doUpload(fileName, dataLength, requestProcessor) {
|
96 | var _this2 = this;
|
97 |
|
98 | return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () {
|
99 | const version = yield _this2._versionPromise;
|
100 | if (version == null) {
|
101 | (0, (_electronBuilderUtil || _load_electronBuilderUtil()).debug)(`Version ${_this2.version} doesn't exist and is not created, artifact ${fileName} is not published`);
|
102 | return;
|
103 | }
|
104 | let badGatewayCount = 0;
|
105 | for (let i = 0; i < 3; i++) {
|
106 | try {
|
107 | return yield (_nodeHttpExecutor || _load_nodeHttpExecutor()).httpExecutor.doApiRequest((0, (_electronBuilderHttp || _load_electronBuilderHttp()).configureRequestOptions)({
|
108 | hostname: "api.bintray.com",
|
109 | path: `/content/${_this2.client.owner}/${_this2.client.repo}/${_this2.client.packageName}/${version.name}/${fileName}`,
|
110 | method: "PUT",
|
111 | headers: {
|
112 | "Content-Length": dataLength,
|
113 | "X-Bintray-Override": "1",
|
114 | "X-Bintray-Publish": "1"
|
115 | }
|
116 | }, _this2.client.auth), _this2.context.cancellationToken, requestProcessor);
|
117 | } catch (e) {
|
118 | if (e instanceof (_electronBuilderHttp || _load_electronBuilderHttp()).HttpError && e.response.statusCode === 502 && badGatewayCount++ < 3) {
|
119 | continue;
|
120 | }
|
121 | throw e;
|
122 | }
|
123 | }
|
124 | })();
|
125 | }
|
126 | //noinspection JSUnusedGlobalSymbols
|
127 | deleteRelease() {
|
128 | if (!this._versionPromise.isFulfilled()) {
|
129 | return (_bluebirdLstC2 || _load_bluebirdLstC2()).default.resolve();
|
130 | }
|
131 | const version = this._versionPromise.value();
|
132 | return version == null ? (_bluebirdLstC2 || _load_bluebirdLstC2()).default.resolve() : this.client.deleteVersion(version.name);
|
133 | }
|
134 | toString() {
|
135 | return `Bintray (user: ${this.client.user || this.client.owner}, owner: ${this.client.owner}, package: ${this.client.packageName}, repository: ${this.client.repo}, version: ${this.version})`;
|
136 | }
|
137 | }
|
138 | exports.BintrayPublisher = BintrayPublisher; //# sourceMappingURL=BintrayPublisher.js.map |
\ | No newline at end of file |