Renaming single file names while copying entire folder using copyTpl

只愿长相守 提交于 2019-12-01 12:06:21

OK, I found a solution. According to yeoman docs:

Any generator author can register a transformStream to modify the file path and/or the content.

Using this method:

this.registerTransformStream();

What that means is I can pipe all generated files through some script:

var rename = require("gulp-rename");
//other dependecies...

module.exports = yeoman.Base.extend({

    //some other things generator do...

    writing: function() {
        var THAT = this;
        this.registerTransformStream(rename(function(path) {
            path.basename = path.basename.replace(/(666replacethat666)/g, THAT.props.appName);
            path.dirname = path.dirname.replace(/(666replacethat666)/g, THAT.props.appName);
        }));
        this.fs.copyTpl(
            this.templatePath(),
            this.destinationPath(), {
                appName: this.props.appName
            });
    }
});

This script will pipe all files through gulp-rename, changing 666replacethat666 to something more intelligent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!