* 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
125 lines
3.4 KiB
JavaScript
125 lines
3.4 KiB
JavaScript
const fs = require('fs');
|
||
const path = require('path');
|
||
const { execSync } = require('child_process');
|
||
|
||
console.log('🚀 使用 Rollup 构建npm包...');
|
||
|
||
async function main() {
|
||
try {
|
||
// 清理旧的dist目录
|
||
if (fs.existsSync('./dist')) {
|
||
console.log('🧹 清理旧的构建文件...');
|
||
execSync('rimraf ./dist', { stdio: 'inherit' });
|
||
}
|
||
|
||
// 执行Rollup构建
|
||
console.log('📦 执行 Rollup 构建...');
|
||
execSync('npx rollup -c rollup.config.cjs', { stdio: 'inherit' });
|
||
|
||
// 生成package.json
|
||
console.log('📋 生成 package.json...');
|
||
generatePackageJson();
|
||
|
||
// 复制其他文件
|
||
console.log('📁 复制必要文件...');
|
||
copyFiles();
|
||
|
||
// 输出构建结果
|
||
showBuildResults();
|
||
|
||
console.log('✅ 构建完成!');
|
||
console.log('\n🚀 发布命令:');
|
||
console.log('cd dist && npm publish');
|
||
|
||
} catch (error) {
|
||
console.error('❌ 构建失败:', error.message);
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
function generatePackageJson() {
|
||
const sourcePackage = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||
|
||
const distPackage = {
|
||
name: sourcePackage.name,
|
||
version: sourcePackage.version,
|
||
description: sourcePackage.description,
|
||
main: 'index.cjs',
|
||
module: 'index.mjs',
|
||
unpkg: 'index.umd.js',
|
||
types: 'index.d.ts',
|
||
exports: {
|
||
'.': {
|
||
import: './index.mjs',
|
||
require: './index.cjs',
|
||
types: './index.d.ts'
|
||
}
|
||
},
|
||
files: [
|
||
'index.mjs',
|
||
'index.mjs.map',
|
||
'index.cjs',
|
||
'index.cjs.map',
|
||
'index.umd.js',
|
||
'index.umd.js.map',
|
||
'index.es5.js',
|
||
'index.es5.js.map',
|
||
'index.d.ts'
|
||
],
|
||
keywords: [
|
||
'ecs',
|
||
'entity-component-system',
|
||
'game-engine',
|
||
'typescript',
|
||
'cocos-creator',
|
||
'laya',
|
||
'rollup'
|
||
],
|
||
author: sourcePackage.author,
|
||
license: sourcePackage.license,
|
||
repository: sourcePackage.repository,
|
||
bugs: sourcePackage.bugs,
|
||
homepage: sourcePackage.homepage,
|
||
engines: {
|
||
node: '>=16.0.0'
|
||
},
|
||
sideEffects: false
|
||
};
|
||
|
||
fs.writeFileSync('./dist/package.json', JSON.stringify(distPackage, null, 2));
|
||
}
|
||
|
||
function copyFiles() {
|
||
const filesToCopy = [
|
||
// 移除不存在的文件以避免警告
|
||
];
|
||
|
||
filesToCopy.forEach(({ src, dest }) => {
|
||
if (fs.existsSync(src)) {
|
||
fs.copyFileSync(src, dest);
|
||
console.log(` ✓ 复制: ${path.basename(dest)}`);
|
||
} else {
|
||
console.log(` ⚠️ 文件不存在: ${src}`);
|
||
}
|
||
});
|
||
|
||
if (filesToCopy.length === 0) {
|
||
console.log(' ℹ️ 没有需要复制的文件');
|
||
}
|
||
}
|
||
|
||
function showBuildResults() {
|
||
const distDir = './dist';
|
||
const files = ['index.mjs', 'index.cjs', 'index.umd.js', 'index.es5.js', 'index.d.ts'];
|
||
|
||
console.log('\n📊 构建结果:');
|
||
files.forEach(file => {
|
||
const filePath = path.join(distDir, file);
|
||
if (fs.existsSync(filePath)) {
|
||
const size = fs.statSync(filePath).size;
|
||
console.log(` ${file}: ${(size / 1024).toFixed(1)}KB`);
|
||
}
|
||
});
|
||
}
|
||
|
||
main().catch(console.error);
|