Skip to content

Commit

Permalink
pathTraverse method support simplify generator rather than standard t…
Browse files Browse the repository at this point in the history
…wo-element array.
  • Loading branch information
huang-xiao-jian committed Apr 16, 2015
1 parent 6f7ce55 commit 9e54cb5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ For example, set postfix `v0.2.5`, will generate tags below:
Type: Array

Value consists of two-element array, the first is `generator`, the second is `config`. Generally speaking, any `gulp-plugin` exports `generator` here, and `config` property pass to the `generator`. Declare how to resolve css type block files. if omitted or null, will only concat related files.
Also, you can just use `generator` here rather than two-element array when no additional options should pass in the `generator`.

For example:
```javascript
Expand Down
10 changes: 9 additions & 1 deletion test/utils.file.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ describe('utils path traverse method', function () {
});
});

it('should achieve path traverse', function () {
it('should support path traverse when provide standard two-element array', function () {
let stream = utils.pathTraverse(['test/fixture/script/origin.js'], [[generatePassStream, {}]]);
let promise = utils.streamToPromise(stream);
return promise.then(function(value) {
value.toString().should.equal("PASS angular.module('cloud', []);");
});
});

it('should support path traverse when provide simplify generator element array', function () {
let stream = utils.pathTraverse(['test/fixture/script/origin.js'], [generatePassStream]);
let promise = utils.streamToPromise(stream);
return promise.then(function(value) {
value.toString().should.equal("PASS angular.module('cloud', []);");
});
});
});

describe('utils resolveFileSource method', function () {
Expand Down
11 changes: 9 additions & 2 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,15 @@ utils.pathTraverse = function(originPath, flow, debug) {
var stream = vfs.src(destinyPath);
if (util.isArray(flow)) {
for (var i = 0; i < flow.length; i++) {
var generator = flow[i][0];
var options = flow[i][1];
let generator, options;
if (util.isArray(flow[i])) {
generator = flow[i][0];
options = flow[i][1];
}
if (util.isFunction(flow[i])) {
generator = flow[i];
options = {};
}
stream = stream.pipe(generator(options));
}
}
Expand Down

0 comments on commit 9e54cb5

Please sign in to comment.