Skip to content

Commit 44ce26b

Browse files
committed
feat: handle view+module template on CLI
1 parent 1ba688a commit 44ce26b

File tree

1 file changed

+53
-25
lines changed
  • packages/create-react-native-library/src

1 file changed

+53
-25
lines changed

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

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const NATIVE_FILES = {
4444
view_legacy: path.resolve(__dirname, '../templates/native-view-legacy'),
4545
view_mixed: path.resolve(__dirname, '../templates/native-view-mixed'),
4646
view_new: path.resolve(__dirname, '../templates/native-view-new'),
47+
view_module_mixed: path.resolve(
48+
__dirname,
49+
'../templates/native-view-library-mixed'
50+
),
4751
} as const;
4852

4953
const JAVA_FILES = {
@@ -60,6 +64,10 @@ const OBJC_FILES = {
6064
view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'),
6165
view_mixed: path.resolve(__dirname, '../templates/objc-view-mixed'),
6266
view_new: path.resolve(__dirname, '../templates/objc-view-new'),
67+
view_module_mixed: path.resolve(
68+
__dirname,
69+
'../templates/objc-view-library-mixed'
70+
),
6371
} as const;
6472

6573
const KOTLIN_FILES = {
@@ -69,6 +77,10 @@ const KOTLIN_FILES = {
6977
view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'),
7078
view_mixed: path.resolve(__dirname, '../templates/kotlin-view-mixed'),
7179
view_new: path.resolve(__dirname, '../templates/kotlin-view-new'),
80+
view_module_mixed: path.resolve(
81+
__dirname,
82+
'../templates/kotlin-view-library-mixed'
83+
),
7284
} as const;
7385

7486
const SWIFT_FILES = {
@@ -104,7 +116,8 @@ type ProjectType =
104116
| 'view-mixed'
105117
| 'view-new'
106118
| 'view-legacy'
107-
| 'library';
119+
| 'library'
120+
| 'view-module-mixed';
108121

109122
type Answers = {
110123
slug: string;
@@ -134,6 +147,7 @@ const LANGUAGE_CHOICES: {
134147
'view-mixed',
135148
'view-new',
136149
'view-legacy',
150+
'view-module-mixed',
137151
],
138152
},
139153
{
@@ -178,6 +192,11 @@ const TYPE_CHOICES: {
178192
value: ProjectType;
179193
description: string;
180194
}[] = [
195+
{
196+
title: 'Fabric view and Turbo module with backward compat',
197+
value: 'view-module-mixed',
198+
description: NEWARCH_DESCRIPTION,
199+
},
181200
{
182201
title: 'JavaScript library',
183202
value: 'library',
@@ -210,7 +229,7 @@ const TYPE_CHOICES: {
210229
},
211230
{
212231
title: 'Fabric view',
213-
value: 'view-new',
232+
value: 'view-module-mixed',
214233
description: NEWARCH_DESCRIPTION,
215234
},
216235
];
@@ -561,11 +580,17 @@ async function create(argv: yargs.Arguments<any>) {
561580
version = FALLBACK_BOB_VERSION;
562581
}
563582

564-
const moduleType = type.startsWith('view-') ? 'view' : 'module';
583+
const moduleType = type.startsWith('view-module')
584+
? 'view_module'
585+
: type.startsWith('view')
586+
? 'view'
587+
: 'module';
565588
const arch =
566589
type === 'module-new' || type === 'view-new'
567590
? 'new'
568-
: type === 'module-mixed' || type === 'view-mixed'
591+
: type === 'module-mixed' ||
592+
type === 'view-mixed' ||
593+
type === 'view-module-mixed'
569594
? 'mixed'
570595
: 'legacy';
571596

@@ -612,8 +637,8 @@ async function create(argv: yargs.Arguments<any>) {
612637
cpp: languages === 'cpp',
613638
kotlin: languages === 'kotlin-objc' || languages === 'kotlin-swift',
614639
swift: languages === 'java-swift' || languages === 'kotlin-swift',
615-
view: moduleType === 'view',
616-
module: moduleType === 'module',
640+
view: moduleType === 'view' || moduleType === 'view_module',
641+
module: moduleType === 'module' || moduleType === 'view_module',
617642
},
618643
author: {
619644
name: authorName,
@@ -714,33 +739,36 @@ async function create(argv: yargs.Arguments<any>) {
714739
await copyDir(NATIVE_COMMON_EXAMPLE_FILES, folder);
715740
}
716741

717-
if (moduleType === 'module') {
718-
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
742+
if (moduleType === 'view_module') {
743+
// View module doesn't have legacy or a new arch only version.
744+
await copyDir(NATIVE_FILES['view_module_mixed'], folder);
745+
await copyDir(OBJC_FILES['view_module_mixed'], folder);
746+
await copyDir(KOTLIN_FILES['view_module_mixed'], folder);
719747
} else {
720748
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
721-
}
722749

723-
if (options.project.swift) {
724-
await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder);
725-
} else {
726-
if (moduleType === 'module') {
727-
await copyDir(OBJC_FILES[`${moduleType}_common`], folder);
750+
if (options.project.swift) {
751+
await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder);
728752
} else {
729-
await copyDir(OBJC_FILES[`view_${arch}`], folder);
753+
if (moduleType === 'module') {
754+
await copyDir(OBJC_FILES[`${moduleType}_common`], folder);
755+
} else {
756+
await copyDir(OBJC_FILES[`view_${arch}`], folder);
757+
}
730758
}
731-
}
732759

733-
const templateType = `${moduleType}_${arch}` as const;
760+
const templateType = `${moduleType}_${arch}` as const;
734761

735-
if (options.project.kotlin) {
736-
await copyDir(KOTLIN_FILES[templateType], folder);
737-
} else {
738-
await copyDir(JAVA_FILES[templateType], folder);
739-
}
762+
if (options.project.kotlin) {
763+
await copyDir(KOTLIN_FILES[templateType], folder);
764+
} else {
765+
await copyDir(JAVA_FILES[templateType], folder);
766+
}
740767

741-
if (options.project.cpp) {
742-
await copyDir(CPP_FILES, folder);
743-
await fs.remove(path.join(folder, 'ios', `${options.project.name}.m`));
768+
if (options.project.cpp) {
769+
await copyDir(CPP_FILES, folder);
770+
await fs.remove(path.join(folder, 'ios', `${options.project.name}.m`));
771+
}
744772
}
745773
}
746774

0 commit comments

Comments
 (0)