@tsdi/pack
Version:
@tsdi/pack is simple build tasks, base on AOP, Ioc container, via @tsdi. dev build pack activities.
75 lines (73 loc) • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransformActivity = void 0;
var tslib_1 = require("tslib");
var ioc_1 = require("@tsdi/ioc");
var NodeActivity_1 = require("../NodeActivity");
var ITransform_1 = require("../ITransform");
/**
* transform activity.
*
* @export
* @abstract
* @class TransfrmActivity
* @extends {NodeActivity<ITransform>}
*/
var TransformActivity = /** @class */ (function (_super) {
tslib_1.__extends(TransformActivity, _super);
function TransformActivity() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* execute stream pipe.
*
* @protected
* @param {NodeActivityContext} ctx
* @param {ITransform} stream stream pipe from
* @param {GActivityType<ITransform>} transform steam pipe to.
* @param {boolean} [waitend=false] wait pipe end or not.
* @returns {Promise<ITransform>}
* @memberof TransformActivity
*/
TransformActivity.prototype.pipeStream = function (ctx, stream, transform, waitend) {
if (waitend === void 0) { waitend = false; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var transPipe, next, defer;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!ITransform_1.isTransform(transform)) return [3 /*break*/, 1];
transPipe = transform;
return [3 /*break*/, 3];
case 1: return [4 /*yield*/, ctx.resolveExpression(transform)];
case 2:
transPipe = _a.sent();
_a.label = 3;
case 3:
next = stream.pipe(transPipe);
next.once('error', function (err) {
console.error(err);
if (ioc_1.isDefined(process)) {
process.exit(1);
}
throw err;
});
if (!waitend) return [3 /*break*/, 5];
defer = ioc_1.PromiseUtil.defer();
next.once('end', defer.resolve);
return [4 /*yield*/, defer.promise];
case 4:
_a.sent();
_a.label = 5;
case 5: return [2 /*return*/, next];
}
});
});
};
TransformActivity.ρAnn = function () {
return { "name": "TransformActivity" };
};
return TransformActivity;
}(NodeActivity_1.NodeActivity));
exports.TransformActivity = TransformActivity;
//# sourceMappingURL=../sourcemaps/transforms/TransformActivity.js.map