diff --git a/src/build/args.rs b/src/build/args.rs index 06efcad..04ff4b3 100644 --- a/src/build/args.rs +++ b/src/build/args.rs @@ -1,4 +1,4 @@ -use clap::{Args, Subcommand}; +use clap::{ArgAction, Args, Subcommand}; use crate::external_cli::{arg_builder::ArgBuilder, cargo::build::CargoBuildArgs}; @@ -16,7 +16,7 @@ pub struct BuildArgs { impl BuildArgs { /// Determine if the app is being built for the web. pub(crate) fn is_web(&self) -> bool { - matches!(self.subcommand, Some(BuildSubcommands::Web)) + matches!(self.subcommand, Some(BuildSubcommands::Web(_))) } /// The profile used to compile the app. @@ -38,5 +38,12 @@ impl BuildArgs { #[derive(Debug, Subcommand)] pub enum BuildSubcommands { /// Build your app for the browser. - Web, + Web(BuildWebArgs), +} + +#[derive(Debug, Args)] +pub struct BuildWebArgs { + // Bundle all web artifacts into a single folder. + #[arg(short = 'b', long = "bundle", action = ArgAction::SetTrue, default_value_t = false)] + pub create_packed_bundle: bool, } diff --git a/src/build/mod.rs b/src/build/mod.rs index 55f4ceb..b9083cb 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -1,6 +1,9 @@ +use args::BuildSubcommands; + use crate::{ external_cli::{cargo, rustup, wasm_bindgen, CommandHelpers}, run::select_run_binary, + web::bundle::{create_web_bundle, PackedBundle, WebBundle}, }; pub use self::args::BuildArgs; @@ -10,7 +13,7 @@ mod args; pub fn build(args: &BuildArgs) -> anyhow::Result<()> { let cargo_args = args.cargo_args_builder(); - if args.is_web() { + if let Some(BuildSubcommands::Web(web_args)) = &args.subcommand { ensure_web_setup()?; let metadata = cargo::metadata::metadata_with_args(["--no-deps"])?; @@ -28,6 +31,14 @@ pub fn build(args: &BuildArgs) -> anyhow::Result<()> { args.profile(), )?; wasm_bindgen::bundle(&bin_target)?; + + if web_args.create_packed_bundle { + let web_bundle = create_web_bundle(&metadata, args.profile(), bin_target, true)?; + + if let WebBundle::Packed(PackedBundle { path }) = &web_bundle { + println!("Created bundle at file://{}", path.display()); + } + } } else { cargo::build::command().args(cargo_args).ensure_status()?; } diff --git a/src/run/args.rs b/src/run/args.rs index 73dda22..080f85f 100644 --- a/src/run/args.rs +++ b/src/run/args.rs @@ -53,5 +53,5 @@ pub struct RunWebArgs { // Bundle all web artifacts into a single folder. #[arg(short = 'b', long = "bundle", action = ArgAction::SetTrue, default_value_t = false)] - pub create_bundle: bool, + pub create_packed_bundle: bool, } diff --git a/src/run/mod.rs b/src/run/mod.rs index 32543d4..355a41b 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -9,7 +9,7 @@ use crate::{ cargo::{self, metadata::Metadata}, wasm_bindgen, CommandHelpers, }, - web::bundle::create_web_bundle, + web::bundle::{create_web_bundle, PackedBundle, WebBundle}, }; pub use self::args::RunArgs; @@ -44,10 +44,14 @@ pub fn run(args: &RunArgs) -> anyhow::Result<()> { &metadata, args.profile(), bin_target, - web_args.create_bundle, + web_args.create_packed_bundle, ) .context("Failed to create web bundle")?; + if let WebBundle::Packed(PackedBundle { path }) = &web_bundle { + println!("Created bundle at file://{}", path.display()); + } + let port = web_args.port; let url = format!("http://localhost:{port}");