11/* eslint-disable @typescript-eslint/no-require-imports */
22/* eslint-disable no-console */
33const { execSync, spawnSync } = require ( 'node:child_process' ) ;
4+ const fs = require ( 'node:fs' ) ;
5+ const path = require ( 'node:path' ) ;
46
57const TYPESCRIPT_VERSION = '5.6.3' ;
68
@@ -9,17 +11,20 @@ function isYarnAvailable() {
911 return ! ! (
1012 execSync ( 'yarn --version' , {
1113 stdio : [ 0 , 'pipe' , 'ignore' ] ,
14+ shell : true ,
1215 } ) . toString ( ) || ''
1316 ) . trim ( ) ;
1417 } catch {
1518 return null ;
1619 }
1720}
21+
1822function isNpmAvailable ( ) {
1923 try {
2024 return ! ! (
2125 execSync ( 'npm --version' , {
2226 stdio : [ 0 , 'pipe' , 'ignore' ] ,
27+ shell : true ,
2328 } ) . toString ( ) || ''
2429 ) . trim ( ) ;
2530 } catch {
@@ -33,7 +38,6 @@ module.exports = {
3338 let packageManager = null ;
3439 let addCmd = null ;
3540
36- // react-native cli prefer yarn so we follow the same logic
3741 if ( isYarnAvailable ( ) ) {
3842 packageManager = 'yarn' ;
3943 addCmd = 'add' ;
@@ -56,7 +60,7 @@ module.exports = {
5660 const installTypeScriptCmd = spawnSync (
5761 packageManager ,
5862 [ addCmd , '-D' , `typescript@${ TYPESCRIPT_VERSION } ` ] ,
59- { stdio : 'inherit' } ,
63+ { stdio : 'inherit' , shell : true } ,
6064 ) ;
6165 if ( installTypeScriptCmd . error ) {
6266 console . error ( installTypeScriptCmd . error ) ;
@@ -67,7 +71,7 @@ module.exports = {
6771 const transpileCmd = spawnSync (
6872 'npx' ,
6973 [ 'tsc' , '--project' , `plugins/compile-js/tsconfig.build.json` ] ,
70- { stdio : 'inherit' } ,
74+ { stdio : 'inherit' , shell : true } ,
7175 ) ;
7276 if ( transpileCmd . error ) {
7377 console . error ( transpileCmd . error ) ;
@@ -76,23 +80,25 @@ module.exports = {
7680
7781 try {
7882 console . log ( '🖼️ Copying assets...' ) ;
79- execSync ( 'cp -R src/theme/assets/images js/src/theme/assets/images' ) ;
80-
83+ fs . cpSync (
84+ path . join ( 'src' , 'theme' , 'assets' , 'images' ) ,
85+ path . join ( 'js' , 'src' , 'theme' , 'assets' , 'images' ) ,
86+ { recursive : true }
87+ ) ;
8188 console . log ( '♻️ Replacing source...' ) ;
82- execSync ( 'rm -rf src', { stdio : 'pipe' } ) ;
83- execSync ( 'cp -R js/ src ./ src', { stdio : 'pipe' } ) ;
84- execSync ( 'rm -rf js', { stdio : 'pipe' } ) ;
89+ fs . rmSync ( ' src', { recursive : true , force : true } ) ;
90+ fs . cpSync ( path . join ( 'js' , ' src' ) , ' src', { recursive : true } ) ;
91+ fs . rmSync ( ' js', { recursive : true , force : true } ) ;
8592 } catch {
8693 console . error (
87- '🚨 Failed to copy assets or replace source. If you are using windows, please use git bash. ' ,
94+ '🚨 Failed to copy assets or replace source.' ,
8895 ) ;
8996 process . exit ( 1 ) ;
9097 }
91-
9298 console . log ( '🌀 Removing types ...' ) ;
93- execSync ( 'rm -rf src/ theme/ types', { stdio : 'pipe' } ) ;
94- execSync ( 'rm -f src/ navigation/ paths.js', { stdio : 'pipe' } ) ;
95- execSync ( 'rm -f src/ navigation/ types.js', { stdio : 'pipe' } ) ;
99+ fs . rmSync ( path . join ( ' src' , ' theme' , ' types') , { recursive : true , force : true } ) ;
100+ fs . rmSync ( path . join ( ' src' , ' navigation' , ' paths.js') , { force : true } ) ;
101+ fs . rmSync ( path . join ( ' src' , ' navigation' , ' types.js') , { force : true } ) ;
96102 }
97103
98104 resolve ( ) ;
0 commit comments