summaryrefslogtreecommitdiff
path: root/build.rs
blob: 3b7abda9c11d43bb6d7e3dc5d42f6b42cdfc3e76 (plain)
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
use std::{io, process::Command};

fn main() -> Result<(), io::Error> {
    // trigger recompilation when a new migration is added
    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=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(())
}