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