# Assemble the flat mount roots the CraftOS-PC harness expects from the
# per-package sources. Lua loads its deps by absolute mount path (require
# '/apis/x') and ccpm installs files flat, but sources now live under
# packages/<pkg>/{apis,programs,daemons,startup,tests}. This merges them back
# into a gitignored .stage/ that the dev/test recipes mount as /apis, /programs,
# /daemons, /startup, /tests, /musics. Regenerated on every run so it always
# reflects the working tree.
stage:
    #!/usr/bin/env bash
    set -euo pipefail
    repo='{{justfile_directory()}}'
    cd "$repo"
    stage="$repo/.stage"
    rm -rf "$stage"
    for dir in apis programs daemons startup tests musics; do
        for pkgdir in packages/*/"$dir"; do
            [ -d "$pkgdir" ] || continue
            mkdir -p "$stage/$dir"
            cp -R "$pkgdir/." "$stage/$dir/"
        done
    done
    printf '%s\n' 'OK: staged .stage/ from packages/'
