Skip to content

Commit 3523d7f

Browse files
atljsatya164
andcommitted
feat: ask to use recommended template (#564)
This is an effort to implement a recommended template. See the [Golden Template RFC](react-native-community/discussions-and-proposals#721) for context. This adds a new parameter called `--with-recommended-options` and the corresponding question to the CLI. Here's how the CLI prompt looks like: ![Screenshot 2024-06-12 at 17 07 18](https://github.com/callstack/react-native-builder-bob/assets/23079646/9567f352-2e46-4073-a5b6-f30f1d97b49d) This also adds the text `(Recommended)` at the end of the recommended options (View + Module with backward compats and Kotlin + Obj-c at the moment). 1. Run `create-react-native-library` and answer the mail address, git repo, etc. questions. 2. Make sure the CLI asks `Do you want to customize the library type and languages?`. 3. Select `Use recommended defaults`. 4. Wait until the library is generated and make sure the library is a view + module, kotlin + objective-c library. 1. Run `create-react-native-library` and answer the mail address, git repo, etc. questions. 2. Make sure the CLI asks `Do you want to customize the library type and languages?`. 3. Select `Customize`. 4. Make sure the `Fabric view and Turbo module with backward compat` option has the `(Recommended)` text. 1. Run `create-react-native-library` with `--with-recommended-options` parameter. 2. Make sure the library doesn't ask you about library or type selection. 3. Make sure the generated library uses the golden template. 1. Run `create-react-native-library` with `--with-recommended-options` and `--type module-view-new`. 2. Make sure it emits an error. --------- Co-authored-by: Satyajit Sahoo <[email protected]>
1 parent b0ada7a commit 3523d7f

File tree

1 file changed

+64
-4
lines changed
  • packages/create-react-native-library/src

1 file changed

+64
-4
lines changed

packages/create-react-native-library/src/index.ts

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ type ArgName =
117117
| 'type'
118118
| 'local'
119119
| 'example'
120-
| 'react-native-version';
120+
| 'react-native-version'
121+
| 'with-recommended-options';
121122

122123
type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js';
123124

@@ -144,6 +145,7 @@ type Answers = {
144145
example?: ExampleType;
145146
reactNativeVersion?: string;
146147
local?: boolean;
148+
withRecommendedOptions?: boolean;
147149
};
148150

149151
const LANGUAGE_CHOICES: {
@@ -152,7 +154,7 @@ const LANGUAGE_CHOICES: {
152154
types: ProjectType[];
153155
}[] = [
154156
{
155-
title: 'Kotlin & Objective-C',
157+
title: `Kotlin & Objective-C`,
156158
value: 'kotlin-objc',
157159
types: ['view-module-legacy', 'view-module-mixed', 'view-module-new'],
158160
},
@@ -241,6 +243,16 @@ const TYPE_CHOICES: {
241243
},
242244
];
243245

246+
const RECOMMENDED_TEMPLATE: {
247+
type: ProjectType;
248+
languages: ProjectLanguages;
249+
description: string;
250+
} = {
251+
type: 'view-module-mixed',
252+
languages: 'kotlin-objc',
253+
description: `Backward compatible Fabric view & Turbo module with Kotlin & Objective-C`,
254+
};
255+
244256
const args: Record<ArgName, yargs.Options> = {
245257
'slug': {
246258
description: 'Name of the npm package',
@@ -287,6 +299,10 @@ const args: Record<ArgName, yargs.Options> = {
287299
type: 'string',
288300
choices: EXAMPLE_CHOICES.map(({ value }) => value),
289301
},
302+
'with-recommended-options': {
303+
description: `Whether to use the recommended template. ${RECOMMENDED_TEMPLATE.description}`,
304+
type: 'boolean',
305+
},
290306
};
291307

292308
// FIXME: fix the type
@@ -455,24 +471,68 @@ async function create(_argv: yargs.Arguments<any>) {
455471
},
456472
validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
457473
},
474+
{
475+
type: 'select',
476+
name: 'withRecommendedOptions',
477+
message: 'Do you want to customize the library type and languages?',
478+
choices: [
479+
{
480+
title: 'Use recommended defaults',
481+
value: true,
482+
description: RECOMMENDED_TEMPLATE.description,
483+
},
484+
{
485+
title: 'Customize',
486+
value: false,
487+
},
488+
],
489+
},
458490
{
459491
type: 'select',
460492
name: 'type',
461493
message: 'What type of library do you want to develop?',
462-
choices: TYPE_CHOICES,
494+
choices: (_, values) => {
495+
if (values.withRecommendedOptions) {
496+
return TYPE_CHOICES.filter(
497+
(choice) => choice.value === RECOMMENDED_TEMPLATE.type
498+
);
499+
}
500+
501+
return TYPE_CHOICES.map((choice) =>
502+
choice.value === RECOMMENDED_TEMPLATE.type
503+
? {
504+
...choice,
505+
title: `${choice.title} ${kleur.yellow('(Recommended)')}`,
506+
}
507+
: choice
508+
);
509+
},
463510
},
464511
{
465512
type: 'select',
466513
name: 'languages',
467514
message: 'Which languages do you want to use?',
468515
choices: (_, values) => {
516+
if (values.withRecommendedOptions) {
517+
return LANGUAGE_CHOICES.filter((choice) => {
518+
return choice.value === RECOMMENDED_TEMPLATE.languages;
519+
});
520+
}
521+
469522
return LANGUAGE_CHOICES.filter((choice) => {
470523
if (choice.types) {
471524
return choice.types.includes(values.type);
472525
}
473526

474527
return true;
475-
});
528+
}).map((choice) =>
529+
choice.value === RECOMMENDED_TEMPLATE.languages
530+
? {
531+
...choice,
532+
title: `${choice.title} ${kleur.yellow('(Recommended)')}`,
533+
}
534+
: choice
535+
);
476536
},
477537
},
478538
{

0 commit comments

Comments
 (0)