在 yeoman 生成器中复制目录时是否可以忽略文件?
Is it possible to ignore files when copying directories in a yeoman generator?
我正在尝试编写一个 yeoman 生成器,有时我需要将 github 存储库的 files/folders 复制到当前工作目录,例如:
this.remote('owner', 'repo', function (err, remote) {
remote.directory('.', '.');
});
但是我想忽略这个 repo 中的一些文件,是否可以这样做?我找到了 function responsible for this 但它似乎不是一个明确的方法,有一个 process
函数可以传递,但我不确定你是否可以 "cancel" a如果文件与特定模式匹配,则正在复制文件。
您应该依赖 this.fs
object 而不是旧的折旧文件方法。
this.fs
上的辅助方法支持 glob 模式,因此忽略某些文件变得微不足道。
您可以在此处了解有关 Yeoman 文件系统的更多信息:http://yeoman.io/authoring/file-system.html
来自 mem-fs-editor docs:
For a globified from, you can optionally pass in an
options.globOptions object to change its pattern matching behavior.
查看选项here:
示例:
this.fs.copy("<from path>/**", "<to path>",
{
globOptions: {
ignore: [
globs to ignore...
]
}
}
);
我正在尝试编写一个 yeoman 生成器,有时我需要将 github 存储库的 files/folders 复制到当前工作目录,例如:
this.remote('owner', 'repo', function (err, remote) {
remote.directory('.', '.');
});
但是我想忽略这个 repo 中的一些文件,是否可以这样做?我找到了 function responsible for this 但它似乎不是一个明确的方法,有一个 process
函数可以传递,但我不确定你是否可以 "cancel" a如果文件与特定模式匹配,则正在复制文件。
您应该依赖 this.fs
object 而不是旧的折旧文件方法。
this.fs
上的辅助方法支持 glob 模式,因此忽略某些文件变得微不足道。
您可以在此处了解有关 Yeoman 文件系统的更多信息:http://yeoman.io/authoring/file-system.html
来自 mem-fs-editor docs:
For a globified from, you can optionally pass in an options.globOptions object to change its pattern matching behavior.
查看选项here:
示例:
this.fs.copy("<from path>/**", "<to path>",
{
globOptions: {
ignore: [
globs to ignore...
]
}
}
);