UNPKG

@squiz/dxp

Version:

The common dxp library for cli commands

1,220 lines (1,141 loc) 41.6 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs')) : typeof define === 'function' && define.amd ? define(['exports', 'rxjs'], factory) : (global = global || self, factory(global.Dxp = {}, global.rxjs)); }(this, (function (exports, rxjs) { 'use strict'; /*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ /** * TODO: * @export * @abstract * @class BaseCommand */ class BaseCommand { constructor() { /** * TODO: * @type {boolean} * @memberof BaseCommand */ this.isAlias = false; } /** * TODO: * @param {CommandContext} context TODO: * @returns {Array<string>} TODO: * @memberof BaseCommand */ aliases(context) { return []; } /** * TODO: * @param {CommandContext} context TODO: * @returns {Array<string>} TODO: * @memberof BaseCommand */ examples(context) { return []; } /** * TODO: * @param {CommandContext} context TODO: * @returns {(Observable<string> | Promise<string> | string)} TODO: * @memberof BaseCommand */ help(context) { return `No help entry for ${context.currentCommand.commandName}`; } /** * TODO: * @param {CommandContext} context TODO: * @returns {Array<string>} TODO: * @memberof BaseCommand */ usages(context) { return []; } } /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } /** PURE_IMPORTS_START PURE_IMPORTS_END */ function isFunction(x) { return typeof x === 'function'; } /** PURE_IMPORTS_START PURE_IMPORTS_END */ var _enable_super_gross_mode_that_will_cause_bad_things = false; var config = { Promise: undefined, set useDeprecatedSynchronousErrorHandling(value) { if (value) { var error = /*@__PURE__*/ new Error(); /*@__PURE__*/ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack); } _enable_super_gross_mode_that_will_cause_bad_things = value; }, get useDeprecatedSynchronousErrorHandling() { return _enable_super_gross_mode_that_will_cause_bad_things; }, }; /** PURE_IMPORTS_START PURE_IMPORTS_END */ function hostReportError(err) { setTimeout(function () { throw err; }, 0); } /** PURE_IMPORTS_START _config,_util_hostReportError PURE_IMPORTS_END */ var empty = { closed: true, next: function (value) { }, error: function (err) { if (config.useDeprecatedSynchronousErrorHandling) { throw err; } else { hostReportError(err); } }, complete: function () { } }; /** PURE_IMPORTS_START PURE_IMPORTS_END */ var isArray = /*@__PURE__*/ (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })(); /** PURE_IMPORTS_START PURE_IMPORTS_END */ function isObject(x) { return x !== null && typeof x === 'object'; } /** PURE_IMPORTS_START PURE_IMPORTS_END */ var UnsubscriptionErrorImpl = /*@__PURE__*/ (function () { function UnsubscriptionErrorImpl(errors) { Error.call(this); this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : ''; this.name = 'UnsubscriptionError'; this.errors = errors; return this; } UnsubscriptionErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype); return UnsubscriptionErrorImpl; })(); var UnsubscriptionError = UnsubscriptionErrorImpl; /** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_UnsubscriptionError PURE_IMPORTS_END */ var Subscription = /*@__PURE__*/ (function () { function Subscription(unsubscribe) { this.closed = false; this._parentOrParents = null; this._subscriptions = null; if (unsubscribe) { this._unsubscribe = unsubscribe; } } Subscription.prototype.unsubscribe = function () { var errors; if (this.closed) { return; } var _a = this, _parentOrParents = _a._parentOrParents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions; this.closed = true; this._parentOrParents = null; this._subscriptions = null; if (_parentOrParents instanceof Subscription) { _parentOrParents.remove(this); } else if (_parentOrParents !== null) { for (var index = 0; index < _parentOrParents.length; ++index) { var parent_1 = _parentOrParents[index]; parent_1.remove(this); } } if (isFunction(_unsubscribe)) { try { _unsubscribe.call(this); } catch (e) { errors = e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e]; } } if (isArray(_subscriptions)) { var index = -1; var len = _subscriptions.length; while (++index < len) { var sub = _subscriptions[index]; if (isObject(sub)) { try { sub.unsubscribe(); } catch (e) { errors = errors || []; if (e instanceof UnsubscriptionError) { errors = errors.concat(flattenUnsubscriptionErrors(e.errors)); } else { errors.push(e); } } } } } if (errors) { throw new UnsubscriptionError(errors); } }; Subscription.prototype.add = function (teardown) { var subscription = teardown; if (!teardown) { return Subscription.EMPTY; } switch (typeof teardown) { case 'function': subscription = new Subscription(teardown); case 'object': if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') { return subscription; } else if (this.closed) { subscription.unsubscribe(); return subscription; } else if (!(subscription instanceof Subscription)) { var tmp = subscription; subscription = new Subscription(); subscription._subscriptions = [tmp]; } break; default: { throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.'); } } var _parentOrParents = subscription._parentOrParents; if (_parentOrParents === null) { subscription._parentOrParents = this; } else if (_parentOrParents instanceof Subscription) { if (_parentOrParents === this) { return subscription; } subscription._parentOrParents = [_parentOrParents, this]; } else if (_parentOrParents.indexOf(this) === -1) { _parentOrParents.push(this); } else { return subscription; } var subscriptions = this._subscriptions; if (subscriptions === null) { this._subscriptions = [subscription]; } else { subscriptions.push(subscription); } return subscription; }; Subscription.prototype.remove = function (subscription) { var subscriptions = this._subscriptions; if (subscriptions) { var subscriptionIndex = subscriptions.indexOf(subscription); if (subscriptionIndex !== -1) { subscriptions.splice(subscriptionIndex, 1); } } }; Subscription.EMPTY = (function (empty) { empty.closed = true; return empty; }(new Subscription())); return Subscription; }()); function flattenUnsubscriptionErrors(errors) { return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []); } /** PURE_IMPORTS_START PURE_IMPORTS_END */ var rxSubscriber = /*@__PURE__*/ (function () { return typeof Symbol === 'function' ? /*@__PURE__*/ Symbol('rxSubscriber') : '@@rxSubscriber_' + /*@__PURE__*/ Math.random(); })(); /** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */ var Subscriber = /*@__PURE__*/ (function (_super) { __extends(Subscriber, _super); function Subscriber(destinationOrNext, error, complete) { var _this = _super.call(this) || this; _this.syncErrorValue = null; _this.syncErrorThrown = false; _this.syncErrorThrowable = false; _this.isStopped = false; switch (arguments.length) { case 0: _this.destination = empty; break; case 1: if (!destinationOrNext) { _this.destination = empty; break; } if (typeof destinationOrNext === 'object') { if (destinationOrNext instanceof Subscriber) { _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; _this.destination = destinationOrNext; destinationOrNext.add(_this); } else { _this.syncErrorThrowable = true; _this.destination = new SafeSubscriber(_this, destinationOrNext); } break; } default: _this.syncErrorThrowable = true; _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete); break; } return _this; } Subscriber.prototype[rxSubscriber] = function () { return this; }; Subscriber.create = function (next, error, complete) { var subscriber = new Subscriber(next, error, complete); subscriber.syncErrorThrowable = false; return subscriber; }; Subscriber.prototype.next = function (value) { if (!this.isStopped) { this._next(value); } }; Subscriber.prototype.error = function (err) { if (!this.isStopped) { this.isStopped = true; this._error(err); } }; Subscriber.prototype.complete = function () { if (!this.isStopped) { this.isStopped = true; this._complete(); } }; Subscriber.prototype.unsubscribe = function () { if (this.closed) { return; } this.isStopped = true; _super.prototype.unsubscribe.call(this); }; Subscriber.prototype._next = function (value) { this.destination.next(value); }; Subscriber.prototype._error = function (err) { this.destination.error(err); this.unsubscribe(); }; Subscriber.prototype._complete = function () { this.destination.complete(); this.unsubscribe(); }; Subscriber.prototype._unsubscribeAndRecycle = function () { var _parentOrParents = this._parentOrParents; this._parentOrParents = null; this.unsubscribe(); this.closed = false; this.isStopped = false; this._parentOrParents = _parentOrParents; return this; }; return Subscriber; }(Subscription)); var SafeSubscriber = /*@__PURE__*/ (function (_super) { __extends(SafeSubscriber, _super); function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) { var _this = _super.call(this) || this; _this._parentSubscriber = _parentSubscriber; var next; var context = _this; if (isFunction(observerOrNext)) { next = observerOrNext; } else if (observerOrNext) { next = observerOrNext.next; error = observerOrNext.error; complete = observerOrNext.complete; if (observerOrNext !== empty) { context = Object.create(observerOrNext); if (isFunction(context.unsubscribe)) { _this.add(context.unsubscribe.bind(context)); } context.unsubscribe = _this.unsubscribe.bind(_this); } } _this._context = context; _this._next = next; _this._error = error; _this._complete = complete; return _this; } SafeSubscriber.prototype.next = function (value) { if (!this.isStopped && this._next) { var _parentSubscriber = this._parentSubscriber; if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(this._next, value); } else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) { this.unsubscribe(); } } }; SafeSubscriber.prototype.error = function (err) { if (!this.isStopped) { var _parentSubscriber = this._parentSubscriber; var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling; if (this._error) { if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(this._error, err); this.unsubscribe(); } else { this.__tryOrSetError(_parentSubscriber, this._error, err); this.unsubscribe(); } } else if (!_parentSubscriber.syncErrorThrowable) { this.unsubscribe(); if (useDeprecatedSynchronousErrorHandling) { throw err; } hostReportError(err); } else { if (useDeprecatedSynchronousErrorHandling) { _parentSubscriber.syncErrorValue = err; _parentSubscriber.syncErrorThrown = true; } else { hostReportError(err); } this.unsubscribe(); } } }; SafeSubscriber.prototype.complete = function () { var _this = this; if (!this.isStopped) { var _parentSubscriber = this._parentSubscriber; if (this._complete) { var wrappedComplete = function () { return _this._complete.call(_this._context); }; if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(wrappedComplete); this.unsubscribe(); } else { this.__tryOrSetError(_parentSubscriber, wrappedComplete); this.unsubscribe(); } } else { this.unsubscribe(); } } }; SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) { try { fn.call(this._context, value); } catch (err) { this.unsubscribe(); if (config.useDeprecatedSynchronousErrorHandling) { throw err; } else { hostReportError(err); } } }; SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) { if (!config.useDeprecatedSynchronousErrorHandling) { throw new Error('bad call'); } try { fn.call(this._context, value); } catch (err) { if (config.useDeprecatedSynchronousErrorHandling) { parent.syncErrorValue = err; parent.syncErrorThrown = true; return true; } else { hostReportError(err); return true; } } return false; }; SafeSubscriber.prototype._unsubscribe = function () { var _parentSubscriber = this._parentSubscriber; this._context = null; this._parentSubscriber = null; _parentSubscriber.unsubscribe(); }; return SafeSubscriber; }(Subscriber)); /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */ var OuterSubscriber = /*@__PURE__*/ (function (_super) { __extends(OuterSubscriber, _super); function OuterSubscriber() { return _super !== null && _super.apply(this, arguments) || this; } OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { this.destination.next(innerValue); }; OuterSubscriber.prototype.notifyError = function (error, innerSub) { this.destination.error(error); }; OuterSubscriber.prototype.notifyComplete = function (innerSub) { this.destination.complete(); }; return OuterSubscriber; }(Subscriber)); /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */ var InnerSubscriber = /*@__PURE__*/ (function (_super) { __extends(InnerSubscriber, _super); function InnerSubscriber(parent, outerValue, outerIndex) { var _this = _super.call(this) || this; _this.parent = parent; _this.outerValue = outerValue; _this.outerIndex = outerIndex; _this.index = 0; return _this; } InnerSubscriber.prototype._next = function (value) { this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this); }; InnerSubscriber.prototype._error = function (error) { this.parent.notifyError(error, this); this.unsubscribe(); }; InnerSubscriber.prototype._complete = function () { this.parent.notifyComplete(this); this.unsubscribe(); }; return InnerSubscriber; }(Subscriber)); /** PURE_IMPORTS_START PURE_IMPORTS_END */ var subscribeToArray = function (array) { return function (subscriber) { for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) { subscriber.next(array[i]); } subscriber.complete(); }; }; /** PURE_IMPORTS_START _hostReportError PURE_IMPORTS_END */ var subscribeToPromise = function (promise) { return function (subscriber) { promise.then(function (value) { if (!subscriber.closed) { subscriber.next(value); subscriber.complete(); } }, function (err) { return subscriber.error(err); }) .then(null, hostReportError); return subscriber; }; }; /** PURE_IMPORTS_START PURE_IMPORTS_END */ function getSymbolIterator() { if (typeof Symbol !== 'function' || !Symbol.iterator) { return '@@iterator'; } return Symbol.iterator; } var iterator = /*@__PURE__*/ getSymbolIterator(); /** PURE_IMPORTS_START _symbol_iterator PURE_IMPORTS_END */ var subscribeToIterable = function (iterable) { return function (subscriber) { var iterator$1 = iterable[iterator](); do { var item = iterator$1.next(); if (item.done) { subscriber.complete(); break; } subscriber.next(item.value); if (subscriber.closed) { break; } } while (true); if (typeof iterator$1.return === 'function') { subscriber.add(function () { if (iterator$1.return) { iterator$1.return(); } }); } return subscriber; }; }; /** PURE_IMPORTS_START PURE_IMPORTS_END */ var observable = /*@__PURE__*/ (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })(); /** PURE_IMPORTS_START _symbol_observable PURE_IMPORTS_END */ var subscribeToObservable = function (obj) { return function (subscriber) { var obs = obj[observable](); if (typeof obs.subscribe !== 'function') { throw new TypeError('Provided object does not correctly implement Symbol.observable'); } else { return obs.subscribe(subscriber); } }; }; /** PURE_IMPORTS_START PURE_IMPORTS_END */ var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; }); /** PURE_IMPORTS_START PURE_IMPORTS_END */ function isPromise(value) { return !!value && typeof value.subscribe !== 'function' && typeof value.then === 'function'; } /** PURE_IMPORTS_START _subscribeToArray,_subscribeToPromise,_subscribeToIterable,_subscribeToObservable,_isArrayLike,_isPromise,_isObject,_symbol_iterator,_symbol_observable PURE_IMPORTS_END */ var subscribeTo = function (result) { if (!!result && typeof result[observable] === 'function') { return subscribeToObservable(result); } else if (isArrayLike(result)) { return subscribeToArray(result); } else if (isPromise(result)) { return subscribeToPromise(result); } else if (!!result && typeof result[iterator] === 'function') { return subscribeToIterable(result); } else { var value = isObject(result) ? 'an invalid object' : "'" + result + "'"; var msg = "You provided " + value + " where a stream was expected." + ' You can provide an Observable, Promise, Array, or Iterable.'; throw new TypeError(msg); } }; /** PURE_IMPORTS_START _Subscriber PURE_IMPORTS_END */ function canReportError(observer) { while (observer) { var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped; if (closed_1 || isStopped) { return false; } else if (destination && destination instanceof Subscriber) { observer = destination; } else { observer = null; } } return true; } /** PURE_IMPORTS_START _Subscriber,_symbol_rxSubscriber,_Observer PURE_IMPORTS_END */ function toSubscriber(nextOrObserver, error, complete) { if (nextOrObserver) { if (nextOrObserver instanceof Subscriber) { return nextOrObserver; } if (nextOrObserver[rxSubscriber]) { return nextOrObserver[rxSubscriber](); } } if (!nextOrObserver && !error && !complete) { return new Subscriber(empty); } return new Subscriber(nextOrObserver, error, complete); } /** PURE_IMPORTS_START PURE_IMPORTS_END */ function noop() { } /** PURE_IMPORTS_START _noop PURE_IMPORTS_END */ function pipeFromArray(fns) { if (!fns) { return noop; } if (fns.length === 1) { return fns[0]; } return function piped(input) { return fns.reduce(function (prev, fn) { return fn(prev); }, input); }; } /** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */ var Observable = /*@__PURE__*/ (function () { function Observable(subscribe) { this._isScalar = false; if (subscribe) { this._subscribe = subscribe; } } Observable.prototype.lift = function (operator) { var observable = new Observable(); observable.source = this; observable.operator = operator; return observable; }; Observable.prototype.subscribe = function (observerOrNext, error, complete) { var operator = this.operator; var sink = toSubscriber(observerOrNext, error, complete); if (operator) { sink.add(operator.call(sink, this.source)); } else { sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ? this._subscribe(sink) : this._trySubscribe(sink)); } if (config.useDeprecatedSynchronousErrorHandling) { if (sink.syncErrorThrowable) { sink.syncErrorThrowable = false; if (sink.syncErrorThrown) { throw sink.syncErrorValue; } } } return sink; }; Observable.prototype._trySubscribe = function (sink) { try { return this._subscribe(sink); } catch (err) { if (config.useDeprecatedSynchronousErrorHandling) { sink.syncErrorThrown = true; sink.syncErrorValue = err; } if (canReportError(sink)) { sink.error(err); } else { console.warn(err); } } }; Observable.prototype.forEach = function (next, promiseCtor) { var _this = this; promiseCtor = getPromiseCtor(promiseCtor); return new promiseCtor(function (resolve, reject) { var subscription; subscription = _this.subscribe(function (value) { try { next(value); } catch (err) { reject(err); if (subscription) { subscription.unsubscribe(); } } }, reject, resolve); }); }; Observable.prototype._subscribe = function (subscriber) { var source = this.source; return source && source.subscribe(subscriber); }; Observable.prototype[observable] = function () { return this; }; Observable.prototype.pipe = function () { var operations = []; for (var _i = 0; _i < arguments.length; _i++) { operations[_i] = arguments[_i]; } if (operations.length === 0) { return this; } return pipeFromArray(operations)(this); }; Observable.prototype.toPromise = function (promiseCtor) { var _this = this; promiseCtor = getPromiseCtor(promiseCtor); return new promiseCtor(function (resolve, reject) { var value; _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); }); }); }; Observable.create = function (subscribe) { return new Observable(subscribe); }; return Observable; }()); function getPromiseCtor(promiseCtor) { if (!promiseCtor) { promiseCtor = Promise; } if (!promiseCtor) { throw new Error('no Promise impl found'); } return promiseCtor; } /** PURE_IMPORTS_START _InnerSubscriber,_subscribeTo,_Observable PURE_IMPORTS_END */ function subscribeToResult(outerSubscriber, result, outerValue, outerIndex, destination) { if (destination === void 0) { destination = new InnerSubscriber(outerSubscriber, outerValue, outerIndex); } if (destination.closed) { return undefined; } if (result instanceof Observable) { return result.subscribe(destination); } return subscribeTo(result)(destination); } /** PURE_IMPORTS_START tslib,_OuterSubscriber,_InnerSubscriber,_util_subscribeToResult PURE_IMPORTS_END */ function catchError(selector) { return function catchErrorOperatorFunction(source) { var operator = new CatchOperator(selector); var caught = source.lift(operator); return (operator.caught = caught); }; } var CatchOperator = /*@__PURE__*/ (function () { function CatchOperator(selector) { this.selector = selector; } CatchOperator.prototype.call = function (subscriber, source) { return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught)); }; return CatchOperator; }()); var CatchSubscriber = /*@__PURE__*/ (function (_super) { __extends(CatchSubscriber, _super); function CatchSubscriber(destination, selector, caught) { var _this = _super.call(this, destination) || this; _this.selector = selector; _this.caught = caught; return _this; } CatchSubscriber.prototype.error = function (err) { if (!this.isStopped) { var result = void 0; try { result = this.selector(err, this.caught); } catch (err2) { _super.prototype.error.call(this, err2); return; } this._unsubscribeAndRecycle(); var innerSubscriber = new InnerSubscriber(this, undefined, undefined); this.add(innerSubscriber); subscribeToResult(this, result, undefined, undefined, innerSubscriber); } }; return CatchSubscriber; }(OuterSubscriber)); /** PURE_IMPORTS_START tslib,_Subscriber,_util_noop,_util_isFunction PURE_IMPORTS_END */ function tap(nextOrObserver, error, complete) { return function tapOperatorFunction(source) { return source.lift(new DoOperator(nextOrObserver, error, complete)); }; } var DoOperator = /*@__PURE__*/ (function () { function DoOperator(nextOrObserver, error, complete) { this.nextOrObserver = nextOrObserver; this.error = error; this.complete = complete; } DoOperator.prototype.call = function (subscriber, source) { return source.subscribe(new TapSubscriber(subscriber, this.nextOrObserver, this.error, this.complete)); }; return DoOperator; }()); var TapSubscriber = /*@__PURE__*/ (function (_super) { __extends(TapSubscriber, _super); function TapSubscriber(destination, observerOrNext, error, complete) { var _this = _super.call(this, destination) || this; _this._tapNext = noop; _this._tapError = noop; _this._tapComplete = noop; _this._tapError = error || noop; _this._tapComplete = complete || noop; if (isFunction(observerOrNext)) { _this._context = _this; _this._tapNext = observerOrNext; } else if (observerOrNext) { _this._context = observerOrNext; _this._tapNext = observerOrNext.next || noop; _this._tapError = observerOrNext.error || noop; _this._tapComplete = observerOrNext.complete || noop; } return _this; } TapSubscriber.prototype._next = function (value) { try { this._tapNext.call(this._context, value); } catch (err) { this.destination.error(err); return; } this.destination.next(value); }; TapSubscriber.prototype._error = function (err) { try { this._tapError.call(this._context, err); } catch (err) { this.destination.error(err); return; } this.destination.error(err); }; TapSubscriber.prototype._complete = function () { try { this._tapComplete.call(this._context); } catch (err) { this.destination.error(err); return; } return this.destination.complete(); }; return TapSubscriber; }(Subscriber)); /*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ /** * Add a plugin to `@squiz/dxp-cli`. * @export * @class PluginAddCommand * @extends {BaseCommand} * @implements {Commandable} */ class PluginAddCommand extends BaseCommand { /** * TODO: * @template T TODO: * @param {CommandContext} context TODO: * @returns {(Observable<unknown> | Promise<unknown> | unknown)} TODO: * @memberof PluginAddCommand */ execute(context) { const plugins = context.input.join(` `); const spinner = context.createSpinner(`Adding plugins ${plugins}`); const command = `npm install --global false --prefix '${context.paths.plugins}' --quiet ${plugins}`; return context.exec$(command).pipe(tap(result => { spinner.succeed(`Successfully added plugins`); context.loadCommands(); Object.keys(context.pluginList).filter(pluginName => { return context.input.includes(pluginName); }).forEach(pluginName => { console.log(pluginName); context.pluginList[pluginName].forEach(commandFullName => { console.log(` - ${commandFullName}`); }); }); }), catchError(error => { spinner.fail(`Adding plugins failed`); context.debug(() => { console.error(error); }); return rxjs.of(null); })); } /** * TODO: * @param {CommandContext} context TODO: * @returns {Array<string>} TODO: * @memberof PluginAddCommand */ usages(context) { return [`dxp plugin add <plugin> [<plugin>...]`]; } } /*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ /** * TODO: * @export * @class PluginListCommand * @extends {BaseCommand} * @implements {Commandable} */ class PluginListCommand extends BaseCommand { /** * TODO: * @param {CommandContext} context TODO: * @returns {Array<string>} TODO: * @memberof PluginListCommand */ aliases(context) { return [`ls`]; } /** * TODO: * @template T TODO: * @param {CommandContext} context TODO: * @returns {(Observable<unknown> | Promise<unknown> | unknown)} TODO: * @memberof PluginListCommand */ execute(context) { const pluginVersions = {}; if (context.flags.includeVersions) { context.commandsMap(command => { pluginVersions[command.pluginName] = command.pluginVersion; }); } Object.keys(context.pluginList).forEach(pluginName => { if (context.flags.includeVersions) { console.log(`${pluginName}@${pluginVersions[pluginName]}`); } else { console.log(pluginName); } if (context.flags.includeCommands) { context.pluginList[pluginName].forEach(commandFullName => { console.log(` - ${commandFullName}`); }); } }); return null; } /** * TODO: * @param {CommandContext} context TODO: * @returns {Array<string>} TODO: * @memberof PluginListCommand */ usages(context) { return [`dxp plugin list`]; } } /*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ /** * TODO: * @export * @class PluginCommand * @extends {BaseCommand} * @implements {Commandable} */ class PluginCommand extends BaseCommand { /** * TODO: * @param {CommandContext} context TODO: * @returns {Array<string>} TODO: * @memberof PluginCommand */ aliases(context) { return [`plugins`]; } /** * TODO: * @template T TODO: * @param {CommandContext} context TODO: * @returns {(Observable<unknown> | Promise<unknown> | unknown)} TODO: * @memberof PluginCommand */ execute(context) { if (context.input.length > 0) { const attemptedCommandName = `${context.currentCommand.commandFullName} ${context.input.join(` `)}`; console.log(`dxp: "${attemptedCommandName}" is not a dxp command. See 'dxp --help'.`); process.exit(1); } if (context.isCommand(context.commands.plugin)) { return null; } if (!context.isCommand(context.commands.plugin.list)) { return null; } context.input.push(`list`); return context.commands.plugin.list.execute(context); } } /*! * @license * Copyright Squiz Australia Pty Ltd. All Rights Reserved. */ /** * TODO: * @export * @class PluginRemoveCommand * @extends {BaseCommand} * @implements {Commandable} */ class PluginRemoveCommand extends BaseCommand { /** * TODO: * @param {CommandContext} context TODO: * @returns {Array<string>} TODO: * @memberof PluginRemoveCommand */ aliases(context) { return [`🔥`, `🗑️`, `del`, `delete`, `rm`]; } /** * TODO: * @template T TODO: * @param {CommandContext} context TODO: * @returns {(Observable<unknown> | Promise<unknown> | unknown)} TODO: * @memberof PluginRemoveCommand */ execute(context) { const plugins = context.input.join(` `); const spinner = context.createSpinner(`Removing plugins ${plugins}`); const command = `npm uninstall --global false --prefix '${context.paths.plugins}' --quiet ${plugins}`; return context.exec$(command).pipe(tap(result => { spinner.succeed(`Successfully removed plugins`); Object.keys(context.pluginList).filter(pluginName => { return context.input.includes(pluginName); }).forEach(pluginName => { console.log(pluginName); context.pluginList[pluginName].forEach(commandFullName => { console.log(` - ${commandFullName}`); }); }); context.loadCommands(); }), catchError(error => { spinner.fail(`Removing plugins failed`); context.debug(() => { console.error(error); }); return rxjs.of(null); })); } /** * TODO: * @param {CommandContext} context TODO: * @returns {Array<string>} TODO: * @memberof PluginRemoveCommand */ usages(context) { return [`dxp plugin remove <plugin> [<plugin>...]`]; } } exports.BaseCommand = BaseCommand; exports.PluginAddCommand = PluginAddCommand; exports.PluginCommand = PluginCommand; exports.PluginListCommand = PluginListCommand; exports.PluginRemoveCommand = PluginRemoveCommand; Object.defineProperty(exports, '__esModule', { value: true }); })));