Skip to main content

euv_cli/build/
struct.rs

1use crate::*;
2
3/// euv CLI for real-time WASM compilation and hot-reload development server.
4///
5/// Defines the command-line interface with three sub-commands
6/// (`run` / `build` / `fmt`). All arguments after `--` are transparently
7/// forwarded to `wasm-pack build` without interpretation.
8#[derive(Clone, Data, Debug, New, Parser)]
9#[command(name = "euv")]
10#[command(about = "euv development server with live WASM compilation")]
11pub struct Cli {
12    /// The mode to run in: run (build + server), build (build only), or fmt (format)
13    #[command(subcommand)]
14    #[get_mut(pub(crate))]
15    #[set(pub(crate))]
16    pub(crate) command: Mode,
17}
18
19/// euv-specific arguments combined with wasm-pack passthrough.
20///
21/// Only `--crate-path`, `--port`, `--www-dir`, `--index-html`, `--no-gitignore`, and `--dev`/`--release`/`--profiling`
22/// belong to euv; everything in `wasm_pack_args` is forwarded to `wasm-pack build` as-is.
23#[derive(Clone, Data, Debug, Parser)]
24pub struct ModeArgs {
25    /// Path to the Rust crate containing the WASM application
26    #[arg(short, long, default_value = ".")]
27    #[get(pub(crate))]
28    #[get_mut(pub(crate))]
29    #[set(pub(crate))]
30    pub(crate) crate_path: PathBuf,
31    /// Port for the development server
32    #[arg(short, long, default_value_t = 80)]
33    #[get(pub(crate), type(copy))]
34    #[get_mut(pub(crate))]
35    #[set(pub(crate))]
36    pub(crate) port: u16,
37    /// Directory name for static assets and generated HTML (relative to crate-path)
38    #[arg(long, default_value = "www")]
39    #[get(pub(crate))]
40    #[get_mut(pub(crate))]
41    #[set(pub(crate))]
42    pub(crate) www_dir: String,
43    /// Path to a custom index.html template file.
44    /// When specified, uses this file instead of the built-in template.
45    /// The placeholders `__IMPORT_PATH__` and `__RELOAD_ROUTE__` will be replaced.
46    #[arg(long)]
47    #[get(pub(crate))]
48    #[get_mut(pub(crate))]
49    #[set(pub(crate))]
50    pub(crate) index_html: Option<PathBuf>,
51    /// Create a development build. Enable debug info, and disable optimizations
52    #[arg(long)]
53    #[get(pub(crate), type(copy))]
54    #[get_mut(pub(crate))]
55    #[set(pub(crate))]
56    pub(crate) dev: bool,
57    /// Create a release build. Enable optimizations and disable debug info
58    #[arg(long)]
59    #[get(pub(crate), type(copy))]
60    #[get_mut(pub(crate))]
61    #[set(pub(crate))]
62    pub(crate) release: bool,
63    /// Create a profiling build. Enable optimizations and debug info
64    #[arg(long)]
65    #[get(pub(crate), type(copy))]
66    #[get_mut(pub(crate))]
67    #[set(pub(crate))]
68    pub(crate) profiling: bool,
69    /// Remove the .gitignore file from the output directory after building
70    #[arg(long)]
71    #[get(pub(crate), type(copy))]
72    #[get_mut(pub(crate))]
73    #[set(pub(crate))]
74    pub(crate) no_gitignore: bool,
75    /// Arguments transparently forwarded to `wasm-pack build`
76    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
77    #[get(pub(crate))]
78    #[get_mut(pub(crate))]
79    #[set(pub(crate))]
80    pub(crate) wasm_pack_args: Vec<String>,
81}
82
83/// Arguments for the `fmt` subcommand.
84///
85/// Formats euv macro invocations (`html!`, `class!`, `vars!`, `watch!`)
86/// in Rust source files.
87#[derive(Clone, Data, Debug, New, Parser)]
88pub struct FmtArgs {
89    /// Path to the directory or file to format
90    #[arg(short, long, default_value = ".")]
91    #[get(pub)]
92    #[get_mut(pub)]
93    #[set(pub)]
94    pub(crate) path: PathBuf,
95    /// Check if formatting is needed without modifying files
96    #[arg(long, default_value_t = false)]
97    #[get(pub, type(copy))]
98    #[get_mut(pub)]
99    #[set(pub)]
100    pub(crate) check: bool,
101}
102
103/// Configuration for server URL display.
104///
105/// Groups all parameters needed by `print_server_urls` into a single struct.
106#[derive(Data, New)]
107pub(crate) struct ServerUrlConfig {
108    /// The port number the server is listening on.
109    #[get(pub(crate), type(copy))]
110    #[get_mut(pub(crate))]
111    #[set(pub(crate))]
112    pub(crate) port: u16,
113    /// The serving route prefix (e.g. "www" or "wwws").
114    #[get(pub(crate))]
115    #[get_mut(pub(crate))]
116    #[set(pub(crate))]
117    pub(crate) route_prefix: String,
118    /// The index HTML file name (e.g. "index.html").
119    #[get(pub(crate))]
120    #[get_mut(pub(crate))]
121    #[set(pub(crate))]
122    pub(crate) index_html_file_name: String,
123}