Fix outdir not work when run dx bundle --platform web --outdir mydir (#3572)

* Make legacy asset dir optional
* properly implement outdir

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
Co-authored-by:  Nathy-bajo <bajon7680@gmail.com>
This commit is contained in:
authored and GitHub committed 2025-01-16 15:17:33 -08:00
1 parent db16de15c5
commit 19d5fae12d
9 files changed
+152 -143

No files matched your search

-62
View File
@@ -11,68 +11,6 @@ use std::{
use brotli::enc::BrotliEncoderParams;
use walkdir::WalkDir;
pub fn copy_asset(src: &Path, dest: &Path) -> std::io::Result<()> {
if src.is_dir() {
copy_dir_to(src, dest, false)?;
} else {
std::fs::copy(src, dest)?;
}
Ok(())
}
pub(crate) fn copy_dir_to(
src_dir: &Path,
dest_dir: &Path,
pre_compress: bool,
) -> std::io::Result<()> {
let entries = std::fs::read_dir(src_dir)?;
let mut children: Vec<std::thread::JoinHandle<std::io::Result<()>>> = Vec::new();
for entry in entries.flatten() {
let entry_path = entry.path();
let path_relative_to_src = entry_path.strip_prefix(src_dir).unwrap();
let output_file_location = dest_dir.join(path_relative_to_src);
children.push(std::thread::spawn(move || {
if entry.file_type()?.is_dir() {
// If the file is a directory, recursively copy it into the output directory
if let Err(err) = copy_dir_to(&entry_path, &output_file_location, pre_compress) {
tracing::error!(
"Failed to pre-compress directory {}: {}",
entry_path.display(),
err
);
}
} else {
// Make sure the directory exists
std::fs::create_dir_all(output_file_location.parent().unwrap())?;
// Copy the file to the output directory
std::fs::copy(&entry_path, &output_file_location)?;
// Then pre-compress the file if needed
if pre_compress {
if let Err(err) = pre_compress_file(&output_file_location) {
tracing::error!(
"Failed to pre-compress static assets {}: {}",
output_file_location.display(),
err
);
}
// If pre-compression isn't enabled, we should remove the old compressed file if it exists
} else if let Some(compressed_path) = compressed_path(&output_file_location) {
_ = std::fs::remove_file(compressed_path);
}
}
Ok(())
}));
}
for child in children {
child.join().unwrap()?;
}
Ok(())
}
/// Get the path to the compressed version of a file
fn compressed_path(path: &Path) -> Option<PathBuf> {
let new_extension = match path.extension() {