Skip to main content

euv_cli/build/
const.rs

1/// Placeholder token used in HTML templates for the JS import path.
2///
3/// Replaced at runtime with the resolved import path relative to the www directory.
4pub const IMPORT_PATH_PLACEHOLDER: &str = "__IMPORT_PATH__";
5
6/// Placeholder token used in HTML templates for the reload endpoint URL.
7///
8/// Replaced at runtime with the actual reload route path.
9pub const RELOAD_ROUTE_PLACEHOLDER: &str = "__RELOAD_ROUTE__";
10
11/// Placeholder token used in HTML templates for the inlined wasm-bindgen JS bridge.
12///
13/// Replaced at runtime with the body of `pkg/<name>.js` (with its top-level
14/// `import` statements stripped and the 2 snippet helper functions inlined),
15/// wrapped in a synchronous IIFE that fetches the wasm module and calls
16/// `main()`. This eliminates the separate HTTP request for the JS bridge file
17/// and skips ES module graph parsing on the critical path.
18pub const INLINE_JS_PLACEHOLDER: &str = "__EUV_INLINE_JS__";
19
20/// Environment variable to disable JS bridge inlining and fall back to the
21/// classic `<script type="module">import init, { main } from '__IMPORT_PATH__'`
22/// bootstrap. Set to any non-empty value to opt out (e.g. when the wasm-pack
23/// output structure changes and the inline pipeline can't recover).
24pub const EUV_NO_INLINE_BRIDGE_ENV: &str = "EUV_NO_INLINE_BRIDGE";
25
26/// The URL path for the reload endpoint.
27///
28/// Used by the live-reload script in the HTML template and the server route registration.
29pub const RELOAD_ROUTE: &str = "/__euv_reload";
30
31/// The wasm-pack flag indicating a release build.
32pub const RELEASE_FLAG: &str = "--release";
33
34/// The CLI command name for wasm-pack.
35pub const WASM_PACK_COMMAND: &str = "wasm-pack";
36
37/// The wasm-pack subcommand for building.
38pub const WASM_PACK_BUILD_SUBCOMMAND: &str = "build";
39
40/// The wasm-pack argument for specifying the output directory.
41pub const OUT_DIR_ARG: &str = "--out-dir";
42
43/// The wasm-pack argument for specifying the output name.
44pub const OUT_NAME_ARG: &str = "--out-name";
45
46/// The wasm-pack argument for specifying the target.
47pub const TARGET_ARG: &str = "--target";
48
49/// The default wasm-pack target for browser usage.
50pub const TARGET_WEB: &str = "web";
51
52/// The default output subdirectory name for wasm-pack artifacts.
53pub const PKG_DIR_NAME: &str = "pkg";
54
55/// The JavaScript file extension.
56pub const JS_EXTENSION: &str = ".js";
57
58/// The source directory name within a Cargo project.
59pub const SRC_DIR_NAME: &str = "src";
60
61/// The name of the gitignore file.
62pub const GITIGNORE_FILE_NAME: &str = ".gitignore";
63
64/// The name of the Cargo manifest file.
65pub const CARGO_TOML_FILE_NAME: &str = "Cargo.toml";
66
67/// The index HTML file name.
68pub const INDEX_HTML_FILE_NAME: &str = "index.html";
69
70/// The relative path prefix used for import path construction.
71pub const RELATIVE_PATH_PREFIX: &str = "./";
72
73/// The path separator used for joining path components.
74pub const PATH_SEPARATOR: &str = "/";
75
76/// The parent directory indicator used in relative path computation.
77pub const PARENT_DIR: &str = "..";
78
79/// The hyphen character used when normalizing crate names to wasm-pack's
80/// underscore output convention.
81pub const STR_HYPHEN: &str = "-";
82
83/// The underscore character used when normalizing crate names to wasm-pack's
84/// output convention.
85pub const STR_UNDERSCORE: &str = "_";
86
87/// The wasm-pack flag for development builds.
88pub const DEV_FLAG: &str = "--dev";
89
90/// The wasm-pack flag for profiling builds.
91pub const PROFILING_FLAG: &str = "--profiling";
92
93/// The euv-specific argument for specifying the crate path.
94pub const CRATE_PATH_ARG: &str = "--crate-path";
95
96/// The short form of the crate-path argument.
97pub const CRATE_PATH_ARG_SHORT: &str = "-c";
98
99/// The euv-specific argument for specifying the server port.
100pub const PORT_ARG: &str = "--port";
101
102/// The short form of the port argument.
103pub const PORT_ARG_SHORT: &str = "-p";
104
105/// The euv-specific argument for specifying the www directory.
106pub const WWW_DIR_ARG: &str = "--www-dir";
107
108/// The euv-specific argument for specifying a custom index.html template.
109pub const INDEX_HTML_ARG: &str = "--index-html";
110
111/// The euv-specific argument for removing the .gitignore file from the output directory.
112pub const NO_GITIGNORE_ARG: &str = "--no-gitignore";
113
114/// The euv-specific argument names that should not be forwarded to wasm-pack.
115pub const EUV_ARGS: &[&str] = &[
116    CRATE_PATH_ARG,
117    CRATE_PATH_ARG_SHORT,
118    PORT_ARG,
119    PORT_ARG_SHORT,
120    WWW_DIR_ARG,
121    INDEX_HTML_ARG,
122    NO_GITIGNORE_ARG,
123];
124
125/// The double-dash separator used to distinguish euv args from wasm-pack args.
126pub const DOUBLE_DASH: &str = "--";
127
128/// The `run` action name used in banner display.
129pub const ACTION_RUN: &str = "run";
130
131/// The `build` action name used in banner display.
132pub const ACTION_BUILD: &str = "build";
133
134/// The environment variable name for setting the minimum stack size of rustc threads.
135pub const RUST_MIN_STACK_ENV: &str = "RUST_MIN_STACK";
136
137/// The minimum stack size in bytes for rustc threads (16 MiB).
138pub const RUST_MIN_STACK_VALUE: &str = "16777216";
139
140/// The `index.html` template for the development profile.
141///
142/// Includes a live-reload `<script>` block that connects to the
143/// `/__euv_reload` endpoint and parses the JSON payload sent by the server.
144/// The JSON uses a tagged enum format:
145/// - `{"type":"Reload"}` — the client should reload the page.
146/// - `{"type":"Error","message":"..."}` — a build error occurred.
147///
148/// The `__IMPORT_PATH__` placeholder is replaced with the resolved JS import path at runtime.
149pub const INDEX_HTML_DEV: &str = r#"<!doctype html>
150<html lang="en">
151  <head>
152    <meta charset="utf-8" />
153    <meta
154      name="viewport"
155      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, interactive-widget=resizes-visual"
156    />
157    <meta name="mobile-web-app-capable" content="yes" />
158    <meta name="apple-mobile-web-app-capable" content="yes" />
159    <meta
160      name="description"
161      content="A declarative, cross-platform UI framework for Rust with virtual DOM, reactive signals, and HTML macros for WebAssembly."
162    />
163    <meta
164      name="keywords"
165      content="rust, webassembly, wasm, ui-framework, virtual-dom, reactive, declarative-ui, euv"
166    />
167    <meta property="og:title" content="euv" />
168    <meta
169      property="og:description"
170      content="A declarative, cross-platform UI framework for Rust with virtual DOM, reactive signals, and HTML macros for WebAssembly."
171    />
172    <meta property="og:type" content="website" />
173    <title>Euv</title>
174    <style>
175      * {
176        -webkit-font-smoothing: antialiased;
177        -moz-osx-font-smoothing: grayscale;
178        text-rendering: optimizeLegibility;
179      }
180      canvas {
181        image-rendering: auto;
182      }
183    </style>
184  </head>
185  <body>
186    <div id="app"></div>
187  </body>
188  <script>
189__EUV_INLINE_JS__
190  </script>
191  <script>
192    (function () {
193      async function connect() {
194        try {
195          const res = await fetch('/__euv_reload');
196          const data = await res.json();
197          if (data.type === 'Reload') {
198            location.reload();
199          } else if (data.type === 'Error') {
200            console.error('[euv] build error:', data.message);
201            setTimeout(connect, 1000);
202          } else {
203            setTimeout(connect, 1000);
204          }
205        } catch (_) {
206          setTimeout(connect, 2000);
207        }
208      }
209      connect();
210    })();
211  </script>
212</html>
213"#;
214
215/// The `index.html` template for the release profile.
216///
217/// A minimal `index.html` without any live-reload instrumentation.
218/// Used when building for release to produce a clean, static entry point.
219/// The `__IMPORT_PATH__` placeholder is replaced with the resolved JS import path at runtime.
220pub const INDEX_HTML_RELEASE: &str = r#"<!doctype html>
221<html lang="en">
222  <head>
223    <meta charset="utf-8" />
224    <meta
225      name="viewport"
226      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, interactive-widget=resizes-visual"
227    />
228    <meta name="mobile-web-app-capable" content="yes" />
229    <meta name="apple-mobile-web-app-capable" content="yes" />
230    <meta
231      name="description"
232      content="A declarative, cross-platform UI framework for Rust with virtual DOM, reactive signals, and HTML macros for WebAssembly."
233    />
234    <meta
235      name="keywords"
236      content="rust, webassembly, wasm, ui-framework, virtual-dom, reactive, declarative-ui, euv"
237    />
238    <meta property="og:title" content="euv" />
239    <meta
240      property="og:description"
241      content="A declarative, cross-platform UI framework for Rust with virtual DOM, reactive signals, and HTML macros for WebAssembly."
242    />
243    <meta property="og:type" content="website" />
244    <title>Euv</title>
245    <style>
246      * {
247        -webkit-font-smoothing: antialiased;
248        -moz-osx-font-smoothing: grayscale;
249        text-rendering: optimizeLegibility;
250      }
251      canvas {
252        image-rendering: auto;
253      }
254    </style>
255  </head>
256  <body>
257    <div id="app"></div>
258  </body>
259  <script>
260__EUV_INLINE_JS__
261  </script>
262</html>
263"#;