@preeternal/react-native-godot 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +22 -0
  2. package/Package.swift +106 -0
  3. package/README.md +631 -2
  4. package/android/build.gradle +289 -0
  5. package/android/consumer-rules.pro +19 -0
  6. package/android/fix-prefab.gradle +54 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/CMakeLists.txt +74 -0
  9. package/android/src/main/cpp/GodotModule.cpp +718 -0
  10. package/android/src/main/cpp/OnLoad.cpp +66 -0
  11. package/android/src/main/cpp/libgodot_android.h +79 -0
  12. package/android/src/main/cpp/libgodot_jni.cpp +585 -0
  13. package/android/src/main/cpp/libgodot_jni.h +130 -0
  14. package/android/src/main/cpp/native_godot_module_jni.cpp +86 -0
  15. package/android/src/main/cpp/native_godot_module_jni.h +58 -0
  16. package/android/src/main/java/com/preeternal/reactnativegodot/NativeGodotModuleModule.kt +83 -0
  17. package/android/src/main/java/com/preeternal/reactnativegodot/NativeGodotModulePackage.kt +41 -0
  18. package/android/src/main/java/com/preeternal/reactnativegodot/NativeLibraryLoader.kt +5 -0
  19. package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotView.kt +81 -0
  20. package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotViewManager.kt +34 -0
  21. package/android/src/main/java/com/preeternal/reactnativegodot/RTNLibGodot.kt +350 -0
  22. package/android/src/main/res/layout/downloading_expansion.xml +165 -0
  23. package/android/src/main/res/layout/godot_app_layout.xml +5 -0
  24. package/android/src/main/res/layout/snackbar.xml +27 -0
  25. package/android/src/main/res/layout/status_bar_ongoing_event_progress_bar.xml +108 -0
  26. package/android/src/main/res/mipmap/icon.png +0 -0
  27. package/android/src/main/res/mipmap/icon_background.png +0 -0
  28. package/android/src/main/res/mipmap/icon_foreground.png +0 -0
  29. package/android/src/main/res/mipmap/icon_monochrome.png +0 -0
  30. package/android/src/main/res/mipmap-anydpi-v26/icon.xml +8 -0
  31. package/android/src/main/res/mipmap-anydpi-v26/themed_icon.xml +11 -0
  32. package/android/src/main/res/mipmap-hdpi/icon.png +0 -0
  33. package/android/src/main/res/mipmap-hdpi/icon_background.png +0 -0
  34. package/android/src/main/res/mipmap-hdpi/icon_foreground.png +0 -0
  35. package/android/src/main/res/mipmap-hdpi/icon_monochrome.png +0 -0
  36. package/android/src/main/res/mipmap-mdpi/icon.png +0 -0
  37. package/android/src/main/res/mipmap-mdpi/icon_background.png +0 -0
  38. package/android/src/main/res/mipmap-mdpi/icon_foreground.png +0 -0
  39. package/android/src/main/res/mipmap-mdpi/icon_monochrome.png +0 -0
  40. package/android/src/main/res/mipmap-xhdpi/icon.png +0 -0
  41. package/android/src/main/res/mipmap-xhdpi/icon_background.png +0 -0
  42. package/android/src/main/res/mipmap-xhdpi/icon_foreground.png +0 -0
  43. package/android/src/main/res/mipmap-xhdpi/icon_monochrome.png +0 -0
  44. package/android/src/main/res/mipmap-xxhdpi/icon.png +0 -0
  45. package/android/src/main/res/mipmap-xxhdpi/icon_background.png +0 -0
  46. package/android/src/main/res/mipmap-xxhdpi/icon_foreground.png +0 -0
  47. package/android/src/main/res/mipmap-xxhdpi/icon_monochrome.png +0 -0
  48. package/android/src/main/res/mipmap-xxxhdpi/icon.png +0 -0
  49. package/android/src/main/res/mipmap-xxxhdpi/icon_background.png +0 -0
  50. package/android/src/main/res/mipmap-xxxhdpi/icon_foreground.png +0 -0
  51. package/android/src/main/res/mipmap-xxxhdpi/icon_monochrome.png +0 -0
  52. package/android/src/main/res/values/dimens.xml +9 -0
  53. package/android/src/main/res/values/strings.xml +61 -0
  54. package/android/src/main/res/values/styles.xml +25 -0
  55. package/android/src/main/res/values-fa/strings.xml +14 -0
  56. package/android/src/main/res/values-ko/strings.xml +54 -0
  57. package/android/src/main/res/xml/godot_provider_paths.xml +15 -0
  58. package/android/src/test/java/com/preeternal/reactnativegodot/NativeGodotModulePackageTest.kt +26 -0
  59. package/app.plugin.js +173 -0
  60. package/cpp/GodotModule.h +103 -0
  61. package/cpp/NativeGodotModule.cpp +825 -0
  62. package/cpp/NativeGodotModule.h +45 -0
  63. package/cpp/godot-log.h +64 -0
  64. package/ios/GodotModule.mm +661 -0
  65. package/ios/NativeGodotModuleProvider.h +35 -0
  66. package/ios/NativeGodotModuleProvider.mm +42 -0
  67. package/ios/RTNGodotView.h +42 -0
  68. package/ios/RTNGodotView.mm +711 -0
  69. package/ios/log.mm +38 -0
  70. package/lib/module/NativeNativeGodotModule.js +59 -0
  71. package/lib/module/NativeNativeGodotModule.js.map +1 -0
  72. package/lib/module/RTNGodotView.js +6 -0
  73. package/lib/module/RTNGodotView.js.map +1 -0
  74. package/lib/module/RTNGodotView.native.js +5 -0
  75. package/lib/module/RTNGodotView.native.js.map +1 -0
  76. package/lib/module/RTNGodotViewNativeComponent.ts +37 -0
  77. package/lib/module/index.js +30 -0
  78. package/lib/module/index.js.map +1 -0
  79. package/lib/module/package.json +1 -0
  80. package/lib/typescript/package.json +1 -0
  81. package/lib/typescript/src/NativeNativeGodotModule.d.ts +26 -0
  82. package/lib/typescript/src/NativeNativeGodotModule.d.ts.map +1 -0
  83. package/lib/typescript/src/RTNGodotView.d.ts +7 -0
  84. package/lib/typescript/src/RTNGodotView.d.ts.map +1 -0
  85. package/lib/typescript/src/RTNGodotView.native.d.ts +3 -0
  86. package/lib/typescript/src/RTNGodotView.native.d.ts.map +1 -0
  87. package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts +11 -0
  88. package/lib/typescript/src/RTNGodotViewNativeComponent.d.ts.map +1 -0
  89. package/lib/typescript/src/index.d.ts +6 -0
  90. package/lib/typescript/src/index.d.ts.map +1 -0
  91. package/package.json +262 -4
  92. package/prebuilt-utils.rb +36 -0
  93. package/react-native-godot.podspec +41 -0
  94. package/react-native.config.js +15 -0
  95. package/scripts/check-16kb.sh +136 -0
  96. package/scripts/check-packaged-artifacts.sh +154 -0
  97. package/scripts/ci/verify-prebuilt-install.cjs +39 -0
  98. package/scripts/download-prebuilt.js +274 -0
  99. package/src/NativeNativeGodotModule.ts +90 -0
  100. package/src/RTNGodotView.native.tsx +2 -0
  101. package/src/RTNGodotView.tsx +12 -0
  102. package/src/RTNGodotViewNativeComponent.ts +37 -0
  103. package/src/index.tsx +28 -0
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ elf_cmd=""
5
+ elf_cmd_kind=""
6
+
7
+ find_elf_tool() {
8
+ local candidates=(
9
+ "llvm-readelf:readelf"
10
+ "readelf:readelf"
11
+ "greadelf:readelf"
12
+ "/opt/homebrew/opt/llvm/bin/llvm-readelf:readelf"
13
+ "/usr/local/opt/llvm/bin/llvm-readelf:readelf"
14
+ "/opt/homebrew/bin/greadelf:readelf"
15
+ "/usr/local/bin/greadelf:readelf"
16
+ "llvm-objdump:objdump"
17
+ "/opt/homebrew/opt/llvm/bin/llvm-objdump:objdump"
18
+ "/usr/local/opt/llvm/bin/llvm-objdump:objdump"
19
+ )
20
+
21
+ for candidate in "${candidates[@]}"; do
22
+ local path="${candidate%%:*}"
23
+ local kind="${candidate##*:}"
24
+
25
+ if command -v "$path" >/dev/null 2>&1; then
26
+ elf_cmd="$(command -v "$path")"
27
+ elf_cmd_kind="$kind"
28
+ return 0
29
+ fi
30
+ if [ -x "$path" ]; then
31
+ elf_cmd="$path"
32
+ elf_cmd_kind="$kind"
33
+ return 0
34
+ fi
35
+ done
36
+
37
+ if command -v xcrun >/dev/null 2>&1; then
38
+ local xcrun_objdump
39
+ xcrun_objdump="$(xcrun --find llvm-objdump 2>/dev/null || true)"
40
+ if [ -x "$xcrun_objdump" ]; then
41
+ elf_cmd="$xcrun_objdump"
42
+ elf_cmd_kind="objdump"
43
+ return 0
44
+ fi
45
+ fi
46
+
47
+ return 1
48
+ }
49
+
50
+ if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
51
+ if command -v llvm-readelf >/dev/null 2>&1; then
52
+ elf_cmd="llvm-readelf"
53
+ elf_cmd_kind="readelf"
54
+ elif command -v readelf >/dev/null 2>&1; then
55
+ elf_cmd="readelf"
56
+ elf_cmd_kind="readelf"
57
+ elif command -v greadelf >/dev/null 2>&1; then
58
+ elf_cmd="greadelf"
59
+ elf_cmd_kind="readelf"
60
+ elif command -v llvm-objdump >/dev/null 2>&1; then
61
+ elf_cmd="llvm-objdump"
62
+ elf_cmd_kind="objdump"
63
+ fi
64
+ else
65
+ find_elf_tool || true
66
+ fi
67
+
68
+ if [ -z "$elf_cmd" ]; then
69
+ echo "ERROR: no ELF inspection tool found (llvm-readelf, readelf, greadelf, or llvm-objdump)" >&2
70
+ if [ "${GITHUB_ACTIONS:-}" != "true" ]; then
71
+ echo "Tip: brew install llvm (llvm-readelf/llvm-objdump) or binutils (greadelf), or export PATH to include them." >&2
72
+ fi
73
+ exit 1
74
+ fi
75
+
76
+ print_load_alignments() {
77
+ if [ "$elf_cmd_kind" = "objdump" ]; then
78
+ "$elf_cmd" --private-headers "$1" | awk '$1 == "LOAD" { print $1, $NF }'
79
+ else
80
+ "$elf_cmd" -l -W "$1" | awk '$1 == "LOAD" { print $1, $NF }'
81
+ fi
82
+ }
83
+
84
+ # Check the final stripped native libraries used by the example APK. Android's
85
+ # current Play requirement applies to 64-bit device variants, so arm64-v8a is
86
+ # the ABI that must be 16KB-aligned here.
87
+ search_roots=(example/android/app/build/intermediates/stripped_native_libs)
88
+ files=()
89
+
90
+ while IFS= read -r file; do
91
+ [ -n "$file" ] && files+=("$file")
92
+ done < <(
93
+ if command -v rg >/dev/null 2>&1; then
94
+ rg --files "${search_roots[@]}" \
95
+ | rg '/arm64-v8a/[^/]+\.so$' \
96
+ || true
97
+ else
98
+ find "${search_roots[@]}" -type f \
99
+ -path '*/arm64-v8a/*.so' \
100
+ -print 2>/dev/null || true
101
+ fi
102
+ )
103
+
104
+ if [ "${#files[@]}" -eq 0 ]; then
105
+ echo "ERROR: no arm64-v8a native libraries found; build Android first" >&2
106
+ echo "Searched: ${search_roots[*]}" >&2
107
+ exit 1
108
+ fi
109
+
110
+ for so in "${files[@]}"; do
111
+ echo "Checking 16KB alignment: $so"
112
+
113
+ if print_load_alignments "$so" | awk '
114
+ $1 == "LOAD" {
115
+ load = 1
116
+ if ($NF != "0x4000" && $NF != "2**14") bad = 1
117
+ }
118
+ END {
119
+ if (!load) exit 2
120
+ exit bad
121
+ }
122
+ '; then
123
+ :
124
+ else
125
+ status=$?
126
+ if [ "$status" -eq 2 ]; then
127
+ echo "ERROR: no LOAD segments found for $so" >&2
128
+ else
129
+ echo "ERROR: expected 16KB alignment (0x4000 or 2**14) for $so" >&2
130
+ fi
131
+ print_load_alignments "$so" || true
132
+ exit 1
133
+ fi
134
+ done
135
+
136
+ echo "OK: 16KB alignment verified for ${#files[@]} native libraries"
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ TMP_DIR="$(mktemp -d)"
6
+
7
+ cleanup() {
8
+ rm -rf "$TMP_DIR"
9
+ }
10
+ trap cleanup EXIT
11
+
12
+ if [[ $# -gt 1 ]]; then
13
+ echo "Usage: $0 [path-to-tarball]" >&2
14
+ exit 1
15
+ fi
16
+
17
+ if [[ $# -eq 1 ]]; then
18
+ TARBALL="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
19
+ else
20
+ cd "$ROOT_DIR"
21
+ NPM_CONFIG_CACHE="$TMP_DIR/npm-cache" \
22
+ npm pack --silent --ignore-scripts \
23
+ --pack-destination "$TMP_DIR" >/dev/null
24
+ TARBALL="$(find "$TMP_DIR" -maxdepth 1 -type f \
25
+ -name '*.tgz' -print -quit)"
26
+ fi
27
+
28
+ cd "$ROOT_DIR"
29
+
30
+ if [[ ! -f "$TARBALL" ]]; then
31
+ echo "Tarball not found: $TARBALL" >&2
32
+ exit 1
33
+ fi
34
+
35
+ CONTENTS_FILE="$TMP_DIR/tar-contents.txt"
36
+ tar -tzf "$TARBALL" > "$CONTENTS_FILE"
37
+
38
+ required_paths=(
39
+ package/package.json
40
+ package/app.plugin.js
41
+ package/Package.swift
42
+ package/react-native-godot.podspec
43
+ package/react-native.config.js
44
+ package/prebuilt-utils.rb
45
+ package/scripts/download-prebuilt.js
46
+ package/src/index.tsx
47
+ package/lib/module/index.js
48
+ package/lib/typescript/src/index.d.ts
49
+ package/android/build.gradle
50
+ package/android/src/main/AndroidManifest.xml
51
+ package/android/src/main/cpp/CMakeLists.txt
52
+ package/ios/GodotModule.mm
53
+ package/cpp/NativeGodotModule.cpp
54
+ )
55
+
56
+ missing=()
57
+ for path in "${required_paths[@]}"; do
58
+ if ! grep -Fxq "$path" "$CONTENTS_FILE"; then
59
+ missing+=("$path")
60
+ fi
61
+ done
62
+
63
+ if (( ${#missing[@]} > 0 )); then
64
+ echo "Packaged tarball is missing required artifacts:" >&2
65
+ printf ' - %s\n' "${missing[@]}" >&2
66
+ exit 1
67
+ fi
68
+
69
+ forbidden_patterns=(
70
+ '^package/(android|ios)/build/'
71
+ '^package/(android|ios)/libs/'
72
+ '^package/(android|ios)/local\.properties$'
73
+ '^package/(example|node_modules)/'
74
+ '^package/\.build/'
75
+ '(^|/)\.DS_Store$'
76
+ )
77
+
78
+ for pattern in "${forbidden_patterns[@]}"; do
79
+ if grep -Eq "$pattern" "$CONTENTS_FILE"; then
80
+ echo "Packaged tarball contains forbidden content matching: $pattern" >&2
81
+ grep -E "$pattern" "$CONTENTS_FILE" | sed 's/^/ - /' >&2
82
+ exit 1
83
+ fi
84
+ done
85
+
86
+ node <<'NODE'
87
+ const fs = require('node:fs');
88
+ const path = require('node:path');
89
+
90
+ const root = process.cwd();
91
+ const packageJson = JSON.parse(
92
+ fs.readFileSync(path.join(root, 'package.json'), 'utf8')
93
+ );
94
+ const entries = packageJson.prebuiltFiles ?? [];
95
+ const errors = [];
96
+ const names = new Set();
97
+
98
+ for (const entry of entries) {
99
+ for (const field of [
100
+ 'name',
101
+ 'filename',
102
+ 'version',
103
+ 'base_url',
104
+ 'shasum',
105
+ 'destination_base_dir',
106
+ 'env',
107
+ ]) {
108
+ if (typeof entry[field] !== 'string' || entry[field].length === 0) {
109
+ errors.push(`${field} is missing for prebuilt entry`);
110
+ }
111
+ }
112
+
113
+ if (names.has(entry.name)) {
114
+ errors.push(`duplicate prebuilt name: ${entry.name}`);
115
+ }
116
+ names.add(entry.name);
117
+
118
+ if (
119
+ entry.base_url !==
120
+ 'https://github.com/Preeternal/libgodot/releases/download/'
121
+ ) {
122
+ errors.push(`unexpected base_url for ${entry.name}: ${entry.base_url}`);
123
+ }
124
+ if (!/^[0-9a-f]{64}$/i.test(entry.shasum)) {
125
+ errors.push(`invalid SHA-256 for ${entry.name}`);
126
+ }
127
+ if (entry.no_unpack !== 'false') {
128
+ errors.push(`${entry.name} must be unpacked by the installer`);
129
+ }
130
+
131
+ const target = path.join(
132
+ root,
133
+ entry.destination_base_dir,
134
+ entry.name,
135
+ entry.version
136
+ );
137
+ if (!fs.existsSync(target) || fs.readdirSync(target).length === 0) {
138
+ errors.push(`prebuilt directory is missing or empty: ${target}`);
139
+ }
140
+ }
141
+
142
+ if (entries.length !== 4) {
143
+ errors.push(`expected 4 prebuilt entries, found ${entries.length}`);
144
+ }
145
+
146
+ if (errors.length > 0) {
147
+ console.error(errors.join('\n'));
148
+ process.exit(1);
149
+ }
150
+
151
+ console.log(`Verified ${entries.length} prebuilt metadata entries and directories`);
152
+ NODE
153
+
154
+ echo "Verified packaged artifacts in: $TARBALL"
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+
6
+ const packageRoot = path.resolve(process.argv[2] ?? process.cwd());
7
+ const packageJsonPath = path.join(packageRoot, 'package.json');
8
+
9
+ if (!fs.existsSync(packageJsonPath)) {
10
+ throw new Error(`Package manifest not found: ${packageJsonPath}`);
11
+ }
12
+
13
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
14
+ const missing = [];
15
+
16
+ for (const entry of packageJson.prebuiltFiles ?? []) {
17
+ const target = path.join(
18
+ packageRoot,
19
+ entry.destination_base_dir,
20
+ entry.name,
21
+ entry.version
22
+ );
23
+
24
+ if (!fs.existsSync(target) || fs.readdirSync(target).length === 0) {
25
+ missing.push(target);
26
+ }
27
+ }
28
+
29
+ if (missing.length > 0) {
30
+ console.error('Missing or empty prebuilt directories:');
31
+ for (const target of missing) {
32
+ console.error(`- ${target}`);
33
+ }
34
+ process.exit(1);
35
+ }
36
+
37
+ console.log(
38
+ `Verified ${packageJson.prebuiltFiles.length} prebuilt directories in ${packageRoot}`
39
+ );
@@ -0,0 +1,274 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Script to download pre‑built Godot zip files defined in the library's package.json.
5
+ *
6
+ * Usage (from the example project):
7
+ * yarn download-prebuilt
8
+ *
9
+ * The script:
10
+ * 1. Reads the `prebuiltFiles` array from @preeternal/react-native-godot's package.json.
11
+ * 2. For each entry it builds a download URL: `${base_url}${version}/${filename}`.
12
+ * 3. If an environment variable named in the entry's `env` key is set and non‑empty,
13
+ * its value is treated as a path to a local archive file. The file is copied into
14
+ * the temporary folder and processed as if it had been downloaded.
15
+ * 4. Otherwise the file is downloaded from the network to a temporary location.
16
+ * **Redirects (301, 302, 303, 307, 308) are now followed automatically via `curl -L`.**
17
+ * 5. Verifies the SHA‑256 checksum against `shasum` unless the environment variable
18
+ * SHASUM_CHECK is set to "false".
19
+ * 6. If the checksum matches (or verification is skipped), extracts the zip into
20
+ * `${destination_base_dir}/${name}/${version}` (creating directories as needed).
21
+ *
22
+ * Additional behaviour:
23
+ * - If the target extraction folder (`destination_base_dir/name/version`) already
24
+ * exists and is not empty, the script skips processing that entry.
25
+ * - If `destination_base_dir/name` exists but does not contain the target version
26
+ * folder (or is otherwise dirty), it is removed recursively before processing.
27
+ *
28
+ * NOTE:
29
+ * The `destination_base_dir` values in package.json are now interpreted as
30
+ * relative to the **parent folder of this script** (i.e. the repository root),
31
+ * not relative to the current working directory from which the script is invoked.
32
+ */
33
+
34
+ const fs = require('fs');
35
+ const path = require('path');
36
+ const os = require('os');
37
+ const crypto = require('crypto');
38
+ const { execSync, execFile } = require('child_process');
39
+
40
+ // Resolve the library's package.json (the script lives in ./scripts/)
41
+ const libPackagePath = path.resolve(__dirname, '..', 'package.json');
42
+ if (!fs.existsSync(libPackagePath)) {
43
+ console.error('Unable to locate package.json of the library.');
44
+ process.exit(1);
45
+ }
46
+ const libPackage = JSON.parse(fs.readFileSync(libPackagePath, 'utf8'));
47
+
48
+ if (
49
+ !Array.isArray(libPackage.prebuiltFiles) ||
50
+ libPackage.prebuiltFiles.length === 0
51
+ ) {
52
+ console.log('No prebuilt files defined in package.json.');
53
+ process.exit(0);
54
+ }
55
+
56
+ /**
57
+ * Download a file from `url` and write it to `destPath`.
58
+ * Uses the external `curl` command with `-L` to follow redirects.
59
+ *
60
+ * @param {string} url - The URL to download.
61
+ * @param {string} destPath - Destination file path.
62
+ * @returns {Promise<void>}
63
+ */
64
+ function downloadFile(url, destPath) {
65
+ return new Promise((resolve, reject) => {
66
+ // Ensure any previous partial file is removed
67
+ if (fs.existsSync(destPath)) {
68
+ try {
69
+ fs.unlinkSync(destPath);
70
+ } catch {
71
+ // ignore
72
+ }
73
+ }
74
+
75
+ execFile('curl', ['-L', '-o', destPath, url], (error) => {
76
+ if (error) {
77
+ // Clean up partial download
78
+ if (fs.existsSync(destPath)) {
79
+ try {
80
+ fs.unlinkSync(destPath);
81
+ } catch {
82
+ // ignore
83
+ }
84
+ }
85
+ reject(new Error(`curl failed for ${url}: ${error.message}`));
86
+ } else {
87
+ resolve();
88
+ }
89
+ });
90
+ });
91
+ }
92
+
93
+ /**
94
+ * Compute SHA‑256 hash of a file.
95
+ */
96
+ function computeSha256(filePath) {
97
+ return new Promise((resolve, reject) => {
98
+ const hash = crypto.createHash('sha256');
99
+ const stream = fs.createReadStream(filePath);
100
+ stream.on('error', reject);
101
+ stream.on('data', (chunk) => hash.update(chunk));
102
+ stream.on('end', () => resolve(hash.digest('hex')));
103
+ });
104
+ }
105
+
106
+ /**
107
+ * Extract a zip file using the system `unzip` command.
108
+ */
109
+ function unzipFile(zipPath, targetDir) {
110
+ try {
111
+ execSync(`unzip -o "${zipPath}" -d "${targetDir}"`, { stdio: 'inherit' });
112
+ } catch (err) {
113
+ throw new Error(`Failed to unzip ${zipPath}: ${err.message}`);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Helper: check whether a directory exists and is non‑empty.
119
+ */
120
+ function isNonEmptyDirectory(dirPath) {
121
+ try {
122
+ const stats = fs.statSync(dirPath);
123
+ if (!stats.isDirectory()) return false;
124
+ const entries = fs.readdirSync(dirPath);
125
+ return entries.length > 0;
126
+ } catch {
127
+ return false;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Resolve a path that is relative to the repository root (the parent folder of this script).
133
+ */
134
+ function resolveRepoRelative(relativePath) {
135
+ const repoRoot = path.resolve(__dirname, '..'); // parent of ./scripts/
136
+ return path.join(repoRoot, relativePath);
137
+ }
138
+
139
+ /**
140
+ * Main processing loop.
141
+ */
142
+ (async () => {
143
+ // Determine whether checksum verification should be performed.
144
+ const skipChecksum =
145
+ process.env.SHASUM_CHECK &&
146
+ process.env.SHASUM_CHECK.toLowerCase() === 'false';
147
+
148
+ const replaceExisting =
149
+ process.env.REPLACE_EXISTING &&
150
+ process.env.REPLACE_EXISTING.toLowerCase() === 'true';
151
+
152
+ for (const entry of libPackage.prebuiltFiles) {
153
+ const {
154
+ name,
155
+ filename,
156
+ version,
157
+ base_url,
158
+ shasum,
159
+ destination_base_dir,
160
+ env,
161
+ no_unpack,
162
+ } = entry;
163
+
164
+ // Build URL – use the `filename` field for the actual archive name.
165
+ const url = `${base_url}${version}/${filename}`;
166
+ console.log(`\nProcessing ${name} (version ${version})`);
167
+ console.log(`Downloading from: ${url}`);
168
+ const need_unzip = no_unpack.toLowerCase() === 'false';
169
+
170
+ // Resolve destination directories relative to the repository root.
171
+ const destBaseFull = resolveRepoRelative(destination_base_dir);
172
+ const extractDir = path.join(destBaseFull, name, version);
173
+ const parentNameDir = path.join(destBaseFull, name);
174
+
175
+ // Temporary location for the zip file.
176
+ const tmpPath = path.join(os.tmpdir(), filename);
177
+
178
+ // -----------------------------------------------------------------
179
+ // Skip logic: if target folder exists and is non‑empty, skip entry.
180
+ // -----------------------------------------------------------------
181
+ if (isNonEmptyDirectory(extractDir)) {
182
+ if (!replaceExisting) {
183
+ console.log(
184
+ `Target directory ${extractDir} already exists and is not empty. Skipping this entry.`
185
+ );
186
+ continue; // move to next prebuilt file
187
+ }
188
+ }
189
+
190
+ // -----------------------------------------------------------------
191
+ // Clean parent folder if it exists (to avoid stale files from previous runs)
192
+ // -----------------------------------------------------------------
193
+ if (fs.existsSync(parentNameDir)) {
194
+ console.log(
195
+ `Cleaning existing directory ${parentNameDir} before processing.`
196
+ );
197
+ try {
198
+ fs.rmSync(parentNameDir, { recursive: true, force: true });
199
+ } catch (err) {
200
+ console.error(`Failed to remove ${parentNameDir}: ${err.message}`);
201
+ process.exit(1);
202
+ }
203
+ }
204
+
205
+ try {
206
+ // -------------------------------------------------------------
207
+ // 1️⃣ If an environment variable is provided, use the local file.
208
+ // -------------------------------------------------------------
209
+ if (env && process.env[env] && process.env[env].trim() !== '') {
210
+ const localFilePath = process.env[env];
211
+ console.log(
212
+ `Environment variable ${env} is set. Using local archive: ${localFilePath}`
213
+ );
214
+
215
+ if (!fs.existsSync(localFilePath)) {
216
+ throw new Error(
217
+ `Local file specified by ${env} does not exist: ${localFilePath}`
218
+ );
219
+ }
220
+
221
+ // Copy the local archive into the temporary location so that the rest
222
+ // of the workflow (checksum, unzip) works unchanged.
223
+ fs.copyFileSync(localFilePath, tmpPath);
224
+ console.log('Copied local archive to temporary location.');
225
+ } else {
226
+ // -------------------------------------------------------------
227
+ // 2️⃣ No env var – download from the network (using curl).
228
+ // -------------------------------------------------------------
229
+ await downloadFile(url, tmpPath);
230
+ console.log('Download completed.');
231
+ }
232
+
233
+ // -------------------------------------------------------------
234
+ // 3️⃣ Verify checksum (unless disabled)
235
+ // -------------------------------------------------------------
236
+ if (!skipChecksum) {
237
+ const actualHash = await computeSha256(tmpPath);
238
+ if (actualHash !== shasum.toLowerCase()) {
239
+ throw new Error(
240
+ `Checksum mismatch for ${name}. Expected ${shasum}, got ${actualHash}`
241
+ );
242
+ }
243
+ console.log('Checksum verified.');
244
+ } else {
245
+ console.log(
246
+ 'Skipping checksum verification because SHASUM_CHECK is set to false.'
247
+ );
248
+ }
249
+
250
+ // -------------------------------------------------------------
251
+ // 4️⃣ Extract
252
+ // -------------------------------------------------------------
253
+ fs.mkdirSync(extractDir, { recursive: true });
254
+ console.log(`Extracting to ${extractDir}`);
255
+ if (need_unzip) {
256
+ unzipFile(tmpPath, extractDir);
257
+ } else {
258
+ const copyPath = path.join(extractDir, filename);
259
+ fs.copyFileSync(tmpPath, copyPath);
260
+ }
261
+ console.log('Extraction completed.');
262
+ } catch (err) {
263
+ console.error(`Error processing ${name}: ${err.message}`);
264
+ process.exit(1);
265
+ } finally {
266
+ // Clean up temporary file
267
+ if (fs.existsSync(tmpPath)) {
268
+ fs.unlinkSync(tmpPath);
269
+ }
270
+ }
271
+ }
272
+
273
+ console.log('\nAll prebuilt files have been processed successfully.');
274
+ })();
@@ -0,0 +1,90 @@
1
+ /**************************************************************************/
2
+ /* NativeGodotModule.ts */
3
+ /**************************************************************************/
4
+ /* Copyright (c) 2024-2025 Slay GmbH */
5
+ /* */
6
+ /* Permission is hereby granted, free of charge, to any person obtaining */
7
+ /* a copy of this software and associated documentation files (the */
8
+ /* "Software"), to deal in the Software without restriction, including */
9
+ /* without limitation the rights to use, copy, modify, merge, publish, */
10
+ /* distribute, sublicense, and/or sell copies of the Software, and to */
11
+ /* permit persons to whom the Software is furnished to do so, subject to */
12
+ /* the following conditions: */
13
+ /* */
14
+ /* The above copyright notice and this permission notice shall be */
15
+ /* included in all copies or substantial portions of the Software. */
16
+ /* */
17
+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
18
+ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
19
+ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
20
+ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
21
+ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
22
+ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
23
+ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24
+ /**************************************************************************/
25
+
26
+ import { TurboModuleRegistry, type TurboModule } from 'react-native';
27
+ import {
28
+ createWorkletRuntime,
29
+ runOnRuntimeAsync,
30
+ type WorkletRuntime,
31
+ } from 'react-native-worklets';
32
+
33
+ export interface Spec extends TurboModule {
34
+ installTurboModule(): boolean;
35
+ }
36
+
37
+ const GodotInstaller = TurboModuleRegistry.get<Spec>('NativeGodotModule');
38
+
39
+ export interface GodotModuleInterface {
40
+ createInstance(args: Array<string>): any;
41
+ getInstance(): any;
42
+ API(): any;
43
+ updateWindow(windowName: string, adding: boolean): void;
44
+ pause(): void;
45
+ resume(): void;
46
+ is_paused(): boolean;
47
+ createGodotQueue(): object;
48
+ destroyInstance(): void;
49
+ }
50
+
51
+ declare global {
52
+ var RTNGodot: GodotModuleInterface | undefined; // Godot
53
+ var __godotWorkletRuntime: WorkletRuntime | undefined;
54
+ }
55
+
56
+ if (globalThis.RTNGodot == null) {
57
+ if (GodotInstaller == null) {
58
+ console.error(
59
+ 'Native Godot Module cannot be found! Make sure you correctly ' +
60
+ 'installed native dependencies and rebuilt your app.'
61
+ );
62
+ } else if (!GodotInstaller.installTurboModule()) {
63
+ console.error('NativeGodotModule installation failed.');
64
+ }
65
+ }
66
+
67
+ const installedGodotModule = globalThis.RTNGodot;
68
+ if (installedGodotModule != null && globalThis.__godotWorkletRuntime == null) {
69
+ const godotQueue = installedGodotModule.createGodotQueue();
70
+ globalThis.__godotWorkletRuntime = createWorkletRuntime({
71
+ name: 'ReactNativeGodot',
72
+ queue: godotQueue,
73
+ initializer: () => {
74
+ 'worklet';
75
+ globalThis.RTNGodot = installedGodotModule;
76
+ },
77
+ });
78
+ }
79
+
80
+ export const RTNGodot = globalThis.RTNGodot as GodotModuleInterface;
81
+
82
+ export function runOnGodotThread<T>(f: () => T): Promise<T> {
83
+ const runtime = globalThis.__godotWorkletRuntime;
84
+ if (runtime == null) {
85
+ return Promise.reject(
86
+ new Error('NativeGodotModule worklet runtime is not installed')
87
+ );
88
+ }
89
+ return runOnRuntimeAsync(runtime, f);
90
+ }
@@ -0,0 +1,2 @@
1
+ export { default as RTNGodotView } from './RTNGodotViewNativeComponent';
2
+ export * from './RTNGodotViewNativeComponent';