go-scm/cmd/scm/cmd_export.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

59 lines
1.3 KiB
Go

package scm
import (
"fmt"
"forge.lthn.ai/core/cli/pkg/cli"
"forge.lthn.ai/core/go-io"
"forge.lthn.ai/core/go-scm/manifest"
)
func addExportCommand(parent *cli.Command) {
var dir string
cmd := &cli.Command{
Use: "export",
Short: "Export compiled manifest as JSON",
Long: "Read core.json from the project root and print it to stdout. Falls back to compiling .core/manifest.yaml if core.json is not found.",
RunE: func(cmd *cli.Command, args []string) error {
return runExport(dir)
},
}
cmd.Flags().StringVarP(&dir, "dir", "d", ".", "Project root directory")
parent.AddCommand(cmd)
}
func runExport(dir string) error {
medium, err := io.NewSandboxed(dir)
if err != nil {
return cli.WrapVerb(err, "open", dir)
}
// Try core.json first.
cm, err := manifest.LoadCompiled(medium, ".")
if err != nil {
// Fall back to compiling from source.
m, loadErr := manifest.Load(medium, ".")
if loadErr != nil {
return cli.WrapVerb(loadErr, "load", "manifest")
}
cm, err = manifest.Compile(m, manifest.CompileOptions{
Commit: gitCommit(dir),
Tag: gitTag(dir),
BuiltBy: "core scm export",
})
if err != nil {
return err
}
}
data, err := manifest.MarshalJSON(cm)
if err != nil {
return cli.WrapVerb(err, "marshal", "manifest")
}
fmt.Println(string(data))
return nil
}