命令行界面-Yeoman Generator:CLI+File而不是Prompt



我一直在使用一些Yeoman生成器来提示用户输入。不过,我更喜欢将我的输入放在JSON文件中。我可以看到yo-rc.json是在之后生成的,但我想使用它(或类似的文件)作为Yeoman的输入。

使用JHipster的示例:

当前行为

$ 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

期望的行为

$ 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

听起来我应该能够利用Yeoman Storage API,但我个人还没有在这条路线上取得成功,也找不到任何类似的例子。

[编辑]下一步

接下来,我想根据(https://jhipster.github.io/managing_relationships.html)。我发现这是一个两步过程:

  1. 创建./.jhipster/MyEntity.json
  2. yo jhipster:entity MyEntity.json
  3. 利润
Jhipster已经做到了,请参阅我对您问题的评论。下面是jhipster读取.yo-rc.json的地方,如果你真的想要任何其他名称,也可以这样做,你只需要使用文件api读取该文件,但为了兼容性,我建议你将json命名为.yo-rc.json

来自app/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;

相关内容

最新更新