Summary
The dev design says the template manifest should include "CLI Parameters (defined with ts-command-line JSON syntax), enforced after calling the template." This would allow individual templates to declare their own custom required/optional parameters beyond the base set provided by the CLI.
Requirements
Schema addition
Add a parameters field to template.json that declares additional CLI flags using ts-command-line JSON definitions:
{
"name": "webpart-react",
"version": "1.0.0",
"spfxVersion": "1.22.2",
"parameters": [
{
"parameterName": "--use-fluent-ui",
"parameterType": "flag",
"description": "Include Fluent UI React dependencies"
},
{
"parameterName": "--react-version",
"parameterType": "choice",
"description": "React version to use",
"alternatives": ["17", "18"],
"defaultValue": "18"
}
]
}
Behavior
- Template-specific parameters are dynamically added to the
create command when a template is selected
- Parameters are validated after template selection
- Parameter values are merged into the template context and available in EJS templates
- In interactive mode, template-specific parameters are prompted for after template selection
- Unknown parameters for a given template produce a clear error
Design considerations
- This requires a two-pass approach: first parse
--template to load the manifest, then dynamically add template-specific flags
@rushstack/ts-command-line may need dynamic parameter registration or a two-phase parse
- Consider whether
contextSchema (existing) and parameters (new) should be unified or kept separate
contextSchema = what the template expects in its rendering context
parameters = what the CLI should collect from the user
- These are related but not identical (CLI may compute context variables from parameters)
Implementation notes
- Extend
ISPFxTemplateJson with optional parameters array
- Define parameter types matching ts-command-line:
flag, string, choice, stringList, choiceList, integer
- Parse
--template first, fetch the template manifest, then validate remaining flags against the manifest's parameter definitions
- Merge parameter values into the render context
Acceptance criteria
Summary
The dev design says the template manifest should include "CLI Parameters (defined with ts-command-line JSON syntax), enforced after calling the template." This would allow individual templates to declare their own custom required/optional parameters beyond the base set provided by the CLI.
Requirements
Schema addition
Add a
parametersfield totemplate.jsonthat declares additional CLI flags using ts-command-line JSON definitions:{ "name": "webpart-react", "version": "1.0.0", "spfxVersion": "1.22.2", "parameters": [ { "parameterName": "--use-fluent-ui", "parameterType": "flag", "description": "Include Fluent UI React dependencies" }, { "parameterName": "--react-version", "parameterType": "choice", "description": "React version to use", "alternatives": ["17", "18"], "defaultValue": "18" } ] }Behavior
createcommand when a template is selectedDesign considerations
--templateto load the manifest, then dynamically add template-specific flags@rushstack/ts-command-linemay need dynamic parameter registration or a two-phase parsecontextSchema(existing) andparameters(new) should be unified or kept separatecontextSchema= what the template expects in its rendering contextparameters= what the CLI should collect from the userImplementation notes
ISPFxTemplateJsonwith optionalparametersarrayflag,string,choice,stringList,choiceList,integer--templatefirst, fetch the template manifest, then validate remaining flags against the manifest's parameter definitionsAcceptance criteria
template.json