Skip to content

Add component category field to template manifest#184

Merged
nick-pape merged 5 commits intoSharePoint:mainfrom
nick-pape:nick-pape/add-template-category
Mar 25, 2026
Merged

Add component category field to template manifest#184
nick-pape merged 5 commits intoSharePoint:mainfrom
nick-pape:nick-pape/add-template-category

Conversation

@nick-pape
Copy link
Contributor

Description

Adds a required category field to the template.json manifest schema, enabling templates to be grouped and filtered by component type. This implements issue #97.

Categories: webpart, extension, ace, library

Changes:

  • Added SPFX_TEMPLATE_CATEGORIES const array and SPFxTemplateCategory type
  • Added category to ISPFxTemplateJson interface and SPFxTemplateDefinitionSchema (Zod enum, required)
  • Added category getter to SPFxTemplateJsonFile and SPFxTemplate
  • Updated SPFxTemplate.toString() to include the category line
  • Exported new symbols from the public API barrel
  • Updated all 17 template.json files with appropriate category values
  • Updated API reference in README

How was this tested

  • rush build — all 22 projects build cleanly with no warnings
  • rushx build in api/spfx-template-api — all 220 unit tests pass (including new category getter tests, schema validation tests for valid/invalid/missing categories)
  • rushx build in apps/spfx-cli — all 46 CLI tests pass
  • Template integration tests (tests/spfx-template-test) — all 19 tests pass with updated snapshots

Type of change

  • New feature (non-breaking change that adds functionality)

Closes #97

🤖 Generated with Claude Code

Add a required `category` field to template.json with allowed values:
webpart, extension, ace, library. This enables grouping and filtering
templates by component type for the future list-templates command.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 24, 2026 19:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a required category field to SPFx template.json manifests and surfaces it through the @microsoft/spfx-template-api object model, enabling templates to be grouped/filtered by component type.

Changes:

  • Introduces SPFX_TEMPLATE_CATEGORIES + SPFxTemplateCategory, and makes category required in ISPFxTemplateJson + Zod schema validation.
  • Exposes category on SPFxTemplateJsonFile and SPFxTemplate and includes it in SPFxTemplate.toString() output.
  • Updates all template manifests and refreshes unit/integration test snapshots and API docs/README.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/spfx-template-test/test-template/template.json Adds category to the test template manifest.
tests/spfx-template-test/src/tests/snapshots/templates.test.ts.snap Updates snapshots to include the new “Category” line in template output.
tests/spfx-template-test/src/tests/snapshots/multi-component.test.ts.snap Updates multi-component snapshots to include the new “Category” line.
templates/ace-data-visualization/template.json Adds category: "ace" to the template manifest.
templates/ace-generic-card/template.json Adds category: "ace" to the template manifest.
templates/ace-generic-image-card/template.json Adds category: "ace" to the template manifest.
templates/ace-generic-primarytext-card/template.json Adds category: "ace" to the template manifest.
templates/ace-search-card/template.json Adds category: "ace" to the template manifest.
templates/extension-application-customizer/template.json Adds category: "extension" to the template manifest.
templates/extension-fieldcustomizer-minimal/template.json Adds category: "extension" to the template manifest.
templates/extension-fieldcustomizer-noframework/template.json Adds category: "extension" to the template manifest.
templates/extension-fieldcustomizer-react/template.json Adds category: "extension" to the template manifest.
templates/extension-formcustomizer-noframework/template.json Adds category: "extension" to the template manifest.
templates/extension-formcustomizer-react/template.json Adds category: "extension" to the template manifest.
templates/extension-listviewcommandset/template.json Adds category: "extension" to the template manifest.
templates/extension-search-query-modifier/template.json Adds category: "extension" to the template manifest.
templates/library/template.json Adds category: "library" to the template manifest.
templates/webpart-minimal/template.json Adds category: "webpart" to the template manifest.
templates/webpart-noframework/template.json Adds category: "webpart" to the template manifest.
templates/webpart-react/template.json Adds category: "webpart" to the template manifest.
common/changes/@microsoft/spfx-cli/add-template-category_2026-03-24.json Adds a Rush change file for the PR.
api/spfx-template-api/src/templating/test/SPFxTemplateJsonFile.test.ts Updates tests for required category + adds schema/category test coverage.
api/spfx-template-api/src/templating/test/SPFxTemplate.test.ts Updates template tests to require/expose category and validates toString() output.
api/spfx-template-api/src/templating/index.ts Re-exports new public category symbols from the templating barrel.
api/spfx-template-api/src/templating/SPFxTemplateJsonFile.ts Defines category constants/types; makes category required and validates via Zod enum; adds getter.
api/spfx-template-api/src/templating/SPFxTemplate.ts Adds category getter and includes it in toString().
api/spfx-template-api/src/repositories/test/SPFxTemplateRepositoryManager.test.ts Updates repository manager tests to include required category.
api/spfx-template-api/src/repositories/test/SPFxTemplateCollection.test.ts Updates template collection tests to include required category.
api/spfx-template-api/src/index.ts Exports new category symbols from the public API entrypoint.
api/spfx-template-api/etc/spfx-template-api.api.md Updates API Extractor output to include new category API surface.
api/spfx-template-api/README.md Updates the API reference table to document category and category-related exports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 24, 2026 19:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 31 out of 31 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

iclanton
iclanton previously approved these changes Mar 24, 2026
nick-pape and others added 2 commits March 25, 2026 10:21
…t in test

- Remove unnecessary \| escaping inside backtick code spans in README table
- Use SPFX_TEMPLATE_CATEGORIES constant in category validation test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nick-pape
Copy link
Contributor Author

Manual Test Results

Ran a manual test pass against the built artifacts on this branch. All tests pass.

Schema Validation

  • PASSSPFX_TEMPLATE_CATEGORIES exports correctly as ['webpart', 'extension', 'ace', 'library']
  • PASS — All 4 valid category values accepted by SPFxTemplateDefinitionSchema
  • PASS — Invalid category ('widget') rejected by schema
  • PASS — Missing category field rejected by schema

Property Getters

  • PASSSPFxTemplateJsonFile.category returns correct value
  • PASSSPFxTemplate.category delegates correctly to definition

toString() Output

  • PASSSPFxTemplate.toString() includes Category: line between Name and Description
  • PASSSPFxTemplateCollection.toString() includes Category for all 17 templates
  • PASS — All 4 category values appear in collection output

Public API Exports

  • PASSSPFX_TEMPLATE_CATEGORIES exported from package index
  • PASSSPFxTemplate prototype has category getter
  • PASSSPFxTemplateJsonFile prototype has category getter

Template Loading (all 17 templates from disk)

  • PASS — 3 webpart templates → category: 'webpart'
  • PASS — 8 extension templates → category: 'extension'
  • PASS — 5 ace templates → category: 'ace'
  • PASS — 1 library template → category: 'library'

End-to-End Rendering

  • PASSSPFxTemplate.fromFolderAsync() loads template with category, renders 23 files
  • PASSSPFxTemplate.fromMemoryAsync() works with category field
  • PASSfromMemoryAsync rejects missing category
  • PASSfromMemoryAsync rejects invalid category

Note on CLI

The spfx list-templates CLI command currently always includes the default GitHub remote source. Since this PR hasn't been merged yet, the remote templates on main don't have the category field and fail validation — this is expected and will resolve once the PR is merged.

@nick-pape nick-pape merged commit c68c88e into SharePoint:main Mar 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add component category field to template manifest

3 participants