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>
59 lines
1.3 KiB
Go
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
|
|
}
|