-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
47 lines (42 loc) · 1.71 KB
/
Copy pathbuild.rs
File metadata and controls
47 lines (42 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Guarantees `frontend/dist` exists before `rust-embed` reads it.
//!
//! The bundle is gitignored, so a fresh clone has no `frontend/dist` and the
//! `RustEmbed` derive would fail to compile with a bare "folder does not
//! exist". That turns "you forgot `make frontend`" into a cryptic macro error.
//! Instead we materialise a placeholder `index.html` that says so in the
//! browser, and warn at build time.
use std::path::Path;
const PLACEHOLDER: &str = r#"<!doctype html>
<meta charset="utf-8">
<title>Red Clippy - frontend not built</title>
<style>
body { font: 15px/1.6 system-ui, sans-serif; max-width: 34rem; margin: 4rem auto; padding: 0 1rem; }
code { background: #f1f5f9; padding: .15rem .35rem; border-radius: .25rem; }
</style>
<h1>Frontend not built</h1>
<p>This binary was compiled without a React bundle, so there is no UI to serve.</p>
<p>Build the SPA and recompile:</p>
<pre><code>make frontend
cargo build --release</code></pre>
<p>The REST API under <code>/api/v1</code> and the MCP server are unaffected.</p>
"#;
fn main() {
let dist = Path::new("frontend/dist");
println!("cargo:rerun-if-changed=frontend/dist");
let index = dist.join("index.html");
if index.exists() {
return;
}
if let Err(e) = std::fs::create_dir_all(dist.join("assets")) {
println!("cargo:warning=could not create {}: {e}", dist.display());
return;
}
if let Err(e) = std::fs::write(&index, PLACEHOLDER) {
println!("cargo:warning=could not write {}: {e}", index.display());
return;
}
println!(
"cargo:warning=frontend/dist/index.html was missing; embedding a placeholder page. \
Run `make frontend` and rebuild to embed the real UI."
);
}