Custom output directory via build.target

This commit is contained in:
2026-02-23 13:51:53 +08:00
parent e0fd729635
commit cb8a3b2001
15 changed files with 91 additions and 31 deletions

View File

@@ -1,9 +1,11 @@
use crate::cli::build::build;
use crate::config::{PROFILE, flags};
use crate::core::config::Config;
use crate::platform;
use crate::utils::fs::check_dir;
use crate::utils::log::{error, warn};
use crate::utils::text::{BOLD_GREEN, colored};
use std::path::Path;
use std::process::Command;
pub fn run(args: &[String]) -> i32 {
@@ -26,6 +28,11 @@ pub fn run(args: &[String]) -> i32 {
.get("package.name")
.and_then(|v| v.as_str())
.unwrap_or("");
let target_dir = config
.get("build.target")
.and_then(|v| v.as_str())
.map(|s| s.trim())
.filter(|s| !s.is_empty());
if let Some(first_arg) = args.first() {
if first_arg.starts_with("--") {
@@ -43,24 +50,34 @@ pub fn run(args: &[String]) -> i32 {
}
let build_status = build(args);
let bin_path = platform::bin_path(&active_profile, project_name, target_dir);
if build_status == 0 {
println!(
"\n {} target/{active_profile}/{project_name}",
colored("Running", BOLD_GREEN)
);
println!("\n {} {}", colored("Running", BOLD_GREEN), bin_path);
println!("--------------------------------");
return Command::new(format!("./target/{active_profile}/{project_name}"))
return Command::new(bin_path)
.status()
.map(|status| status.code().unwrap_or(1))
.unwrap_or(1);
}
if check_dir(Some(&format!("target/{active_profile}")))
.unwrap_or_default()
.contains(&active_profile)
if target_dir.is_none()
&& check_dir(Some(&format!("target/{active_profile}")))
.unwrap_or_default()
.contains(&active_profile)
{
warn("Launch of the latest release");
return Command::new(format!("./target/{active_profile}/{project_name}"))
return Command::new(platform::bin_path(
&active_profile,
project_name,
target_dir,
))
.status()
.map(|status| status.code().unwrap_or(1))
.unwrap_or(1);
}
if target_dir.is_some() && Path::new(&bin_path).exists() {
warn("Launch of the latest release");
return Command::new(bin_path)
.status()
.map(|status| status.code().unwrap_or(1))
.unwrap_or(1);