-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
96 lines (87 loc) · 3.3 KB
/
Copy pathbuild.rs
File metadata and controls
96 lines (87 loc) · 3.3 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#![allow(
clippy::expect_used,
clippy::panic,
reason = "build scripts use panic for error handling"
)]
use std::path::PathBuf;
use std::process::Command;
fn main() {
// Check if we're in CI - fail hard on missing dependencies
let is_ci = std::env::var("CI").is_ok();
// Output directory for generated TypeScript types
let output_dir = PathBuf::from("web/shared/src/generated");
// Ensure output directory exists
std::fs::create_dir_all(&output_dir).expect("Failed to create output directory");
// Run TypeShare CLI to generate TypeScript types
// This requires 'typeshare' to be installed: cargo install typeshare-cli
let status = Command::new("typeshare")
.arg(".")
.arg("--lang=typescript")
.arg(format!("--output-file={}/index.ts", output_dir.display()))
.status();
match status {
Ok(exit_status) if exit_status.success() => {
println!("cargo:warning=TypeShare generation completed successfully");
}
Ok(exit_status) => {
let msg = format!(
"TypeShare CLI failed with status: {exit_status}. Install typeshare-cli: cargo install typeshare-cli"
);
if is_ci {
panic!("{msg}");
} else {
println!("cargo:warning={msg}");
}
}
Err(e) => {
let msg = format!(
"Failed to run TypeShare CLI: {e}. Install typeshare-cli: cargo install typeshare-cli"
);
if is_ci {
panic!("{msg}");
} else {
println!("cargo:warning={msg}");
}
}
}
// Check that frontend dist directory exists
// Frontend must be built before Rust compilation for static file embedding
let frontend_dist = PathBuf::from("web/frontend/dist");
if !frontend_dist.is_dir() {
let msg = "Frontend dist directory not found. Build the frontend first: cd web/frontend && bun run build";
if is_ci {
panic!("{msg}");
} else {
if let Err(e) = std::fs::create_dir_all(&frontend_dist) {
println!(
"cargo:warning=Failed to create frontend dist directory {}: {e}",
frontend_dist.display()
);
}
println!("cargo:warning={msg}");
}
}
// Check that docs dist directory exists
// Docs must be built before Rust compilation for static file embedding
let docs_dist = PathBuf::from("docs/dist");
if !docs_dist.is_dir() {
let msg = "Docs dist directory not found. Build the docs first: cd docs && bun run build";
if is_ci {
panic!("{msg}");
} else {
if let Err(e) = std::fs::create_dir_all(&docs_dist) {
println!(
"cargo:warning=Failed to create docs dist directory {}: {e}",
docs_dist.display()
);
}
println!("cargo:warning={msg}");
}
}
// Trigger rebuild if any Rust source files change
println!("cargo:rerun-if-changed=src/");
// Also rebuild if frontend dist changes
println!("cargo:rerun-if-changed=web/frontend/dist/");
// Also rebuild if docs dist changes
println!("cargo:rerun-if-changed=docs/dist/");
}