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,