47 lines
934 B
Cheetah
47 lines
934 B
Cheetah
package schemas
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"cuelang.org/go/cue"
|
|
"cuelang.org/go/cue/cuecontext"
|
|
)
|
|
|
|
type CoreKind struct {
|
|
Name string
|
|
CueFile cue.Value
|
|
}
|
|
|
|
func GetCoreKinds() ([]CoreKind, error) {
|
|
ctx := cuecontext.New()
|
|
kinds := make([]CoreKind, 0)
|
|
|
|
_, caller, _, _ := runtime.Caller(0)
|
|
root := filepath.Join(caller, "../../../..")
|
|
|
|
{{- range .Schemas }}
|
|
|
|
{{ .Name }}Cue, err := loadCueFile(ctx, filepath.Join(root, "{{ .FilePath }}"))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
kinds = append(kinds, CoreKind{
|
|
Name: "{{ .Name }}",
|
|
CueFile: {{ .Name }}Cue,
|
|
})
|
|
{{- end }}
|
|
|
|
return kinds, nil
|
|
}
|
|
|
|
func loadCueFile(ctx *cue.Context, path string) (cue.Value, error) {
|
|
cueFile, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return cue.Value{}, err
|
|
}
|
|
|
|
return ctx.CompileBytes(cueFile), nil
|
|
}
|