What's the recommended way to copy multiple dotfiles with yeoman?

I found this question through Google as I was looking for the solution, and then I figured it out myself.

Using the new fs API, you can use globs!

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

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

Adding to @callumacrae 's answer: you can also define dot: true in the globOptions of copy(). That way a /** glob will include dotfiles. Example:

this.fs.copy(
  this.templatePath('files/**'),
  this.destinationPath('client'),
  { globOptions: { dot: true } }
);

A list of available Glob options can be found in the README of node-glob.


Just got this working for me: the globOptions needs to be in the fifth argument:

this.fs.copyTpl(
  this.templatePath('sometemplate/**/*'),
  this.destinationPath(this.destinationRoot()),
  null,
  null,
  { globOptions: { dot: true } }
);