【问题标题】:Yeoman Generator: CLI+File Instead of PromptYeoman 生成器:CLI+文件而不是提示
【发布时间】:2015-07-01 20:39:08
【问题描述】:

我一直在使用一些提示我输入用户输入的 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 已经这样做了,制作一个相同格式的 .yo-rc.file 并在该文件夹中运行 yo jhipster,它不会提示您回答。确保遵循 jhipster 的 yo-rc 格式

标签: command-line-interface yeoman yeoman-generator jhipster


【解决方案1】:

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;

【讨论】:

  • Deepu 上面的评论(在文件夹中创建 {{.yo-rc.json}};执行 {{yo jhipster}})有效。这个答案有很好的附加信息。 smh...我可以发誓我试过了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多