1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var stream_1 = require("stream");
|
5 | var gulp_util_1 = require("gulp-util");
|
6 | var FileContentStream_1 = require("./FileContentStream");
|
7 | var common_1 = require("./common");
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | var GulpTransformStream = (function (_super) {
|
14 | tslib_1.__extends(GulpTransformStream, _super);
|
15 | function GulpTransformStream(transform) {
|
16 | var _this = _super.call(this, { objectMode: true }) || this;
|
17 | _this.transform = transform;
|
18 | return _this;
|
19 | }
|
20 | GulpTransformStream.prototype._transform = function (file, _encoding, next) {
|
21 | if (file.isBuffer())
|
22 | return void this.transformBufferFile(file, next);
|
23 | if (file.isStream())
|
24 | return void this.transformStreamFile(file, next);
|
25 | next(null, file);
|
26 | };
|
27 | GulpTransformStream.prototype.transformBufferFile = function (file, next) {
|
28 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
29 | var _a, error_1;
|
30 | return tslib_1.__generator(this, function (_b) {
|
31 | switch (_b.label) {
|
32 | case 0:
|
33 | _b.trys.push([0, 2, , 3]);
|
34 | _a = file;
|
35 | return [4 , this.transform(file.contents, file)];
|
36 | case 1:
|
37 | _a.contents = _b.sent();
|
38 | next(null, file);
|
39 | return [3 , 3];
|
40 | case 2:
|
41 | error_1 = _b.sent();
|
42 | next(new gulp_util_1.PluginError(common_1.PLUGIN_NAME, error_1));
|
43 | return [3 , 3];
|
44 | case 3: return [2 ];
|
45 | }
|
46 | });
|
47 | });
|
48 | };
|
49 | GulpTransformStream.prototype.transformStreamFile = function (file, next) {
|
50 | var stream = new FileContentStream_1.FileContentStream(this.transform, file);
|
51 | stream.on("error", this.emit.bind(this, "error"));
|
52 | file.contents = file.contents.pipe(stream);
|
53 | next(null, file);
|
54 | };
|
55 | return GulpTransformStream;
|
56 | }(stream_1.Transform));
|
57 | exports.GulpTransformStream = GulpTransformStream;
|
58 |
|
\ | No newline at end of file |