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