From 16d86665afea2f3515a54d7266bc2a3e98c32037 Mon Sep 17 00:00:00 2001 From: jon-stewart Date: Thu, 22 Feb 2024 14:14:52 +0000 Subject: [PATCH] fix: cdk backwards compatibility --- lwcomponent/catalog.go | 22 +++++++++++++++++++--- lwcomponent/host_info.go | 8 ++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lwcomponent/catalog.go b/lwcomponent/catalog.go index 76c3dce0c..a136d5644 100644 --- a/lwcomponent/catalog.go +++ b/lwcomponent/catalog.go @@ -347,14 +347,30 @@ func LoadLocalComponents() (components map[string]CDKComponent, err error) { components = make(map[string]CDKComponent, len(subDir)) + // Prototype backwards compatibility + prototypeState, err := LocalState() + prototypeComponents := make(map[string]Component, len(prototypeState.Components)) + for _, component := range prototypeState.Components { + prototypeComponents[component.Name] = component + } + for _, file := range subDir { if !file.IsDir() { continue } - hostInfo, err := NewHostInfo(filepath.Join(cacheDir, file.Name())) - if err != nil { - continue + hostInfo, _ := NewHostInfo(filepath.Join(cacheDir, file.Name())) + if hostInfo == nil { + + component, found := prototypeComponents[file.Name()] + if !found { + continue + } + + hostInfo, err = CreateHostInfo(filepath.Join(cacheDir, file.Name()), component.Description, component.Type) + if err != nil { + return nil, err + } } if hostInfo.Development() { diff --git a/lwcomponent/host_info.go b/lwcomponent/host_info.go index 836c45483..035db8d9c 100644 --- a/lwcomponent/host_info.go +++ b/lwcomponent/host_info.go @@ -46,7 +46,7 @@ func NewHostInfo(dir string) (*HostInfo, error) { return &info, nil } -func CreateHostInfo(dir string, desc string, componentType Type) error { +func CreateHostInfo(dir string, desc string, componentType Type) (*HostInfo, error) { path := filepath.Join(dir, InfoFile) if !file.FileExists(path) { @@ -58,13 +58,13 @@ func CreateHostInfo(dir string, desc string, componentType Type) error { buf := new(bytes.Buffer) if err := json.NewEncoder(buf).Encode(info); err != nil { - return err + return nil, err } - return os.WriteFile(path, buf.Bytes(), 0644) + return info, os.WriteFile(path, buf.Bytes(), 0644) } - return nil + return NewHostInfo(dir) } func (h *HostInfo) Delete() error {