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: add type-check validation for all example projects
esenginedff3819cb56d
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex b1a2718e7..02a876597 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -126,6 +126,9 @@ jobs:- name: Type-check Editorrun: pnpm exec tsc --noEmit -p editor/tsconfig.json+ - name: Type-check Examples+ run: node build-tools/cli.js check-examples+- name: Run SDK testsrun: pnpm --filter ./sdk exec vitest rundiff --git a/build-tools/cli.js b/build-tools/cli.jsindex 560a35934..53ed418e8 100644--- a/build-tools/cli.js+++ b/build-tools/cli.js@@ -15,6 +15,7 @@ import { startWatch } from './tasks/watch.js';import { BuildManifest } from './manifest.js';import { handleBuildError } from './utils/errorHelp.js';import { zipExamples } from './tasks/examples.js';+import { checkExamples } from './tasks/check-examples.js';program.name('esengine-build')@@ -202,6 +203,16 @@ programlogger.printTime(Date.now() - startTime);});+program+ .command('check-examples')+ .description('Type-check all example projects against current SDK types')+ .action(async () => {+ logger.header('Check Examples');+ const startTime = Date.now();+ await checkExamples(config.paths.root);+ logger.printTime(startTime);+ });+program.command('toolchain').description('Package local emsdk + cmake into Tauri resources for bundling')diff --git a/build-tools/tasks/check-examples.js b/build-tools/tasks/check-examples.jsnew file mode 100644index 000000000..9449758eb--- /dev/null+++ b/build-tools/tasks/check-examples.js@@ -0,0 +1,125 @@+/**+ * @file check-examples.js+ * @brief Type-check all example projects against current SDK/editor types+ */++import { existsSync, readdirSync, statSync, mkdirSync, symlinkSync, rmSync, lstatSync, unlinkSync } from 'fs';+import path from 'path';+import { execSync } from 'child_process';+import { fileURLToPath } from 'url';+import * as logger from '../utils/logger.js';++const EXAMPLES_DIR = 'examples';++function discoverExamples(rootDir) {+ const examplesPath = path.join(rootDir, EXAMPLES_DIR);+ if (!existsSync(examplesPath)) return [];++ return readdirSync(examplesPath)+ .filter(entry => {+ const fullPath = path.join(examplesPath, entry);+ return statSync(fullPath).isDirectory() &&+ existsSync(path.join(fullPath, 'tsconfig.json')) &&+ existsSync(path.join(fullPath, 'src'));+ })+ .map(name => ({ name, dir: path.join(rootDir, EXAMPLES_DIR, name) }));+}++function setupTypeLinks(exampleDir, rootDir) {+ const sdkDist = path.join(rootDir, 'sdk', 'dist');+ const editorDist = path.join(rootDir, 'editor', 'dist');++ if (!existsSync(sdkDist)) {+ throw new Error(`SDK dist not found at ${sdkDist}. Run "pnpm --filter ./sdk build" first.`);+ }++ const esengineDir = path.join(exampleDir, '.esengine');+ const sdkLink = path.join(esengineDir, 'sdk');+ const editorLink = path.join(esengineDir, 'editor');++ mkdirSync(esengineDir, { recursive: true });++ if (!existsSync(sdkLink)) {+ symlinkSync(sdkDist, sdkLink, 'dir');+ }++ if (!existsSync(editorLink) && existsSync(editorDist)) {+ symlinkSync(editorDist, editorLink, 'dir');+ }+}++function isSymlinkOrExists(p) {+ try { lstatSync(p); return true; } catch { return false; }+}++function cleanTypeLinks(exampleDir) {+ const sdkLink = path.join(exampleDir, '.esengine', 'sdk');+ const editorLink = path.join(exampleDir, '.esengine', 'editor');++ try { if (isSymlinkOrExists(sdkLink)) unlinkSync(sdkLink); } catch {}+ try { if (isSymlinkOrExists(editorLink)) unlinkSync(editorLink); } catch {}+}++export async function checkExamples(rootDir) {+ logger.step('Type-checking example projects...');++ const examples = discoverExamples(rootDir);+ if (examples.length === 0) {+ logger.warn('No example projects found');+ return { passed: 0, failed: 0, errors: [] };+ }++ const sdkDist = path.join(rootDir, 'sdk', 'dist');+ if (!existsSync(sdkDist)) {+ logger.error('SDK dist not found. Build SDK first: pnpm --filter ./sdk build');+ process.exit(1);+ }++ const tscCandidates = [+ path.join(rootDir, 'node_modules', 'typescript', 'bin', 'tsc'),+ path.join(rootDir, 'sdk', 'node_modules', 'typescript', 'bin', 'tsc'),+ path.join(rootDir, 'editor', 'node_modules', 'typescript', 'bin', 'tsc'),+ ];+ const tscBin = tscCandidates.find(p => existsSync(p));+ if (!tscBin) {+ logger.error('TypeScript not found. Run "pnpm install" first.');+ process.exit(1);+ }++ const results = { passed: 0, failed: 0, errors: [] };++ for (const example of examples) {+ try {+ setupTypeLinks(example.dir, rootDir);+ execSync(`node ${tscBin} --noEmit`, {+ cwd: example.dir,+ stdio: 'pipe',+ timeout: 30000,+ });+ logger.success(example.name);+ results.passed++;+ } catch (err) {+ const stderr = err.stdout?.toString() || err.stderr?.toString() || err.message;+ logger.error(`${example.name}`);+ const lines = stderr.split('\n').filter(l => l.includes('error TS'));+ for (const line of lines.slice(0, 10)) {+ logger.error(` ${line.trim()}`);+ }+ if (lines.length > 10) {+ logger.error(` ... and ${lines.length - 10} more errors`);+ }+ results.failed++;+ results.errors.push({ name: example.name, errors: lines });+ } finally {+ cleanTypeLinks(example.dir);+ }+ }++ logger.step(`Results: ${results.passed} passed, ${results.failed} failed out of ${examples.length} examples`);++ if (results.failed > 0) {+ process.exitCode = 1;+ }++ return results;+}diff --git a/examples/event-system/src/systems/score.ts b/examples/event-system/src/systems/score.tsindex 0b964f819..a6dbcc3d0 100644--- a/examples/event-system/src/systems/score.ts+++ b/examples/event-system/src/systems/score.ts@@ -7,7 +7,7 @@ export const scoreSystem = defineSystem([EventReader(CollectEventDef), ResMut(Score)],(reader, score) => {for (const event of reader) {- score.value += event.points;+ score.modify(s => { s.value += event.points; });}},{ name: 'ScoreSystem' }