简体   繁体   English

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

[英]Copy files with Yeoman generator doesn't work

I'm developing my own generator with Yeoman. 我正在与Yeoman开发自己的发电机。 When I try to copy some files, nothing happens. 当我尝试复制一些文件时,什么也没发生。 No error, the process continues until it reach the end, but no files are copied. 没错,该过程一直持续到结束,但是没有文件被复制。 The generator has a /templates dir with a bunch of html files, each file has a few html lines, at the moment quite simple stuff. 生成器有一个/ templates目录,其中包含一堆html文件,每个文件都有几行html行,此刻非常简单。 This is my copy method: 这是我的复制方法:

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');
},

this is the console output: 这是控制台输出:

$ yo trx $ yo trx

method 1 just ran 方法1刚运行

method 2 just ran 方法2刚运行

? What is your app's name ? 您的应用名称是什么? Kosheen Kosheen

? Would you like to generate a demo section ? 您要生成一个演示版块吗? Yes

all dirs created 创建的所有目录

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

file exists? 文件已存在? false

footer copied 页脚已复制

gruntfile copied gruntfile已复制

package copied 包复制

main.css copied main.css复制了

all files copied 复制所有文件

header template processed 标头模板已处理

running npm 运行npm

and that's it. 就是这样。 Never returns to system prompt. 从不返回系统提示。

Besides the fact that fs.existsSync returns false (the file exists: htdocs\\generator-trx\\generators\\app\\templates_footer.html ), if I try to copy a non-existent file I get the typical error. 除了fs.existsSync返回false的事实(文件存在:htdocs \\ generator-trx \\ generators \\ app \\ templates_footer.html)之外,如果我尝试复制不存在的文件,也会得到典型错误。

Folders are created previously with no issue. 先前创建的文件夹没有问题。 There's a .yo_rc.json file with {} in the root of the destination folder. 在目标文件夹的根目录中有一个带有{}的.yo_rc.json文件。 The Yeoman version is 1.4.8, working on Windows 7. Yeoman版本为1.4.8,可在Windows 7上使用。

Is copy() the proper way to do this or is no longer valid? copy()是执行此操作的正确方法还是不再有效? How can I copy a simple file in this scenario? 在这种情况下如何复制简单文件?

Beside the fact of I was using deprecated methods, the proper way to achive this task is as follow: 除了我使用过时的方法外,实现此任务的正确方法如下:

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

Not sure what your issue is, but you should read the Yeoman official documentation on how to handle files: http://yeoman.io/authoring/file-system.html 不确定您的问题是什么,但是您应该阅读有关如何处理文件的Yeoman官方文档:http: //yeoman.io/authoring/file-system.html

You're using old and deprecated methods. 您正在使用旧的和过时的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM