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 #[arg(long)]
41 pub external_tailwind: bool,
42}
43
44impl BuildOpts {
45 pub fn get_public_path(&self) -> String {
46 self.inner.public_path.clone().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 name_os = path.file_name();
70 self.new_path_in_static_make(&[name_os.as_str()])
71 }
72
73 pub fn get_dest_dir(&self) -> WasmPath {
74 WasmPath::new(PathBuf::from(self.common.dest_dir.as_str()))
75 }
76}