From b96cd4b7c20de1e38793d88e8f2ef08ced8fb078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Wed, 16 Sep 2026 19:07:33 +0800 Subject: [PATCH] =?UTF-8?q?ts-rs=20=E7=BB=91=E5=AE=9A=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E8=B5=B0=20cargo=20test=20export=5Fbindings=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=80=80=E5=BD=B9=E7=B1=BB=E5=9E=8B=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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:按生成器原始格式更新(与上述路径一致,无内容漂移) --- .eslintrc.cjs | 1 + .prettierignore | 2 + .../src/ui_editor/commands/binding.rs | 44 +------------------ .../generated/GameCreationAppAssetKind.ts | 21 +-------- .../src/game_creation_app/asset_kind.rs | 11 ++++- 5 files changed, 16 insertions(+), 63 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 793e2b4a4..03e4291ff 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -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', diff --git a/.prettierignore b/.prettierignore index 9ec6037f3..d37969f8d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -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 diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/binding.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/binding.rs index 056d511da..9d9b9bb3b 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/binding.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/binding.rs @@ -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, } -#[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, } @@ -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}" - ); - } - } } diff --git a/apps/ai-game-creator-shell/src/contracts/generated/GameCreationAppAssetKind.ts b/apps/ai-game-creator-shell/src/contracts/generated/GameCreationAppAssetKind.ts index 37ede755d..81c2ba217 100644 --- a/apps/ai-game-creator-shell/src/contracts/generated/GameCreationAppAssetKind.ts +++ b/apps/ai-game-creator-shell/src/contracts/generated/GameCreationAppAssetKind.ts @@ -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"; diff --git a/server-rs/crates/shared-contracts/src/game_creation_app/asset_kind.rs b/server-rs/crates/shared-contracts/src/game_creation_app/asset_kind.rs index b26abbef0..607d9ce7b 100644 --- a/server-rs/crates/shared-contracts/src/game_creation_app/asset_kind.rs +++ b/server-rs/crates/shared-contracts/src/game_creation_app/asset_kind.rs @@ -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,