Unified Agent + reusable Go agent core.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

build: add backend builder with optional console embed

Lyric 0beb81db 82f2b6f0

+140 -23
+7 -12
cmd/mistermorph/consolecmd/console_assets.go
··· 1 + //go:build !noembedconsole 2 + 1 3 package consolecmd 2 4 3 5 import ( 4 6 "embed" 5 - "fmt" 6 7 "io/fs" 7 8 ) 8 9 ··· 11 12 12 13 var consoleStaticFS = mustConsoleStaticFS() 13 14 15 + func embeddedConsoleAssetsEnabled() bool { 16 + return true 17 + } 18 + 14 19 func mustConsoleStaticFS() fs.FS { 15 20 staticFS, err := fs.Sub(embeddedConsoleAssets, "static") 16 21 if err != nil { 17 - panic(fmt.Sprintf("console embedded assets unavailable: %v", err)) 22 + panic("console embedded assets unavailable: " + err.Error()) 18 23 } 19 24 if err := validateConsoleStaticFS(staticFS); err != nil { 20 25 panic(err.Error()) 21 26 } 22 27 return staticFS 23 28 } 24 - 25 - func validateConsoleStaticFS(staticFS fs.FS) error { 26 - if staticFS == nil { 27 - return fmt.Errorf("console embedded assets missing index.html; run scripts/stage-console-assets.sh before building: static fs is nil") 28 - } 29 - if _, err := fs.Stat(staticFS, "index.html"); err != nil { 30 - return fmt.Errorf("console embedded assets missing index.html; run scripts/stage-console-assets.sh before building: %w", err) 31 - } 32 - return nil 33 - }
+16
cmd/mistermorph/consolecmd/console_assets_common.go
··· 1 + package consolecmd 2 + 3 + import ( 4 + "fmt" 5 + "io/fs" 6 + ) 7 + 8 + func validateConsoleStaticFS(staticFS fs.FS) error { 9 + if staticFS == nil { 10 + return fmt.Errorf("console embedded assets missing index.html; run scripts/stage-console-assets.sh before building: static fs is nil") 11 + } 12 + if _, err := fs.Stat(staticFS, "index.html"); err != nil { 13 + return fmt.Errorf("console embedded assets missing index.html; run scripts/stage-console-assets.sh before building: %w", err) 14 + } 15 + return nil 16 + }
+11
cmd/mistermorph/consolecmd/console_assets_noembed.go
··· 1 + //go:build noembedconsole 2 + 3 + package consolecmd 4 + 5 + import "io/fs" 6 + 7 + var consoleStaticFS fs.FS 8 + 9 + func embeddedConsoleAssetsEnabled() bool { 10 + return false 11 + }
+5 -2
cmd/mistermorph/consolecmd/serve_test.go
··· 231 231 if cfg.staticDir != "" { 232 232 t.Fatalf("cfg.staticDir = %q, want empty", cfg.staticDir) 233 233 } 234 - if cfg.staticFS == nil { 235 - t.Fatalf("cfg.staticFS is nil, want embedded assets") 234 + if got, want := cfg.staticFS != nil, embeddedConsoleAssetsEnabled(); got != want { 235 + t.Fatalf("cfg.staticFS enabled = %v, want %v", got, want) 236 + } 237 + if got, want := cfg.staticAssetsEnabled(), embeddedConsoleAssetsEnabled(); got != want { 238 + t.Fatalf("cfg.staticAssetsEnabled() = %v, want %v", got, want) 236 239 } 237 240 } 238 241
+7 -3
desktop/wails/README.md
··· 25 25 Build console assets first: 26 26 27 27 ```bash 28 - pnpm --dir web/console build 29 - ./scripts/stage-console-assets.sh 30 - CGO_ENABLED=0 go build -o ./bin/mistermorph ./cmd/mistermorph 28 + ./scripts/build-backend.sh --output ./bin/mistermorph 29 + ``` 30 + 31 + To build a backend binary without embedding the Console SPA, use: 32 + 33 + ```bash 34 + ./scripts/build-backend.sh --no-embed-frontend --output ./bin/mistermorph 31 35 ``` 32 36 33 37 The bundled `mistermorph` backend should stay `CGO_ENABLED=0`.
+93
scripts/build-backend.sh
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 5 + cd "${ROOT_DIR}" 6 + 7 + OUTPUT="./bin/mistermorph" 8 + EMBED_FRONTEND=1 9 + BUILD_FRONTEND=1 10 + 11 + usage() { 12 + cat <<'EOF' 13 + Usage: scripts/build-backend.sh [options] 14 + 15 + Build the backend binary used by CLI and desktop packaging. 16 + 17 + Options: 18 + --output PATH Override backend binary output path 19 + --no-embed-frontend Build backend without embedded Console SPA assets 20 + --skip-frontend-build Reuse existing web/console/dist instead of rebuilding it 21 + -h, --help Show this help 22 + 23 + Notes: 24 + - Default behavior embeds the Console frontend into the backend binary. 25 + - --no-embed-frontend adds the Go build tag: noembedconsole 26 + - When embedding the frontend, this script stages web/console/dist into 27 + cmd/mistermorph/consolecmd/static before go build. 28 + - CGO defaults to disabled for this backend build; override with CGO_ENABLED=1 29 + if you intentionally need a cgo-enabled backend binary. 30 + EOF 31 + } 32 + 33 + while [[ $# -gt 0 ]]; do 34 + case "$1" in 35 + --output) 36 + OUTPUT="${2:-}" 37 + shift 2 38 + ;; 39 + --no-embed-frontend) 40 + EMBED_FRONTEND=0 41 + shift 42 + ;; 43 + --skip-frontend-build) 44 + BUILD_FRONTEND=0 45 + shift 46 + ;; 47 + -h|--help) 48 + usage 49 + exit 0 50 + ;; 51 + *) 52 + echo "Unknown option: $1" >&2 53 + usage >&2 54 + exit 1 55 + ;; 56 + esac 57 + done 58 + 59 + if [[ -z "${OUTPUT}" ]]; then 60 + echo "Output path cannot be empty." >&2 61 + exit 1 62 + fi 63 + 64 + mkdir -p "$(dirname "${OUTPUT}")" 65 + 66 + build_tags=() 67 + if [[ "${EMBED_FRONTEND}" == "1" ]]; then 68 + if [[ "${BUILD_FRONTEND}" == "1" ]]; then 69 + echo "==> Building web/console" 70 + pnpm --dir web/console build 71 + fi 72 + 73 + echo "==> Staging console assets" 74 + ./scripts/stage-console-assets.sh 75 + else 76 + build_tags+=(noembedconsole) 77 + fi 78 + 79 + echo "==> Building backend ${OUTPUT}" 80 + if [[ ${#build_tags[@]} -gt 0 ]]; then 81 + echo " tags: ${build_tags[*]}" 82 + CGO_ENABLED="${CGO_ENABLED:-0}" go build -tags "${build_tags[*]}" -o "${OUTPUT}" ./cmd/mistermorph 83 + else 84 + CGO_ENABLED="${CGO_ENABLED:-0}" go build -o "${OUTPUT}" ./cmd/mistermorph 85 + fi 86 + 87 + echo 88 + echo "Built backend: ${OUTPUT}" 89 + if [[ "${EMBED_FRONTEND}" == "1" ]]; then 90 + echo "Console frontend: embedded" 91 + else 92 + echo "Console frontend: external (--console-static-dir required for SPA serving)" 93 + fi
+1 -6
scripts/build-desktop.sh
··· 79 79 fi 80 80 81 81 if [[ "${BUILD_BACKEND}" == "1" ]]; then 82 - echo "==> Staging console assets" 83 - ./scripts/stage-console-assets.sh 84 - fi 85 - 86 - if [[ "${BUILD_BACKEND}" == "1" ]]; then 87 82 echo "==> Building backend ${BACKEND_OUTPUT}" 88 - CGO_ENABLED=0 go build -o "${BACKEND_OUTPUT}" ./cmd/mistermorph 83 + ./scripts/build-backend.sh --skip-frontend-build --output "${BACKEND_OUTPUT}" 89 84 fi 90 85 91 86 desktop_tags=(wailsdesktop)