|
1 | 1 | package registry |
2 | 2 |
|
| 3 | +import ( |
| 4 | + "io/ioutil" |
| 5 | + |
| 6 | + "github.com/commitdev/zero/internal/constants" |
| 7 | + "github.com/hashicorp/go-getter" |
| 8 | + |
| 9 | + yaml "gopkg.in/yaml.v2" |
| 10 | +) |
| 11 | + |
3 | 12 | type Registry []Stack |
| 13 | + |
4 | 14 | type Stack struct { |
5 | | - Name string |
6 | | - ModuleSources []string |
| 15 | + Name string `yaml:"name"` |
| 16 | + ModuleSources []string `yaml:"moduleSources"` |
7 | 17 | } |
8 | 18 |
|
9 | | -func GetRegistry(path string) Registry { |
10 | | - return Registry{ |
11 | | - // TODO: better place to store these options as configuration file or any source |
12 | | - { |
13 | | - "EKS + Go + React + Gatsby", |
14 | | - []string{ |
15 | | - path + "/zero-aws-eks-stack", |
16 | | - path + "/zero-static-site-gatsby", |
17 | | - path + "/zero-backend-go", |
18 | | - path + "/zero-frontend-react", |
19 | | - }, |
20 | | - }, |
21 | | - { |
22 | | - "EKS + NodeJS + React + Gatsby", |
23 | | - []string{ |
24 | | - path + "/zero-aws-eks-stack", |
25 | | - path + "/zero-static-site-gatsby", |
26 | | - path + "/zero-backend-node", |
27 | | - path + "/zero-frontend-react", |
28 | | - }, |
29 | | - }, |
| 19 | +func GetRegistry(localModulePath, registryFilePath string) (Registry, error) { |
| 20 | + registry := Registry{} |
| 21 | + |
| 22 | + err := getter.GetFile(constants.TmpRegistryYml, registryFilePath) |
| 23 | + if err != nil { |
| 24 | + return nil, err |
| 25 | + } |
| 26 | + |
| 27 | + data, err := ioutil.ReadFile(constants.TmpRegistryYml) |
| 28 | + if err != nil { |
| 29 | + return nil, err |
30 | 30 | } |
| 31 | + |
| 32 | + err = yaml.Unmarshal(data, ®istry) |
| 33 | + if err != nil { |
| 34 | + return nil, err |
| 35 | + } |
| 36 | + |
| 37 | + for i := 0; i < len(registry); i++ { |
| 38 | + for j := 0; j < len(registry[i].ModuleSources); j++ { |
| 39 | + registry[i].ModuleSources[j] = localModulePath + registry[i].ModuleSources[j] |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + return registry, nil |
31 | 44 | } |
32 | 45 |
|
33 | 46 | func GetModulesByName(registry Registry, name string) []string { |
|
0 commit comments