diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-22 21:12:32 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-22 21:14:06 -0400 |
| commit | e7d4b6d7ddbcd0128e47476e6cd1d824a1929f3c (patch) | |
| tree | c8f134624171bdefa1010fe6a0cd374ea0901c2f /build.rs | |
| parent | 6430854352745f45281021c305b4e350bc92d535 (diff) | |
Let `cargo` handle building the UI, where possible.
This allows skipping the `target/ui` rebuild if the UI has not changed, which has otherwise been a bit of a source of drag on my development speed.
Diffstat (limited to 'build.rs')
| -rw-r--r-- | build.rs | 45 |
1 files changed, 42 insertions, 3 deletions
@@ -1,5 +1,44 @@ -// generated by `sqlx migrate build-script` -fn main() { +use std::{io, process::Command}; + +fn main() -> Result<(), io::Error> { // trigger recompilation when a new migration is added - println!("cargo:rerun-if-changed=migrations"); + println!("cargo::rerun-if-changed=migrations"); + + // rerun npm install whenever packages or npm config are changed + println!("cargo::rerun-if-changed=.npmrc"); + println!("cargo::rerun-if-changed=package.json"); + // `node_modules` and `package-lock.json` are always touched if `npm install` + // runs, leading to spurious rebuilds. + // + // See: <https://github.com/npm/cli/issues/7874> + // println!("cargo::rerun-if-changed=package-lock.json"); + // println!("cargo::rerun-if-changed=node_modules"); + let status = Command::new("npm").args(["install"]).status()?; + if !status.success() { + return Err(io::Error::other(format!( + "'npm install' exited with status {status:?}" + ))); + } + + // rerun `npm run build` whenever the UI changes. + // + // `node_modules` is always touched if `npm install` runs, leading to spurious + // rebuilds. (This duplicate is purely organizational; it reflects that the ui + // depends on node_modules.) + // + // See: <https://github.com/npm/cli/issues/7874> + // println!("cargo::rerun-if-changed=node_modules"); + println!("cargo::rerun-if-changed=postcss.config.js"); + println!("cargo::rerun-if-changed=svelte.config.js"); + println!("cargo::rerun-if-changed=tailwind.config.js"); + println!("cargo::rerun-if-changed=vite.config.js"); + println!("cargo::rerun-if-changed=ui"); + let status = Command::new("npm").args(["run", "build"]).status()?; + if !status.success() { + return Err(io::Error::other(format!( + "'npm run build' exited with status {status:?}" + ))); + } + + Ok(()) } |
