mem-fs-editor:如何复制相关的符号链接?

我有一个包含大量文件和一个(或多个) symlinkname -> . 符号链接。 我想将整个目录的内容复制到一个新的位置。 下面的代码复制一切正常,虽然它跳过了符号链接。 添加globOptions.follow = true只会使其无限循环,这是有道理的,因为它会尝试对其进行解引用。 我怎样才能使它复制所有的内容+符号链接,而不是试图跟随他们?

 this.fs.copy( this.destinationPath() + '/**', this.destinationPath('build/html'), { globOptions: { follow: true // This will make the copy loop infinitely, which makes sense. } } }); 

在发现Yeoman通过排除对符号链接的支持来避免糟糕的用户体验(见Simon Boudrias的评论)之后,我知道我必须解决这个问题。 我做了以下解决方法,请注意,这应该只适用于如果你不能像我一样避免符号链接。

 var fs = require('fs'); // Find out if there are symlinks var files = fs.readdirSync(this.destinationPath()); for (var i = 0; i < files.length; i++) { var path = this.destinationPath(files[i]), stats = fs.lstatSync(path); if (stats.isSymbolicLink()) { // Find the target of the symlink and make an identical link into the new location var link = fs.readlinkSync(path); fs.symlinkSync(link, this.destinationPath('build/html/' + files[i])); } }