优化创建项目的后端处理
This commit is contained in:
@@ -65,7 +65,20 @@ pub async fn create_shadcn_project(
|
|||||||
]);
|
]);
|
||||||
cmd.current_dir(&target_dir);
|
cmd.current_dir(&target_dir);
|
||||||
|
|
||||||
|
// Log the full command for debugging
|
||||||
|
let cmd_display = format!(
|
||||||
|
"{} {} shadcn@latest init -n {} -t {} -p {} -y (cwd={})",
|
||||||
|
program,
|
||||||
|
prefix_args.join(" "),
|
||||||
|
project_name,
|
||||||
|
template,
|
||||||
|
preset_code,
|
||||||
|
target_dir
|
||||||
|
);
|
||||||
|
eprintln!("[ProjectBoot] executing: {cmd_display}");
|
||||||
|
|
||||||
let output = cmd.output().await.map_err(|e| {
|
let output = cmd.output().await.map_err(|e| {
|
||||||
|
eprintln!("[ProjectBoot] spawn error: {e}");
|
||||||
if e.kind() == std::io::ErrorKind::NotFound {
|
if e.kind() == std::io::ErrorKind::NotFound {
|
||||||
AppCommandError::dependency_missing(format!(
|
AppCommandError::dependency_missing(format!(
|
||||||
"{program} is not installed. Please install Node.js first."
|
"{program} is not installed. Please install Node.js first."
|
||||||
@@ -78,10 +91,36 @@ pub async fn create_shadcn_project(
|
|||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if !output.status.success() {
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
||||||
let detail = if stderr.is_empty() { stdout } else { stderr };
|
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
|
||||||
|
|
||||||
|
eprintln!(
|
||||||
|
"[ProjectBoot] exit={} stdout_len={} stderr_len={}",
|
||||||
|
output.status,
|
||||||
|
stdout.len(),
|
||||||
|
stderr.len()
|
||||||
|
);
|
||||||
|
if !stdout.is_empty() {
|
||||||
|
eprintln!("[ProjectBoot] stdout: {stdout}");
|
||||||
|
}
|
||||||
|
if !stderr.is_empty() {
|
||||||
|
eprintln!("[ProjectBoot] stderr: {stderr}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
let mut detail = String::new();
|
||||||
|
if !stderr.is_empty() {
|
||||||
|
detail.push_str(&stderr);
|
||||||
|
}
|
||||||
|
if !stdout.is_empty() {
|
||||||
|
if !detail.is_empty() {
|
||||||
|
detail.push('\n');
|
||||||
|
}
|
||||||
|
detail.push_str(&stdout);
|
||||||
|
}
|
||||||
|
if detail.is_empty() {
|
||||||
|
detail = format!("Command exited with status: {}", output.status);
|
||||||
|
}
|
||||||
return Err(AppCommandError::external_command(
|
return Err(AppCommandError::external_command(
|
||||||
"Project creation command failed",
|
"Project creation command failed",
|
||||||
detail,
|
detail,
|
||||||
|
|||||||
@@ -207,6 +207,9 @@ pub async fn open_folder_window(
|
|||||||
if let Some(w) = app.get_webview_window("welcome") {
|
if let Some(w) = app.get_webview_window("welcome") {
|
||||||
let _ = w.close();
|
let _ = w.close();
|
||||||
}
|
}
|
||||||
|
if let Some(w) = app.get_webview_window("project-boot") {
|
||||||
|
let _ = w.close();
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,11 +223,12 @@ pub async fn open_folder_window(
|
|||||||
.map_err(|e| AppCommandError::window("Failed to open folder window", e.to_string()))?;
|
.map_err(|e| AppCommandError::window("Failed to open folder window", e.to_string()))?;
|
||||||
ensure_windows_undecorated(&folder_window);
|
ensure_windows_undecorated(&folder_window);
|
||||||
|
|
||||||
// Close welcome window
|
// Close welcome and project-boot windows
|
||||||
if let Some(w) = app.get_webview_window("welcome") {
|
if let Some(w) = app.get_webview_window("welcome") {
|
||||||
w.close().map_err(|e| {
|
let _ = w.close();
|
||||||
AppCommandError::window("Failed to close welcome window", e.to_string())
|
}
|
||||||
})?;
|
if let Some(w) = app.get_webview_window("project-boot") {
|
||||||
|
let _ = w.close();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
} from "@/components/ui/dialog"
|
} from "@/components/ui/dialog"
|
||||||
import { openFileDialog } from "@/lib/platform"
|
import { openFileDialog } from "@/lib/platform"
|
||||||
import { createShadcnProject, openFolderWindow } from "@/lib/api"
|
import { createShadcnProject, openFolderWindow } from "@/lib/api"
|
||||||
|
import { toErrorMessage } from "@/lib/app-error"
|
||||||
import { FRAMEWORK_OPTIONS, PACKAGE_MANAGER_OPTIONS } from "./constants"
|
import { FRAMEWORK_OPTIONS, PACKAGE_MANAGER_OPTIONS } from "./constants"
|
||||||
|
|
||||||
interface CreateProjectDialogProps {
|
interface CreateProjectDialogProps {
|
||||||
@@ -67,10 +68,7 @@ export function CreateProjectDialog({
|
|||||||
resetForm()
|
resetForm()
|
||||||
await openFolderWindow(projectPath)
|
await openFolderWindow(projectPath)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message =
|
const message = toErrorMessage(err)
|
||||||
err && typeof err === "object" && "message" in err
|
|
||||||
? (err as { message: string }).message
|
|
||||||
: String(err)
|
|
||||||
setError(message)
|
setError(message)
|
||||||
toast.error(t("toasts.createFailed"), { description: message })
|
toast.error(t("toasts.createFailed"), { description: message })
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user