-
Notifications
You must be signed in to change notification settings - Fork 14
Update with main. #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Update with main. #166
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2efbb0b
Handle SPFx version numbers that contain hyphens. (#163)
iclanton 6a7cd4f
Update Rush. (#164)
iclanton de2cb5a
Remove unnecessary dependencies in templates. (#171)
iclanton 7978c76
Remove the unused eslintProfle property. (#169)
iclanton 49cbf08
Add --package-manager flag to spfx create command (#167)
nick-pape d10c04f
Add NPM-focused READMEs for published packages (#168)
nick-pape 5bae317
Prettify templates. (#170)
iclanton b1a9917
Include Node 24 in the test matrix. (#172)
iclanton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # @microsoft/spfx-template-api | ||
|
|
||
| > **Pre-release:** APIs may change before the stable 1.0 release. | ||
|
|
||
| Programmatic API for loading, rendering, and writing [SharePoint Framework (SPFx)](https://aka.ms/spfx) project templates. This is the engine that powers [`@microsoft/spfx-cli`](https://www.npmjs.com/package/@microsoft/spfx-cli). Use it directly when you need to integrate SPFx scaffolding into your own tooling. | ||
|
|
||
| ```bash | ||
| npm install @microsoft/spfx-template-api | ||
| ``` | ||
|
|
||
| **Requires Node.js `>=22.14.0 <23.0.0` or `>=24.12.0 <25.0.0`** | ||
|
|
||
| --- | ||
|
|
||
| ## Quick start | ||
|
|
||
| ```typescript | ||
| import { | ||
| SPFxTemplateRepositoryManager, | ||
| PublicGitHubRepositorySource, | ||
| SPFxTemplateWriter | ||
| } from '@microsoft/spfx-template-api'; | ||
|
|
||
| // 1. Load templates from GitHub | ||
| const manager = new SPFxTemplateRepositoryManager(); | ||
| manager.addSource(new PublicGitHubRepositorySource('https://github.com/SharePoint/spfx')); | ||
|
|
||
| const templates = await manager.getTemplatesAsync(); | ||
| const template = templates.get('webpart-react'); | ||
| if (!template) throw new Error('Template not found'); | ||
|
|
||
| // 2. Render to an in-memory file system | ||
| const fs = await template.renderAsync( | ||
| { | ||
| solution_name: 'my-solution', | ||
| libraryName: 'my-spfx-library', | ||
| spfxVersion: template.spfxVersion, | ||
| spfxVersionForBadgeUrl: template.spfxVersion.replace(/-/g, '--'), | ||
| componentId: '<uuid>', | ||
| featureId: '<uuid>', | ||
| solutionId: '<uuid>', | ||
| componentAlias: 'MyWebPart', | ||
| componentNameUnescaped: 'My Web Part', | ||
| componentNameCamelCase: 'myWebPart', | ||
| componentNameHyphenCase: 'my-web-part', | ||
| componentNameCapitalCase: 'MyWebPart', | ||
| componentNameAllCaps: 'MY_WEB_PART', | ||
| componentDescription: 'My Web Part description', | ||
| eslintProfile: 'react' | ||
| }, | ||
| '/path/to/output' | ||
| ); | ||
|
|
||
| // 3. Write files to disk (merges into existing SPFx solutions automatically) | ||
| const writer = new SPFxTemplateWriter(); | ||
| await writer.writeAsync(fs, '/path/to/output'); | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Template sources | ||
|
|
||
| ### `PublicGitHubRepositorySource` | ||
|
|
||
| Fetches templates from a public GitHub repository. Pin a specific SPFx version with an optional branch/tag ref. | ||
|
|
||
| ```typescript | ||
| import { PublicGitHubRepositorySource } from '@microsoft/spfx-template-api'; | ||
|
|
||
| // Latest (default branch) | ||
| new PublicGitHubRepositorySource('https://github.com/SharePoint/spfx'); | ||
|
|
||
| // Specific version | ||
| new PublicGitHubRepositorySource('https://github.com/SharePoint/spfx', '1.22'); | ||
| ``` | ||
|
|
||
| ### `LocalFileSystemRepositorySource` | ||
|
|
||
| Loads templates from a local directory — useful for offline workflows, CI environments, or authoring custom templates. | ||
|
|
||
| ```typescript | ||
| import { LocalFileSystemRepositorySource } from '@microsoft/spfx-template-api'; | ||
|
|
||
| new LocalFileSystemRepositorySource('./path/to/templates'); | ||
| ``` | ||
|
|
||
| ### Combining sources | ||
|
|
||
| `SPFxTemplateRepositoryManager` merges templates from all registered sources. Later sources can override templates from earlier ones. | ||
|
|
||
| ```typescript | ||
| import { | ||
| SPFxTemplateRepositoryManager, | ||
| PublicGitHubRepositorySource, | ||
| LocalFileSystemRepositorySource | ||
| } from '@microsoft/spfx-template-api'; | ||
|
|
||
| const manager = new SPFxTemplateRepositoryManager(); | ||
| manager.addSource(new PublicGitHubRepositorySource('https://github.com/SharePoint/spfx')); | ||
| manager.addSource(new LocalFileSystemRepositorySource('./my-custom-templates')); | ||
|
|
||
| const templates = await manager.getTemplatesAsync(); | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Writing to disk | ||
|
|
||
| `SPFxTemplateWriter` commits the in-memory `MemFsEditor` to the target directory. When scaffolding into an existing SPFx solution, it merges generated content into existing files rather than overwriting them. | ||
|
|
||
| ```typescript | ||
| const writer = new SPFxTemplateWriter(); | ||
| await writer.writeAsync(fs, targetDir); | ||
| ``` | ||
|
|
||
| ### Merge helpers | ||
|
|
||
| The writer uses these helpers internally. You can also import them directly for custom merge scenarios: | ||
|
|
||
| | Class | Merges | | ||
| |-------|--------| | ||
| | `JsonMergeHelper` | Abstract base for JSON/JSONC merge helpers (parse/serialize utilities) | | ||
| | `PackageJsonMergeHelper` | `package.json` (preserves existing scripts and dependencies) | | ||
| | `ConfigJsonMergeHelper` | SPFx `config/` files | | ||
| | `PackageSolutionJsonMergeHelper` | `config/package-solution.json` | | ||
| | `ServeJsonMergeHelper` | `config/serve.json` | | ||
|
|
||
| --- | ||
|
|
||
| ## API reference | ||
|
|
||
| | Export | Description | | ||
| |--------|-------------| | ||
| | `SPFxTemplateRepositoryManager` | Aggregates sources and returns a `SPFxTemplateCollection` | | ||
| | `SPFxTemplateCollection` | `Map<string, SPFxTemplate>` of all loaded templates | | ||
| | `SPFxTemplate` | Single template — exposes `name`, `spfxVersion`, and `renderAsync()` | | ||
| | `PublicGitHubRepositorySource` | Loads templates from a public GitHub repo | | ||
| | `LocalFileSystemRepositorySource` | Loads templates from the local filesystem | | ||
| | `BaseSPFxTemplateRepositorySource` | Base class for building custom template sources | | ||
| | `SPFxRepositorySource` | Interface implemented by all source types | | ||
| | `SPFxTemplateWriter` | Writes a rendered `MemFsEditor` to disk with merge support | | ||
| | `IMergeHelper` | Interface for implementing custom merge helpers | | ||
| | `ServeJsonMergeHelper` | Merges `config/serve.json` (also available standalone) | | ||
| | `ISPFxTemplateJson` | Shape of the `template.json` manifest | | ||
| | `SPFxTemplateDefinitionSchema` | Zod schema for validating a `template.json` | | ||
| | `SPFxTemplateJsonFile` | Typed wrapper around a parsed `template.json` file | | ||
| | `SPFxTemplateRepositorySourceTypes` | Union type of all built-in repository source types | | ||
| | `IRenderOptions` | Context object passed to `template.renderAsync()` | | ||
|
|
||
| --- | ||
|
|
||
| ## License | ||
|
|
||
| MIT © Microsoft Corporation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,140 @@ | ||
| # @microsoft/spfx-cli | ||
| # @microsoft/spfx-cli | ||
|
|
||
| > **Pre-release:** APIs and commands may change before the stable 1.0 release. | ||
|
|
||
| The official CLI for scaffolding [SharePoint Framework (SPFx)](https://aka.ms/spfx) projects. | ||
|
|
||
| ```bash | ||
| npm install -g @microsoft/spfx-cli | ||
| ``` | ||
|
|
||
| **Requires Node.js `>=22.14.0 <23.0.0` or `>=24.12.0 <25.0.0`** | ||
|
|
||
| --- | ||
|
|
||
| ## Quick start | ||
|
|
||
| ```bash | ||
| spfx create \ | ||
| --template webpart-react \ | ||
| --library-name my-spfx-library \ | ||
| --component-name "Hello World" | ||
| ``` | ||
|
|
||
| This downloads the `webpart-react` template from the [SharePoint/spfx](https://github.com/SharePoint/spfx) template repository and scaffolds a React-based web part into the current directory. | ||
|
|
||
| --- | ||
|
|
||
| ## `spfx create` | ||
|
|
||
| Scaffolds a new SPFx component. Templates are pulled from the [SharePoint/spfx](https://github.com/SharePoint/spfx) GitHub repository by default. | ||
|
|
||
| ### Required flags | ||
|
|
||
| | Flag | Description | | ||
| |------|-------------| | ||
| | `--template NAME` | Template to use (see [Templates](#templates) below) | | ||
| | `--library-name NAME` | npm library name for the component (e.g. `my-spfx-lib`) | | ||
| | `--component-name NAME` | Display name of the component (e.g. `"Hello World"`) | | ||
|
|
||
| ### Optional flags | ||
|
|
||
| | Flag | Default | Description | | ||
| |------|---------|-------------| | ||
| | `--target-dir PATH` | current directory | Directory to scaffold into | | ||
| | `--solution-name NAME` | kebab-cased component name | SharePoint solution name | | ||
| | `--component-alias ALIAS` | same as `--component-name` | Short identifier for the component | | ||
| | `--component-description TEXT` | `"<name> description"` | Component description string | | ||
| | `--spfx-version VERSION` | repo default branch | Branch/tag in the template repo to use (e.g. `1.22`, `1.23-rc.0`) | | ||
| | `--template-url URL` | `https://github.com/SharePoint/spfx` | Custom GitHub template repository | | ||
| | `--local-template PATH` | — | Path to a local template folder (repeatable; bypasses GitHub) | | ||
|
|
||
| ### Environment variables | ||
|
|
||
| | Variable | Description | | ||
| |----------|-------------| | ||
| | `SPFX_TEMPLATE_REPO_URL` | Equivalent to `--template-url` | | ||
| | `SPFX_CI_MODE=1` | Internal/testing-only: produces deterministic UUIDs for CI; not shown in `--help`; subject to change | | ||
|
|
||
| --- | ||
|
|
||
| ## Templates | ||
|
|
||
| Templates are fetched at runtime from the [SharePoint/spfx](https://github.com/SharePoint/spfx) GitHub repository. Use `--spfx-version` to target a specific release branch, or `--local-template` to use templates from disk. | ||
|
|
||
| ### Web Parts | ||
|
|
||
| | Name | Description | | ||
| |------|-------------| | ||
| | `webpart-minimal` | Bare-bones web part, no UI framework | | ||
| | `webpart-noframework` | Full web part scaffold, no UI framework | | ||
| | `webpart-react` | Web part with React and Fluent UI | | ||
|
|
||
| ### Extensions | ||
|
|
||
| | Name | Description | | ||
| |------|-------------| | ||
| | `extension-application-customizer` | Application Customizer | | ||
| | `extension-fieldcustomizer-minimal` | Field Customizer, no UI framework (minimal) | | ||
| | `extension-fieldcustomizer-noframework` | Field Customizer, no UI framework | | ||
| | `extension-fieldcustomizer-react` | Field Customizer with React | | ||
| | `extension-formcustomizer-noframework` | Form Customizer, no UI framework | | ||
| | `extension-formcustomizer-react` | Form Customizer with React | | ||
| | `extension-listviewcommandset` | List View Command Set | | ||
| | `extension-search-query-modifier` | Search Query Modifier | | ||
|
|
||
| ### Adaptive Card Extensions | ||
|
|
||
| | Name | Description | | ||
| |------|-------------| | ||
| | `ace-data-visualization` | Data Visualization card | | ||
| | `ace-generic-card` | Generic card | | ||
| | `ace-generic-image-card` | Generic image card | | ||
| | `ace-generic-primarytext-card` | Generic primary text card | | ||
| | `ace-search-card` | Search card | | ||
|
|
||
| ### Other | ||
|
|
||
| | Name | Description | | ||
| |------|-------------| | ||
| | `library` | Shared SPFx library component | | ||
|
|
||
| --- | ||
|
|
||
| ## More examples | ||
|
|
||
| Scaffold into a specific directory: | ||
|
|
||
| ```bash | ||
| spfx create \ | ||
| --template webpart-react \ | ||
| --library-name my-spfx-library \ | ||
| --component-name "My Dashboard" \ | ||
| --target-dir ./my-project | ||
| ``` | ||
|
|
||
| Target a specific SPFx version: | ||
|
|
||
| ```bash | ||
| spfx create \ | ||
| --template webpart-react \ | ||
| --library-name my-spfx-library \ | ||
| --component-name "My Web Part" \ | ||
| --spfx-version 1.22 | ||
| ``` | ||
|
|
||
| Use a local template (offline / custom templates): | ||
|
|
||
| ```bash | ||
| spfx create \ | ||
| --template webpart-minimal \ | ||
| --library-name my-spfx-library \ | ||
| --component-name "My Web Part" \ | ||
| --local-template ./path/to/templates | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## License | ||
|
|
||
| MIT © Microsoft Corporation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.