Skip to content

Commit

Permalink
[0.76] Introducing --list option to init-windows (#13991)
Browse files Browse the repository at this point in the history
* Introducing `--list` option to `init-windows` (#13986)

* Added --list option to init-windows

* Change files

* Remove unnecessary indentation

* Indicate the default template

* Change files

---------

Co-authored-by: Tatiana Kapos <[email protected]>
  • Loading branch information
danielayala94 and TatianaKapos authored Oct 18, 2024
1 parent 8bf9607 commit c147dcb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Introducing `--list` option to `init-windows` (#13986)",
"packageName": "@react-native-windows/cli",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,29 @@ export class InitWindows {
return name;
}

protected printTemplateList() {
if (this.templates.size === 0) {
console.log('\nNo templates found.\n');
return;
}

for (const [key, value] of this.templates.entries()) {
const defaultLabel = value.isDefault ? chalk.yellow('[Default] ') : '';
console.log(`\n${key} - ${value.name}\n ${defaultLabel}${value.description}`);
}
console.log(`\n`)
}

public async run(spinner: Ora) {
await this.loadTemplates();

spinner.info();

if (this.options.list) {
this.printTemplateList();
return;
}

this.options.template ??= this.getDefaultTemplateName();

spinner.info(`Using template '${this.options.template}'...`);
Expand Down Expand Up @@ -259,6 +277,7 @@ function optionSanitizer(key: keyof InitOptions, value: any): any {
case 'template':
case 'overwrite':
case 'telemetry':
case 'list':
return value === undefined ? false : value; // Return value
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface InitOptions {
namespace?: string;
overwrite?: boolean;
telemetry?: boolean;
list?: boolean;
}

export const initOptions: CommandOption[] = [
Expand Down Expand Up @@ -46,4 +47,9 @@ export const initOptions: CommandOption[] = [
description:
'Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',
},
{
name: '--list',
description:
'Shows a list with all available templates with their descriptions.',
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function validateOptionName(
case 'namespace':
case 'overwrite':
case 'telemetry':
case 'list':
return true;
}
throw new Error(
Expand Down

0 comments on commit c147dcb

Please sign in to comment.