Search code examples
jsonyeomanyeoman-generator

Move yo-rc.json file to root folder


I'm creating a generator with yeoman and I have a small issue.

Basically my generator will be abble to create a module structure like that :

  • nameofmodule
    • classes
    • controllers
    • nameofmodule.php

When I execute my generator I'm in the parent folder of nameofmodule (nameofmodule folder is created by the generator).

Now I would like to save a yo-rc.json file to save some configurations (as the module name).

The issue is that I would like the yo-rc.json file to be in the nameofmodule folder and not in the folder where I've initiated the yeoman generator.

Do you know how I could change the yo-rc.json file path ? Or maybe create a new one in nameofmodule ?

Thanks a lot


Solution

  • I managed to change .yo-rc.json path by changing destination root path:

    this.destinationRoot(path.join(this.destinationRoot(), '/' + this.appDir));
    

    So after I created my app structure I called:

    this.on('end', function () {
      this.destinationRoot(path.join(this.destinationRoot(), '/' + this.appDir));
      this.config.set('appName', this.appName);
      this.config.set('appDir', this.appDir);
      this.config.set('modules', []);
    });
    

    Right now it works for me only with Base generator. I have no idea how to apply destination root across NamedBase generators.

    I hope this is helpful.