vertigo_cli/build/
build_opts.rs

1use clap::Args;
2use vertigo::VERTIGO_PUBLIC_BUILD_PATH_PLACEHOLDER;
3use std::path::{Path, PathBuf};
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 common: CommonOpts,
13    #[clap(flatten)]
14    pub inner: BuildOptsInner,
15}
16
17#[derive(Args, Debug, Clone)]
18pub struct BuildOptsInner {
19    pub package_name: Option<String>,
20    /// Hard-code public path so the build can be used statically
21    #[arg(long)]
22    pub public_path: Option<String>,
23    #[arg(short, long)]
24    pub disable_wasm_opt: bool,
25    #[arg(long)]
26    pub wasm_run_source_map: bool,
27}
28
29impl BuildOpts {
30    pub fn get_public_path(&self) -> String {
31        // Use predefined public_path or use VERTIGO_PUBLIC_BUILD_PATH_PLACEHOLDER to keep public path dynamic.
32        self.inner.public_path.clone().unwrap_or(VERTIGO_PUBLIC_BUILD_PATH_PLACEHOLDER.to_string())
33    }
34
35    pub fn public_path_to(&self, path: impl Into<String>) -> String {
36        let public_path_str = self.get_public_path();
37        let public_path = Path::new(&public_path_str);
38        let path_str = path.into();
39        let path = Path::new(&path_str);
40        public_path.join(path).to_string_lossy().into_owned()
41    }
42
43    pub fn new_path_in_static_make(&self, path: &[&str]) -> WasmPath {
44        let mut result = self.get_dest_dir();
45
46        for chunk in path {
47            result.push(*chunk);
48        }
49
50        result
51    }
52
53    pub fn new_path_in_static_from(&self, path: &WasmPath) -> WasmPath {
54        let name_os = path.file_name();
55        self.new_path_in_static_make(&[name_os.as_str()])
56    }
57
58    pub fn get_dest_dir(&self) -> WasmPath {
59        WasmPath::new(PathBuf::from(self.common.dest_dir.as_str()))
60    }
61}