Skip to content

Commit 79fdbc1

Browse files
setup_dev script
1 parent ba41d11 commit 79fdbc1

File tree

5 files changed

+154
-57
lines changed

5 files changed

+154
-57
lines changed

.github/workflows/android.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@ jobs:
88
steps:
99
- name: Checkout Repo
1010
uses: actions/[email protected]
11-
- name: NPM Install (Binary Package)
12-
run: npm install
13-
working-directory: ./Package
14-
- name: Build BabylonNative source tree
15-
run: npx gulp buildBabylonNativeSourceTree
16-
working-directory: ./Package
17-
18-
- name: NPM Install (Playground)
19-
run: npm install
20-
working-directory: ./Apps/Playground
11+
- name: Setting up developer environment
12+
run: node setup_dev.js
13+
working-directory: ./
2114
# - name: Build Android Bundle
2215
# run: npm run build:android
2316
# working-directory: ./Apps/Playground

.github/workflows/ios.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@ jobs:
1010
- name: Checkout Repo
1111
uses: actions/[email protected]
1212

13-
- name: NPM Install (Binary Package)
14-
run: npm install
15-
working-directory: ./Package
16-
- name: Build BabylonNative source tree
17-
run: npx gulp buildBabylonNativeSourceTree
18-
working-directory: ./Package
19-
20-
- name: NPM Install (Playground)
21-
run: npm install
22-
working-directory: ./Apps/Playground
13+
- name: Setting up developer environment
14+
run: node setup_dev.js
15+
working-directory: ./
2316

2417
- name: Clean and Install Pods
2518
run: |

.github/workflows/typescript.yml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,13 @@ jobs:
88
steps:
99
- name: Checkout Repo
1010
uses: actions/[email protected]
11-
with:
12-
submodules: 'recursive'
13-
- name: Setup Node 18
14-
uses: actions/setup-node@v3
15-
with:
16-
node-version: 18
17-
- name: NPM Install (Binary Package)
18-
run: npm install
19-
working-directory: ./Package
20-
- name: NPM Install (Modules)
21-
run: |
22-
export BABYLON_NO_CMAKE_POSTINSTALL=1
23-
npm install
24-
working-directory: ./Modules/@babylonjs/react-native
25-
- name: NPM Install (Playground)
11+
12+
- name: Setting up developer environment
2613
run: |
2714
export BABYLON_NO_CMAKE_POSTINSTALL=1
28-
npm install
29-
working-directory: ./Apps/Playground
15+
node setup_dev.js
16+
working-directory: ./
17+
3018
- name: Gulp
3119
run: npx gulp buildAssembled
3220
working-directory: ./Package

.github/workflows/windows.yml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,16 @@ jobs:
1818
run: choco install watchman
1919
working-directory: ./Apps/Playground
2020

21-
- name: NPM Install (Binary Package)
22-
run: npm install
23-
working-directory: ./Package
24-
- name: Build BabylonNative source tree
25-
run: npx gulp buildBabylonNativeSourceTree
26-
working-directory: ./Package
2721

28-
- name: NPM Install (Playground)
22+
- name: Setting up developer environment
2923
run: |
30-
Copy-Item -Path "package-windows.json" -Destination "package.json" -Force
31-
Copy-Item -Path "package-lock-windows.json" -Destination "package-lock.json" -Force
32-
npm install
33-
working-directory: ./Apps/Playground
24+
Copy-Item -Path "Apps/Playground/package-windows.json" -Destination "Apps/Playground/package.json" -Force
25+
Copy-Item -Path "Apps/Playground/package-lock-windows.json" -Destination "Apps/Playground/package-lock.json" -Force
26+
node setup_dev.js
27+
working-directory: ./
3428

3529
# Windows development version need a bundle to be built
3630
# building bundle consists in running tsc in package, copy needed files in modules and running bundling command
37-
- name: Install Module
38-
run: npm install
39-
working-directory: ./Modules/@babylonjs/react-native
40-
41-
- name: Build Type script
42-
run: |
43-
npx gulp buildTypeScript
44-
Copy-Item -Path ../Package/Assembled/* -Destination ../Modules/@babylonjs/react-native -Recurse -Force
45-
working-directory: ./Package
4631

4732
# - name: Build Windows Bundle
4833
# run: npm run build:windows

setup_dev.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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

Comments
 (0)