Skip to content

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.

feat(pipeline): a project packages from the command line, with no editor installed

esengine90e0261ce486
diff --git a/.github/workflows/android-canary-apk.yml b/.github/workflows/android-canary-apk.yml
index 6e5d78be3..ae42c395c 100644
--- a/.github/workflows/android-canary-apk.yml
+++ b/.github/workflows/android-canary-apk.yml
@@ -169,7 +169,7 @@ jobs:
name=$(echo "$name" | xargs)
[ -z "$name" ] && continue
echo "::group::packaging $name"
- node desktop/scripts/export-project.mjs "examples/$name" \
+ node pipeline/bin/estella.mjs export "examples/$name" \
--platform android --template template \
--out "build/pkg/$name" --json "build/pkg/$name.json"
APK=$(node -e "process.stdout.write(require('./build/pkg/$name.json').apkFile || '')")
diff --git a/build-tools/cli.js b/build-tools/cli.js
index 114bc8793..f31f2b418 100644
--- a/build-tools/cli.js
+++ b/build-tools/cli.js
@@ -297,6 +297,23 @@ program
logger.printTime(startTime);
});
+// Forwarded rather than reimplemented: the pipeline owns packaging, and its own
+// entry is what CI and a build server call. This is here so someone who already
+// knows `cli.js` does not have to learn a second command to ship a project.
+program
+ .command('export <projectDir>')
+ .description('Package a project (no editor) — see pipeline/bin/estella.mjs for the options')
+ .allowUnknownOption()
+ .helpOption(false)
+ .action(async (projectDir, _opts, command) => {
+ const { spawnSync } = await import('child_process');
+ const bin = path.join(config.paths.root, 'pipeline', 'bin', 'estella.mjs');
+ const result = spawnSync(process.execPath, [bin, 'export', projectDir, ...command.args.slice(1)], {
+ stdio: 'inherit',
+ });
+ process.exit(result.status ?? 1);
+ });
+
program
.command('verify-template <archives...>')
.description('Check published runtime-template archives carry everything a release must')
diff --git a/desktop/scripts/export-project.mjs b/desktop/scripts/export-project.mjs
deleted file mode 100644
index 2cc3e4fcb..000000000
--- a/desktop/scripts/export-project.mjs
+++ /dev/null
@@ -1,266 +0,0 @@
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
-//
-// Package a project the way the editor's "Package Project" does, without the
-// editor: `exportGame` is plain node + esbuild (no electron), so a headless run is
-// just a matter of bundling the TypeScript and calling it.
-//
-// This exists because the native app's content comes from an export, and verifying
-// a platform means packaging real projects for it repeatedly — one example after
-// another. Doing that through the editor UI is not repeatable, and a second export
-// path written by hand would drift from the one every game takes.
-//
-// node desktop/scripts/export-project.mjs <projectDir> [options]
-// --platform <id> web | desktop | wechat | playable | android | ios (default android)
-// --out <dir> output dir (default <projectDir>/dist-<platform>)
-// --scene <path> entry scene, project-relative (default: the project's own)
-// --title <name> app title (default: the project's name)
-// --scripts <path> scripts entry, project-relative (default src/main.ts if present)
-// --template <dir> android/ios: the runtime template to wrap, else the installed one
-// --json <file> also write the result here, for a caller that reads it back
-// --enforce-budget fail (exit 1) when the package is over a size limit
-// --steam-sdk <dir> desktop: a Steamworks SDK whose redistributable ships in the app
-// --steam-appid <id> desktop: also write the Steam depot scripts for this app id
-//
-// Prints the export result as JSON — errors, warnings, and what the package weighs
-// against the limits in force — so a caller can tell a clean package from one that
-// silently dropped half a scene, or from one that will be refused for being too big.
-//
-// The size report rides the result rather than being a second file: one artifact a
-// CI job reads, `result.size`, with the same verdicts the build dialog draws.
-import path from 'node:path';
-import { existsSync, readFileSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs';
-import { fileURLToPath } from 'node:url';
-import { createRequire } from 'node:module';
-import { installedTemplateDir, iosTemplateSources } from '../../build-tools/utils/nativeTemplate.js';
-
-const HERE = path.dirname(fileURLToPath(import.meta.url));
-const DESKTOP = path.join(HERE, '..');
-const REPO = path.join(DESKTOP, '..');
-const PIPELINE = path.join(REPO, 'pipeline');
-
-function parseArgs(argv) {
- const [projectDir, ...rest] = argv;
- if (!projectDir) {
- console.error('usage: node desktop/scripts/export-project.mjs <projectDir> '
- + '[--platform android] [--out dir] [--output package|project] [--template dir] '
- + '[--enforce-budget]');
- process.exit(2);
- }
- const opts = { projectDir: path.resolve(projectDir), platform: 'android' };
- // Options take a value; these do not. Without the distinction a trailing
- // `--enforce-budget` swallows nothing and ends the loop, so a CI job would
- // pass the flag and silently get no gate.
- const FLAGS = new Set(['enforce-budget']);
- for (let i = 0; i < rest.length;) {
- const key = rest[i]?.replace(/^--/, '');
- if (!key) break;
- if (FLAGS.has(key)) {
- opts[key] = true;
- i += 1;
- continue;
- }
- const value = rest[i + 1];
- if (value === undefined) break;
- opts[key] = value;
- i += 2;
- }
- return opts;
-}
-
-/** Which desktop template this machine can also RUN, for --template. */
-const HOST_DESKTOP_OS = process.platform === 'darwin' ? 'macos'
- : process.platform === 'win32' ? 'windows' : 'linux';
-
-const fileUrl = (p) => `file:///${p.replace(/\\/g, '/')}`;
-
-// Bundle exportGame.ts to a temp module and import it. ESM, because the cook reads
-// `import.meta.url` (the basis encoder locates its binary that way) — and with a
-// `require` shim bound to desktop/, because some of its dependencies are CommonJS
-// (pngjs). esbuild itself stays external: the module resolves it at runtime the
-// same way the electron main process does.
-async function loadExportGame() {
- const require = createRequire(path.join(PIPELINE, 'package.json'));
- const esbuild = require('esbuild');
- // Inside the pipeline package, so the bundle's own `import 'esbuild'` resolves
- // the way it does for the module being bundled.
- const dir = mkdtempSync(path.join(PIPELINE, 'src', '.export-'));
- const outfile = path.join(dir, 'exportGame.mjs');
- await esbuild.build({
- entryPoints: [path.join(PIPELINE, 'src', 'export', 'exportGame.ts')],
- outfile, bundle: true, format: 'esm', platform: 'node', target: 'node20',
- // The Basis encoder finds its own .cjs/.wasm through `import.meta.url`,
- // so inlining it makes it look beside the BUNDLE. External keeps the
- // specifier, and the temp dir sits as deep in the package as the cook does.
- external: ['esbuild', 'electron', 'sharp', '../../../build-tools/basis/encoder.mjs'],
- logLevel: 'error',
- banner: {
- js: "import { createRequire as __esCreateRequire } from 'node:module';\n"
- + `const require = __esCreateRequire('${fileUrl(path.join(PIPELINE, 'package.json'))}');\n`,
- },
- });
- const mod = await import(fileUrl(outfile));
- return { exportGame: mod.exportGame, cleanup: () => rmSync(dir, { recursive: true, force: true }) };
-}
-
-/**
- * The editor's own project-format helpers, bundled the same way.
- *
- * Reading the manifest by hand here is how this script drifts from the editor,
- * which is the one thing it exists not to do: orientation was read as a
- * top-level `orientation` field, a key the format does not have, so every
- * project packaged landscape — a 600x1080 shmup included.
- */
-async function loadProjectFormat() {
- const require = createRequire(path.join(PIPELINE, 'package.json'));
- const esbuild = require('esbuild');
- const dir = mkdtempSync(path.join(PIPELINE, '.format-'));
- const outfile = path.join(dir, 'format.mjs');
- await esbuild.build({
- // runtimeConfig re-exports nothing of format's, so both entries are bundled
- // into one module: a headless export that derived the project's settings by
- // hand would be a second answer to what a project MEANS.
- stdin: {
- contents: "export * from './src/project/format';\nexport * from './src/project/runtimeConfig';\n",
- resolveDir: PIPELINE,
- sourcefile: 'projectFormat.ts',
- loader: 'ts',
- },
- outfile, bundle: true, format: 'esm', platform: 'node', target: 'node20',
- external: ['esbuild', 'electron', 'sharp'], logLevel: 'error',
- });
- const mod = await import(fileUrl(outfile));
- rmSync(dir, { recursive: true, force: true });
- return mod;
-}
-
-/** The project's own settings, so a headless export matches what the editor would do. */
-function projectSettings(projectDir) {
- for (const name of ['project.esproject', 'project.esproj', 'project.json']) {
- const file = path.join(projectDir, name);
- if (existsSync(file)) {
- try {
- return JSON.parse(readFileSync(file, 'utf8'));
- } catch {
- return {};
- }
- }
- }
- return {};
-}
-
-function firstExisting(candidates) {
- return candidates.find((c) => existsSync(c));
-}
-
-const opts = parseArgs(process.argv.slice(2));
-const project = projectSettings(opts.projectDir);
-const platform = opts.platform;
-
-const entryScene = opts.scene ?? project.defaultScene ?? (
- firstExisting([
- path.join(opts.projectDir, 'assets', 'scenes', 'main.esscene'),
- path.join(opts.projectDir, 'scenes', 'main.esscene'),
- ])?.slice(opts.projectDir.length + 1).replace(/\\/g, '/')
-);
-if (!entryScene) {
- console.error(`No entry scene found in ${opts.projectDir} (pass --scene <project-relative path>).`);
- process.exit(2);
-}
-
-const scriptsEntry = opts.scripts ?? (existsSync(path.join(opts.projectDir, 'src', 'main.ts'))
- ? 'src/main.ts' : undefined);
-
-const outDir = path.resolve(opts.out ?? path.join(opts.projectDir, `dist-${platform}`));
-
-// The native half the editor resolves through the installed-template store. Named
-// explicitly with --template, else looked up the way the editor does, so a headless
-// export assembles the same package the dialog would rather than content alone.
-const engineVersion = JSON.parse(readFileSync(path.join(DESKTOP, 'package.json'), 'utf8')).version;
-const nativePlatform = platform === 'android' || platform === 'ios';
-const templateDir = nativePlatform
- ? (opts.template
- ? path.resolve(opts.template)
- : firstExisting([installedTemplateDir(engineVersion, platform)]) ?? null)
- : null;
-// Desktop takes a template PER OS, and assembles one app for each it finds: the
-// assembler is pure Node, so a headless run on one machine produces the same set
-// the editor would. --template names one and then it is the only one.
-const desktopTemplates = platform !== 'desktop' ? [] : (opts.template
- ? [{ os: HOST_DESKTOP_OS, dir: path.resolve(opts.template) }]
- : ['windows', 'macos', 'linux'].flatMap((os) => {
- const dir = firstExisting([installedTemplateDir(engineVersion, os)]);
- return dir ? [{ os, dir }] : [];
- }));
-// The engine runtime for this target — the headless half of the editor's
-// `platformRuntimeDirs`. WeChat's is a different build (WXWebAssembly glue, `-t
-// wechat`), and handing it the web one produced either a "runtime not found"
-// failure or a package that could not boot on a device.
-const wasmDir = platform === 'wechat'
- ? firstExisting([
- path.join(DESKTOP, 'public', 'wasm-wechat'),
- path.join(REPO, 'build', 'wasm', 'wechat'),
- ]) ?? path.join(DESKTOP, 'public', 'wasm')
- : path.join(DESKTOP, 'public', 'wasm');
-
-const { resolveOrientation, parseManifest, runtimeConfigOf, cookOptionsOf } = await loadProjectFormat();
-// PARSED, not read by hand: the parser normalizes legacy platform ids and drops
-// values that could not be judged against, and a budget read straight off the JSON
-// here would be the orientation bug again with a different field.
-const manifest = parseManifest(project);
-const sizeBudgetBytes = manifest.packaging?.sizeBudget?.[platform];
-const { exportGame, cleanup } = await loadExportGame();
-let code = 1;
-try {
- const result = await exportGame({
- root: opts.projectDir,
- entryScene,
- scriptsEntry,
- gameHostEntry: path.join(DESKTOP, '..', 'pipeline', 'src', 'runtime', 'gameHost.ts'),
- sdkDistDir: path.join(REPO, 'sdk', 'dist'),
- wasmDir,
- outDir,
- platform,
- title: opts.title ?? project.name ?? path.basename(opts.projectDir),
- orientation: resolveOrientation(project),
- // The project's OWN settings, through the editor's own derivation: without
- // it a headless package ships every setting at its default while claiming
- // to be the package the dialog makes.
- runtime: runtimeConfigOf(manifest),
- // Same bargain, one field over: the cook flags are ALSO the project's
- // own, and passing none of them shipped every automated package raw.
- ...cookOptionsOf(manifest),
- androidTemplate: platform === 'android' ? templateDir : null,
- desktopTemplates,
- desktopChannel: opts['steam-appid'] ? 'steam' : undefined,
- steam: (opts['steam-appid'] || opts['steam-sdk'])
- ? { appId: Number(opts['steam-appid']) || undefined, sdkPath: opts['steam-sdk'] }
- : undefined,
- iosSources: platform === 'ios' && templateDir ? iosTemplateSources(templateDir) : null,
- androidOutput: opts.output === 'project' ? 'project' : undefined,
- sizeBudgetBytes,
- });
- const report = { ...result, outDir };
- console.log(JSON.stringify(report, null, 2));
- // stdout carries the cook's own progress too, so a caller that wants the
- // result mechanically cannot just redirect it.
- if (opts.json) writeFileSync(path.resolve(opts.json), `${JSON.stringify(report, null, 2)}\n`);
- code = result.ok ? 0 : 1;
-
- // The gate is opt-in. A package over its limit is still a package — it built,
- // it runs, and whether that is a release-blocking fact belongs to the caller,
- // not to the exporter. Said in prose on stderr as well as in the exit code,
- // because a CI log that only goes red tells nobody which limit or by how much.
- const over = (result.size?.verdicts ?? []).filter((v) => v.status === 'over');
- for (const v of over) {
- const mb = (n) => `${(n / 1024 / 1024).toFixed(2)}MB`;
- console.error(`size budget: ${v.budget.scope} is ${mb(v.measuredBytes)}, over the `
- + `${mb(v.budget.maxBytes)} limit (${v.budget.note}).`);
- }
- if (over.length > 0 && opts['enforce-budget']) code = 1;
-} finally {
- // Before the exit, not after: process.exit() in the try block would skip this
- // and leave the bundle dir behind.
- cleanup();
-}
-process.exit(code);
diff --git a/desktop/scripts/launch-export.mjs b/desktop/scripts/launch-export.mjs
index d632296f8..b3da22fec 100644
--- a/desktop/scripts/launch-export.mjs
+++ b/desktop/scripts/launch-export.mjs
@@ -3,7 +3,7 @@
/**
* @file launch-export.mjs — a packaged web build actually starts, and draws.
*
- * Exporting is checked (export-project reports errors, warnings and size) and
+ * Exporting is checked (the pipeline reports errors, warnings and size) and
* the ENGINE is checked (verify:render). Between them sits the thing nobody ran
* in CI: the package itself, opened the way a player opens it. That gap is
* where a wrong export default, a missing runtime config or a path that only
diff --git a/docs/astro/src/content/docs/publishing/overview.mdx b/docs/astro/src/content/docs/publishing/overview.mdx
index b6f0d2a1a..d8b975da1 100644
--- a/docs/astro/src/content/docs/publishing/overview.mdx
+++ b/docs/astro/src/content/docs/publishing/overview.mdx
@@ -378,7 +378,7 @@ platform's own limit.
The headless exporter carries the same report on its result and can fail on it:
```bash
-node desktop/scripts/export-project.mjs ./my-game \
+node pipeline/bin/estella.mjs export ./my-game \
--platform wechat --json report.json --enforce-budget
```
diff --git a/docs/astro/src/content/docs/zh-cn/publishing/overview.mdx b/docs/astro/src/content/docs/zh-cn/publishing/overview.mdx
index e4c9e35a9..6e01b80ea 100644
--- a/docs/astro/src/content/docs/zh-cn/publishing/overview.mdx
+++ b/docs/astro/src/content/docs/zh-cn/publishing/overview.mdx
@@ -296,7 +296,7 @@ which a block-compressed texture must be
无头导出器的结果里带着同一份报告,并且可以据此失败:
```bash
-node desktop/scripts/export-project.mjs ./my-game \
+node pipeline/bin/estella.mjs export ./my-game \
--platform wechat --json report.json --enforce-budget
```
diff --git a/pipeline/bin/estella.mjs b/pipeline/bin/estella.mjs
new file mode 100644
index 000000000..64c5c7d7c
--- /dev/null
+++ b/pipeline/bin/estella.mjs
@@ -0,0 +1,229 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+//
+// Package a project without the editor. `--help` states the options.
+import path from 'node:path';
+import { existsSync, readFileSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { createRequire } from 'node:module';
+import { installedTemplateDir, iosTemplateSources } from '../../build-tools/utils/nativeTemplate.js';
+
+const HERE = path.dirname(fileURLToPath(import.meta.url));
+const PIPELINE = path.join(HERE, '..');
+const REPO = path.join(PIPELINE, '..');
+
+const USAGE = `usage: node pipeline/bin/estella.mjs export <projectDir> [options]
+
+ --platform <id> web | desktop | wechat | playable | android | ios (default web)
+ --out <dir> output dir (default <projectDir>/dist-<platform>)
+ --scene <path> entry scene, project-relative (default: the project's own)
+ --title <name> app title (default: the project's name)
+ --scripts <path> scripts entry, project-relative (default src/main.ts if present)
+ --template <dir> android/ios/desktop: the runtime template to wrap, else the installed one
+ --output project android: emit a Gradle project instead of an apk
+ --json <file> also write the result here, for a caller that reads it back
+ --enforce-budget fail (exit 1) when the package is over a size limit
+ --steam-sdk <dir> desktop: a Steamworks SDK whose redistributable ships in the app
+ --steam-appid <id> desktop: also write the Steam depot scripts for this app id
+
+The result is printed as JSON: errors, warnings, and what the package weighs
+against the limits in force. The size report rides the result rather than being a
+second file — \`result.size\` carries the verdicts the build dialog draws, so CI
+and the editor cannot disagree about whether a build fits.`;
+
+/** Options take a value; these do not — without the distinction a trailing flag
+ * swallows nothing, ends the loop, and a CI job silently gets no gate. */
+const FLAGS = new Set(['enforce-budget']);
+
+function parseArgs(argv) {
+ const [command, projectDir, ...rest] = argv;
+ if (command === '--help' || command === '-h' || command === 'help') {
+ console.log(USAGE);
+ process.exit(0);
+ }
+ if (command !== 'export' || !projectDir) {
+ console.error(USAGE);
+ process.exit(2);
+ }
+ const opts = { projectDir: path.resolve(projectDir), platform: 'web' };
+ for (let i = 0; i < rest.length;) {
+ const key = rest[i]?.replace(/^--/, '');
+ if (!key) break;
+ if (FLAGS.has(key)) { opts[key] = true; i += 1; continue; }
+ const value = rest[i + 1];
+ if (value === undefined) break;
+ opts[key] = value;
+ i += 2;
+ }
+ return opts;
+}
+
+const firstExisting = (candidates) => candidates.find((c) => c && existsSync(c));
+const fileUrl = (p) => `file:///${p.replace(/\\/g, '/')}`;
+
+/** Which desktop template this machine can also RUN, for --template. */
+const HOST_DESKTOP_OS = process.platform === 'darwin' ? 'macos'
+ : process.platform === 'win32' ? 'windows' : 'linux';
+
+/**
+ * Bundle a pipeline entry to a temp module and import it. ESM, because the cook
+ * reads `import.meta.url` (the basis encoder locates its binary that way) — and
+ * with a `require` shim, because some dependencies are CommonJS (pngjs). esbuild
+ * itself stays external and resolves at runtime.
+ */
+async function loadPipeline(entry, outName) {
+ const require = createRequire(path.join(PIPELINE, 'package.json'));
+ const esbuild = require('esbuild');
+ // As deep in the package as the cook is: the Basis encoder is kept external so
+ // it finds its own .cjs/.wasm, which means its relative specifier has to
+ // resolve from the temp dir the same way it does from the cook.
+ const dir = mkdtempSync(path.join(PIPELINE, 'src', '.build-'));
+ const outfile = path.join(dir, outName);
+ await esbuild.build({
+ entryPoints: [entry],
+ outfile,
+ bundle: true,
+ format: 'esm',
+ platform: 'node',
+ target: 'node20',
+ external: ['esbuild', 'electron', 'sharp', '../../../build-tools/basis/encoder.mjs'],
+ logLevel: 'error',
+ banner: {
+ js: "import { createRequire as __esCreateRequire } from 'node:module';\n"
+ + `const require = __esCreateRequire('${fileUrl(path.join(PIPELINE, 'package.json'))}');\n`,
+ },
+ });
+ const mod = await import(fileUrl(outfile));
+ return { mod, cleanup: () => rmSync(dir, { recursive: true, force: true }) };
+}
+
+/** The project's raw settings file, for the fields read before the parser runs. */
+function projectSettings(projectDir) {
+ for (const name of ['project.esproject', 'project.esproj', 'project.json']) {
+ const file = path.join(projectDir, name);
+ if (existsSync(file)) {
+ try {
+ return JSON.parse(readFileSync(file, 'utf8'));
+ } catch {
+ return {};
+ }
+ }
+ }
+ return {};
+}
+
+/**
+ * The engine runtime for this target. The build tree is preferred over the copy
+ * synced into the editor's public/, so a machine that built the engine and never
+ * built the editor can still package. WeChat's is a different build (WXWebAssembly
+ * glue) — handing it the web one produces a package that cannot boot on a device.
+ */
+function engineRuntimeDir(platform) {
+ const dirs = platform === 'wechat'
+ ? [path.join(REPO, 'build', 'wasm', 'wechat'), path.join(REPO, 'desktop', 'public', 'wasm-wechat')]
+ : [path.join(REPO, 'build', 'wasm', 'web'), path.join(REPO, 'desktop', 'public', 'wasm')];
+ return firstExisting(dirs) ?? dirs[dirs.length - 1];
+}
+
+const opts = parseArgs(process.argv.slice(2));
+const project = projectSettings(opts.projectDir);
+const platform = opts.platform;
+
+const entryScene = opts.scene ?? project.defaultScene ?? (
+ firstExisting([
+ path.join(opts.projectDir, 'assets', 'scenes', 'main.esscene'),
+ path.join(opts.projectDir, 'scenes', 'main.esscene'),
+ ])?.slice(opts.projectDir.length + 1).replace(/\\/g, '/')
+);
+if (!entryScene) {
+ console.error(`No entry scene found in ${opts.projectDir} (pass --scene <project-relative path>).`);
+ process.exit(2);
+}
+
+const scriptsEntry = opts.scripts ?? (existsSync(path.join(opts.projectDir, 'src', 'main.ts'))
+ ? 'src/main.ts' : undefined);
+
+const outDir = path.resolve(opts.out ?? path.join(opts.projectDir, `dist-${platform}`));
+
+// The editor's package.json is the version of the whole product, and the runtime
+// templates are stored per version.
+const engineVersion = JSON.parse(readFileSync(path.join(REPO, 'desktop', 'package.json'), 'utf8')).version;
+const nativePlatform = platform === 'android' || platform === 'ios';
+const templateDir = nativePlatform
+ ? (opts.template ? path.resolve(opts.template) : firstExisting([installedTemplateDir(engineVersion, platform)]) ?? null)
+ : null;
+// Desktop takes a template PER OS and assembles one app for each it finds; the
+// assembler is pure Node, so one machine produces the set the editor would.
+// --template names one and then it is the only one.
+const desktopTemplates = platform !== 'desktop' ? [] : (opts.template
+ ? [{ os: HOST_DESKTOP_OS, dir: path.resolve(opts.template) }]
+ : ['windows', 'macos', 'linux'].flatMap((os) => {
+ const dir = firstExisting([installedTemplateDir(engineVersion, os)]);
+ return dir ? [{ os, dir }] : [];
+ }));
+
+const { mod: fmt, cleanup: cleanupFmt } = await loadPipeline(
+ path.join(PIPELINE, 'src', 'project', 'index.ts'), 'projectFormat.mjs');
+const { resolveOrientation, parseManifest, runtimeConfigOf, cookOptionsOf } = fmt;
+// PARSED, not read by hand: the parser normalizes legacy platform ids and drops
+// values that could not be judged against. A setting read straight off the JSON
+// here is a second answer to what a project means.
+const manifest = parseManifest(project);
+const sizeBudgetBytes = manifest.packaging?.sizeBudget?.[platform];
+
+const { mod: exporter, cleanup: cleanupExport } = await loadPipeline(
+ path.join(PIPELINE, 'src', 'export', 'exportGame.ts'), 'exportGame.mjs');
+
+let code = 1;
+try {
+ const result = await exporter.exportGame({
+ root: opts.projectDir,
+ entryScene,
+ scriptsEntry,
+ gameHostEntry: path.join(PIPELINE, 'src', 'runtime', 'gameHost.ts'),
+ playableHostEntry: path.join(PIPELINE, 'src', 'runtime', 'playableHost.ts'),
+ sdkDistDir: path.join(REPO, 'sdk', 'dist'),
+ wasmDir: engineRuntimeDir(platform),
+ outDir,
+ platform,
+ title: opts.title ?? project.name ?? path.basename(opts.projectDir),
+ orientation: resolveOrientation(project),
+ // The project's OWN settings, through the same derivation the editor uses:
+ // without it a headless package ships every setting at its default while
+ // claiming to be the package the dialog makes.
+ runtime: runtimeConfigOf(manifest),
+ ...cookOptionsOf(manifest),
+ androidTemplate: platform === 'android' ? templateDir : null,
+ desktopTemplates,
+ desktopChannel: opts['steam-appid'] ? 'steam' : undefined,
+ steam: (opts['steam-appid'] || opts['steam-sdk'])
+ ? { appId: Number(opts['steam-appid']) || undefined, sdkPath: opts['steam-sdk'] }
+ : undefined,
+ iosSources: platform === 'ios' && templateDir ? iosTemplateSources(templateDir) : null,
+ androidOutput: opts.output === 'project' ? 'project' : undefined,
+ sizeBudgetBytes,
+ });
+ const report = { ...result, outDir };
+ console.log(JSON.stringify(report, null, 2));
+ // stdout carries the cook's own progress too, so a caller that wants the result
+ // mechanically cannot just redirect it.
+ if (opts.json) writeFileSync(path.resolve(opts.json), `${JSON.stringify(report, null, 2)}\n`);
+ code = result.ok ? 0 : 1;
+
+ // The gate is opt-in. A package over its limit is still a package — whether that
+ // blocks a release belongs to the caller. Said in prose on stderr as well as in
+ // the exit code, because a CI log that only goes red tells nobody which limit.
+ const over = (result.size?.verdicts ?? []).filter((v) => v.status === 'over');
+ for (const v of over) {
+ const mb = (n) => `${(n / 1024 / 1024).toFixed(2)}MB`;
+ console.error(`size budget: ${v.budget.scope} is ${mb(v.measuredBytes)}, over the `
+ + `${mb(v.budget.maxBytes)} limit (${v.budget.note}).`);
+ }
+ if (over.length > 0 && opts['enforce-budget']) code = 1;
+} finally {
+ // Before the exit, not after: process.exit() in the try block would skip this
+ // and leave the bundle dirs behind.
+ cleanupExport();
+ cleanupFmt();
+}
+process.exit(code);
diff --git a/pipeline/src/project/index.ts b/pipeline/src/project/index.ts
new file mode 100644
index 000000000..35b3f6396
--- /dev/null
+++ b/pipeline/src/project/index.ts
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file What a project is: its manifest, the platforms it can target, the
+ * runtime settings derived from it, and the settings its assets carry.
+ */
+export * from './format';
+export * from './platforms';
+export * from './runtimeConfig';
+export * from './sizeBudget';
+export * from './targetSupport';
+export * from './importSettings';
+export * from './pluginPaths';
+export * from './readProject';
diff --git a/tools/verify-desktop-render.mjs b/tools/verify-desktop-render.mjs
index 27fc02f48..34ea371c7 100644
--- a/tools/verify-desktop-render.mjs
+++ b/tools/verify-desktop-render.mjs
@@ -87,7 +87,7 @@ function packageAndRun(project, templateDir, work) {
const out = path.join(work, path.basename(project));
mkdirSync(out, { recursive: true });
execFileSync(process.execPath, [
- path.join(ROOT, 'desktop', 'scripts', 'export-project.mjs'), project,
+ path.join(ROOT, 'pipeline', 'bin', 'estella.mjs'), 'export', project,
'--platform', 'desktop', '--out', out, '--template', templateDir,
], { cwd: ROOT, stdio: 'inherit' });
diff --git a/tools/verify-golden.mjs b/tools/verify-golden.mjs
index e9b74d502..d706ba8aa 100644
--- a/tools/verify-golden.mjs
+++ b/tools/verify-golden.mjs
@@ -145,7 +145,7 @@ for (const { id, target } of pairs) {
rmSync(out, { recursive: true, force: true });
const exported = spawnSync(process.execPath, [
- path.join(DESKTOP, 'scripts', 'export-project.mjs'), projectDir(id),
+ path.join(ROOT, 'pipeline', 'bin', 'estella.mjs'), 'export', projectDir(id),
'--platform', target, '--out', out,
], { encoding: 'utf8', cwd: ROOT });
diff --git a/tools/verify-native-boot.mjs b/tools/verify-native-boot.mjs
index 82701cf09..43802fb76 100644
--- a/tools/verify-native-boot.mjs
+++ b/tools/verify-native-boot.mjs
@@ -678,7 +678,7 @@ function packageExample(driver, name, opts) {
rmSync(work, { recursive: true, force: true });
mkdirSync(work, { recursive: true });
quietly('export', process.execPath, [
- path.join(ROOT, 'desktop', 'scripts', 'export-project.mjs'),
+ path.join(ROOT, 'pipeline', 'bin', 'estella.mjs'), 'export',
path.join(ROOT, 'examples', name),
'--platform', driver.name,
'--template', opts.template,
diff --git a/tools/verify-playthrough.mjs b/tools/verify-playthrough.mjs
index d980cff7d..0628ffa66 100644
--- a/tools/verify-playthrough.mjs
+++ b/tools/verify-playthrough.mjs
@@ -48,7 +48,7 @@ mkdirSync(WORK, { recursive: true });
const out = path.join(WORK, PROJECT);
const exported = spawnSync(process.execPath, [
- path.join(DESKTOP, 'scripts', 'export-project.mjs'), projectDir,
+ path.join(ROOT, 'pipeline', 'bin', 'estella.mjs'), 'export', projectDir,
'--platform', 'web', '--out', out,
], { encoding: 'utf8', cwd: ROOT });