|
1 | 1 | use cornucopia::{CodegenSettings, Error}; |
2 | 2 | use postgres::{Client, NoTls}; |
3 | | -use std::path::PathBuf; |
4 | | -use std::process::Command; |
5 | | - |
6 | | -fn ensure_webui_built() { |
7 | | - let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); |
8 | | - let webui_dir = manifest_dir.join("../../webui"); |
9 | | - let dist_index = webui_dir.join("dist/index.html"); |
10 | | - |
11 | | - // Only re-run this build script when dist/ changes (or is created). |
12 | | - // We intentionally do NOT track webui/src/ here — the webui has its own |
13 | | - // build toolchain. Developers who modify the frontend should run |
14 | | - // `pnpm build` in webui/ themselves; this block only bootstraps |
15 | | - // an initial build so that `cargo build` works out of the box. |
16 | | - println!( |
17 | | - "cargo:rerun-if-changed={}", |
18 | | - webui_dir.join("dist").display() |
19 | | - ); |
20 | | - |
21 | | - if dist_index.exists() { |
22 | | - return; |
23 | | - } |
24 | | - |
25 | | - eprintln!("webui/dist not found — building the web UI..."); |
26 | | - |
27 | | - // Verify pnpm is available |
28 | | - let pnpm = Command::new("pnpm").arg("--version").output(); |
29 | | - if pnpm.is_err() || !pnpm.unwrap().status.success() { |
30 | | - panic!( |
31 | | - "\n\n\ |
32 | | - ========================================================\n\ |
33 | | - pnpm is required to build the Arroyo web UI but was not\n\ |
34 | | - found on $PATH.\n\ |
35 | | - ========================================================\n" |
36 | | - ); |
37 | | - } |
38 | | - |
39 | | - // Install dependencies (frozen so the lockfile is never mutated by a Rust build) |
40 | | - let install = Command::new("pnpm") |
41 | | - .args(["install", "--frozen-lockfile"]) |
42 | | - .current_dir(&webui_dir) |
43 | | - .status() |
44 | | - .expect("failed to spawn `pnpm install`"); |
45 | | - |
46 | | - if !install.success() { |
47 | | - panic!("pnpm install failed in webui/ — see output above"); |
48 | | - } |
49 | | - |
50 | | - // Build the frontend |
51 | | - let build = Command::new("pnpm") |
52 | | - .arg("build") |
53 | | - .current_dir(&webui_dir) |
54 | | - .status() |
55 | | - .expect("failed to spawn `pnpm build`"); |
56 | | - |
57 | | - if !build.success() { |
58 | | - panic!("pnpm build failed in webui/ — see output above"); |
59 | | - } |
60 | | - |
61 | | - // Sanity check |
62 | | - if !dist_index.exists() { |
63 | | - panic!( |
64 | | - "pnpm build succeeded but webui/dist/index.html was not created. \ |
65 | | - Check the vite config in webui/." |
66 | | - ); |
67 | | - } |
68 | | - |
69 | | - eprintln!("webui built successfully."); |
70 | | -} |
71 | 3 |
|
72 | 4 | fn main() -> Result<(), Error> { |
73 | | - ensure_webui_built(); |
74 | | - |
75 | 5 | let queries_path = "queries"; |
76 | 6 | let destination = format!("{}/api-sql.rs", std::env::var("OUT_DIR").unwrap()); |
77 | 7 | let settings = CodegenSettings { |
|
0 commit comments