1+ #!/usr/bin/env node
2+
3+ const { execSync } = require ( 'child_process' ) ;
4+ const path = require ( 'path' ) ;
5+ const fs = require ( 'fs' ) ;
6+
7+ /**
8+ * Recursively copy files and directories
9+ * @param {string } src - Source directory
10+ * @param {string } dest - Destination directory
11+ */
12+ function copyRecursive ( src , dest ) {
13+ if ( ! fs . existsSync ( src ) ) {
14+ throw new Error ( `Source directory ${ src } does not exist` ) ;
15+ }
16+
17+ // Create destination directory if it doesn't exist
18+ if ( ! fs . existsSync ( dest ) ) {
19+ fs . mkdirSync ( dest , { recursive : true } ) ;
20+ }
21+
22+ const entries = fs . readdirSync ( src , { withFileTypes : true } ) ;
23+
24+ for ( const entry of entries ) {
25+ const srcPath = path . join ( src , entry . name ) ;
26+ const destPath = path . join ( dest , entry . name ) ;
27+
28+ if ( entry . isDirectory ( ) ) {
29+ copyRecursive ( srcPath , destPath ) ;
30+ } else {
31+ fs . copyFileSync ( srcPath , destPath ) ;
32+ }
33+ }
34+ }
35+
36+ /**
37+ * Execute a command in a specific directory
38+ * @param {string } command - The command to execute
39+ * @param {string } workingDir - The working directory
40+ * @param {string } stepName - Name of the step for logging
41+ */
42+ function executeStep ( command , workingDir , stepName ) {
43+ console . log ( `\n🔄 ${ stepName } ` ) ;
44+ console . log ( `Working directory: ${ workingDir } ` ) ;
45+ console . log ( `Command: ${ command } ` ) ;
46+
47+ // Check if directory exists
48+ if ( ! fs . existsSync ( workingDir ) ) {
49+ console . error ( `❌ Error: Directory ${ workingDir } does not exist` ) ;
50+ process . exit ( 1 ) ;
51+ }
52+
53+ try {
54+ execSync ( command , {
55+ cwd : workingDir ,
56+ stdio : 'inherit' , // This will show the output in real-time
57+ encoding : 'utf8'
58+ } ) ;
59+ console . log ( `✅ ${ stepName } completed successfully` ) ;
60+ } catch ( error ) {
61+ console . error ( `❌ ${ stepName } failed with error:` ) ;
62+ console . error ( error . message ) ;
63+ process . exit ( 1 ) ;
64+ }
65+ }
66+
67+ async function main ( ) {
68+ console . log ( 'Setting up developer environment ...' ) ;
69+
70+ const rootDir = process . cwd ( ) ;
71+
72+ // Step 1: NPM Install (Binary Package)
73+ const packageDir = path . join ( rootDir , 'Package' ) ;
74+ executeStep ( 'npm install' , packageDir , 'NPM Install (Binary Package)' ) ;
75+
76+ // Step 2: Build BabylonNative source tree
77+ executeStep ( 'npx gulp buildBabylonNativeSourceTree' , packageDir , 'Build BabylonNative source tree' ) ;
78+
79+ // Step 3: NPM Install (Playground)
80+ const playgroundDir = path . join ( rootDir , 'Apps' , 'Playground' ) ;
81+ executeStep ( 'npm install' , playgroundDir , 'NPM Install (Playground)' ) ;
82+
83+ // Step 4: Install Module
84+ const moduleDir = path . join ( rootDir , 'Modules' , '@babylonjs' , 'react-native' ) ;
85+ executeStep ( 'npm install' , moduleDir , 'Install Module' ) ;
86+
87+ // Step 5: Build TypeScript and Copy Files
88+ console . log ( '\n🔄 Build Type script' ) ;
89+ console . log ( `Working directory: ${ packageDir } ` ) ;
90+ console . log ( 'Command: npx gulp buildTypeScript' ) ;
91+
92+ try {
93+ execSync ( 'npx gulp buildTypeScript' , {
94+ cwd : packageDir ,
95+ stdio : 'inherit' ,
96+ encoding : 'utf8'
97+ } ) ;
98+ console . log ( '✅ TypeScript build completed successfully' ) ;
99+ } catch ( error ) {
100+ console . error ( '❌ TypeScript build failed with error:' ) ;
101+ console . error ( error . message ) ;
102+ process . exit ( 1 ) ;
103+ }
104+
105+ // Copy files from Package/Assembled to Modules/@babylonjs /react-native
106+ console . log ( '\n📁 Copying files from Package/Assembled to Modules/@babylonjs/react-native' ) ;
107+ const sourceDir = path . join ( packageDir , 'Assembled' ) ;
108+ const targetDir = path . join ( rootDir , 'Modules' , '@babylonjs' , 'react-native' ) ;
109+
110+ try {
111+ copyRecursive ( sourceDir , targetDir ) ;
112+ console . log ( '✅ Files copied successfully' ) ;
113+ } catch ( error ) {
114+ console . error ( '❌ File copy failed with error:' ) ;
115+ console . error ( error . message ) ;
116+ process . exit ( 1 ) ;
117+ }
118+
119+ console . log ( '\n🎉 All steps completed successfully!' ) ;
120+ }
121+
122+ // Handle unhandled promise rejections
123+ process . on ( 'unhandledRejection' , ( reason , promise ) => {
124+ console . error ( 'Unhandled Rejection at:' , promise , 'reason:' , reason ) ;
125+ process . exit ( 1 ) ;
126+ } ) ;
127+
128+ // Handle uncaught exceptions
129+ process . on ( 'uncaughtException' , ( error ) => {
130+ console . error ( 'Uncaught Exception:' , error ) ;
131+ process . exit ( 1 ) ;
132+ } ) ;
133+
134+ // Run the main function
135+ main ( ) . catch ( ( error ) => {
136+ console . error ( 'Script failed:' , error ) ;
137+ process . exit ( 1 ) ;
138+ } ) ;
0 commit comments