Skip to content

Commit

Permalink
Introducing --list option to init-windows (#13986)
Browse files Browse the repository at this point in the history
* Added --list option to init-windows

* Change files

* Remove unnecessary indentation

* Indicate the default template
  • Loading branch information
danielayala94 authored Oct 17, 2024
1 parent 8a13861 commit 916e2de
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": "none",
"comment": "Added --list option to init-windows",
"packageName": "@react-native-windows/cli",
"email": "[email protected]",
"dependentChangeType": "none"
}
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 916e2de

Please sign in to comment.