go-scm/cmd/scm/cmd_index.go
Snider 631ddd4887
Some checks failed
Security Scan / security (push) Failing after 7s
Test / test (push) Failing after 2m47s
feat(manifest): add compile step and marketplace index builder
Add manifest compilation (.core/manifest.yaml → core.json) with build
metadata (commit, tag, timestamp, signature) and marketplace index
generation by crawling directories for compiled or source manifests.

New files:
- manifest/compile.go: CompiledManifest, Compile(), ParseCompiled(),
  WriteCompiled(), LoadCompiled(), MarshalJSON()
- marketplace/builder.go: Builder.BuildFromDirs(), BuildFromManifests(),
  WriteIndex()
- cmd/scm/: CLI commands — compile, index, export

Tests: 26 new (12 manifest, 14 marketplace), all passing.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-15 14:12:52 +00:00

61 lines
1.6 KiB
Go

package scm
import (
"fmt"
"path/filepath"
"forge.lthn.ai/core/cli/pkg/cli"
"forge.lthn.ai/core/go-scm/marketplace"
)
func addIndexCommand(parent *cli.Command) {
var (
dirs []string
output string
baseURL string
org string
)
cmd := &cli.Command{
Use: "index",
Short: "Build marketplace index from directories",
Long: "Scan directories for core.json or .core/manifest.yaml files and generate a marketplace index.json.",
RunE: func(cmd *cli.Command, args []string) error {
if len(dirs) == 0 {
dirs = []string{"."}
}
return runIndex(dirs, output, baseURL, org)
},
}
cmd.Flags().StringArrayVarP(&dirs, "dir", "d", nil, "Directories to scan (repeatable, default: current directory)")
cmd.Flags().StringVarP(&output, "output", "o", "index.json", "Output path for the index file")
cmd.Flags().StringVar(&baseURL, "base-url", "", "Base URL for repo links (e.g. https://forge.lthn.ai)")
cmd.Flags().StringVar(&org, "org", "", "Organisation for repo links")
parent.AddCommand(cmd)
}
func runIndex(dirs []string, output, baseURL, org string) error {
b := &marketplace.Builder{
BaseURL: baseURL,
Org: org,
}
idx, err := b.BuildFromDirs(dirs...)
if err != nil {
return cli.WrapVerb(err, "build", "index")
}
absOutput, _ := filepath.Abs(output)
if err := marketplace.WriteIndex(absOutput, idx); err != nil {
return err
}
cli.Blank()
cli.Print(" %s %s\n", successStyle.Render("index built"), valueStyle.Render(output))
cli.Print(" %s %s\n", dimStyle.Render("modules:"), numberStyle.Render(fmt.Sprintf("%d", len(idx.Modules))))
cli.Blank()
return nil
}