Skip to content

Commit 99888a7

Browse files
authored
Simplify repo setup and update (#258)
1 parent 9294989 commit 99888a7

File tree

6 files changed

+56
-28
lines changed

6 files changed

+56
-28
lines changed

Apps/Playground/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Apps/Playground/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"start": "react-native start",
1111
"test": "jest",
1212
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
13-
"postinstall": "node scripts/postinstall.js"
13+
"postinstall": "node scripts/tools.js postinstall",
14+
"iosCmake": "node scripts/tools.js iosCMake"
1415
},
1516
"dependencies": {
1617
"@babylonjs/core": "^5.0.0-alpha.30",
@@ -36,6 +37,7 @@
3637
"@typescript-eslint/eslint-plugin": "^2.27.0",
3738
"@typescript-eslint/parser": "^2.27.0",
3839
"babel-jest": "^26.6.3",
40+
"chalk": "^4.1.1",
3941
"eslint": "7.14.0",
4042
"jest": "^26.6.3",
4143
"metro-config": "^0.64.0",

Apps/Playground/scripts/postinstall.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

Apps/Playground/scripts/tools.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const os = require('os');
2+
const shelljs = require('shelljs');
3+
const chalk = require('chalk');
4+
5+
function iosCmake() {
6+
console.log(chalk.black.bgCyan('Running CMake for iOS...'));
7+
shelljs.exec('cmake -G Xcode -DCMAKE_TOOLCHAIN_FILE=../submodules/BabylonNative/Dependencies/ios-cmake/ios.toolchain.cmake -DPLATFORM=OS64COMBINED -DENABLE_ARC=0 -DENABLE_BITCODE=1 -DDEPLOYMENT_TARGET=12 -DENABLE_GLSLANG_BINARIES=OFF -DSPIRV_CROSS_CLI=OFF -DENABLE_PCH=OFF .', {cwd: 'node_modules/@babylonjs/react-native/ios'});
8+
}
9+
10+
function postInstall() {
11+
const version = shelljs.exec('npm --version', {silent: true});
12+
13+
if (!version.trim().match(/6\.\d+\.\d+/g)) {
14+
throw `Error: BabylonReactNative Playground development requires npm version 6.13.*, Your current npm version is ${version}. Run npm install -g [email protected] to update your npm version.`;
15+
}
16+
17+
console.log(chalk.black.bgCyan('Updating submodules...'));
18+
shelljs.exec('git submodule update --init --recursive', {cwd: '../../'});
19+
20+
if (os.platform() === 'darwin') {
21+
iosCmake();
22+
23+
console.log(chalk.black.bgCyan('Installing iOS pods...'));
24+
shelljs.exec('pod install', {cwd: 'ios'});
25+
}
26+
}
27+
28+
// First arg will be 'node', second arg will be 'tools.js'
29+
const [command] = process.argv.slice(2);
30+
31+
if (command === 'postinstall') {
32+
postInstall();
33+
} else if (command === 'iosCMake') {
34+
iosCmake();
35+
} else {
36+
console.error(chalk.black.bgRedBright(`Unkown command: ${command}`));
37+
process.exit(1);
38+
}

Modules/@babylonjs/react-native/ios/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++")
1111
set(NAPI_JAVASCRIPT_ENGINE "JSI" CACHE STRING "The JavaScript engine to power N-API")
1212

1313
get_filename_component(REACTNATIVE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../react-native" ABSOLUTE)
14+
if(NOT EXISTS ${REACTNATIVE_DIR})
15+
get_filename_component(REACTNATIVE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../Apps/Playground/node_modules/react-native" ABSOLUTE)
16+
endif()
17+
1418
# The CMake generator for XCode produces relative paths to source files. Additionally, when an XCode project
1519
# that lives in a sym linked directory is added to an XCode workspace, XCode resolves the actual path of the
1620
# XCode project. This combination results in incorrect relative paths, so just copy the jsi directory locally.

README.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,20 @@ Step 1 for all development environments and targets is to clone the repo. Use a
3535
git clone https://github.com/BabylonJS/BabylonReactNative
3636
```
3737

38-
Babylon React Native makes extensive use of submodules to supply its dependencies, so it's also necessary to set up the submodules.
39-
40-
```
41-
cd BabylonReactNative
42-
git submodule update --init --recursive
43-
```
44-
45-
The Playground sample/test app is a standard React Native app, and as such also makes extensive use of NPM packages to supply its dependencies, so it's also necessary to install these packages.
38+
The Playground sample/test app is a standard React Native app, and as such makes extensive use of NPM packages to supply its dependencies, so it's also necessary to install these packages.
4639

4740
```
4841
cd Apps/Playground
4942
npm install
5043
```
5144

52-
For iOS, CocoaPods are also used, and these must be installed.
45+
This will also automatically do the following to prepare your repo for development:
5346

54-
```
55-
cd Apps/Playground/ios
56-
pod install --repo-update
57-
```
47+
- Update git submodules to fetch Babylon Native and its dependencies
48+
- [MacOS only] Run CMake to generate the iOS XCode project for Babylon React Native
49+
- [MacOS only] Run `pod install` to install cocoa pod depdendencies
50+
51+
After merging upstream changes in the future, you will need to either run `npm install` again, or run individual commands for the above operations (e.g. `git submodule update --init --submodule` / `npm run iosCMake` / `pod install`).
5852

5953
### **Configuring a Mac Dev Environment**
6054

@@ -128,13 +122,9 @@ After having run the above commands, you can also open `Apps/Playground/android`
128122

129123
#### iOS
130124

131-
iOS can only be built on a Mac. Additionally, `CMake` must manually be run to generate the XCode project that the [Playground XCode workspace](Apps/Playground/ios/Playground.xcworkspace/contents.xcworkspacedata) includes.
125+
iOS can only be built on a Mac.
132126

133127
```
134-
pushd Apps/Playground/node_modules/@babylonjs/react-native/ios
135-
cmake -G Xcode -DCMAKE_TOOLCHAIN_FILE=../submodules/BabylonNative/Dependencies/ios-cmake/ios.toolchain.cmake -DPLATFORM=OS64COMBINED -DENABLE_ARC=0 -DENABLE_BITCODE=1 -DDEPLOYMENT_TARGET=12 -DENABLE_GLSLANG_BINARIES=OFF -DSPIRV_CROSS_CLI=OFF -DENABLE_PCH=OFF .
136-
popd
137-
138128
cd Apps/Playground
139129
npm run ios
140130
```

0 commit comments

Comments
 (0)