最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nrwl nx - How do I merge custom options with the Angular library generator schema in an Nx custom generator? - Stack Overflow

programmeradmin4浏览0评论

I'm developing an Nx plugin where I want to extend the built-in Angular library generator. My goal is to merge the original Angular library generator schema with my own custom options so that when the generator runs, the CLI prompts for both the original options and my additional ones.

Here's my current setup:

generators.json:

{
  "generators": {
    "init": {
      "factory": "./dist/generators/init/init",
      "schema": "./dist/generators/init/schema.json",
      "description": "init generator"
    }
  }
}

schema.json:

{
  "$schema": ";,
  "$id": "Domain",
  "title": "",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "",
      "$default": {
        "$source": "argv",
        "index": 0
      },
      "x-prompt": "What name would you like to use?"
    }
  },
  "required": ["name"]
}

I attempted to merge my schema with the original Angular library generator’s schema using JSON Schema composition with allOf:

{
  "allOf": [
    {
      "$ref": "./node_modules/@nrwl/angular/generators/library/schema.json"
    },
    {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "Your custom name",
          "$default": {
            "$source": "argv",
            "index": 0
          },
          "x-prompt": "What name would you like to use?"
        },
        "customOption": {
          "type": "string",
          "description": "A custom option for your extended generator",
          "x-prompt": "Provide your custom option"
        }
      },
      "required": ["name", "customOption"]
    }
  ]
}

However, when I run my generator, I’m not seeing the prompts for the original Angular library generator options—only my custom options show up.

My Question:
How can I correctly merge the original schema with my custom schema so that the generator prompts include both sets of options? Is there a different approach for extending an existing Nx generator’s schema?

Any suggestions or workarounds would be greatly appreciated!

发布评论

评论列表(0)

  1. 暂无评论