Skip to content

Commit

Permalink
Add copying of assets folder
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Dec 23, 2024
1 parent 92e8a34 commit 7e00d35
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ actix-web = "4.9.0"

# Opening the app in the browser
webbrowser = "1.0.2"

# Copying directories
fs_extra = "1.3.0"
69 changes: 40 additions & 29 deletions src/run/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum WebBundle {
Packed(PackedBundle),
}

pub fn create_bundle(
pub fn create_web_bundle(
metadata: &Metadata,
profile: &str,
bin_target: BinTarget,
Expand All @@ -50,37 +50,48 @@ pub fn create_bundle(
index: Index::Static(default_index(&bin_target)),
};

if packed {
let base_path = metadata
.target_directory
.join("bevy_web")
.join(profile)
.join(bin_target.bin_name);

// Build artifacts
fs::create_dir_all(base_path.join("build"))?;
fs::copy(
linked.wasm_path,
base_path.join("build").join(&wasm_file_name),
if !packed {
return Ok(WebBundle::Linked(linked));
}

let base_path = metadata
.target_directory
.join("bevy_web")
.join(profile)
.join(bin_target.bin_name);

// Build artifacts
fs::create_dir_all(base_path.join("build"))?;
fs::copy(
linked.wasm_path,
base_path.join("build").join(&wasm_file_name),
)?;
fs::copy(linked.js_path, base_path.join("build").join(&js_file_name))?;

// Assets
if let Some(assets_path) = linked.assets_path {
fs_extra::dir::copy(
assets_path,
base_path.join("assets"),
&fs_extra::dir::CopyOptions {
overwrite: true,
..Default::default()
},
)?;
fs::copy(linked.js_path, base_path.join("build").join(&js_file_name))?;

// TODO: Copy assets

let index_path = base_path.join("index.html");
match linked.index {
Index::File(path) => {
fs::copy(path, index_path)?;
}
Index::Static(contents) => {
fs::write(index_path, contents)?;
}
}
}

Ok(WebBundle::Packed(PackedBundle { path: base_path }))
} else {
Ok(WebBundle::Linked(linked))
// Index
let index_path = base_path.join("index.html");
match linked.index {
Index::File(path) => {
fs::copy(path, index_path)?;
}
Index::Static(contents) => {
fs::write(index_path, contents)?;
}
}

Ok(WebBundle::Packed(PackedBundle { path: base_path }))
}

/// Create the default `index.html` if the user didn't provide one.
Expand Down

0 comments on commit 7e00d35

Please sign in to comment.