-
Notifications
You must be signed in to change notification settings - Fork 33
add --bundle-dir option to web subcommand
#650
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,6 @@ | ||||||
| #[cfg(feature = "web")] | ||||||
| use std::path::PathBuf; | ||||||
|
|
||||||
| #[cfg(feature = "web")] | ||||||
| use clap::ArgAction; | ||||||
| use clap::{Args, Subcommand}; | ||||||
|
|
@@ -156,6 +159,10 @@ pub struct BuildWebArgs { | |||||
| #[arg(long = "wasm-opt", allow_hyphen_values = true)] | ||||||
| pub wasm_opt: Vec<String>, | ||||||
|
|
||||||
| /// Copy packed bundle directory to this directory | ||||||
| #[arg(long = "bundle-dir", allow_hyphen_values = true)] | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: While technically directories could start with a
Suggested change
|
||||||
| pub bundle_dir: Option<PathBuf>, | ||||||
|
|
||||||
| #[cfg(feature = "unstable")] | ||||||
| #[clap(flatten)] | ||||||
| pub unstable: UnstableWebArgs, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| #[cfg(feature = "web")] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to support this for |
||
| use std::path::PathBuf; | ||
|
|
||
| #[cfg(feature = "web")] | ||
| use clap::ArgAction; | ||
| use clap::{Args, Subcommand}; | ||
|
|
@@ -172,6 +175,10 @@ pub struct RunWebArgs { | |
| #[arg(long = "wasm-opt", allow_hyphen_values = true)] | ||
| pub wasm_opt: Vec<String>, | ||
|
|
||
| /// Copy packed bundle directory to this directory | ||
| #[arg(long = "bundle-dir", allow_hyphen_values = true)] | ||
| pub bundle_dir: Option<PathBuf>, | ||
|
|
||
| #[cfg(feature = "unstable")] | ||
| #[clap(flatten)] | ||
| pub unstable: UnstableWebArgs, | ||
|
|
@@ -187,6 +194,7 @@ impl Default for RunWebArgs { | |
| create_packed_bundle: false, | ||
| headers: Vec::new(), | ||
| wasm_opt: Vec::new(), | ||
| bundle_dir: None, | ||
| #[cfg(feature = "unstable")] | ||
| unstable: UnstableWebArgs::default(), | ||
| } | ||
|
|
@@ -227,6 +235,7 @@ impl From<RunArgs> for BuildArgs { | |
| wasm_opt: web_args.wasm_opt, | ||
| #[cfg(feature = "unstable")] | ||
| unstable: web_args.unstable, | ||
| bundle_dir: web_args.bundle_dir, | ||
| }), | ||
| }), | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| use std::fs; | ||
|
|
||
| use anyhow::Context as _; | ||
| use cargo_metadata::Metadata; | ||
| use fs_extra::dir::{self, CopyOptions}; | ||
| use tracing::info; | ||
|
|
||
| use super::bundle::WebBundle; | ||
| use crate::{ | ||
| bin_target::BinTarget, | ||
| commands::build::{BuildArgs, BuildSubcommands}, | ||
| commands::build::{BuildArgs, BuildSubcommands, BuildWebArgs}, | ||
| external_cli::{cargo, wasm_bindgen, wasm_opt}, | ||
| web::{ | ||
| bundle::{PackedBundle, create_web_bundle}, | ||
|
|
@@ -82,6 +85,15 @@ pub fn build_web( | |
|
|
||
| if let WebBundle::Packed(PackedBundle { path }) = &web_bundle { | ||
| info!("created bundle at file://{}", path.display()); | ||
| if let Some(BuildWebArgs { | ||
| bundle_dir: Some(target), | ||
| .. | ||
| }) = web_args | ||
| { | ||
| fs::create_dir_all(target).context("failed to create target directory")?; | ||
| dir::copy(path, target, &CopyOptions::new().content_only(true)) | ||
| .context("failed to copy packed bundle directory to target directory")?; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I would like an additional log line that explains that the cli copied the files to the new dir. |
||
| } | ||
|
|
||
| Ok(web_bundle) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,3 +126,33 @@ fn should_build_web_release() -> anyhow::Result<()> { | |
| ensure_path_exists(target_artifact_path.join("bevy_default.js")) | ||
| .context("JS bindings do not exist") | ||
| } | ||
|
|
||
| #[test] | ||
| #[serial] | ||
| fn should_copy_web_bundle() -> anyhow::Result<()> { | ||
| let target_artifact_path = target_path() | ||
| .join("wasm32-unknown-unknown") | ||
| .join("web-release"); | ||
| clean_target_artifacts(&target_artifact_path)?; | ||
|
|
||
| let _ = fs::remove_dir_all(test_path().join("web-dir")); | ||
| let mut cmd = Command::cargo_bin("bevy")?; | ||
| cmd.current_dir(test_path()).args([ | ||
| "build", | ||
| "-p=bevy_default", | ||
| "--release", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: We could save CI time by not using the release profile here. |
||
| "--yes", | ||
| "web", | ||
| "--bundle", | ||
| "--bundle-dir=web-dir", | ||
| ]); | ||
|
|
||
| cmd.assert().success(); | ||
|
|
||
| ensure_path_exists(test_path().join("web-dir/index.html")) | ||
| .context("index.html do not exist")?; | ||
| ensure_path_exists(test_path().join("web-dir/build/bevy_default_bg.wasm")) | ||
| .context("Wasm bindings do not exist")?; | ||
| ensure_path_exists(test_path().join("web-dir/build/bevy_default.js")) | ||
| .context("JS bindings do not exist") | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.