Gulp保存流保留目录结构

时间:2014-11-22 03:06:23

标签: javascript node.js stream gulp

我有一个插件,可以使用此功能在流中生成新文件

var pass = through2.obj(function (file, enc, callback) {
        if (!gulpmatch(file, __json_condition)) {
            this.push(file);
        }else {
            compiled_files = bootsie_compiler.build_from_buffer(file.contents, {stream:true});
            for (var i =0; i<compiled_files.length; i++){
                this.push(new gutil.File(
                    {
                        base: compiled_files[i].base,
                        path: compiled_files[i].path,
                        contents: new Buffer(compiled_files[i].contents)
                    })
                );
            }

        }
        callback();
    });

一切都按预期工作,gulp-filelogs在流中输出3个文件

[21:51:34] [1] [Path:/home/michael/Projects/OpenSource/Portfolio/www/build/index.html]   [Base:/home/michael/Projects/OpenSource/Portfolio/www/build] [CWD:/home/michael/Projects/OpenSource/Portfolio/www]
[21:51:34] [2] [Path:/home/michael/Projects/OpenSource/Portfolio/www/build/archive/test/index.html] [Base:/home/michael/Projects/OpenSource/Portfolio/www/build/archive/test] [CWD:/home/michael/Projects/OpenSource/Portfolio/www]
[21:51:34] [3] [Path:/home/michael/Projects/OpenSource/Portfolio/www/build/archive/test2/index.html] [Base:/home/michael/Projects/OpenSource/Portfolio/www/build/archive/test2] [CWD:/home/michael/Projects/OpenSource/Portfolio/www]

我的gulp任务就是这个

gulp.task("bootsie-build",["copy-assets"], function(){
    var build_dir = "./build";
    var src_dir = "./src";

    return gulp.src([src_dir+"/website.json"]) //Configuration file parsed
        .pipe(bootsie.build())  // function that generates the 3 files
        .pipe(filelog())        // filelog, outputs the 3 lines above
        .pipe(gulp.dest(build_dir))   //Save files
}

我的问题是结构没有保留,所以我在这种情况下

./build/index.html

包含保存的最后一个文件(其他两个被覆盖), 而不是

./build/index.html
./build/test/index.html
./build/test2/index.html

如何保留结构?

0 个答案:

没有答案
相关问题