Rai*_*ere 23 yeoman yeoman-generator
我正在为一个相当典型的节点应用程序构建一个yeoman生成器:
/
|--package.json
|--.gitignore
|--.travis.yml
|--README.md
|--app/
|--index.js
|--models
|--views
|--controllers
Run Code Online (Sandbox Code Playgroud)
在我的yeoman生成器的templates文件夹中,我必须重命名dotfiles(和package.json)以防止它们作为生成器的一部分进行处理:
templates/
|--_package.json
|--_gitignore
|--_travis.yml
|--README.md
|--app/
|--index.js
|--models
|--views
|--controllers
Run Code Online (Sandbox Code Playgroud)
我看到很多生成器手动复制dotfiles:
this.copy('_package.json', 'package.json')
this.copy('_gitignore', '.gitignore')
this.copy('_gitattributes', '.gitattributes')
Run Code Online (Sandbox Code Playgroud)
我认为在添加新模板文件时手动更改生成器代码很麻烦.我想自动复制/ templates文件夹中的所有文件,并重命名前缀为_的文件.
最好的方法是什么?
如果我在想象的正则表达式中描述我的意图,那就是它的样子:
this.copy(/^_(.*)/, '.$1')
ths.copy(/^[^_]/)
Run Code Online (Sandbox Code Playgroud)
编辑 这是我能管理的最好的:
this.expandFiles('**', { cwd: this.sourceRoot() }).map(function() {
this.copy file, file.replace(/^_/, '.')
}, this);
Run Code Online (Sandbox Code Playgroud)
cal*_*rae 31
我通过谷歌找到了这个问题,因为我正在寻找解决方案,然后我自己想出来了.
使用新fsAPI,您可以使用globs!
// Copy all non-dotfiles
this.fs.copy(
this.templatePath('static/**/*'),
this.destinationRoot()
);
// Copy all dotfiles
this.fs.copy(
this.templatePath('static/.*'),
this.destinationRoot()
);
Run Code Online (Sandbox Code Playgroud)
sth*_*hzg 22
添加到@callumacrae的回答是:你还可以定义dot: true在globOptions的copy().这样一个/**glob将包括 dotfiles.例:
this.fs.copy(
this.templatePath('files/**'),
this.destinationPath('client'),
{ globOptions: { dot: true } }
);
Run Code Online (Sandbox Code Playgroud)
可以在README中找到可用的Glob选项列表node-glob.
刚刚为我工作:globOptions需要在第四个参数:
this.fs.copyTpl(
this.templatePath('sometemplate/**/*'),
this.destinationPath(this.destinationRoot()),
null,
null,
{ globOptions: { dot: true } }
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6939 次 |
| 最近记录: |