particle-commands
Version:
Library of UX-neutral commands that provide key functionality for developer tools
128 lines (99 loc) • 4.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LibraryPublishCommand = exports.LibraryPublishCommandSite = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _command = require('./command');
var _api = require('./api');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/**
*/
var LibraryPublishCommandSite = exports.LibraryPublishCommandSite = function (_CommandSite) {
_inherits(LibraryPublishCommandSite, _CommandSite);
function LibraryPublishCommandSite() {
_classCallCheck(this, LibraryPublishCommandSite);
return _possibleConstructorReturn(this, (LibraryPublishCommandSite.__proto__ || Object.getPrototypeOf(LibraryPublishCommandSite)).call(this));
}
_createClass(LibraryPublishCommandSite, [{
key: 'apiClient',
value: function apiClient() {
throw new Error('apiClient not available');
}
/**
* Retrieves the co-ordinates of the library to publish.
*/
}, {
key: 'libraryIdent',
value: function libraryIdent() {
throw Error('not implemented');
}
}, {
key: 'error',
value: function error(err) {
throw err;
}
/**
* Notification that library publishing is starting
* @param {Promise} _promise The promise that will publish the library.
* @param {string} _ident The library identifier
*/
}, {
key: 'publishingLibrary',
value: function publishingLibrary(_promise, _ident) {}
/**
* Notification that the library publishing has completed.
* @param {Library} _library the library that was published.
*/
}, {
key: 'publishLibraryComplete',
value: function publishLibraryComplete(_library) {}
}]);
return LibraryPublishCommandSite;
}(_command.CommandSite);
/**
* Implements the library contribute command.
*/
var LibraryPublishCommand = exports.LibraryPublishCommand = function (_Command) {
_inherits(LibraryPublishCommand, _Command);
function LibraryPublishCommand() {
_classCallCheck(this, LibraryPublishCommand);
return _possibleConstructorReturn(this, (LibraryPublishCommand.__proto__ || Object.getPrototypeOf(LibraryPublishCommand)).apply(this, arguments));
}
_createClass(LibraryPublishCommand, [{
key: 'run',
/**
* @param {object} state The current conversation state.
* @param {LibraryPublishCommandSite} site external services.
* @returns {Promise} To run the library publish command.
*/
value: function run(state, site) {
var _this3 = this;
var name = void 0;
return Promise.resolve(site.libraryIdent()).then(function (ident) {
return name = ident;
}).then(function () {
return site.apiClient();
}).then(function (apiClient) {
var promise = apiClient.publishLibrary(name).catch(function (err) {
throw _this3.apiError(err);
});
var publishPromise = site.publishingLibrary(promise, name) || promise;
return publishPromise.then(function (library) {
site.publishLibraryComplete(library);
return library;
}).catch(function (err) {
site.error(err);
});
});
}
}, {
key: 'apiError',
value: function apiError(err) {
return (0, _api.convertApiError)(err);
}
}]);
return LibraryPublishCommand;
}(_command.Command);