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)]
44 pub precompress: Option<bool>,
45 #[arg(long)]
46 pub wasm_run_source_map: bool,
47
48 #[arg(last = true)]
49 pub cargo_opts: Vec<String>,
50}
51
52impl BuildOpts {
53 pub fn get_public_path(&self) -> String {
54 self.inner
56 .public_path
57 .clone()
58 .unwrap_or(VERTIGO_PUBLIC_BUILD_PATH_PLACEHOLDER.to_string())
59 }
60
61 pub fn public_path_to(&self, path: impl Into<String>) -> String {
62 let public_path_str = self.get_public_path();
63 let public_path = Path::new(&public_path_str);
64 let path_str = path.into();
65 let path = Path::new(&path_str);
66 public_path.join(path).to_string_lossy().into_owned()
67 }
68
69 pub fn new_path_in_static_make(&self, path: &[&str]) -> WasmPath {
70 let mut result = self.get_dest_dir();
71
72 for chunk in path {
73 result.push(*chunk);
74 }
75
76 result
77 }
78
79 pub fn new_path_in_static_from(&self, path: &WasmPath) -> WasmPath {
80 let Ok(name_os) = path.file_name() else {
81 log::error!("Can't get file name from path: {}", path.as_string());
82 return self.new_path_in_static_make(&[]);
83 };
84 self.new_path_in_static_make(&[name_os.as_str()])
85 }
86
87 pub fn get_dest_dir(&self) -> WasmPath {
88 WasmPath::new(PathBuf::from(self.common.dest_dir.as_str()))
89 }
90}