Yeoman Generator: CLI + File instead of Request

I am using several Yeoman generators that prompt me for user input. I would rather put my inputs in a JSON file. I see what is created after this yo-rc.json

, but I would like to use it (or a file like it) as an input to Yeoman.

Example using JHipster :

Current behavior

$ yo jhipster

Welcome to the JHipster Generator v2.16.1
? (1/15) What is the base name of your application? (jhipster) helpme
? (2/15) What is your default Java package name? com.mycompany.helpme
...

# Yeoman Generator creates project via user inputs

      

Desired behavior

$ cat my-custom.json
{
  "generator-jhipster": {
    "baseName": "helpme",
    "packageName": "com.mycompany.helpme",
    ...

$ yo jhipster --file my-custom.json
...

# Yeoman Generator creates project via input file

      

It looks like I will be able to use the Yeoman Storage API , but I personally have not succeeded and I cannot find similar examples.

[Edit] Next steps

Next I wanted to create entities, unprompted, with complex per relationships ( https://jhipster.github.io/managing_relationships.html ). I found this a two step process:

  • Create a ./.jhipster/MyEntity.json

  • yo jhipster:entity MyEntity.json

  • Profit
+3


source to share


1 answer


Jhipster is already doing this to see my comment on your question. Below is where jhipster reads .yo-rc.json, if you really want any other name to be able to match as well, you just need to read that file using the api file, but I would suggest you save the json as .yo-rc .json for compatibility

Code from application /index.js



this.baseName = this.config.get('baseName');
   this.packageName = this.config.get('packageName');
   this.authenticationType =  this.config.get('authenticationType');
   this.clusteredHttpSession = this.config.get('clusteredHttpSession');
   this.searchEngine = this.config.get('searchEngine');
   this.websocket = this.config.get('websocket');
   this.databaseType = this.config.get('databaseType');
   if (this.databaseType == 'mongodb') {
       this.devDatabaseType = 'mongodb';
       this.prodDatabaseType = 'mongodb';
       this.hibernateCache = 'no';
   } else if (this.databaseType == 'cassandra') {
       this.devDatabaseType = 'cassandra';
       this.prodDatabaseType = 'cassandra';
       this.hibernateCache = 'no';
   } else { // sql
       this.devDatabaseType = this.config.get('devDatabaseType');
       this.prodDatabaseType = this.config.get('prodDatabaseType');
       this.hibernateCache = this.config.get('hibernateCache');
}
   this.useCompass = this.config.get('useCompass');
   this.javaVersion = this.config.get('javaVersion');
   this.buildTool = this.config.get('buildTool');
   this.frontendBuilder =   this.config.get('frontendBuilder');
   this.rememberMeKey = this.config.get('rememberMeKey');
   this.enableTranslation = this.config.get('enableTranslation'); // this is enabled by default to avoid conflicts for existing applications
   this.packagejs = packagejs;

      

+1


source







All Articles