A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(native): ship an exported project into the app
esengine5133a32cf454
diff --git a/build-tools/cli.js b/build-tools/cli.jsindex 5adb86009..f7af1928d 100644--- a/build-tools/cli.js+++ b/build-tools/cli.js@@ -171,6 +171,7 @@ program.option('--package', 'Android: also package a signed APK (aapt2 + zipalign + apksigner)', false).option('--host <host>', 'Android --package: js (QuickJS host) or cpp (smoke test)').option('--keystore <path>', 'Android --package: signing keystore (default: the debug one)')+ .option('--content <dir>', 'Ship an exported project (cli exportGame --platform native) as the app content').option('-v, --verbose', 'Verbose output', false).action(async (options) => {logger.setVerbose(options.verbose);@@ -187,6 +188,7 @@ programpackage: options.package,host: options.host,keystore: options.keystore,+ content: options.content,});} catch (err) {logger.error(err.message);diff --git a/build-tools/tasks/native.js b/build-tools/tasks/native.jsindex 33bfbeeea..f5201a4df 100644--- a/build-tools/tasks/native.js+++ b/build-tools/tasks/native.js@@ -10,7 +10,7 @@import path from 'path';import { existsSync, readFileSync, writeFileSync } from 'fs';-import { mkdir, rm } from 'fs/promises';+import { mkdir, rm, cp } from 'fs/promises';import config from '../build.config.js';import * as logger from '../utils/logger.js';import { runCommand, getCpuCount, resolvePython } from '../utils/emscripten.js';@@ -142,7 +142,7 @@ async function buildAndroidHost(options) {if (options.package) {await packageNativeApk({host: options.host || (quickjs ? 'js' : 'cpp'),- dawnBuild, abi, platform, keystore: options.keystore,+ dawnBuild, abi, platform, keystore: options.keystore, content: options.content,});}}@@ -184,6 +184,19 @@ async function assembleXcframework(rootDir, env) {logger.success(`iOS framework: ${XCFRAMEWORK} (${libs.length / 2} slice${libs.length === 2 ? '' : 's'})`);}+// Stage an exported project into the Xcode project's Content/ folder reference —+// the iOS counterpart of the APK's assets/. Replaces whatever was there, so a+// re-export never leaves an old build's files behind.+async function stageIosContent(rootDir, contentDir) {+ const from = path.isAbsolute(contentDir) ? contentDir : path.join(rootDir, contentDir);+ if (!existsSync(from)) throw new Error(`--content dir not found: ${from}`);+ const to = path.join(rootDir, 'native', 'ios', 'Content');+ await rm(to, { recursive: true, force: true });+ await mkdir(to, { recursive: true });+ await cp(from, to, { recursive: true });+ logger.success(`iOS content: native/ios/Content ← ${path.relative(rootDir, from)}`);+}+async function buildIosHost(options) {if (process.platform !== 'darwin') throw new Error('The iOS host builds on macOS only.');const rootDir = config.paths.root;@@ -228,6 +241,7 @@ async function buildIosHost(options) {logger.success(`iOS host: ${path.join(slice.dir, 'libestella_ios.a')}`);await assembleXcframework(rootDir, env);+ if (options.content) await stageIosContent(rootDir, options.content);logger.info('Next: cd native/ios && xcodegen && open EstellaiOS.xcodeproj — pick your Team, then Run.');}diff --git a/build-tools/tasks/nativePackage.js b/build-tools/tasks/nativePackage.jsindex 578d1c702..3b9bc6b13 100644--- a/build-tools/tasks/nativePackage.js+++ b/build-tools/tasks/nativePackage.js@@ -8,7 +8,7 @@import path from 'path';import { existsSync } from 'fs';-import { mkdir, copyFile, rm } from 'fs/promises';+import { mkdir, copyFile, cp, rm } from 'fs/promises';import config from '../build.config.js';import * as logger from '../utils/logger.js';import { runCommand } from '../utils/emscripten.js';@@ -89,8 +89,17 @@ export async function packageNativeApk(options = {}) {'--strip-all', '-o', path.join(libDir, 'libwebgpu_dawn.so'), dawnLib,]);+ // assets/ is what the host's readAsset() sees. `--content <dir>` ships an+ // exported project (cooked assets + manifests + scenes + game.config.json);+ // without it the built-in demo assets ride along instead.let assetsDir = null;- if (host.assets.length) {+ if (options.content) {+ const content = path.isAbsolute(options.content) ? options.content : path.join(rootDir, options.content);+ if (!existsSync(content)) throw new Error(`--content dir not found: ${content}`);+ assetsDir = path.join(staging, 'assets');+ await cp(content, assetsDir, { recursive: true });+ logger.step(`Staging exported content from ${path.relative(rootDir, content)}...`);+ } else if (host.assets.length) {assetsDir = path.join(staging, 'assets');await mkdir(assetsDir, { recursive: true });for (const asset of host.assets) {diff --git a/native/ios/project.yml b/native/ios/project.ymlindex 8be628103..8745ac99f 100644--- a/native/ios/project.yml+++ b/native/ios/project.yml@@ -27,6 +27,12 @@ targets:- path: ../host_js/logo.pngbuildPhase: resourcestype: file+ # An exported project, staged by `cli native --target ios --content <dir>`.+ # A folder reference (not a group) so cooked subdirectories keep their+ # shape — the host reads Content/ first, the bundle root second.+ - path: Content+ buildPhase: resources+ type: foldersettings:base:PRODUCT_BUNDLE_IDENTIFIER: com.estella.EstellaiOS