frame-cli 0.3.0

CLI for Frame — five intention-verbs over one application: frame new scaffolds it, frame run serves it, frame test proves it (real browser included), frame check verifies it statically, frame doctor walks the prerequisites
Documentation
//! Builds the generated Gleam component into loadable BEAM files.

use std::env;
use std::fs;
use std::io;
use std::path::PathBuf;
use std::process::Command;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("cargo:rerun-if-changed=../component/src");
    println!("cargo:rerun-if-changed=../component/gleam.toml");

    let component = PathBuf::from("../component");
    let version = Command::new("gleam").arg("--version").output().map_err(|error| {
        io::Error::new(
            error.kind(),
            format!("Gleam toolchain is required; install it from https://gleam.run/getting-started/installing/ ({error})"),
        )
    })?;
    if !version.status.success() {
        return Err(io::Error::other(format!(
            "Gleam toolchain check failed; install a working gleam command: {}",
            String::from_utf8_lossy(&version.stderr)
        ))
        .into());
    }
    let output = Command::new("gleam")
        .arg("build")
        .current_dir(&component)
        .output()?;
    if !output.status.success() {
        return Err(io::Error::other(format!(
            "gleam build failed: {}",
            String::from_utf8_lossy(&output.stderr)
        ))
        .into());
    }

    let ebin = component.join("build/dev/erlang/{{GLEAM_NAME}}/ebin");
    let out = PathBuf::from(env::var("OUT_DIR")?);
    for module in ["{{GLEAM_NAME}}", "{{GLEAM_NAME}}_ffi"] {
        let source = ebin.join(format!("{module}.beam"));
        fs::copy(&source, out.join(format!("{module}.beam"))).map_err(|error| {
            io::Error::new(
                error.kind(),
                format!(
                    "copying compiled component bytecode from {} failed: {error}",
                    source.display()
                ),
            )
        })?;
    }
    Ok(())
}