ts-rs 绑定统一走 cargo test export_bindings,删除退役类型导出

- asset_kind.rs:`GameCreationAppAssetKind` 自带 `#[ts(export, export_to = ../apps/ai-game-creator-shell/src/contracts/generated/)]`,`cargo test export_bindings` 即可复现生成文件
- binding.rs:删除手写的 `exports_ui_editor_types` 测试,不再由测试就地重写生成文件或重建退役类型
- binding.rs:`BindingChange` / `BindingDTO` 去掉 `TS` derive 与 `ts(export_to)`,只作为内部结构使用,不再导出退役的前端绑定
- binding.rs:清理仅为该测试存在的 `ts_rs` / `GameCreationAppAssetKind` 导入
- .prettierignore、.eslintrc.cjs:忽略 `src/contracts/generated/`,保留 ts-rs 原始格式使生成幂等且不污染工作树
- GameCreationAppAssetKind.ts:按生成器原始格式更新(与上述路径一致,无内容漂移)
This commit is contained in:
2026-09-16 19:07:33 +08:00
parent f185d21f55
commit b96cd4b7c2
5 changed files with 16 additions and 63 deletions
+1
View File
@@ -164,6 +164,7 @@ module.exports = {
'server-rs/target-*',
'apps/desktop-shell/src-tauri/target',
'apps/ai-game-creator-shell/src/features/ui-editor/types/**',
'apps/ai-game-creator-shell/src/contracts/generated/**',
'target',
'src/main.tsx',
'src/App.tsx',
+2
View File
@@ -4,6 +4,8 @@ node_modules
.codex-logs
public/Icons
apps/ai-game-creator-shell/src/features/ui-editor/types/
# ts-rs 直接落盘的生成产物:保持生成器原始格式,`cargo test export_bindings` 才可幂等复现。
apps/ai-game-creator-shell/src/contracts/generated/
apps/ai-game-creator-shell/src-tauri/resources/agc-skills/
media
*.log
@@ -15,11 +15,8 @@ use platform_llm::{
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[cfg(test)]
use shared_contracts::game_creation_app::GameCreationAppAssetKind;
use std::collections::HashSet;
use std::path::Path;
use ts_rs::TS;
pub const ASSET_BATCH_SIZE: usize = 5;
@@ -64,16 +61,14 @@ struct BindingResponse {
changes: Vec<BindingChangeDraft>,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct BindingChange {
pub node_id: NodeId,
pub component: NodeComponent,
pub component_status: StageStatus,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct BindingDTO {
pub changes: Vec<BindingChange>,
}
@@ -436,7 +431,6 @@ pub(crate) async fn bind_components_impl_with_provider(
mod tests {
use super::*;
use crate::ui_editor::component::text::{FontSource, TextComponent};
use ts_rs::{Config, TS};
fn id(value: &str) -> NodeId {
NodeId::new(value).expect("valid id")
@@ -639,38 +633,4 @@ mod tests {
assert!(read_ui_reference_image_data_url(path).await.is_err());
}
#[test]
fn exports_ui_editor_types() {
let config = Config::from_env();
BindingDTO::export_all(&config).expect("BindingDTO TypeScript export succeeds");
Node::export_all(&config).expect("Node TypeScript export succeeds");
TextComponent::export_all(&config).expect("TextComponent TypeScript export succeeds");
FontSource::export_all(&config).expect("FontSource TypeScript export succeeds");
let game_creation_config = Config::new().with_out_dir(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../src/contracts/generated/"
));
GameCreationAppAssetKind::export_all(&game_creation_config)
.expect("GameCreationAppAssetKind TypeScript export succeeds");
let generated = std::fs::read_to_string(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../src/contracts/generated/GameCreationAppAssetKind.ts"
))
.expect("generated GameCreationAppAssetKind binding exists");
for value in [
"\"image\"",
"\"audio\"",
"\"sound-effect\"",
"\"background-music\"",
"\"font\"",
"\"unknown\"",
] {
assert!(
generated.contains(value),
"generated binding misses {value}"
);
}
}
}
@@ -6,23 +6,4 @@
* JSON 使用 kebab-case`Unknown` 只表示解析边界遇到尚未登记的输入,
* 正常资源写入路径不应主动选择它。
*/
export type GameCreationAppAssetKind =
| 'image'
| 'scene'
| 'character'
| 'character-animation'
| 'icon'
| 'icon-spritesheet'
| 'icon-spec'
| 'ui-design'
| 'ui-design-doc'
| 'publication-material'
| 'spec'
| 'video'
| 'audio'
| 'sound-effect'
| 'background-music'
| 'font'
| 'document'
| 'code'
| 'unknown';
export type GameCreationAppAssetKind = "image" | "scene" | "character" | "character-animation" | "icon" | "icon-spritesheet" | "icon-spec" | "ui-design" | "ui-design-doc" | "publication-material" | "spec" | "video" | "audio" | "sound-effect" | "background-music" | "font" | "document" | "code" | "unknown";
@@ -9,7 +9,16 @@ use std::str::FromStr;
/// 正常资源写入路径不应主动选择它。
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "ts-bindings", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-bindings", ts(export_to = "GameCreationAppAssetKind.ts"))]
#[cfg_attr(
feature = "ts-bindings",
ts(
export,
export_to = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../apps/ai-game-creator-shell/src/contracts/generated/"
)
)
)]
pub enum GameCreationAppAssetKind {
#[cfg_attr(feature = "ts-bindings", ts(rename = "image"))]
Image,