UNPKG

3.65 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt
7 * The complete set of authors may be found at
8 * http://polymer.github.io/AUTHORS.txt
9 * The complete set of contributors may be found at
10 * http://polymer.github.io/CONTRIBUTORS.txt
11 * Code distributed by Google as part of the polymer project is also
12 * subject to an additional IP rights grant found at
13 * http://polymer.github.io/PATENTS.txt
14 */
15var __asyncValues = (this && this.__asyncValues) || function (o) {
16 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17 var m = o[Symbol.asyncIterator], i;
18 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
19 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
20 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
21};
22var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
23var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
24 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
25 var g = generator.apply(thisArg, _arguments || []), i, q = [];
26 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
27 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
28 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
29 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
30 function fulfill(value) { resume("next", value); }
31 function reject(value) { resume("throw", value); }
32 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
33};
34Object.defineProperty(exports, "__esModule", { value: true });
35const streams_1 = require("./streams");
36function forkStream(stream) {
37 const fork = new ForkedVinylStream();
38 stream.pipe(fork);
39 return fork;
40}
41exports.forkStream = forkStream;
42/**
43 * Forks a stream of Vinyl files, cloning each file before emitting on the fork.
44 */
45class ForkedVinylStream extends streams_1.AsyncTransformStream {
46 constructor() {
47 super({ objectMode: true });
48 }
49 _transformIter(files) {
50 return __asyncGenerator(this, arguments, function* _transformIter_1() {
51 var e_1, _a;
52 try {
53 for (var files_1 = __asyncValues(files), files_1_1; files_1_1 = yield __await(files_1.next()), !files_1_1.done;) {
54 const file = files_1_1.value;
55 yield yield __await(file.clone({ deep: true, contents: true }));
56 }
57 }
58 catch (e_1_1) { e_1 = { error: e_1_1 }; }
59 finally {
60 try {
61 if (files_1_1 && !files_1_1.done && (_a = files_1.return)) yield __await(_a.call(files_1));
62 }
63 finally { if (e_1) throw e_1.error; }
64 }
65 });
66 }
67}
68exports.ForkedVinylStream = ForkedVinylStream;
69//# sourceMappingURL=fork-stream.js.map
\No newline at end of file