scripts/dev.nu

#!/usr/bin/env nu
# dev.nu โ€” one-step rebuild + restart for local dev.
#
# Run this after ANY change under ~/cyberia-to/optica (Rust source,
# templates/*.html, static/*.css|js|woff2). Optica's binary embeds
# templates and static assets via include_str!, so editing the source
# files alone has no effect on the running serve.
#
# Sequence: cargo build (release) โ†’ kill any running optica serve โ†’
# launch a fresh serve in the background. Returns once the new serve
# has started; readiness is then verified by the caller.

def main [
    --port: int = 8888
] {
    let optica_dir = $"($env.HOME)/cyberia-to/optica"
    let workspace = $"($env.HOME)/cyberia-to/cyber"

    print "โ–ธ build"
    do {
        cd $optica_dir
        ^cargo build --release
    }

    print "โ–ธ stop old serve"
    # Use bash to kill matching processes โ€” nu's `ps` schema and pipe
    # syntax vary across versions; bash + pgrep + xargs is portable.
    ^bash -c 'pgrep -f "optica serve" | xargs kill 2>/dev/null; pgrep -f "scripts/serve.nu" | xargs kill 2>/dev/null; true'
    sleep 1sec

    print $"โ–ธ start serve on ($port)"
    cd $workspace
    nu scripts/serve.nu --port $port
}

Graph