fix(release): zip 文件名带项目名前缀
发布包现在从 canonicalize 后的项目目录提取项目名,并生成 <项目名>_release_<版本>.zip。这样在项目根目录直接执行 release 时也能得到稳定、可区分的产物名称。
This commit is contained in:
@@ -10,7 +10,7 @@ use walkdir;
|
|||||||
use zip::write::SimpleFileOptions;
|
use zip::write::SimpleFileOptions;
|
||||||
|
|
||||||
use crate::commands::ReleaseArgs;
|
use crate::commands::ReleaseArgs;
|
||||||
use crate::error::Result;
|
use crate::error::{CliError, Result};
|
||||||
use crate::utils::file;
|
use crate::utils::file;
|
||||||
use crate::{entity, entity::project::ReleaseInfo};
|
use crate::{entity, entity::project::ReleaseInfo};
|
||||||
|
|
||||||
@@ -160,7 +160,30 @@ fn package_project(
|
|||||||
pack_dirs: &PackDirs,
|
pack_dirs: &PackDirs,
|
||||||
version: &str,
|
version: &str,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
let output_path = format!("{}/release_{}.zip", project_dir.display(), version);
|
let canonical_project_dir = project_dir
|
||||||
|
.canonicalize()
|
||||||
|
.map_err(|e| file::io_error("解析项目目录", project_dir, e))?;
|
||||||
|
let project_name = canonical_project_dir
|
||||||
|
.file_name()
|
||||||
|
.ok_or_else(|| {
|
||||||
|
CliError::InvalidInput(format!(
|
||||||
|
"无法从项目目录 '{}' 确定项目名",
|
||||||
|
canonical_project_dir.display()
|
||||||
|
))
|
||||||
|
})?
|
||||||
|
.to_str()
|
||||||
|
.ok_or_else(|| {
|
||||||
|
CliError::InvalidInput(format!(
|
||||||
|
"项目目录名不是有效的 UTF-8: '{}'",
|
||||||
|
canonical_project_dir.display()
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
let output_path = format!(
|
||||||
|
"{}/{}_release_{}.zip",
|
||||||
|
project_dir.display(),
|
||||||
|
project_name,
|
||||||
|
version
|
||||||
|
);
|
||||||
let output_pathbuf = PathBuf::from(&output_path);
|
let output_pathbuf = PathBuf::from(&output_path);
|
||||||
let file = fs::File::create(&output_path)
|
let file = fs::File::create(&output_path)
|
||||||
.map_err(|e| file::io_error("创建打包文件", &output_pathbuf, e))?;
|
.map_err(|e| file::io_error("创建打包文件", &output_pathbuf, e))?;
|
||||||
|
|||||||
Reference in New Issue
Block a user