Skip to content

Replace contextSchema with parameters, add built-in context builder#131

Draft
nick-pape wants to merge 3 commits intoSharePoint:mainfrom
nick-pape:claude/template-parameter-refactor
Draft

Replace contextSchema with parameters, add built-in context builder#131
nick-pape wants to merge 3 commits intoSharePoint:mainfrom
nick-pape:claude/template-parameter-refactor

Conversation

@nick-pape
Copy link
Contributor

Description

Refactors the template parameter system to separate built-in context variables from custom template parameters:

  • New buildBuiltInContext() in API package — All ~15 derived template variables (name variants, UUIDs, etc.) are now computed in a shared function and automatically injected into every template. Templates no longer need to redeclare them in contextSchema.
  • contextSchemaparameters — Replaced with a new field for custom-only params, supporting required (default true) and default values. Zod validation rejects collisions with built-in names.
  • --param key=value CLI flag — Repeatable flag for passing custom template parameters, with early validation against the template's parameter definitions.
  • Removed lodash and uuid from CLI — String transforms implemented inline in the API package (~40 lines); UUIDs use Node's built-in crypto.randomUUID().
  • Cleaned up all 18 template.json files — Removed contextSchema entirely since all current templates only use built-in variables.

How was this tested?

  • rush build — all 21 projects compile (0 errors, 0 lint warnings)
  • cd api/spfx-template-api && heft test — 148 unit tests pass (including 19 new tests for buildBuiltInContext)
  • cd tests/spfx-template-test && heft test — all 18 E2E template scaffolding tests pass
  • Manual test: scaffolded test template with --param flag

Type of change

  • Bug fix
  • New feature / enhancement
  • Template change
  • Documentation / CI / governance

🤖 Generated with Claude Code

nick-pape and others added 3 commits March 7, 2026 00:55
…lder and --param CLI flag

Move all ~15 derived template variables (name variants, UUIDs, etc.) into a
shared buildBuiltInContext() function in the API package so they are always
injected automatically. Templates no longer need to redeclare them.

Replace contextSchema with a new parameters field for custom-only params that
supports required/default. Add --param key=value CLI flag for passing custom
parameters. Remove lodash and uuid dependencies from the CLI (string transforms
are now inline in the API; UUIDs use Node crypto.randomUUID).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eter-refactor

# Conflicts:
#	api/spfx-template-api/src/templating/test/SPFxTemplate.test.ts
#	common/config/rush/repo-state.json
#	templates/AGENTS.md
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant