livewire-rust 0.1.5

Livewire for Rust: server-rendered reactive components for Laravel for Rust.
Documentation
//! Makes the compiled-in asset id follow the build of `dist/`, so the server can tell a browser
//! which bundle it is served and compare it with a published copy.

use std::path::Path;

/// The key the build writes the bundle into `dist/manifest.json`.
const MANIFEST_KEY: &str = "/livewire.js";

fn main() {
    let manifest = Path::new("dist/manifest.json");
    println!("cargo:rerun-if-changed={}", manifest.display());
    println!("cargo:rerun-if-changed=dist/livewire.min.js");

    let id = std::fs::read_to_string(manifest)
        .ok()
        .and_then(|contents| manifest_id(&contents))
        .unwrap_or_default();

    println!("cargo:rustc-env=LIVEWIRE_ASSET_ID={id}");
}

/// The id under [`MANIFEST_KEY`], read without a JSON dependency in the build script.
fn manifest_id(contents: &str) -> Option<String> {
    let rest = contents.split(&format!("\"{MANIFEST_KEY}\"")).nth(1)?;
    let value = rest.split('"').nth(1)?;
    (!value.is_empty()).then(|| value.to_owned())
}