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!