vertigo_cli/build/
build_opts.rs1use clap::Args;
2use std::path::{Path, PathBuf};
3use vertigo::dev::VERTIGO_PUBLIC_BUILD_PATH_PLACEHOLDER;
4
5use crate::commons::models::CommonOpts;
6
7use super::wasm_path::WasmPath;
8
9#[derive(Args, Debug, Clone)]
10pub struct BuildOpts {
11 #[clap(flatten)]
12 pub inner: BuildOptsInner,
13 #[clap(flatten)]
14 pub common: CommonOpts,
15}
16
17#[derive(Args, Debug, Clone)]
18pub struct BuildOptsInner {
19 pub package_name: Option<String>,
20 #[arg(long)]
22 pub public_path: Option<String>,
23 #[arg(short, long)]
28 pub wasm_opt: Option<bool>,
29 #[arg(short, long)]
36 pub release_mode: Option<bool>,
37 #[arg(long)]
38 pub wasm_run_source_map: bool,
39}
40
41impl BuildOpts {
42 pub fn get_public_path(&self) -> String {
43 self.inner
45 .public_path
46 .clone()
47 .unwrap_or(VERTIGO_PUBLIC_BUILD_PATH_PLACEHOLDER.to_string())
48 }
49
50 pub fn public_path_to(&self, path: impl Into<String>) -> String {
51 let public_path_str = self.get_public_path();
52 let public_path = Path::new(&public_path_str);
53 let path_str = path.into();
54 let path = Path::new(&path_str);
55 public_path.join(path).to_string_lossy().into_owned()
56 }
57
58 pub fn new_path_in_static_make(&self, path: &[&str]) -> WasmPath {
59 let mut result = self.get_dest_dir();
60
61 for chunk in path {
62 result.push(*chunk);
63 }
64
65 result
66 }
67
68 pub fn new_path_in_static_from(&self, path: &WasmPath) -> WasmPath {
69 let Ok(name_os) = path.file_name() else {
70 log::error!("Can't get file name from path: {}", path.as_string());
71 return self.new_path_in_static_make(&[]);
72 };
73 self.new_path_in_static_make(&[name_os.as_str()])
74 }
75
76 pub fn get_dest_dir(&self) -> WasmPath {
77 WasmPath::new(PathBuf::from(self.common.dest_dir.as_str()))
78 }
79}