diff --git a/internal/fileutil/yaml.go b/internal/fileutil/yaml.go index 10888aa..419b5ad 100644 --- a/internal/fileutil/yaml.go +++ b/internal/fileutil/yaml.go @@ -91,7 +91,23 @@ func FindSubdirsOfMatching(path string, matching []string) []string { return dirs } -func FindYAMLFiles(path string, name ...string) []string { +func FindYAMLFilesByName(path string, name ...string) []string { + return FindYAMLFiles(path, func(f string) bool { + for _, ext := range []string{".yaml", ".yml"} { + for _, n := range name { + if n+ext != f { + continue + } + + return true + } + } + + return false + }) +} + +func FindYAMLFiles(path string, match func(string) bool) []string { var files []string pathMap := make(map[string]struct{}) @@ -110,19 +126,13 @@ func FindYAMLFiles(path string, name ...string) []string { return nil } - for _, ext := range []string{".yaml", ".yml"} { - for _, n := range name { - if n+ext != info.Name() { - continue - } - - files = append(files, path) - pathMap[path] = struct{}{} - - return nil - } + if !match(info.Name()) { + return nil } + files = append(files, path) + pathMap[path] = struct{}{} + return nil }) diff --git a/pkg/config/app.go b/pkg/config/app.go index c5d5c95..3029992 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -67,12 +67,17 @@ func (i *AppDeployInfo) Proto() *apiv1.AppDeployInfo { } type AppNeed struct { + Dep string `yaml:"dependency,omitempty"` Other map[string]interface{} `yaml:"-,remain"` dep *Dependency } func (n *AppNeed) Normalize(name string, cfg *Project, data []byte) error { + if n.Dep != "" { + name = n.Dep + } + dep := cfg.DependencyByName(name) if dep == nil { return fileutil.YAMLError(fmt.Sprintf("$.needs.%s", name), fmt.Sprintf("'%s' not found in project dependencies", name), data) diff --git a/pkg/config/project.go b/pkg/config/project.go index fc4dd2b..7f44769 100644 --- a/pkg/config/project.go +++ b/pkg/config/project.go @@ -20,12 +20,14 @@ import ( apiv1 "github.com/outblocks/outblocks-plugin-go/gen/api/v1" plugin_util "github.com/outblocks/outblocks-plugin-go/util" "github.com/pterm/pterm" + "golang.org/x/exp/slices" ) const ( - ProjectYAMLName = "project.outblocks" - LockfileName = "outblocks.lock" - AppYAMLName = "app.outblocks" + ProjectYAMLName = "project.outblocks" + LockfileName = "outblocks.lock" + AppYAMLName = "app.outblocks" + AppYAMLNameSuffix = ".app.outblocks" ) var ( @@ -196,7 +198,26 @@ func (p *Project) LoadApps(mode LoadMode) error { return nil } - files := fileutil.FindYAMLFiles(p.Dir, AppYAMLNames...) + files := fileutil.FindYAMLFiles(p.Dir, func(f string) bool { + idx := strings.LastIndex(f, ".") + if idx == -1 { + return false + } + + ext := f[idx+1:] + + if ext != "yaml" && ext != "yml" { + return false + } + + name := f[:idx] + + if slices.Contains(AppYAMLNames, name) { + return true + } + + return strings.HasSuffix(name, AppYAMLNameSuffix) + }) if err := p.LoadAppFiles(files, mode); err != nil { return err