From 285279629e18c87cacada5ae154dd94f5279d10d Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Wed, 15 Oct 2025 09:19:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8A=A0=E8=BD=BD=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor-app/src-tauri/src/main.rs | 13 ++++++++++--- packages/editor-app/src/App.tsx | 2 +- .../editor-core/src/Services/ProjectService.ts | 15 ++++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/editor-app/src-tauri/src/main.rs b/packages/editor-app/src-tauri/src/main.rs index 438c6ef2..4733a5ca 100644 --- a/packages/editor-app/src-tauri/src/main.rs +++ b/packages/editor-app/src-tauri/src/main.rs @@ -46,17 +46,24 @@ async fn open_project_dialog(app: AppHandle) -> Result, String> { #[tauri::command] fn scan_directory(path: String, pattern: String) -> Result, String> { use glob::glob; - use std::path::Path; + use std::path::{Path, MAIN_SEPARATOR}; let base_path = Path::new(&path); if !base_path.exists() { return Err(format!("Directory does not exist: {}", path)); } - let glob_pattern = format!("{}/{}", path, pattern); + let separator = if path.contains('\\') { '\\' } else { '/' }; + let glob_pattern = format!("{}{}{}", path.trim_end_matches(&['/', '\\'][..]), separator, pattern); + let normalized_pattern = if cfg!(windows) { + glob_pattern.replace('/', "\\") + } else { + glob_pattern.replace('\\', "/") + }; + let mut files = Vec::new(); - match glob(&glob_pattern) { + match glob(&normalized_pattern) { Ok(entries) => { for entry in entries { match entry { diff --git a/packages/editor-app/src/App.tsx b/packages/editor-app/src/App.tsx index a8ec53ec..29704802 100644 --- a/packages/editor-app/src/App.tsx +++ b/packages/editor-app/src/App.tsx @@ -169,7 +169,7 @@ function App() { if (componentsPath) { const componentInfos = await discoveryService.scanComponents({ basePath: componentsPath, - pattern: '**/*Component.ts', + pattern: '**/*.ts', scanFunction: TauriAPI.scanDirectory, readFunction: TauriAPI.readFileContent }); diff --git a/packages/editor-core/src/Services/ProjectService.ts b/packages/editor-core/src/Services/ProjectService.ts index a513941f..446e06da 100644 --- a/packages/editor-core/src/Services/ProjectService.ts +++ b/packages/editor-core/src/Services/ProjectService.ts @@ -81,10 +81,14 @@ export class ProjectService implements IService { } public getComponentsPath(): string | null { - if (!this.currentProject || !this.projectConfig?.componentsPath) { + if (!this.currentProject) { return null; } - return `${this.currentProject.path}/${this.projectConfig.componentsPath}`; + if (!this.projectConfig?.componentsPath) { + return this.currentProject.path; + } + const sep = this.currentProject.path.includes('\\') ? '\\' : '/'; + return `${this.currentProject.path}${sep}${this.projectConfig.componentsPath}`; } private async validateProject(projectPath: string): Promise { @@ -96,7 +100,8 @@ export class ProjectService implements IService { name: projectName }; - const configPath = `${projectPath}/ecs-editor.config.json`; + const sep = projectPath.includes('\\') ? '\\' : '/'; + const configPath = `${projectPath}${sep}ecs-editor.config.json`; try { projectInfo.configPath = configPath; @@ -111,8 +116,8 @@ export class ProjectService implements IService { private async loadConfig(configPath: string): Promise { return { projectType: 'cocos', - componentsPath: 'assets/scripts/components', - componentPattern: '**/*Component.ts', + componentsPath: '', + componentPattern: '**/*.ts', buildOutput: 'temp/editor-components' }; }