Search code examples
javascriptnode.jsyeomanyeoman-generator

Copy files with Yeoman generator doesn't work


I'm developing my own generator with 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. 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

method 1 just ran

method 2 just ran

? What is your app's name ? Kosheen

? Would you like to generate a demo section ? Yes

all dirs created

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

file exists? false

footer copied

gruntfile copied

package copied

main.css copied

all files copied

header template processed

running 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.

Folders are created previously with no issue. There's a .yo_rc.json file with {} in the root of the destination folder. The Yeoman version is 1.4.8, working on Windows 7.

Is copy() the proper way to do this or is no longer valid? How can I copy a simple file in this scenario?


Solution

  • 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')
    );