yeoman - 使用 yeoman 复制多个点文件的推荐方法是什么?

标签 yeoman yeoman-generator

我正在为一个相当典型的节点应用程序构建一个自耕农生成器:

/
|--package.json
|--.gitignore
|--.travis.yml
|--README.md
|--app/
    |--index.js
    |--models
    |--views
    |--controllers

在我的 yeoman 生成器的模板文件夹中,我必须重命名 dotfiles(和 package.json)以防止它们作为生成器的一部分被处理:
templates/
 |--_package.json
 |--_gitignore
 |--_travis.yml
 |--README.md
 |--app/
     |--index.js
     |--models
     |--views
     |--controllers

我看到很多生成器手动单独复制点文件:
this.copy('_package.json', 'package.json')
this.copy('_gitignore', '.gitignore')
this.copy('_gitattributes', '.gitattributes')

我认为在添加新模板文件时手动更改生成器代码很痛苦。我想自动复制/templates 文件夹中的所有文件,并重命名以 _ 为前缀的文件。

做到这一点的最佳方法是什么?

如果我用虚构的正则表达式来描述我的意图,它会是这样的:
this.copy(/^_(.*)/, '.$1')
ths.copy(/^[^_]/)

编辑
这是我能管理的最好的:
this.expandFiles('**', { cwd: this.sourceRoot() }).map(function() {
    this.copy file, file.replace(/^_/, '.')
}, this);

最佳答案

我在寻找解决方案时通过谷歌发现了这个问题,然后我自己弄清楚了。

使用新 fs API,你可以使用globs!

// Copy all non-dotfiles
this.fs.copy(
  this.templatePath('static/**/*'),
  this.destinationRoot()
);

// Copy all dotfiles
this.fs.copy(
  this.templatePath('static/.*'),
  this.destinationRoot()
);

关于yeoman - 使用 yeoman 复制多个点文件的推荐方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24844951/

相关文章:

javascript - 如何将 Yeoman 的输出的所有脚本、图像分组到自定义文件夹

node.js - Yeoman 的 angular-fullstack 有 jpegtran-bin 错误并且 3 次失败

javascript - 在 Angular-fullstack 上用 ui-router 替换 ng-router

javascript - 我如何告诉 Grunt 不要在构建任务中缩小或连接 js 文件?

node.js - 我正在用 Yeoman 克隆一个 repo,我的电脑需要什么配置?

angularjs - 如何将我的 AngularJS 静态站点上传到 Github Pages?

javascript - grunt-usemin 海报属性 html 视频标签的自定义模式

javascript - 如何在 Yeoman 生成器中正确执行条件提示

angularjs - 如何安装旧版本(恢复)的 Yeoman 生成器?