Skip to content

Commit 30df719

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 09e7a3a commit 30df719

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

+64-4
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ type ArgName =
118118
| 'type'
119119
| 'local'
120120
| 'example'
121-
| 'react-native-version';
121+
| 'react-native-version'
122+
| 'with-recommended-options';
122123

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

@@ -145,6 +146,7 @@ type Answers = {
145146
example?: ExampleType;
146147
reactNativeVersion?: string;
147148
local?: boolean;
149+
withRecommendedOptions?: boolean;
148150
};
149151

150152
const LANGUAGE_CHOICES: {
@@ -153,7 +155,7 @@ const LANGUAGE_CHOICES: {
153155
types: ProjectType[];
154156
}[] = [
155157
{
156-
title: 'Kotlin & Objective-C',
158+
title: `Kotlin & Objective-C`,
157159
value: 'kotlin-objc',
158160
types: ['view-module-legacy', 'view-module-mixed', 'view-module-new'],
159161
},
@@ -242,6 +244,16 @@ const TYPE_CHOICES: {
242244
},
243245
];
244246

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

293309
// FIXME: fix the type
@@ -463,24 +479,68 @@ async function create(_argv: yargs.Arguments<any>) {
463479
},
464480
validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
465481
},
482+
{
483+
type: 'select',
484+
name: 'withRecommendedOptions',
485+
message: 'Do you want to customize the library type and languages?',
486+
choices: [
487+
{
488+
title: 'Use recommended defaults',
489+
value: true,
490+
description: RECOMMENDED_TEMPLATE.description,
491+
},
492+
{
493+
title: 'Customize',
494+
value: false,
495+
},
496+
],
497+
},
466498
{
467499
type: 'select',
468500
name: 'type',
469501
message: 'What type of library do you want to develop?',
470-
choices: TYPE_CHOICES,
502+
choices: (_, values) => {
503+
if (values.withRecommendedOptions) {
504+
return TYPE_CHOICES.filter(
505+
(choice) => choice.value === RECOMMENDED_TEMPLATE.type
506+
);
507+
}
508+
509+
return TYPE_CHOICES.map((choice) =>
510+
choice.value === RECOMMENDED_TEMPLATE.type
511+
? {
512+
...choice,
513+
title: `${choice.title} ${kleur.yellow('(Recommended)')}`,
514+
}
515+
: choice
516+
);
517+
},
471518
},
472519
{
473520
type: 'select',
474521
name: 'languages',
475522
message: 'Which languages do you want to use?',
476523
choices: (_, values) => {
524+
if (values.withRecommendedOptions) {
525+
return LANGUAGE_CHOICES.filter((choice) => {
526+
return choice.value === RECOMMENDED_TEMPLATE.languages;
527+
});
528+
}
529+
477530
return LANGUAGE_CHOICES.filter((choice) => {
478531
if (choice.types) {
479532
return choice.types.includes(values.type);
480533
}
481534

482535
return true;
483-
});
536+
}).map((choice) =>
537+
choice.value === RECOMMENDED_TEMPLATE.languages
538+
? {
539+
...choice,
540+
title: `${choice.title} ${kleur.yellow('(Recommended)')}`,
541+
}
542+
: choice
543+
);
484544
},
485545
},
486546
];

0 commit comments

Comments
 (0)