Skip to content
Merged
Changes from all commits
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
68 changes: 4 additions & 64 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ type ArgName =
| 'type'
| 'local'
| 'example'
| 'react-native-version'
| 'with-recommended-options';
| 'react-native-version';

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

Expand All @@ -141,7 +140,6 @@ type Answers = {
type?: ProjectType;
example?: boolean;
reactNativeVersion?: string;
withRecommendedOptions?: boolean;
};

const LANGUAGE_CHOICES: {
Expand All @@ -150,7 +148,7 @@ const LANGUAGE_CHOICES: {
types: ProjectType[];
}[] = [
{
title: `Kotlin & Objective-C`,
title: 'Kotlin & Objective-C',
value: 'kotlin-objc',
types: ['view-module-legacy', 'view-module-mixed', 'view-module-new'],
},
Expand Down Expand Up @@ -221,16 +219,6 @@ const TYPE_CHOICES: {
},
];

const RECOMMENDED_TEMPLATE: {
type: ProjectType;
languages: ProjectLanguages;
description: string;
} = {
type: 'view-module-mixed',
languages: 'kotlin-objc',
description: `Backward compatible Fabric view & Turbo module with Kotlin & Objective-C`,
};

const args: Record<ArgName, yargs.Options> = {
'slug': {
description: 'Name of the npm package',
Expand Down Expand Up @@ -277,10 +265,6 @@ const args: Record<ArgName, yargs.Options> = {
type: 'boolean',
default: true,
},
'with-recommended-options': {
description: `Whether to use the recommended template. ${RECOMMENDED_TEMPLATE.description}`,
type: 'boolean',
},
};

// FIXME: fix the type
Expand Down Expand Up @@ -448,68 +432,24 @@ async function create(argv: yargs.Arguments<any>) {
},
validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
},
'with-recommended-options': {
type: 'select',
name: 'withRecommendedOptions',
message: 'Do you want to customize the library type and languages?',
choices: [
{
title: 'Use recommended defaults',
value: true,
description: RECOMMENDED_TEMPLATE.description,
},
{
title: 'Customize',
value: false,
},
],
},
'type': {
type: 'select',
name: 'type',
message: 'What type of library do you want to develop?',
choices: (_, values) => {
if (values.withRecommendedOptions) {
return TYPE_CHOICES.filter(
(choice) => choice.value === RECOMMENDED_TEMPLATE.type
);
}

return TYPE_CHOICES.map((choice) =>
choice.value === RECOMMENDED_TEMPLATE.type
? {
...choice,
title: `${choice.title} ${kleur.yellow('(Recommended)')}`,
}
: choice
);
},
choices: TYPE_CHOICES,
},
'languages': {
type: 'select',
name: 'languages',
message: 'Which languages do you want to use?',
choices: (_, values) => {
if (values.withRecommendedOptions) {
return LANGUAGE_CHOICES.filter((choice) => {
return choice.value === RECOMMENDED_TEMPLATE.languages;
});
}

return LANGUAGE_CHOICES.filter((choice) => {
if (choice.types) {
return choice.types.includes(values.type);
}

return true;
}).map((choice) =>
choice.value === RECOMMENDED_TEMPLATE.languages
? {
...choice,
title: `${choice.title} ${kleur.yellow('(Recommended)')}`,
}
: choice
);
});
},
},
};
Expand Down