Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions apps/spfx-cli/src/cli/actions/ListTemplatesAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class ListTemplatesAction extends SPFxActionBase {
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.'
'and any additional sources specified with --local-source or --remote-source. ' +
'Use --spfx-version to filter templates by version (e.g., "--spfx-version 1.22").'
Comment on lines 16 to +18
},
terminal
);
Expand All @@ -37,8 +38,26 @@ export class ListTemplatesAction extends SPFxActionBase {

const templates: SPFxTemplateCollection = await this._fetchTemplatesAsync(manager);

const formattedTable: string = await templates.toFormattedStringAsync();
terminal.writeLine(formattedTable);
// Apply --spfx-version filter if provided (user expects filter, not just branch selection)
const spfxVersion: string | undefined = this._spfxVersionParameter.value?.trim();
if (spfxVersion) {
const filteredTemplates = [...templates.values()].filter(
(t) => t.spfxVersion && t.spfxVersion.startsWith(spfxVersion)
);
Comment on lines +42 to +52
if (filteredTemplates.length === 0) {
terminal.writeLine(
`No templates found for SPFx version "${spfxVersion}". ` +
`Use "spfx list-templates" (without --spfx-version) to see all available versions.`
);
return;
Comment on lines +41 to +58
Comment on lines +41 to +58
}
const displayCollection: SPFxTemplateCollection = new SPFxTemplateCollection(filteredTemplates);
const formattedTable: string = await displayCollection.toFormattedStringAsync();
terminal.writeLine(formattedTable);
Comment on lines +47 to +62
} else {
const formattedTable: string = await templates.toFormattedStringAsync();
terminal.writeLine(formattedTable);
}
} catch (error: unknown) {
const message: string = error instanceof Error ? error.message : String(error);
terminal.writeErrorLine(`Error listing templates: ${message}`);
Expand Down