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