使用 Yeoman 生成器复制文件不起作用

Copy files with Yeoman generator doesn't work

我正在使用 Yeoman 开发我自己的生成器。当我尝试复制一些文件时,没有任何反应。没有错误,该过程一直持续到结束,但没有文件被复制。生成器有一个 /templates 目录,里面有一堆 html 文件,每个文件都有几行 html 行,目前非常简单。 这是我的复制方法:

copyMainFiles: function(){
    console.log('copyMainFiles dir:' + process.cwd() + '+++++');
    console.log('file exists? '+fs.existsSync('_footer.html') );
    this.copy("_footer.html",  "app/footer.html");
    console.log('footer copied');
    this.copy("_gruntfile.js", "Gruntfile.js");
    console.log('gruntfile copied');
    this.copy("_package.json", "package.json");
    console.log('package copied');
    this.copy("_main.css",     "app/css/main.css");
    console.log('main.css copied');

    var context = { 
        site_name: this.appName 
    };

    console.log('all files copied');
    //template method makes the replacement and then copy
    this.template("_header.html", "app/header.html", context);
    console.log('header template processed');
},

这是控制台输出:

$ 哟 trx

方法一就是运行

方法二只是运行

?您的应用程序名称是什么? 科欣

?你想生成一个演示部分吗?是

已创建所有目录

copyMainFiles dir:C:\cygwin\Applications\MAMP\htdocs\prueba-trx+++++

文件存在?假

已复制页脚

已复制 grunt 文件

包已复制

main.css 已复制

已复制所有文件

header 模板已处理

运行 npm

就是这样。从不 returns 系统提示。

除了 fs.existsSync returns false (文件存在: htdocs\generator-trx\generators\app\templates_footer.html )之外,如果我尝试复制 non-existent 文件我得到了典型的错误。

以前创建的文件夹没有问题。在目标文件夹的根目录中有一个带有 {} 的 .yo_rc.json 文件。 Yeoman 版本为 1.4.8,正在处理 Windows 7。

copy() 是执行此操作的正确方法还是不再有效?在这种情况下如何复制一个简单的文件?

不确定你的问题是什么,但你应该阅读有关如何处理文件的 Yeoman 官方文档:http://yeoman.io/authoring/file-system.html

您正在使用旧的和已弃用的方法。

除了我使用过时的方法之外,完成此任务的正确方法如下:

this.fs.copy(
  this.templatePath('_bower.json'),
  this.destinationPath('bower.json')
);