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:
YHH
2025-12-26 14:50:35 +08:00
committed by GitHub
parent a84ff902e4
commit 155411e743
1936 changed files with 4147 additions and 11578 deletions

View File

@@ -12,8 +12,7 @@ permissions:
jobs:
ai-helper:
runs-on: ubuntu-latest
# 只在真实用户提到 @ai-helper 时触发,忽略机器人评论
if: |
# å<EFBFBD>ªåœ¨çœŸå®žç”¨æˆ·æ<EFBFBD><EFBFBD>到 @ai-helper 时触å<C2A6>,忽略机器人评è®? if: |
contains(github.event.comment.body, '@ai-helper') &&
github.event.comment.user.type != 'Bot'
steps:
@@ -31,7 +30,7 @@ jobs:
issue_number: context.issue.number
});
// 限制长度,避免超过 token 限制
// é™<EFBFBD>制长度,é<EFBFBD>¿å…<EFBFBD>è¶…è¿?token é™<C3A9>åˆ
const maxLength = 1000;
const truncate = (str, max) => {
if (!str) return '';
@@ -55,8 +54,7 @@ jobs:
评论: ${{ env.COMMENT_BODY }}
请搜索项目代码并提供解决方案。
PROMPT_EOF
请æ<EFBFBD>œç´¢é¡¹ç®ä»£ç <EFBFBD>å¹¶æ<EFBFBD><EFBFBD>ä¾è§£å†³æ¹æ¡ˆã€? PROMPT_EOF
- name: AI Analysis
uses: actions/ai-inference@v1
@@ -66,10 +64,7 @@ jobs:
enable-github-mcp: true
max-tokens: 1500
system-prompt: |
你是 ECS Framework (TypeScript ECS 框架) 的 AI 助手。
主要代码在 packages/core/src。
搜索相关代码后,用中文简洁回答问题,包含问题分析、解决方案和代码引用。
prompt-file: prompt.txt
你是 ECS Framework (TypeScript ECS 框架) çš?AI 助手ã€? 主è¦<C3A8>代ç <C3A7>åœ?packages/framework/core/srcã€? æ<>œç´¢ç¸å…³ä»£ç <C3A7>å<EFBFBD>Žï¼Œç”¨ä¸­æ‡ç®€æ´<C3A6>åžç­”问题,包å<E280A6>«é—®é¢˜åˆ†æž<C3A6>ã€<C3A3>è§£å†³æ¹æ¡ˆåŒä»£ç <C3A7>引用ã€? prompt-file: prompt.txt
- name: Post AI Response
env:

View File

@@ -8,14 +8,14 @@ on:
required: true
type: choice
options:
- 'recent' # 最近 20 个 issue
- 'open' # 所有打开的 issue
- 'recent' # 最�20 �issue
- 'open' # 所有打开�issue
- 'unlabeled' # å<>ªå¤„ç<E2809E>†æ²¡æœ‰æ ‡ç­¾çš„ issue
- 'all' # 所有 issue慎用
- 'all' # 所�issue(慎用)
default: 'recent'
skip_labeled:
description: '跳过已有标签的 issue'
description: '跳过已有标签�issue'
required: false
type: boolean
default: true
@@ -45,20 +45,20 @@ jobs:
echo "📊 开姿‰¹é‡<C3A9>打标签..."
echo "模å¼<C3A5>: $MODE"
echo "跳过已标签: $SKIP_LABELED"
echo "跳过已标� $SKIP_LABELED"
# 获å<C2B7> issue 列表
if [ "$MODE" = "recent" ]; then
echo "📋 获取最近 20 个 issue..."
echo "📋 获å<C2B7>最è¿?20 ä¸?issue..."
ISSUES=$(gh issue list --limit 20 --json number,labels,title,body --jq '.[] | {number, labels: [.labels[].name], title, body}')
elif [ "$MODE" = "open" ]; then
echo "📋 获取所有打开的 issue..."
echo "📋 获å<C2B7>所有打开çš?issue..."
ISSUES=$(gh issue list --state open --json number,labels,title,body --jq '.[] | {number, labels: [.labels[].name], title, body}')
elif [ "$MODE" = "unlabeled" ]; then
echo "📋 获取没有标签的 issue..."
echo "📋 获å<C2B7>没有标签çš?issue..."
ISSUES=$(gh issue list --state all --json number,labels,title,body --jq '.[] | select(.labels | length == 0) | {number, labels: [.labels[].name], title, body}')
else
echo "📋 获取所有 issue限制 100 个)..."
echo "📋 获å<C2B7>所æœ?issue(é™<C3A9>åˆ?100 个)..."
ISSUES=$(gh issue list --state all --limit 100 --json number,labels,title,body --jq '.[] | {number, labels: [.labels[].name], title, body}')
fi
@@ -76,7 +76,7 @@ jobs:
echo "ðŸ”<C5B8> 处ç<E2809E>† Issue #$ISSUE_NUM: $TITLE"
echo " 现有标签: $EXISTING_LABELS"
# 跳过已有标签的 issue
# 跳过已有标签�issue
if [ "$SKIP_LABELED" = "true" ] && [ ! -z "$EXISTING_LABELS" ]; then
echo " â<>­ï¸<C3AF> 跳过(已有标签)"
continue
@@ -85,55 +85,55 @@ jobs:
# 分æž<C3A6>内容并打标签
LABELS_TO_ADD=""
# 检测 bug
# 检�bug
if echo "$TITLE $BODY" | grep -iE "(bug|错误|崩溃|crash|error|exception|问题|fix)" > /dev/null; then
LABELS_TO_ADD="$LABELS_TO_ADD bug"
echo " ðŸ<C3B0> 检测到: bug"
fi
# 检测 feature request
# 检�feature request
if echo "$TITLE $BODY" | grep -iE "(feature|功能|enhancement|improve|优化|建议|新增|添加|add)" > /dev/null; then
LABELS_TO_ADD="$LABELS_TO_ADD enhancement"
echo " ✨ 检测到: enhancement"
echo " �检测到: enhancement"
fi
# 检测 question
if echo "$TITLE $BODY" | grep -iE "(question|疑问|how to|如何|怎么|为什么|why|咨询|\?|)" > /dev/null; then
# 检�question
if echo "$TITLE $BODY" | grep -iE "(question|疑问|how to|如何|怎么|为什么|why|咨询|\?|�" > /dev/null; then
LABELS_TO_ADD="$LABELS_TO_ADD question"
echo " ❓ 检测到: question"
echo " â<EFBFBD>?检测到: question"
fi
# 检测 documentation
# 检�documentation
if echo "$TITLE $BODY" | grep -iE "(doc|文档|readme|guide|tutorial|教程|说明)" > /dev/null; then
LABELS_TO_ADD="$LABELS_TO_ADD documentation"
echo " 📖 检测到: documentation"
fi
# 检测 performance
# 检�performance
if echo "$TITLE $BODY" | grep -iE "(performance|性能|slow|æ…¢|lag|å<>¡é¡¿|optimize|优化)" > /dev/null; then
LABELS_TO_ADD="$LABELS_TO_ADD performance"
echo " ⚡ 检测到: performance"
echo " �检测到: performance"
fi
# 检测 core
if echo "$TITLE $BODY" | grep -iE "(@esengine/ecs-framework|packages/core|core package|核心包)" > /dev/null; then
# 检�core
if echo "$TITLE $BODY" | grep -iE "(@esengine/ecs-framework|packages/framework/core|core package|核心�" > /dev/null; then
LABELS_TO_ADD="$LABELS_TO_ADD core"
echo " 🎯 检测到: core"
fi
# 检测 editor
# 检�editor
if echo "$TITLE $BODY" | grep -iE "(editor|编辑器|tauri)" > /dev/null; then
LABELS_TO_ADD="$LABELS_TO_ADD editor"
echo " 🎨 检测到: editor"
fi
# 检测 network
# 检�network
if echo "$TITLE $BODY" | grep -iE "(network|网络|multiplayer|多人|å<>Œæ­¥)" > /dev/null; then
LABELS_TO_ADD="$LABELS_TO_ADD network"
echo " ðŸŒ<C5B8> 检测到: network"
fi
# 检测 help wanted
# 检�help wanted
if echo "$TITLE $BODY" | grep -iE "(help wanted|需è¦<C3A8>帮助|求助)" > /dev/null; then
LABELS_TO_ADD="$LABELS_TO_ADD help wanted"
echo " 🆘 检测到: help wanted"
@@ -141,12 +141,12 @@ jobs:
# 添加标签
if [ ! -z "$LABELS_TO_ADD" ]; then
echo " ✅ 添加标签: $LABELS_TO_ADD"
echo " �添加标签: $LABELS_TO_ADD"
for label in $LABELS_TO_ADD; do
gh issue edit $ISSUE_NUM --add-label "$label" 2>&1 | grep -v "already exists" || true
done
echo " 💬 添加说明评论..."
gh issue comment $ISSUE_NUM --body $'🤖 自动标签系统检测到此 issue 并添加了相关标签。如有误判,请告知维护者。\n\n🤖 Auto-labeling system detected and labeled this issue. Please let maintainers know if this is incorrect.' || true
gh issue comment $ISSUE_NUM --body $'🤖 自动标签系统检测到�issue 并添加了相关标签。如有误判,请告知维护者。\n\n🤠Auto-labeling system detected and labeled this issue. Please let maintainers know if this is incorrect.' || true
else
echo " ℹï¸<C3AF> 未检测到明确类型"
fi
@@ -156,5 +156,5 @@ jobs:
done
echo ""
echo "✅ 批量标签完成!"
echo "âœ?批é‡<C3A9>标签完æˆ<C3A6>ï¼?
echo "查看结果: https://github.com/${{ github.repository }}/issues"

View File

@@ -42,57 +42,35 @@ jobs:
node-version: '20.x'
cache: 'pnpm'
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
# 缓存 Rust 编译结果
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/engine
cache-on-failure: true
# 缓存 wasm-pack
- name: Cache wasm-pack
uses: actions/cache@v4
with:
path: ~/.cargo/bin/wasm-pack
key: wasm-pack-${{ runner.os }}
- name: Install wasm-pack
run: |
if ! command -v wasm-pack &> /dev/null; then
cargo install wasm-pack
fi
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
# 构建所有包 (使用 Turborepo Remote Cache)
- name: Build all packages
run: pnpm run build
- name: Copy WASM files to ecs-engine-bindgen
# 构建 framework 包 (可独立发布的通用库,无外部依赖)
- name: Build framework packages
run: |
mkdir -p packages/ecs-engine-bindgen/src/wasm
cp packages/engine/pkg/es_engine.js packages/ecs-engine-bindgen/src/wasm/
cp packages/engine/pkg/es_engine.d.ts packages/ecs-engine-bindgen/src/wasm/
cp packages/engine/pkg/es_engine_bg.wasm packages/ecs-engine-bindgen/src/wasm/
cp packages/engine/pkg/es_engine_bg.wasm.d.ts packages/ecs-engine-bindgen/src/wasm/
pnpm --filter @esengine/ecs-framework build
pnpm --filter @esengine/ecs-framework-math build
pnpm --filter @esengine/behavior-tree build
pnpm --filter @esengine/blueprint build
pnpm --filter @esengine/fsm build
pnpm --filter @esengine/timer build
pnpm --filter @esengine/spatial build
pnpm --filter @esengine/procgen build
pnpm --filter @esengine/pathfinding build
pnpm --filter @esengine/network-protocols build
pnpm --filter @esengine/network build
# 类型检查
- name: Type check
run: pnpm run type-check
# 类型检查 (仅 framework 包)
- name: Type check (framework packages)
run: pnpm run type-check:framework
# Lint 检查
- name: Lint check
run: pnpm run lint
# Lint 检查 (仅 framework 包)
- name: Lint check (framework packages)
run: pnpm run lint:framework
# 测试
# 测试 (仅 framework 包)
- name: Run tests with coverage
run: pnpm run test:ci
run: pnpm run test:ci:framework
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
@@ -103,9 +81,11 @@ jobs:
name: codecov-umbrella
fail_ci_if_error: false
# 构建 npm 包
# 构建 npm 包 (core 和 math)
- name: Build npm packages
run: pnpm run build:npm
run: |
pnpm run build:npm:core
pnpm run build:npm:math
# 上传构建产物
- name: Upload build artifacts
@@ -113,6 +93,6 @@ jobs:
with:
name: build-artifacts
path: |
packages/*/dist/
packages/*/bin/
packages/framework/**/dist/
packages/framework/**/bin/
retention-days: 7

View File

@@ -28,7 +28,7 @@ jobs:
- name: Run tests with coverage
run: |
cd packages/core
cd packages/framework/core
pnpm run test:coverage
- name: Upload coverage to Codecov
@@ -36,7 +36,7 @@ jobs:
continue-on-error: true
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./packages/core/coverage/coverage-final.json
files: ./packages/framework/core/coverage/coverage-final.json
flags: core
name: core-coverage
fail_ci_if_error: false
@@ -46,4 +46,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: packages/core/coverage/
path: packages/framework/core/coverage/

View File

@@ -50,7 +50,7 @@ jobs:
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/editor-app/src-tauri
workspaces: packages/editor/editor-app/src-tauri
cache-on-failure: true
- name: Install dependencies (Ubuntu)
@@ -65,7 +65,7 @@ jobs:
- name: Update version in config files (for manual trigger)
if: github.event_name == 'workflow_dispatch'
run: |
cd packages/editor-app
cd packages/editor/editor-app
node -e "const pkg=require('./package.json'); pkg.version='${{ github.event.inputs.version }}'; require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2)+'\n')"
node scripts/sync-version.js
@@ -80,15 +80,15 @@ jobs:
- name: Copy WASM files to ecs-engine-bindgen
shell: bash
run: |
mkdir -p packages/ecs-engine-bindgen/src/wasm
cp packages/engine/pkg/es_engine.js packages/ecs-engine-bindgen/src/wasm/
cp packages/engine/pkg/es_engine.d.ts packages/ecs-engine-bindgen/src/wasm/
cp packages/engine/pkg/es_engine_bg.wasm packages/ecs-engine-bindgen/src/wasm/
cp packages/engine/pkg/es_engine_bg.wasm.d.ts packages/ecs-engine-bindgen/src/wasm/
mkdir -p packages/engine/ecs-engine-bindgen/src/wasm
cp packages/rust/engine/pkg/es_engine.js packages/engine/ecs-engine-bindgen/src/wasm/
cp packages/rust/engine/pkg/es_engine.d.ts packages/engine/ecs-engine-bindgen/src/wasm/
cp packages/rust/engine/pkg/es_engine_bg.wasm packages/engine/ecs-engine-bindgen/src/wasm/
cp packages/rust/engine/pkg/es_engine_bg.wasm.d.ts packages/engine/ecs-engine-bindgen/src/wasm/
- name: Bundle runtime files for Tauri
run: |
cd packages/editor-app
cd packages/editor/editor-app
node scripts/bundle-runtime.mjs
- name: Build Tauri app
@@ -99,7 +99,7 @@ jobs:
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
with:
projectPath: packages/editor-app
projectPath: packages/editor/editor-app
tagName: ${{ github.event_name == 'workflow_dispatch' && format('editor-v{0}', github.event.inputs.version) || github.ref_name }}
releaseName: 'ECS Editor v${{ github.event.inputs.version || github.ref_name }}'
releaseBody: 'See the assets to download this version and install.'
@@ -116,8 +116,8 @@ jobs:
with:
name: windows-unsigned
path: |
packages/editor-app/src-tauri/target/release/bundle/nsis/*.exe
packages/editor-app/src-tauri/target/release/bundle/msi/*.msi
packages/editor/editor-app/src-tauri/target/release/bundle/nsis/*.exe
packages/editor/editor-app/src-tauri/target/release/bundle/msi/*.msi
retention-days: 1
# SignPath 代码签名Windows
@@ -221,7 +221,7 @@ jobs:
- name: Update version files
run: |
cd packages/editor-app
cd packages/editor/editor-app
node -e "const pkg=require('./package.json'); pkg.version='${{ github.event.inputs.version }}'; require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2)+'\n')"
node scripts/sync-version.js
@@ -239,8 +239,8 @@ jobs:
This PR updates the editor version after successful release build.
### Changes
- Updated `packages/editor-app/package.json` → `${{ github.event.inputs.version }}`
- Updated `packages/editor-app/src-tauri/tauri.conf.json` → `${{ github.event.inputs.version }}`
- Updated `packages/editor/editor-app/package.json` → `${{ github.event.inputs.version }}`
- Updated `packages/editor/editor-app/src-tauri/tauri.conf.json` → `${{ github.event.inputs.version }}`
### Release
- [GitHub Release](https://github.com/${{ github.repository }}/releases/tag/editor-v${{ github.event.inputs.version }})

View File

@@ -1,7 +1,7 @@
name: Release NPM Packages
on:
# 标签触发:支持 v* 和 {package}-v* 格式
# 标签触å<EFBFBD>:支æŒ?v* å’?{package}-v* æ ¼å¼<EFBFBD>
# Tag trigger: supports v* and {package}-v* formats
push:
tags:
@@ -20,7 +20,7 @@ on:
workflow_dispatch:
inputs:
package:
description: '选择要发布的包 | Select package to publish'
description: '选æ©è¦<EFBFBD>å<EFBFBD>布的åŒ?| Select package to publish'
required: true
type: choice
options:
@@ -65,7 +65,7 @@ jobs:
TAG="${GITHUB_REF#refs/tags/}"
echo "tag=$TAG" >> $GITHUB_OUTPUT
# 解析格式:v1.0.0 package-v1.0.0
# è§£æž<EFBFBD>æ ¼å¼<EFBFBD>:v1.0.0 æˆ?package-v1.0.0
# Parse format: v1.0.0 or package-v1.0.0
if [[ "$TAG" =~ ^v([0-9]+\.[0-9]+\.[0-9]+.*)$ ]]; then
PACKAGE="core"
@@ -85,7 +85,7 @@ jobs:
echo "📦 Package: $PACKAGE"
echo "📌 Version: $VERSION"
else
# 手动触发:从 package.json 读取并 bump 版本
# æ‰åŠ¨è§¦å<EFBFBD>:从 package.json 读å<C2BB>å¹?bump 版本
# Manual trigger: read from package.json and bump version
PACKAGE="${{ github.event.inputs.package }}"
echo "package=$PACKAGE" >> $GITHUB_OUTPUT
@@ -125,7 +125,7 @@ jobs:
exit 1
fi
echo "Version verified: $EXPECTED_VERSION"
echo "�Version verified: $EXPECTED_VERSION"
- name: Bump version (manual mode)
if: steps.parse.outputs.mode == 'manual'
@@ -147,7 +147,7 @@ jobs:
node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json')); pkg.version='$NEW_VERSION'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)+'\n')"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "📌 Bumped version: $CURRENT $NEW_VERSION"
echo "📌 Bumped version: $CURRENT �$NEW_VERSION"
- name: Set final version
id: version
@@ -161,7 +161,7 @@ jobs:
- name: Build core package (if needed)
if: ${{ steps.parse.outputs.package != 'core' && steps.parse.outputs.package != 'node-editor' && steps.parse.outputs.package != 'worker-generator' }}
run: |
cd packages/core
cd packages/framework/core
pnpm run build
- name: Build node-editor package (if needed for blueprint)
@@ -188,8 +188,7 @@ jobs:
with:
tag_name: ${{ steps.parse.outputs.tag }}
name: "${{ steps.parse.outputs.package }} v${{ steps.version.outputs.value }}"
# 不设置为 latestlatest 保留给编辑器热更新使用
# Don't mark as latest, reserve latest for editor auto-update
# ä¸<EFBFBD>设置为 latest,latest ä¿<C3A4>留给ç¼è¾å™¨çƒ­æ´æ°ä½¿ç”? # Don't mark as latest, reserve latest for editor auto-update
make_latest: false
body: |
## 🚀 @esengine/${{ steps.parse.outputs.package }} v${{ steps.version.outputs.value }}
@@ -218,14 +217,13 @@ jobs:
body: |
## 🚀 Release v${{ steps.version.outputs.value }}
此 PR 更新 `@esengine/${{ steps.parse.outputs.package }}` 包的版本号
æ­?PR æ›´æ–° `@esengine/${{ steps.parse.outputs.package }}` 包的版本å<EFBFBD>?
### å<>˜æ´
- ✅ 已发布到 npm: [@esengine/${{ steps.parse.outputs.package }}@${{ steps.version.outputs.value }}](https://www.npmjs.com/package/@esengine/${{ steps.parse.outputs.package }}/v/${{ steps.version.outputs.value }})
- ✅ 更新 `packages/${{ steps.parse.outputs.package }}/package.json` `${{ steps.version.outputs.value }}`
- âœ?å·²å<C2B2>布到 npm: [@esengine/${{ steps.parse.outputs.package }}@${{ steps.version.outputs.value }}](https://www.npmjs.com/package/@esengine/${{ steps.parse.outputs.package }}/v/${{ steps.version.outputs.value }})
- �更新 `packages/${{ steps.parse.outputs.package }}/package.json` �`${{ steps.version.outputs.value }}`
---
*此 PR 由发布工作流自动创建*
*æ­?PR ç”±å<C2B1>布工作æµ<C3A6>自动åˆå»º*
labels: |
release
${{ steps.parse.outputs.package }}

View File

@@ -6,8 +6,8 @@ on:
- master
- main
paths:
- 'packages/core/src/**'
- 'packages/core/package.json'
- 'packages/framework/core/src/**'
- 'packages/framework/core/package.json'
- '.size-limit.json'
permissions:
@@ -36,7 +36,7 @@ jobs:
- name: Build core package
run: |
cd packages/core
cd packages/framework/core
pnpm run build:npm
- name: Check bundle size