euv_cli/build/struct.rs
1use super::*;
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 pub(crate) path: PathBuf,
92 /// Check if formatting is needed without modifying files
93 #[arg(long, default_value_t = false)]
94 #[get(type(copy))]
95 pub(crate) check: bool,
96}
97
98/// Configuration for server URL display.
99///
100/// Groups all parameters needed by `print_server_urls` into a single struct.
101#[derive(Clone, Data, Debug, New)]
102pub(crate) struct ServerUrlConfig {
103 /// The port number the server is listening on.
104 #[get(pub(crate), type(copy))]
105 #[get_mut(pub(crate))]
106 #[set(pub(crate))]
107 pub(crate) port: u16,
108 /// The serving route prefix (e.g. "www" or "wwws").
109 #[get(pub(crate))]
110 #[get_mut(pub(crate))]
111 #[set(pub(crate))]
112 pub(crate) route_prefix: String,
113 /// The index HTML file name (e.g. "index.html").
114 #[get(pub(crate))]
115 #[get_mut(pub(crate))]
116 #[set(pub(crate))]
117 pub(crate) index_html_file_name: String,
118}
119
120/// A namespace import clause found in the bridge: `import * as alias from
121/// "spec"`.
122///
123/// Collected while scanning the bridge's imports so the inlined IIFE can
124/// rebuild the alias as a plain object once the module graph is gone.
125pub(crate) struct NamespaceImport {
126 /// The local binding the clause introduces.
127 pub(crate) alias: String,
128 /// The module specifier, verbatim with its quotes.
129 pub(crate) spec: String,
130}