-
Notifications
You must be signed in to change notification settings - Fork 3
Implement spfx list-templates command #175
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
nick-pape
merged 9 commits into
SharePoint:main
from
nick-pape:nick-pape/list-templates
Mar 24, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a734614
Implement spfx list-templates command (closes #89)
nick-pape e9788bf
Address PR review comments
nick-pape 2aca086
Address second round of PR review comments
nick-pape 6229912
Use realistic template mock output in ListTemplatesAction snapshots
nick-pape c3fd092
Extract full parameter definitions to shared constants
nick-pape 277051b
Merge main: fold version/ branch prefix into addDefaultGitHubSource
nick-pape 6d10360
Refactor shared parameters into SPFxAction base class
nick-pape 32bfbe5
Rename SPFxAction to SPFxActionBase
nick-pape 70ee724
Rename SPFxAction.ts to SPFxActionBase.ts
nick-pape 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
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,90 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import type { CommandLineStringListParameter } from '@rushstack/ts-command-line'; | ||
| import type { Terminal } from '@rushstack/terminal'; | ||
| import { | ||
| LocalFileSystemRepositorySource, | ||
| PublicGitHubRepositorySource, | ||
| type SPFxTemplateCollection, | ||
| SPFxTemplateRepositoryManager | ||
| } from '@microsoft/spfx-template-api'; | ||
|
|
||
| import { parseGitHubUrlAndRef } from '../../utilities/github'; | ||
| import { SPFxActionBase } from './SPFxActionBase'; | ||
|
|
||
| export class ListTemplatesAction extends SPFxActionBase { | ||
| private readonly _localSourcesParameter: CommandLineStringListParameter; | ||
| private readonly _remoteSourcesParameter: CommandLineStringListParameter; | ||
|
|
||
| public constructor(terminal: Terminal) { | ||
| super( | ||
| { | ||
| actionName: 'list-templates', | ||
| summary: 'Lists available SPFx templates from configured sources', | ||
| documentation: | ||
| 'This command lists all available templates from the default GitHub source ' + | ||
| 'and any additional sources specified with --local-source or --remote-source.' | ||
| }, | ||
| terminal | ||
| ); | ||
|
|
||
| this._localSourcesParameter = this.defineStringListParameter({ | ||
| parameterLongName: '--local-source', | ||
| argumentName: 'PATH', | ||
| description: 'Path to a local template folder to include (repeatable)' | ||
| }); | ||
|
|
||
| this._remoteSourcesParameter = this.defineStringListParameter({ | ||
| parameterLongName: '--remote-source', | ||
| argumentName: 'URL', | ||
| description: 'Public GitHub repository URL to include as an additional template source (repeatable)' | ||
| }); | ||
| } | ||
|
|
||
| protected override async onExecuteAsync(): Promise<void> { | ||
| const terminal: Terminal = this._terminal; | ||
|
|
||
| try { | ||
| const manager: SPFxTemplateRepositoryManager = new SPFxTemplateRepositoryManager(); | ||
|
|
||
| // Additive model: default GitHub source is always added first | ||
| this._addGitHubTemplateSource(manager); | ||
|
|
||
| // Additive: also include any --local-source paths | ||
| for (const localPath of this._localSourcesParameter.values) { | ||
| terminal.writeLine(`Adding local template source: ${localPath}`); | ||
| manager.addSource(new LocalFileSystemRepositorySource(localPath)); | ||
| } | ||
|
|
||
| // Additive: also include any --remote-source URLs | ||
| for (const remoteUrl of this._remoteSourcesParameter.values) { | ||
| const { repoUrl: additionalRepoUrl, urlBranch: additionalUrlBranch } = | ||
| parseGitHubUrlAndRef(remoteUrl); | ||
| terminal.writeLine( | ||
| `Adding remote template source: ${additionalRepoUrl}` + | ||
| `${additionalUrlBranch ? ` (branch: ${additionalUrlBranch})` : ''}` | ||
| ); | ||
| manager.addSource(new PublicGitHubRepositorySource(additionalRepoUrl, additionalUrlBranch, terminal)); | ||
| } | ||
|
|
||
| let templates: SPFxTemplateCollection; | ||
| try { | ||
| templates = await manager.getTemplatesAsync(); | ||
| } catch (fetchError: unknown) { | ||
| const fetchMessage: string = fetchError instanceof Error ? fetchError.message : String(fetchError); | ||
| throw new Error( | ||
| `Failed to fetch templates. If you are offline or behind a firewall, ` + | ||
| `use ${this._localSourcesParameter.longName} to specify a local template source. Details: ${fetchMessage}`, | ||
| { cause: fetchError } | ||
| ); | ||
| } | ||
nick-pape marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
nick-pape marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| terminal.writeLine(templates.toString()); | ||
| } catch (error: unknown) { | ||
nick-pape marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const message: string = error instanceof Error ? error.message : String(error); | ||
| terminal.writeErrorLine(`Error listing templates: ${message}`); | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
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.