Skip to content

feat(nuspec): include license file in docs and track files list #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions crates/nuspec/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ enum ManifestCrateType {

fn load_package_config(out_dir: PathBuf) -> Result<Package, Box<dyn error::Error>> {
let manifest_file = PathBuf::from(env::var("CARGO_MANIFEST_PATH")?);
let manifest_content = std::fs::read_to_string(manifest_file)?;
let manifest_content = fs::read_to_string(manifest_file)?;
let manifest: Manifest = toml::from_str(&manifest_content)?;
let build_artifacts_path = get_build_artifacts_path()?;
let mut files = vec![];

let mut pkg = manifest
.package
Expand Down Expand Up @@ -140,7 +141,17 @@ fn load_package_config(out_dir: PathBuf) -> Result<Package, Box<dyn error::Error
if path.is_empty() {
None
} else {
Some(License::File(get_relative_path(out_dir.clone(), path)?))
let license_path = get_relative_path(out_dir.clone(), path)?;
let license_file_name = Path::new(&license_path).file_name().ok_or(format!(
"Failed to get the file name from the license: {license_path}"
))?;
let docs_license = Path::new("docs").join(license_file_name);
files.push(File {
src: license_path,
target: Some("docs".to_string()),
..Default::default()
});
Some(License::File(docs_license.to_string_lossy().to_string()))
}
}
_ => None,
Expand All @@ -161,17 +172,16 @@ fn load_package_config(out_dir: PathBuf) -> Result<Package, Box<dyn error::Error
_ => None,
};
}
let mut files = vec![];
if pkg.metadata.readme.is_none() && pkg.files.is_none() {
pkg.metadata.readme = match env::var("CARGO_PKG_README") {
Ok(path) => {
if path.is_empty() {
None
} else {
let readme_path = get_relative_path(out_dir.clone(), path)?;
let readme_file_name = Path::new(&readme_path)
.file_name()
.ok_or("Failed to get file name from readme")?;
let readme_file_name = Path::new(&readme_path).file_name().ok_or(format!(
"Failed to get the file name from readme: {readme_path}"
))?;
let docs_readme = Path::new("docs").join(readme_file_name);
files.push(File {
src: readme_path,
Expand Down