@preeternal/react-native-godot 0.1.0 → 0.2.1
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.
- package/Package.swift +4 -4
- package/README.md +411 -452
- package/android/build.gradle +24 -22
- package/android/consumer-rules.pro +1 -0
- package/android/src/main/cpp/CMakeLists.txt +6 -2
- package/android/src/main/cpp/GodotModule.cpp +124 -78
- package/android/src/main/cpp/libgodot_android.h +2 -8
- package/android/src/main/cpp/libgodot_jni.cpp +364 -291
- package/android/src/main/cpp/libgodot_jni.h +2 -16
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotIO.kt +123 -0
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNGodotView.kt +36 -25
- package/android/src/main/java/com/preeternal/reactnativegodot/RTNLibGodot.kt +19 -154
- package/app.plugin.js +4 -8
- package/cpp/AppleRendererPolicy.h +95 -0
- package/cpp/GodotModule.h +24 -1
- package/cpp/LibGodotABI.h +52 -0
- package/cpp/NativeGodotModule.cpp +1 -1
- package/ios/GodotModule.mm +142 -99
- package/ios/RTNGodotView.mm +260 -300
- package/package.json +35 -15
- package/prebuilt-utils.rb +13 -3
- package/react-native-godot.podspec +1 -1
- package/react-native.config.js +1 -0
- package/scripts/check-packaged-artifacts.sh +2 -0
- package/scripts/ci/verify-ios-simulator.py +48 -0
- package/scripts/ci/verify-prebuilt-install.cjs +5 -3
- package/scripts/download-prebuilt.js +41 -32
- package/scripts/prebuilt-config.js +80 -0
- package/scripts/spm-autolinking-plugin.js +87 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preeternal/react-native-godot",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Embed Godot into React Native apps",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -150,43 +150,63 @@
|
|
|
150
150
|
"prebuiltFiles": [
|
|
151
151
|
{
|
|
152
152
|
"name": "libgodot",
|
|
153
|
-
"filename": "libgodot.xcframework.zip",
|
|
154
|
-
"version": "4.
|
|
153
|
+
"filename": "libgodot-no-record.xcframework.zip",
|
|
154
|
+
"version": "4.7.2.preeternal.2",
|
|
155
155
|
"base_url": "https://github.com/Preeternal/libgodot/releases/download/",
|
|
156
|
-
"shasum": "
|
|
156
|
+
"shasum": "e088cbbf952bc073ec79748239c6fb10284b587158794de9cb3a2d59587b9239",
|
|
157
157
|
"destination_base_dir": "ios/libs",
|
|
158
158
|
"env": "LIBGODOT_XCFRAMEWORK_PATH",
|
|
159
|
-
"no_unpack": "false"
|
|
159
|
+
"no_unpack": "false",
|
|
160
|
+
"with_recording": {
|
|
161
|
+
"filename": "libgodot.xcframework.zip",
|
|
162
|
+
"version": "4.7.2.preeternal.1",
|
|
163
|
+
"shasum": "6bbf51634153ad9206352e36d069cbdf4e8a2a63e11e828a73b38e9a6adc5de5"
|
|
164
|
+
}
|
|
160
165
|
},
|
|
161
166
|
{
|
|
162
167
|
"name": "libgodot-cpp",
|
|
163
168
|
"filename": "libgodot-cpp.xcframework.zip",
|
|
164
|
-
"version": "4.
|
|
169
|
+
"version": "4.7.2.preeternal.2",
|
|
165
170
|
"base_url": "https://github.com/Preeternal/libgodot/releases/download/",
|
|
166
|
-
"shasum": "
|
|
171
|
+
"shasum": "06454281ae25121d086dded03c88037568152e0c97ccaea2d97c6f6cb1567a4b",
|
|
167
172
|
"destination_base_dir": "ios/libs",
|
|
168
173
|
"env": "LIBGODOT_CPP_XCFRAMEWORK_PATH",
|
|
169
|
-
"no_unpack": "false"
|
|
174
|
+
"no_unpack": "false",
|
|
175
|
+
"with_recording": {
|
|
176
|
+
"version": "4.7.2.preeternal.1",
|
|
177
|
+
"shasum": "a6a7f0737c9cd5eb981098fe253f794df27aafd14835f6889da3536de92d550e"
|
|
178
|
+
}
|
|
170
179
|
},
|
|
171
180
|
{
|
|
172
181
|
"name": "libgodot-android",
|
|
173
|
-
"filename": "libgodot-android.zip",
|
|
174
|
-
"version": "4.
|
|
182
|
+
"filename": "libgodot-android-no-record.zip",
|
|
183
|
+
"version": "4.7.2.preeternal.2",
|
|
175
184
|
"base_url": "https://github.com/Preeternal/libgodot/releases/download/",
|
|
176
|
-
"shasum": "
|
|
185
|
+
"shasum": "409d6395bd60b68c9b42e5695d41f21a6dd8c618ecb671edd00b978c706fb3a1",
|
|
177
186
|
"destination_base_dir": "android/libs",
|
|
178
187
|
"env": "LIBGODOT_ANDROID_PATH",
|
|
179
|
-
"no_unpack": "false"
|
|
188
|
+
"no_unpack": "false",
|
|
189
|
+
"maven_version": "4.7.2.preeternal.2",
|
|
190
|
+
"with_recording": {
|
|
191
|
+
"filename": "libgodot-android.zip",
|
|
192
|
+
"version": "4.7.2.preeternal.1",
|
|
193
|
+
"shasum": "e5b94be7fe7f74ce2f147f90ccb2c28a972a91638734d6518807593c15d2c7db",
|
|
194
|
+
"maven_version": "4.7.2.preeternal.1-SNAPSHOT"
|
|
195
|
+
}
|
|
180
196
|
},
|
|
181
197
|
{
|
|
182
198
|
"name": "libgodot-cpp-android",
|
|
183
199
|
"filename": "godot-cpp-android.zip",
|
|
184
|
-
"version": "4.
|
|
200
|
+
"version": "4.7.2.preeternal.2",
|
|
185
201
|
"base_url": "https://github.com/Preeternal/libgodot/releases/download/",
|
|
186
|
-
"shasum": "
|
|
202
|
+
"shasum": "f8a596f023b65eabf0afb0b88f699d5ac52ca301a6e61e6ca8e1db1d681d2c48",
|
|
187
203
|
"destination_base_dir": "android/libs",
|
|
188
204
|
"env": "LIBGODOT_CPP_ANDROID_PATH",
|
|
189
|
-
"no_unpack": "false"
|
|
205
|
+
"no_unpack": "false",
|
|
206
|
+
"with_recording": {
|
|
207
|
+
"version": "4.7.2.preeternal.1",
|
|
208
|
+
"shasum": "90966d0add089ebffe3baa3f4ea918d329e22fbc0b1a3c267d3c7ef7476f41cc"
|
|
209
|
+
}
|
|
190
210
|
}
|
|
191
211
|
],
|
|
192
212
|
"react-native-builder-bob": {
|
package/prebuilt-utils.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
require "fileutils"
|
|
3
|
+
require "open3"
|
|
3
4
|
|
|
4
5
|
# ----------------------------------------------------------------------
|
|
5
6
|
# Helper: Returns the relative path to the pre‑built library directory.
|
|
@@ -23,9 +24,18 @@ def prebuilt_path(lib_name)
|
|
|
23
24
|
raise "Unable to locate package.json at #{package_path}"
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
app_root = if defined?(Pod::Config)
|
|
28
|
+
Pod::Config.instance.installation_root.to_s
|
|
29
|
+
else
|
|
30
|
+
Dir.pwd
|
|
31
|
+
end
|
|
32
|
+
node = ENV.fetch("NODE_BINARY", "node")
|
|
33
|
+
output, error, status = Open3.capture3(
|
|
34
|
+
node, File.join(__dir__, "scripts/prebuilt-config.js"), "--app-root", app_root
|
|
35
|
+
)
|
|
36
|
+
raise "[RTNGodot] Unable to select LibGodot: #{error}" unless status.success?
|
|
37
|
+
selection = JSON.parse(output)
|
|
38
|
+
entry = selection["prebuiltFiles"]&.find { |e| e["name"] == lib_name }
|
|
29
39
|
|
|
30
40
|
unless entry
|
|
31
41
|
raise "Prebuilt entry not found for library '#{lib_name}'. Ensure it exists in package.json."
|
|
@@ -14,7 +14,7 @@ Pod::Spec.new do |s|
|
|
|
14
14
|
s.description = package["description"]
|
|
15
15
|
s.homepage = package["homepage"]
|
|
16
16
|
s.license = package["license"]
|
|
17
|
-
s.platforms = { :ios => "
|
|
17
|
+
s.platforms = { :ios => "15.0" }
|
|
18
18
|
s.author = package["author"]
|
|
19
19
|
s.source = { :git => repository_url, :tag => "v#{s.version}" }
|
|
20
20
|
s.frameworks = 'AVFAudio'
|
package/react-native.config.js
CHANGED
|
@@ -43,6 +43,8 @@ required_paths=(
|
|
|
43
43
|
package/react-native.config.js
|
|
44
44
|
package/prebuilt-utils.rb
|
|
45
45
|
package/scripts/download-prebuilt.js
|
|
46
|
+
package/scripts/prebuilt-config.js
|
|
47
|
+
package/scripts/spm-autolinking-plugin.js
|
|
46
48
|
package/src/index.tsx
|
|
47
49
|
package/lib/module/index.js
|
|
48
50
|
package/lib/typescript/src/index.d.ts
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Check that installed XCFrameworks contain the requested Simulator binaries."""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import plistlib
|
|
8
|
+
import subprocess
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def verify(root, architectures):
|
|
12
|
+
package = json.loads((root / "package.json").read_text())
|
|
13
|
+
entries = {entry["name"]: entry for entry in package["prebuiltFiles"]}
|
|
14
|
+
for name in ("libgodot", "libgodot-cpp"):
|
|
15
|
+
entry = entries[name]
|
|
16
|
+
framework = (root / entry["destination_base_dir"] / name /
|
|
17
|
+
entry["version"] / (name + ".xcframework"))
|
|
18
|
+
with (framework / "Info.plist").open("rb") as stream:
|
|
19
|
+
libraries = plistlib.load(stream)["AvailableLibraries"]
|
|
20
|
+
simulators = [item for item in libraries
|
|
21
|
+
if item.get("SupportedPlatform") == "ios" and
|
|
22
|
+
item.get("SupportedPlatformVariant") == "simulator"]
|
|
23
|
+
matching = [item for item in simulators
|
|
24
|
+
if set(architectures).issubset(item["SupportedArchitectures"])]
|
|
25
|
+
if len(matching) != 1:
|
|
26
|
+
available = [item["SupportedArchitectures"] for item in simulators]
|
|
27
|
+
raise ValueError(f"{name}: need Simulator {architectures}; available {available}")
|
|
28
|
+
selected = matching[0]
|
|
29
|
+
library = framework / selected["LibraryIdentifier"] / selected["LibraryPath"]
|
|
30
|
+
binary = library / library.stem if library.suffix == ".framework" else library
|
|
31
|
+
if not binary.is_file():
|
|
32
|
+
raise ValueError(f"{name}: missing Simulator binary {binary}")
|
|
33
|
+
actual = subprocess.check_output(
|
|
34
|
+
["xcrun", "lipo", "-archs", str(binary)], text=True).split()
|
|
35
|
+
if not set(selected["SupportedArchitectures"]).issubset(actual):
|
|
36
|
+
raise ValueError(f"{name}: Info.plist architectures differ from binary {actual}")
|
|
37
|
+
print(f"{name}: {selected['LibraryIdentifier']} {architectures} PASS")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
42
|
+
parser.add_argument("--arch", action="append", dest="architectures")
|
|
43
|
+
parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[2])
|
|
44
|
+
args = parser.parse_args()
|
|
45
|
+
try:
|
|
46
|
+
verify(args.root, args.architectures or ["arm64"])
|
|
47
|
+
except (OSError, ValueError, KeyError, subprocess.CalledProcessError) as error:
|
|
48
|
+
parser.exit(1, f"iOS Simulator prebuilt check failed: {error}\n")
|
|
@@ -10,10 +10,12 @@ if (!fs.existsSync(packageJsonPath)) {
|
|
|
10
10
|
throw new Error(`Package manifest not found: ${packageJsonPath}`);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const { prebuiltFiles } = require(
|
|
14
|
+
path.join(packageRoot, 'scripts/prebuilt-config.js')
|
|
15
|
+
).resolvePrebuiltConfig();
|
|
14
16
|
const missing = [];
|
|
15
17
|
|
|
16
|
-
for (const entry of
|
|
18
|
+
for (const entry of prebuiltFiles) {
|
|
17
19
|
const target = path.join(
|
|
18
20
|
packageRoot,
|
|
19
21
|
entry.destination_base_dir,
|
|
@@ -35,5 +37,5 @@ if (missing.length > 0) {
|
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
console.log(
|
|
38
|
-
`Verified ${
|
|
40
|
+
`Verified ${prebuiltFiles.length} prebuilt directories in ${packageRoot}`
|
|
39
41
|
);
|
|
@@ -22,8 +22,9 @@
|
|
|
22
22
|
* Additional behaviour:
|
|
23
23
|
* - If the target extraction folder (`destination_base_dir/name/version`) already
|
|
24
24
|
* exists and is not empty, the script skips processing that entry.
|
|
25
|
-
* -
|
|
26
|
-
*
|
|
25
|
+
* - The app's reactNativeGodot.microphone selects one complete release set.
|
|
26
|
+
* - --with-recording / --without-recording save that choice in the app package.json.
|
|
27
|
+
* - Previously installed versions are preserved when switching variants.
|
|
27
28
|
*
|
|
28
29
|
* NOTE:
|
|
29
30
|
* The `destination_base_dir` values in package.json are now interpreted as
|
|
@@ -35,7 +36,12 @@ const fs = require('fs');
|
|
|
35
36
|
const path = require('path');
|
|
36
37
|
const os = require('os');
|
|
37
38
|
const crypto = require('crypto');
|
|
38
|
-
const {
|
|
39
|
+
const { execFileSync, execFile } = require('child_process');
|
|
40
|
+
const {
|
|
41
|
+
resolvePrebuiltConfig,
|
|
42
|
+
setMicrophone,
|
|
43
|
+
parseArguments,
|
|
44
|
+
} = require('./prebuilt-config');
|
|
39
45
|
|
|
40
46
|
// Resolve the library's package.json (the script lives in ./scripts/)
|
|
41
47
|
const libPackagePath = path.resolve(__dirname, '..', 'package.json');
|
|
@@ -72,7 +78,7 @@ function downloadFile(url, destPath) {
|
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
execFile('curl', ['-
|
|
81
|
+
execFile('curl', ['-fL', '-o', destPath, url], (error) => {
|
|
76
82
|
if (error) {
|
|
77
83
|
// Clean up partial download
|
|
78
84
|
if (fs.existsSync(destPath)) {
|
|
@@ -108,7 +114,9 @@ function computeSha256(filePath) {
|
|
|
108
114
|
*/
|
|
109
115
|
function unzipFile(zipPath, targetDir) {
|
|
110
116
|
try {
|
|
111
|
-
|
|
117
|
+
execFileSync('unzip', ['-qo', zipPath, '-d', targetDir], {
|
|
118
|
+
stdio: 'inherit',
|
|
119
|
+
});
|
|
112
120
|
} catch (err) {
|
|
113
121
|
throw new Error(`Failed to unzip ${zipPath}: ${err.message}`);
|
|
114
122
|
}
|
|
@@ -140,6 +148,14 @@ function resolveRepoRelative(relativePath) {
|
|
|
140
148
|
* Main processing loop.
|
|
141
149
|
*/
|
|
142
150
|
(async () => {
|
|
151
|
+
const options = parseArguments(process.argv.slice(2));
|
|
152
|
+
if (options.microphone !== undefined) {
|
|
153
|
+
setMicrophone(options.appRoot, options.microphone);
|
|
154
|
+
}
|
|
155
|
+
const selection = resolvePrebuiltConfig(options.appRoot);
|
|
156
|
+
console.log(
|
|
157
|
+
`LibGodot microphone: ${selection.microphone ? 'enabled (.1)' : 'excluded (.2)'}`
|
|
158
|
+
);
|
|
143
159
|
// Determine whether checksum verification should be performed.
|
|
144
160
|
const skipChecksum =
|
|
145
161
|
process.env.SHASUM_CHECK &&
|
|
@@ -149,7 +165,7 @@ function resolveRepoRelative(relativePath) {
|
|
|
149
165
|
process.env.REPLACE_EXISTING &&
|
|
150
166
|
process.env.REPLACE_EXISTING.toLowerCase() === 'true';
|
|
151
167
|
|
|
152
|
-
for (const entry of
|
|
168
|
+
for (const entry of selection.prebuiltFiles) {
|
|
153
169
|
const {
|
|
154
170
|
name,
|
|
155
171
|
filename,
|
|
@@ -170,10 +186,6 @@ function resolveRepoRelative(relativePath) {
|
|
|
170
186
|
// Resolve destination directories relative to the repository root.
|
|
171
187
|
const destBaseFull = resolveRepoRelative(destination_base_dir);
|
|
172
188
|
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
189
|
|
|
178
190
|
// -----------------------------------------------------------------
|
|
179
191
|
// Skip logic: if target folder exists and is non‑empty, skip entry.
|
|
@@ -187,20 +199,8 @@ function resolveRepoRelative(relativePath) {
|
|
|
187
199
|
}
|
|
188
200
|
}
|
|
189
201
|
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
}
|
|
202
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rtngodot-prebuilt-'));
|
|
203
|
+
const tmpPath = path.join(tmpDir, filename);
|
|
204
204
|
|
|
205
205
|
try {
|
|
206
206
|
// -------------------------------------------------------------
|
|
@@ -250,25 +250,34 @@ function resolveRepoRelative(relativePath) {
|
|
|
250
250
|
// -------------------------------------------------------------
|
|
251
251
|
// 4️⃣ Extract
|
|
252
252
|
// -------------------------------------------------------------
|
|
253
|
-
|
|
253
|
+
const stagedDir = path.join(tmpDir, 'extracted');
|
|
254
|
+
fs.mkdirSync(stagedDir);
|
|
254
255
|
console.log(`Extracting to ${extractDir}`);
|
|
255
256
|
if (need_unzip) {
|
|
256
|
-
unzipFile(tmpPath,
|
|
257
|
+
unzipFile(tmpPath, stagedDir);
|
|
257
258
|
} else {
|
|
258
|
-
const copyPath = path.join(
|
|
259
|
+
const copyPath = path.join(stagedDir, filename);
|
|
259
260
|
fs.copyFileSync(tmpPath, copyPath);
|
|
260
261
|
}
|
|
262
|
+
if (fs.existsSync(extractDir)) fs.rmSync(extractDir, { recursive: true });
|
|
263
|
+
fs.mkdirSync(path.dirname(extractDir), { recursive: true });
|
|
264
|
+
fs.cpSync(stagedDir, extractDir, {
|
|
265
|
+
recursive: true,
|
|
266
|
+
verbatimSymlinks: true,
|
|
267
|
+
});
|
|
261
268
|
console.log('Extraction completed.');
|
|
262
269
|
} catch (err) {
|
|
263
270
|
console.error(`Error processing ${name}: ${err.message}`);
|
|
264
|
-
process.
|
|
271
|
+
process.exitCode = 1;
|
|
272
|
+
return;
|
|
265
273
|
} finally {
|
|
266
274
|
// Clean up temporary file
|
|
267
|
-
|
|
268
|
-
fs.unlinkSync(tmpPath);
|
|
269
|
-
}
|
|
275
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
270
276
|
}
|
|
271
277
|
}
|
|
272
278
|
|
|
273
279
|
console.log('\nAll prebuilt files have been processed successfully.');
|
|
274
|
-
})()
|
|
280
|
+
})().catch((error) => {
|
|
281
|
+
console.error(error.message);
|
|
282
|
+
process.exitCode = 1;
|
|
283
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
|
|
4
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
5
|
+
const library = require('../package.json');
|
|
6
|
+
|
|
7
|
+
function findAppPackage(start) {
|
|
8
|
+
let directory = path.resolve(start);
|
|
9
|
+
while (true) {
|
|
10
|
+
const filename = path.join(directory, 'package.json');
|
|
11
|
+
if (fs.existsSync(filename)) {
|
|
12
|
+
const manifest = JSON.parse(fs.readFileSync(filename, 'utf8'));
|
|
13
|
+
if (manifest.name !== library.name) return { filename, manifest };
|
|
14
|
+
}
|
|
15
|
+
const parent = path.dirname(directory);
|
|
16
|
+
if (parent === directory) return null;
|
|
17
|
+
directory = parent;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function resolvePrebuiltConfig(appRoot) {
|
|
22
|
+
const start =
|
|
23
|
+
appRoot ||
|
|
24
|
+
process.env.INIT_CWD ||
|
|
25
|
+
process.env.npm_config_local_prefix ||
|
|
26
|
+
process.cwd();
|
|
27
|
+
const app = findAppPackage(start);
|
|
28
|
+
const microphone = app?.manifest.reactNativeGodot?.microphone ?? false;
|
|
29
|
+
if (typeof microphone !== 'boolean') {
|
|
30
|
+
throw new Error(
|
|
31
|
+
'reactNativeGodot.microphone must be a boolean in the app package.json.'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
microphone,
|
|
36
|
+
appPackagePath: app?.filename ?? null,
|
|
37
|
+
prebuiltFiles: library.prebuiltFiles.map(({ with_recording, ...entry }) =>
|
|
38
|
+
microphone ? { ...entry, ...with_recording } : entry
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Explicit CLI changes are saved in the app, so later installs and native
|
|
44
|
+
// dependency resolution select the same payload without editing node_modules.
|
|
45
|
+
function setMicrophone(appRoot, microphone) {
|
|
46
|
+
const { appPackagePath } = resolvePrebuiltConfig(appRoot);
|
|
47
|
+
if (!appPackagePath || path.dirname(appPackagePath) === packageRoot) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
'Run the microphone selector from the consuming app, or pass --app-root <app>.'
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const contents = fs.readFileSync(appPackagePath, 'utf8');
|
|
53
|
+
const manifest = JSON.parse(contents);
|
|
54
|
+
manifest.reactNativeGodot = { ...manifest.reactNativeGodot, microphone };
|
|
55
|
+
const indent = /\n([ \t]+)"/.exec(contents)?.[1] ?? ' ';
|
|
56
|
+
fs.writeFileSync(
|
|
57
|
+
appPackagePath,
|
|
58
|
+
`${JSON.stringify(manifest, null, indent)}\n`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function parseArguments(args) {
|
|
63
|
+
const options = {};
|
|
64
|
+
for (let index = 0; index < args.length; index++) {
|
|
65
|
+
const arg = args[index];
|
|
66
|
+
if (arg === '--app-root' && args[index + 1])
|
|
67
|
+
options.appRoot = args[++index];
|
|
68
|
+
else if (arg === '--with-recording') options.microphone = true;
|
|
69
|
+
else if (arg === '--without-recording') options.microphone = false;
|
|
70
|
+
else throw new Error(`Unknown argument: ${arg}`);
|
|
71
|
+
}
|
|
72
|
+
return options;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { resolvePrebuiltConfig, setMicrophone, parseArguments };
|
|
76
|
+
|
|
77
|
+
if (require.main === module) {
|
|
78
|
+
const { appRoot } = parseArguments(process.argv.slice(2));
|
|
79
|
+
process.stdout.write(JSON.stringify(resolvePrebuiltConfig(appRoot)));
|
|
80
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { resolvePrebuiltConfig } = require('./prebuilt-config');
|
|
4
|
+
|
|
5
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
6
|
+
|
|
7
|
+
module.exports = function godotSpmAutolinkingPlugin(context) {
|
|
8
|
+
const selection = resolvePrebuiltConfig(context.appRoot);
|
|
9
|
+
const iosRoot =
|
|
10
|
+
context.autolinking?.project?.ios?.sourceDir ||
|
|
11
|
+
path.join(context.appRoot, 'ios');
|
|
12
|
+
const manifestRoot = path.join(
|
|
13
|
+
context.outputDir,
|
|
14
|
+
'plugins',
|
|
15
|
+
'ReactNativeGodot'
|
|
16
|
+
);
|
|
17
|
+
const relative = (target) =>
|
|
18
|
+
JSON.stringify(
|
|
19
|
+
path.relative(manifestRoot, target).split(path.sep).join('/')
|
|
20
|
+
);
|
|
21
|
+
let manifest = fs.readFileSync(
|
|
22
|
+
path.join(packageRoot, 'Package.swift'),
|
|
23
|
+
'utf8'
|
|
24
|
+
);
|
|
25
|
+
manifest = manifest.replace(
|
|
26
|
+
'// swift-tools-version: 6.0',
|
|
27
|
+
'// swift-tools-version: 6.0\n// Generated by @preeternal/react-native-godot; do not edit.'
|
|
28
|
+
);
|
|
29
|
+
manifest = manifest.replace(
|
|
30
|
+
/let libGodotVersion = .*\nlet libGodotBaseURL = .*\n/,
|
|
31
|
+
''
|
|
32
|
+
);
|
|
33
|
+
manifest = manifest.replace(/path: "cpp"/g, 'path: "root/cpp"');
|
|
34
|
+
manifest = manifest.replace(/path: "ios"/g, 'path: "root/ios"');
|
|
35
|
+
|
|
36
|
+
for (const [target, name] of [
|
|
37
|
+
['LibGodot', 'libgodot'],
|
|
38
|
+
['LibGodotCpp', 'libgodot-cpp'],
|
|
39
|
+
]) {
|
|
40
|
+
const entry = selection.prebuiltFiles.find((item) => item.name === name);
|
|
41
|
+
manifest = manifest.replace(
|
|
42
|
+
new RegExp(
|
|
43
|
+
`\\.binaryTarget\\(\\s*name: "${target}",[\\s\\S]*?\\n \\)`
|
|
44
|
+
),
|
|
45
|
+
`.binaryTarget(\n name: "${target}",\n url: "${entry.base_url}${entry.version}/${entry.filename}",\n checksum: "${entry.shasum}"\n )`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Plugin packages live deeper than ordinary autolinked packages. Resolve all
|
|
50
|
+
// local dependencies from the generated manifest, not the package template.
|
|
51
|
+
const react = context.react?.packageRef;
|
|
52
|
+
const reactDependency = react?.url
|
|
53
|
+
? `.package(name: "${react.name}", url: "${react.url}", exact: "${react.version}")`
|
|
54
|
+
: `.package(name: "ReactNative", path: ${relative(react?.path || path.join(iosRoot, 'build', 'xcframeworks'))})`;
|
|
55
|
+
manifest = manifest.replace(
|
|
56
|
+
/\.package\(name: "ReactNative", path: "[^"]+"\)/,
|
|
57
|
+
reactDependency
|
|
58
|
+
);
|
|
59
|
+
manifest = manifest.replace(
|
|
60
|
+
/\.package\(name: "React-GeneratedCode", path: "[^"]+"\)/,
|
|
61
|
+
`.package(name: "React-GeneratedCode", path: ${relative(path.join(iosRoot, 'build', 'generated', 'ios'))})`
|
|
62
|
+
);
|
|
63
|
+
manifest = manifest.replace(
|
|
64
|
+
/\.package\(name: "RNWorklets", path: "[^"]+"\)/,
|
|
65
|
+
`.package(name: "RNWorklets", path: ${relative(path.join(context.outputDir, 'libs', 'RNWorklets'))})`
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
fs.mkdirSync(manifestRoot, { recursive: true });
|
|
69
|
+
const rootLink = path.join(manifestRoot, 'root');
|
|
70
|
+
fs.rmSync(rootLink, { force: true });
|
|
71
|
+
fs.symlinkSync(packageRoot, rootLink, 'dir');
|
|
72
|
+
fs.writeFileSync(path.join(manifestRoot, 'Package.swift'), manifest);
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
packageDependencies: [{ name: 'ReactNativeGodot', path: manifestRoot }],
|
|
76
|
+
productDependencies: [
|
|
77
|
+
{ name: 'ReactNativeGodot', package: 'ReactNativeGodot' },
|
|
78
|
+
],
|
|
79
|
+
watchPaths: [
|
|
80
|
+
path.join(packageRoot, 'Package.swift'),
|
|
81
|
+
path.join(packageRoot, 'package.json'),
|
|
82
|
+
path.join(packageRoot, 'scripts', 'prebuilt-config.js'),
|
|
83
|
+
path.join(packageRoot, 'scripts', 'spm-autolinking-plugin.js'),
|
|
84
|
+
...(selection.appPackagePath ? [selection.appPackagePath] : []),
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
};
|