@@ -8,10 +8,9 @@ export type TemplateVersions = {
88 nitro : string | undefined ;
99} ;
1010
11- export type ModuleConfig =
12- 'native-modules' | 'turbo-modules' | 'nitro-modules' | null ;
11+ export type ModuleConfig = 'turbo-modules' | 'nitro-modules' | null ;
1312
14- export type ViewConfig = 'paper-view' | ' fabric-view' | 'nitro-view' | null ;
13+ export type ViewConfig = 'fabric-view' | 'nitro-view' | null ;
1514
1615// Please think at least 5 times before introducing a new config key
1716// You can just reuse the existing ones most of the time
@@ -201,9 +200,10 @@ export function generateTemplateConfiguration({
201200 ? // If the project name is already in PascalCase, use it as-is
202201 basename
203202 : // Otherwise, convert it to PascalCase and remove any non-alphanumeric characters
204- `${ project . charAt ( 0 ) . toUpperCase ( ) } ${ project
205- . replace ( / [ ^ a - z 0 - 9 ] ( \w ) / g, ( _ , $1 : string ) => $1 . toUpperCase ( ) )
206- . slice ( 1 ) } `,
203+ project
204+ . split ( / [ ^ a - z 0 - 9 ] + / )
205+ . map ( ( part ) => `${ part . charAt ( 0 ) . toUpperCase ( ) } ${ part . slice ( 1 ) } ` )
206+ . join ( '' ) ,
207207 package : pack ,
208208 package_dir : pack . replace ( / \. / g, path . sep ) ,
209209 package_cpp : pack . replace ( / \. / g, '_' ) ,
@@ -277,104 +277,52 @@ export async function applyTemplates(
277277 }
278278 }
279279
280- if ( answers . languages === 'js' ) {
281- await applyTemplate ( config , JS_FILES , folder ) ;
282-
283- if ( config . example != null ) {
284- if ( config . example === 'expo' ) {
285- await applyTemplate ( config , EXAMPLE_EXPO_FILES , folder ) ;
286- } else {
287- await applyTemplate ( config , EXAMPLE_BARE_FILES , folder ) ;
288- }
280+ if ( config . example != null ) {
281+ if ( config . example === 'expo' ) {
282+ await applyTemplate ( config , EXAMPLE_EXPO_FILES , folder ) ;
283+ } else {
284+ await applyTemplate ( config , EXAMPLE_BARE_FILES , folder ) ;
289285 }
290- } else {
291- if ( answers . languages === 'cpp' ) {
292- if ( config . example === 'expo' ) {
293- await applyTemplate ( config , EXAMPLE_EXPO_FILES , folder ) ;
294-
295- if ( config . project . native ) {
296- await applyTemplate ( config , EXAMPLE_NATIVE_COMMON_FILES , folder ) ;
297- }
298- } else if ( config . example != null ) {
299- await applyTemplate ( config , EXAMPLE_BARE_FILES , folder ) ;
300-
301- if ( config . project . native ) {
302- await applyTemplate ( config , EXAMPLE_NATIVE_COMMON_FILES , folder ) ;
303- }
304- }
305286
306- await applyTemplate ( config , NATIVE_FILES [ 'module_new' ] , folder ) ;
307- await applyTemplate ( config , CPP_FILES , folder ) ;
308-
309- if ( config . example === 'expo' || config . tools . includes ( 'vite' ) ) {
310- await applyTemplate ( config , JS_FILES , folder ) ;
311- }
312-
313- return ;
287+ if ( config . project . native ) {
288+ await applyTemplate ( config , EXAMPLE_NATIVE_COMMON_FILES , folder ) ;
314289 }
290+ }
315291
316- await applyTemplate ( config , NATIVE_COMMON_FILES , folder ) ;
317-
318- if ( config . example === 'expo' ) {
319- await applyTemplate ( config , EXAMPLE_EXPO_FILES , folder ) ;
292+ if ( answers . languages === 'js' ) {
293+ await applyTemplate ( config , JS_FILES , folder ) ;
320294
321- if ( config . project . native ) {
322- await applyTemplate ( config , EXAMPLE_NATIVE_COMMON_FILES , folder ) ;
323- }
324- } else if ( config . example != null ) {
325- await applyTemplate ( config , EXAMPLE_BARE_FILES , folder ) ;
295+ return ;
296+ }
326297
327- if ( config . project . native ) {
328- await applyTemplate ( config , EXAMPLE_NATIVE_COMMON_FILES , folder ) ;
329- }
330- }
298+ if ( answers . languages === 'cpp' ) {
299+ await applyTemplate ( config , NATIVE_FILES [ 'module_new' ] , folder ) ;
300+ await applyTemplate ( config , CPP_FILES , folder ) ;
301+ } else {
302+ await applyTemplate ( config , NATIVE_COMMON_FILES , folder ) ;
331303
332304 if ( config . project . moduleConfig === 'nitro-modules' ) {
333305 await applyTemplate ( config , NITRO_COMMON_FILES , folder ) ;
334306 await applyTemplate ( config , NATIVE_FILES [ 'module_nitro' ] , folder ) ;
335-
336- if ( config . example === 'expo' || config . tools . includes ( 'vite' ) ) {
337- await applyTemplate ( config , JS_FILES , folder ) ;
338- }
339-
340- return ;
341- }
342-
343- if ( config . project . viewConfig === 'nitro-view' ) {
307+ } else if ( config . project . viewConfig === 'nitro-view' ) {
344308 await applyTemplate ( config , NITRO_COMMON_FILES , folder ) ;
345309 await applyTemplate ( config , NATIVE_FILES [ 'view_nitro' ] , folder ) ;
346-
347- if ( config . example === 'expo' || config . tools . includes ( 'vite' ) ) {
348- await applyTemplate ( config , JS_VIEW_FILES , folder ) ;
349- }
350-
351- return ;
352- }
353-
354- if ( config . project . moduleConfig !== null ) {
355- await applyTemplate ( config , NATIVE_FILES [ `module_new` ] , folder ) ;
310+ } else if ( config . project . moduleConfig !== null ) {
311+ await applyTemplate ( config , NATIVE_FILES [ 'module_new' ] , folder ) ;
312+ await applyTemplate ( config , OBJC_FILES [ 'module_common' ] , folder ) ;
313+ await applyTemplate ( config , KOTLIN_FILES [ 'module_new' ] , folder ) ;
356314 } else {
357- await applyTemplate ( config , NATIVE_FILES [ `view_new` ] , folder ) ;
315+ await applyTemplate ( config , NATIVE_FILES [ 'view_new' ] , folder ) ;
316+ await applyTemplate ( config , OBJC_FILES [ 'view_new' ] , folder ) ;
317+ await applyTemplate ( config , KOTLIN_FILES [ 'view_new' ] , folder ) ;
358318 }
319+ }
359320
360- if ( config . project . moduleConfig !== null ) {
361- await applyTemplate ( config , OBJC_FILES [ `module_common` ] , folder ) ;
321+ if ( config . example === 'expo' || config . tools . includes ( 'vite' ) ) {
322+ if ( config . project . viewConfig !== null ) {
323+ await applyTemplate ( config , JS_VIEW_FILES , folder ) ;
362324 } else {
363- await applyTemplate ( config , OBJC_FILES [ `view_new` ] , folder ) ;
364- }
365-
366- const templateType = `${
367- config . project . moduleConfig !== null ? 'module' : 'view'
368- } _new` as const ;
369-
370- await applyTemplate ( config , KOTLIN_FILES [ templateType ] , folder ) ;
371-
372- if ( config . example === 'expo' || config . tools . includes ( 'vite' ) ) {
373- if ( config . project . viewConfig !== null ) {
374- await applyTemplate ( config , JS_VIEW_FILES , folder ) ;
375- } else {
376- await applyTemplate ( config , JS_FILES , folder ) ;
377- }
325+ await applyTemplate ( config , JS_FILES , folder ) ;
378326 }
379327 }
380328}
0 commit comments