1- import { copyFileSync , renameSync , rmSync } from 'fs'
2- import { join } from 'path'
31import { execSync } from 'child_process'
2+ import { copyFileSync , cpSync , readFileSync , renameSync , rmSync } from 'fs'
3+ import { join , resolve } from 'path'
4+ import Arborist from '@npmcli/arborist'
5+ import packlist from 'npm-packlist'
46
57// This script enhances source files inside /app with a fresh React Native template.
68const appName = '<%= pascal %>App'
79const isBun = typeof Bun !== 'undefined'
810
911console . log ( '⌛ Initializing a fresh RN project...' )
1012
11- execSync ( `${ isBun ? 'bunx' : 'npx' } react-native init ${ appName } --skip-git-init true --install-pods true` , {
13+ execSync ( `${ isBun ? 'bunx' : 'npx' } @ react-native-community/cli init ${ appName } --skip-git-init true --install-pods true` , {
1214 // Write output to cnosole.
1315 stdio : 'inherit' ,
1416} )
@@ -24,17 +26,24 @@ execSync(`${isBun ? 'bun' : 'npm'} run build`, {
2426 stdio : 'inherit' ,
2527} )
2628
27- // Install this package locally, avoiding symlinks.
28- execSync ( 'npm install $(npm pack .. | tail -1)' , {
29- cwd : join ( process . cwd ( ) , 'app' ) ,
30- stdio : 'inherit' ,
31- } )
29+ const packageName = JSON . parse ( readFileSync ( './package.json' ) ) . name
30+ const packageDirectory = resolve ( `app/node_modules/${ packageName } ` )
31+
32+ // Package files and copy them to app node_modules.
33+ // Couldn't get symlinks to work with metro.
34+ const arborist = new Arborist ( { path : process . cwd ( ) } )
35+ const tree = await arborist . loadActual ( )
36+ const files = await packlist ( tree )
37+
38+ mkdirSync ( packageDirectory , { recursive : true } )
39+
40+ files . forEach ( ( file ) => cpSync ( join ( process . cwd ( ) , file ) , join ( packageDirectory , file ) , { recursive : true } ) )
3241
3342console . log ( '' )
3443console . log ( '🍞 React Native App created inside /app.' )
3544console . log ( '🛠️ To run the example with the plugin included:' )
3645console . log ( '🐚 cd app' )
37- console . log ( '🐚 npm run ios / npm run android' )
46+ console . log ( '🐚 npm run ios / npm run android | bun ios / bun android ' )
3847console . log ( '🌪️ To copy over the changes from the plugin source run:' )
39- console . log ( '🐚 npm run watch' )
48+ console . log ( '🐚 npm run watch | bun watch ' )
4049console . log ( '🛠️ This will copy changes over to the app.' )
0 commit comments