UNPKG

electron-builder

Version:

A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box

129 lines (109 loc) 4.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BintrayPublisher = undefined; var _bluebirdLstC; function _load_bluebirdLstC() { return _bluebirdLstC = require("bluebird-lst-c"); } var _bluebirdLstC2; function _load_bluebirdLstC2() { return _bluebirdLstC2 = _interopRequireDefault(require("bluebird-lst-c")); } var _publisher; function _load_publisher() { return _publisher = require("./publisher"); } var _restApiRequest; function _load_restApiRequest() { return _restApiRequest = require("./restApiRequest"); } var _log; function _load_log() { return _log = require("../util/log"); } var _util; function _load_util() { return _util = require("../util/util"); } var _bintray; function _load_bintray() { return _bintray = require("./bintray"); } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class BintrayPublisher extends (_publisher || _load_publisher()).Publisher { constructor(info, version) { let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; super(); this.version = version; this.options = options; let token = info.token; if ((0, (_util || _load_util()).isEmptyOrSpaces)(token)) { token = process.env.BT_TOKEN; if ((0, (_util || _load_util()).isEmptyOrSpaces)(token)) { throw new Error(`Bintray token is not set, neither programmatically, nor using env "BT_TOKEN"`); } } this.client = new (_bintray || _load_bintray()).BintrayClient(info, token); this._versionPromise = this.init(); } init() { var _this = this; return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () { try { return yield _this.client.getVersion(_this.version); } catch (e) { if (e instanceof (_restApiRequest || _load_restApiRequest()).HttpError && e.response.statusCode === 404) { if (_this.options.publish !== "onTagOrDraft") { (0, (_log || _load_log()).log)(`Version ${ _this.version } doesn't exist, creating one`); return _this.client.createVersion(_this.version); } else { (0, (_log || _load_log()).log)(`Version ${ _this.version } doesn't exist, artifacts will be not published`); } } throw e; } })(); } doUpload(fileName, dataLength, requestProcessor) { var _this2 = this; return (0, (_bluebirdLstC || _load_bluebirdLstC()).coroutine)(function* () { const version = yield _this2._versionPromise; if (version == null) { (0, (_util || _load_util()).debug)(`Version ${ _this2.version } doesn't exist and is not created, artifact ${ fileName } is not published`); return; } let badGatewayCount = 0; for (let i = 0; i < 3; i++) { try { return yield (0, (_restApiRequest || _load_restApiRequest()).doApiRequest)({ hostname: "api.bintray.com", path: `/content/${ _this2.client.owner }/${ _this2.client.repo }/${ _this2.client.packageName }/${ version.name }/${ fileName }`, method: "PUT", headers: { "User-Agent": "electron-builder", "Content-Length": dataLength, "X-Bintray-Override": "1", "X-Bintray-Publish": "1" } }, _this2.client.auth, requestProcessor); } catch (e) { if (e instanceof (_restApiRequest || _load_restApiRequest()).HttpError && e.response.statusCode === 502 && badGatewayCount++ < 3) { continue; } throw e; } } })(); } //noinspection JSUnusedGlobalSymbols deleteRelease() { if (!this._versionPromise.isFulfilled()) { return (_bluebirdLstC2 || _load_bluebirdLstC2()).default.resolve(); } const version = this._versionPromise.value(); return version == null ? (_bluebirdLstC2 || _load_bluebirdLstC2()).default.resolve() : this.client.deleteVersion(version.name); } } exports.BintrayPublisher = BintrayPublisher; //# sourceMappingURL=BintrayPublisher.js.map