gulp:没有从流中获取正确的文件集

时间:2015-07-19 10:35:20

标签: javascript gulp

我的gulpfile.js中有以下内容:

onlyJson = filter('package.json');
onlyReadme = filter('readme.txt');

// get all the files to bump version in

return gulp.src(['package.json', 'readme.txt', 'README.md' ])
    .pipe(onlyJson)
    // bump the version number in those files
    .pipe(bump({type: importance}))
    // save it back to filesystem
    .pipe(gulp.dest('./'))


    .pipe(onlyJson.restore())
    .pipe(dbg({title: 'After Json Restore'}))

    .pipe(onlyReadme)
    .pipe(dbg({title: 'After Readme Filter '}))
    .pipe(replace('Stable tag: ' + version, 'Stable tag: ' + nextV))
    .pipe(gulp.dest('./'))

    .pipe(readme())
    .pipe(dbg({title: 'After Readme Process '}))
    .pipe(gulp.dest('./'))

     // restore the original filter
    .pipe(onlyReadme.restore())

    .pipe(dbg({title: 'After Readme Restore'}))

在我第二次调用filter.restore()(onlyReadme.restore)后,我原本希望在我的流中有我原来的三个文件,但由于一些奇怪的原因,我有:package.json,README.md和 README.md 再次......

调试的输出是:

(...)

[12:24:49] Finished 'patch' after 41 ms
[12:24:49] Bumped 'package.json' version to: 0.6.2
[12:24:49] After Json Restore readme.txt
[12:24:49] After Readme Filter  readme.txt
[12:24:49] After Json Restore package.json
[12:24:49] After Readme Restore package.json
[12:24:49] After Json Restore README.md
[12:24:49] After Readme Restore README.md
[12:24:49] After Json Restore 3 items
[12:24:49] After Readme Filter  1 items
[12:24:49] After Readme Process  README.md
[12:24:49] After Readme Process  1 items
[12:24:49] After Readme Restore README.md
[12:24:49] After Readme Restore 3 items

(...)

如果不是通过gulp-filter来实现,而是通过合并流来实现,我会得到完全相同的结果......

readme = gulp.src('readme.txt')
    .pipe(replace('Stable tag: ' + version, 'Stable tag: ' + nextV))
    .pipe(gulp.dest('./'))
    .pipe(readme())
    .pipe(gulp.dest('./'));

json = gulp.src('package.json')
    .pipe(bump({type: importance}))
    .pipe(gulp.dest('./'));


readmeme = gulp.src('README.md');

return merge([readme, json, readmeme])
    .pipe(git.add())
    .pipe(dbg({title: 'After Merge'}));

结果:

[12:58:56] After Merge README.md
[12:58:56] After Merge package.json
[12:58:56] After Merge README.md
[12:58:56] After Merge 3 items

我在这里做错了什么? gulp的新手,所以我想我可能会误解一些基本的gulp工作流程......

1 个答案:

答案 0 :(得分:0)

知道了。 :P

对readme()的调用正在改变我的流并将其设置为' README.md'。