vertigo_cli/build/
build_opts.rs1use 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 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)]
34 pub release_mode: Option<bool>,
35 #[arg(long)]
36 pub wasm_run_source_map: bool,
37}
38
39impl BuildOpts {
40 pub fn get_public_path(&self) -> String {
41 self.inner.public_path.clone().unwrap_or(VERTIGO_PUBLIC_BUILD_PATH_PLACEHOLDER.to_string())
43 }
44
45 pub fn public_path_to(&self, path: impl Into<String>) -> String {
46 let public_path_str = self.get_public_path();
47 let public_path = Path::new(&public_path_str);
48 let path_str = path.into();
49 let path = Path::new(&path_str);
50 public_path.join(path).to_string_lossy().into_owned()
51 }
52
53 pub fn new_path_in_static_make(&self, path: &[&str]) -> WasmPath {
54 let mut result = self.get_dest_dir();
55
56 for chunk in path {
57 result.push(*chunk);
58 }
59
60 result
61 }
62
63 pub fn new_path_in_static_from(&self, path: &WasmPath) -> WasmPath {
64 let name_os = path.file_name();
65 self.new_path_in_static_make(&[name_os.as_str()])
66 }
67
68 pub fn get_dest_dir(&self) -> WasmPath {
69 WasmPath::new(PathBuf::from(self.common.dest_dir.as_str()))
70 }
71}