Skip to content

Commit 7be7513

Browse files
Move Kotlin templates to separate directory
1 parent 733d2cc commit 7be7513

File tree

9 files changed

+50
-20
lines changed

9 files changed

+50
-20
lines changed

β€Žpackages/create-react-native-library/src/index.ts

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library');
1717
const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library');
1818
const EXAMPLE_FILES = path.resolve(__dirname, '../templates/example');
1919

20-
// Android
20+
// Common native library template files
2121
const NATIVE_FILES = (moduleType: ModuleType) => {
2222
switch (moduleType) {
2323
case 'module':
@@ -37,6 +37,16 @@ const OBJC_FILES = (moduleType: ModuleType) => {
3737
}
3838
};
3939

40+
// Kotlin
41+
const KOTLIN_FILES = (moduleType: ModuleType) => {
42+
switch (moduleType) {
43+
case 'module':
44+
return path.resolve(__dirname, '../templates/kotlin-library');
45+
case 'view':
46+
return path.resolve(__dirname, '../templates/kotlin-view-library');
47+
}
48+
};
49+
4050
// Swift
4151
const SWIFT_FILES = (moduleType: ModuleType) => {
4252
switch (moduleType) {
@@ -59,12 +69,12 @@ type ArgName =
5969
type ModuleType = 'module' | 'view';
6070

6171
type LibraryType =
62-
| 'native-view'
63-
| 'native-view-swift'
64-
| 'native'
65-
| 'native-swift'
66-
| 'js'
72+
| 'native-kotlin'
73+
| 'native-kotlin-swift'
74+
| 'native-view-kotlin'
75+
| 'native-view-kotlin-swift'
6776
| 'cpp'
77+
| 'js'
6878
| 'expo';
6979

7080
type Answers = {
@@ -104,7 +114,15 @@ const args: Record<ArgName, yargs.Options> = {
104114
},
105115
'type': {
106116
description: 'Type package do you want to develop',
107-
choices: ['native', 'native-swift', 'js', 'cpp', 'expo'],
117+
choices: [
118+
'native-kotlin',
119+
'native-kotlin-swift',
120+
'native-view-kotlin',
121+
'native-view-kotlin-swift',
122+
'cpp',
123+
'js',
124+
'expo',
125+
],
108126
},
109127
};
110128

@@ -218,17 +236,23 @@ async function create(argv: yargs.Arguments<any>) {
218236
name: 'type',
219237
message: 'What type of package do you want to develop?',
220238
choices: [
221-
{ title: 'Native module in Kotlin and Objective-C', value: 'native' },
222-
{ title: 'Native module in Kotlin and Swift', value: 'native-swift' },
223-
{ title: 'Native module with C++ code', value: 'cpp' },
239+
{
240+
title: 'Native module in Kotlin and Objective-C',
241+
value: 'native-kotlin',
242+
},
243+
{
244+
title: 'Native module in Kotlin and Swift',
245+
value: 'native-kotlin-swift',
246+
},
224247
{
225248
title: 'Native view in Kotlin and Objective-C',
226-
value: 'native-view',
249+
value: 'native-view-kotlin',
227250
},
228251
{
229252
title: 'Native view in Kotlin and Swift',
230-
value: 'native-view-swift',
253+
value: 'native-view-kotlin-swift',
231254
},
255+
{ title: 'Native module with C++ code', value: 'cpp' },
232256
{
233257
title: 'JavaScript library with native example',
234258
value: 'js',
@@ -265,7 +289,9 @@ async function create(argv: yargs.Arguments<any>) {
265289

266290
const project = slug.replace(/^(react-native-|@[^/]+\/)/, '');
267291
const moduleType: ModuleType =
268-
type === 'native-view' || type === 'native-view-swift' ? 'view' : 'module';
292+
type === 'native-view-kotlin' || type === 'native-view-kotlin-swift'
293+
? 'view'
294+
: 'module';
269295

270296
// Get latest version of Bob from NPM
271297
let version: string;
@@ -308,13 +334,13 @@ async function create(argv: yargs.Arguments<any>) {
308334
package: slug.replace(/[^a-z0-9]/g, '').toLowerCase(),
309335
podspec: slug.replace(/[^a-z0-9]+/g, '-').replace(/^-/, ''),
310336
native:
311-
type === 'native' ||
312337
type === 'cpp' ||
313-
'native-swift' ||
314-
'native-view' ||
315-
'native-view-swift',
338+
type === 'native-kotlin' ||
339+
type === 'native-kotlin-swift' ||
340+
type === 'native-view-kotlin' ||
341+
type === 'native-view-kotlin-swift',
316342
cpp: type === 'cpp',
317-
swift: type === 'native-swift' || 'native-view-swift',
343+
swift: type === 'native-kotlin-swift' || 'native-view-kotlin-swift',
318344
module: type !== 'js',
319345
moduleType,
320346
},
@@ -374,11 +400,15 @@ async function create(argv: yargs.Arguments<any>) {
374400

375401
await copyDir(NATIVE_FILES(moduleType), folder);
376402

377-
if (type === 'cpp') {
403+
if (options.project.cpp) {
378404
await copyDir(CPP_FILES, folder);
379-
} else if (type === 'native-swift') {
405+
}
406+
407+
if (options.project.swift) {
408+
await copyDir(KOTLIN_FILES(moduleType), folder);
380409
await copyDir(SWIFT_FILES(moduleType), folder);
381410
} else {
411+
await copyDir(KOTLIN_FILES(moduleType), folder);
382412
await copyDir(OBJC_FILES(moduleType), folder);
383413
}
384414
}

0 commit comments

Comments
Β (0)