refactor: reorganize package structure and decouple framework packages (#338)
* refactor: reorganize package structure and decouple framework packages ## Package Structure Reorganization - Reorganized 55 packages into categorized subdirectories: - packages/framework/ - Generic framework (Laya/Cocos compatible) - packages/engine/ - ESEngine core modules - packages/rendering/ - Rendering modules (WASM dependent) - packages/physics/ - Physics modules - packages/streaming/ - World streaming - packages/network-ext/ - Network extensions - packages/editor/ - Editor framework and plugins - packages/rust/ - Rust WASM engine - packages/tools/ - Build tools and SDK ## Framework Package Decoupling - Decoupled behavior-tree and blueprint packages from ESEngine dependencies - Created abstracted interfaces (IBTAssetManager, IBehaviorTreeAssetContent) - ESEngine-specific code moved to esengine/ subpath exports - Framework packages now usable with Cocos/Laya without ESEngine ## CI Configuration - Updated CI to only type-check and lint framework packages - Added type-check:framework and lint:framework scripts ## Breaking Changes - Package import paths changed due to directory reorganization - ESEngine integrations now use subpath imports (e.g., '@esengine/behavior-tree/esengine') * fix: update es-engine file path after directory reorganization * docs: update README to focus on framework over engine * ci: only build framework packages, remove Rust/WASM dependencies * fix: remove esengine subpath from behavior-tree and blueprint builds ESEngine integration code will only be available in full engine builds. Framework packages are now purely engine-agnostic. * fix: move network-protocols to framework, build both in CI * fix: update workflow paths from packages/core to packages/framework/core * fix: exclude esengine folder from type-check in behavior-tree and blueprint * fix: update network tsconfig references to new paths * fix: add test:ci:framework to only test framework packages in CI * fix: only build core and math npm packages in CI * fix: exclude test files from CodeQL and fix string escaping security issue
This commit is contained in:
125
packages/physics/rapier2d/scripts/gen-src.mjs
Normal file
125
packages/physics/rapier2d/scripts/gen-src.mjs
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Generate 2D-specific source code from rapier.js source.
|
||||
* 从 rapier.js 源码生成 2D 专用代码。
|
||||
*
|
||||
* This script:
|
||||
* 1. Copies TypeScript source from rapier.js/src.ts
|
||||
* 2. Removes #if DIM3 ... #endif blocks (keeps only 2D code)
|
||||
* 3. Overwrites raw.ts and init.ts with 2D-specific versions
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync, readdirSync, mkdirSync, cpSync, existsSync, renameSync } from 'fs';
|
||||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const packageRoot = join(__dirname, '..');
|
||||
const rapierRoot = join(packageRoot, '..', '..', 'thirdparty', 'rapier.js');
|
||||
const srcTsDir = join(rapierRoot, 'src.ts');
|
||||
const src2dDir = join(rapierRoot, 'rapier-compat', 'src2d');
|
||||
const outputDir = join(packageRoot, 'src');
|
||||
|
||||
// Check if rapier.js exists
|
||||
if (!existsSync(srcTsDir)) {
|
||||
console.error(`Error: rapier.js source not found at ${rapierRoot}`);
|
||||
console.error('Please clone https://github.com/esengine/rapier.js.git to thirdparty/rapier.js');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove #if DIM3 ... #endif blocks from source code
|
||||
*/
|
||||
function removeDim3Blocks(content) {
|
||||
// Remove lines between #if DIM3 and #endif (inclusive)
|
||||
const lines = content.split('\n');
|
||||
const result = [];
|
||||
let skipDepth = 0;
|
||||
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
|
||||
if (trimmed.startsWith('//#if DIM3') || trimmed.startsWith('// #if DIM3')) {
|
||||
skipDepth++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (skipDepth > 0 && (trimmed.startsWith('//#endif') || trimmed.startsWith('// #endif'))) {
|
||||
skipDepth--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (skipDepth === 0) {
|
||||
// Also remove #if DIM2 and its #endif (but keep the content)
|
||||
if (trimmed.startsWith('//#if DIM2') || trimmed.startsWith('// #if DIM2')) {
|
||||
continue;
|
||||
}
|
||||
if (trimmed.startsWith('//#endif') || trimmed.startsWith('// #endif')) {
|
||||
continue;
|
||||
}
|
||||
result.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
return result.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a single TypeScript file
|
||||
*/
|
||||
function processFile(srcPath, destPath) {
|
||||
const content = readFileSync(srcPath, 'utf-8');
|
||||
const processed = removeDim3Blocks(content);
|
||||
writeFileSync(destPath, processed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively copy and process directory
|
||||
*/
|
||||
function processDirectory(srcDir, destDir) {
|
||||
mkdirSync(destDir, { recursive: true });
|
||||
|
||||
const entries = readdirSync(srcDir, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const srcPath = join(srcDir, entry.name);
|
||||
const destPath = join(destDir, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
processDirectory(srcPath, destPath);
|
||||
} else if (entry.name.endsWith('.ts')) {
|
||||
processFile(srcPath, destPath);
|
||||
console.log(`Processed: ${entry.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main
|
||||
console.log('Generating 2D source code...');
|
||||
console.log(`Source: ${srcTsDir}`);
|
||||
console.log(`Output: ${outputDir}`);
|
||||
|
||||
// Step 1: Copy and process src.ts directory
|
||||
processDirectory(srcTsDir, outputDir);
|
||||
|
||||
// Step 2: Overwrite with 2D-specific files (raw.ts, init.ts)
|
||||
if (existsSync(src2dDir)) {
|
||||
const entries = readdirSync(src2dDir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (entry.isFile() && entry.name.endsWith('.ts')) {
|
||||
const srcPath = join(src2dDir, entry.name);
|
||||
const destPath = join(outputDir, entry.name);
|
||||
cpSync(srcPath, destPath);
|
||||
console.log(`Overwrote: ${entry.name} (2D-specific)`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Rename rapier.ts to index.ts
|
||||
const rapierTs = join(outputDir, 'rapier.ts');
|
||||
const indexTs = join(outputDir, 'index.ts');
|
||||
if (existsSync(rapierTs)) {
|
||||
renameSync(rapierTs, indexTs);
|
||||
console.log('Renamed: rapier.ts -> index.ts');
|
||||
}
|
||||
|
||||
console.log('Done!');
|
||||
Reference in New Issue
Block a user