|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | ociregistry "github.com/intelops/compage/cmd/artifacts" |
5 | 6 | "github.com/intelops/compage/cmd/models" |
6 | 7 | "github.com/intelops/compage/internal/converter/cmd" |
@@ -62,38 +63,79 @@ func GenerateCode() error { |
62 | 63 | return err |
63 | 64 | } |
64 | 65 |
|
65 | | - if len(coreProject.License.Path) > 0 { |
66 | | - // assign absolute path to the license file Path if it's not |
67 | | - absPath, err := filepath.Abs(coreProject.License.Path) |
68 | | - if err != nil { |
69 | | - log.Errorf("error while getting absolute path [" + err.Error() + "]") |
70 | | - return err |
| 66 | + if project.Metadata != nil { |
| 67 | + license := &models.License{} |
| 68 | + l, ok := project.Metadata["license"] |
| 69 | + if ok { |
| 70 | + // convert the license data to byte array |
| 71 | + licenseData, err1 := json.Marshal(l) |
| 72 | + if err1 != nil { |
| 73 | + log.Errorf("error while marshalling license data [" + err1.Error() + "]") |
| 74 | + return err1 |
| 75 | + } |
| 76 | + // convert the license data to license struct |
| 77 | + err1 = json.Unmarshal(licenseData, license) |
| 78 | + if err1 != nil { |
| 79 | + log.Errorf("error while unmarshalling license data [" + err1.Error() + "]") |
| 80 | + return err1 |
| 81 | + } |
| 82 | + // assign absolute path to the license file Path if it's not set |
| 83 | + if len(license.Path) > 0 { |
| 84 | + // assign absolute path to the license file Path if it's not |
| 85 | + absPath, err2 := filepath.Abs(license.Path) |
| 86 | + if err2 != nil { |
| 87 | + log.Errorf("error while getting absolute path [" + err2.Error() + "]") |
| 88 | + return err2 |
| 89 | + } |
| 90 | + license.Path = absPath |
| 91 | + } |
| 92 | + project.Metadata["license"] = license |
| 93 | + } else { |
| 94 | + log.Warn("license data not found in project metadata") |
71 | 95 | } |
72 | | - coreProject.License.Path = absPath |
73 | 96 | } |
74 | 97 |
|
75 | 98 | // assign absolute path to the license file path if it's not (if supplied for the nodes) |
76 | 99 | for _, node := range coreProject.CompageJSON.Nodes { |
77 | | - if len(node.License.Path) > 0 { |
78 | | - absPath, err := filepath.Abs(node.License.Path) |
79 | | - if err != nil { |
80 | | - log.Errorf("error while getting absolute path [" + err.Error() + "]") |
81 | | - return err |
| 100 | + license := &models.License{} |
| 101 | + l, ok := node.Metadata["license"] |
| 102 | + if ok { |
| 103 | + // convert the license data to byte array |
| 104 | + licenseData, err1 := json.Marshal(l) |
| 105 | + if err1 != nil { |
| 106 | + log.Errorf("error while marshalling license data [" + err1.Error() + "]") |
| 107 | + return err1 |
| 108 | + } |
| 109 | + // convert the license data to license struct |
| 110 | + err1 = json.Unmarshal(licenseData, license) |
| 111 | + if err1 != nil { |
| 112 | + log.Errorf("error while unmarshalling license data [" + err1.Error() + "]") |
| 113 | + return err1 |
| 114 | + } |
| 115 | + // assign absolute path to the license file Path if it's not set |
| 116 | + if len(license.Path) > 0 { |
| 117 | + // assign absolute path to the license file Path if it's not |
| 118 | + absPath, err2 := filepath.Abs(license.Path) |
| 119 | + if err2 != nil { |
| 120 | + log.Errorf("error while getting absolute path [" + err2.Error() + "]") |
| 121 | + return err2 |
| 122 | + } |
| 123 | + license.Path = absPath |
82 | 124 | } |
83 | | - node.License.Path = absPath |
| 125 | + node.Metadata["license"] = license |
84 | 126 | } |
85 | 127 | } |
86 | 128 |
|
87 | 129 | // pull all required templates |
88 | 130 | // pull the common templates |
89 | | - err = ociregistry.PullOCIArtifact("common", project.Version) |
| 131 | + err = ociregistry.PullOCIArtifact("common", project.CompageCoreVersion) |
90 | 132 | if err != nil { |
91 | 133 | log.Errorf("error while pulling the common templates [" + err.Error() + "]") |
92 | 134 | return err |
93 | 135 | } |
94 | 136 | for _, node := range coreProject.CompageJSON.Nodes { |
95 | 137 | // make sure that the latest template is pulled |
96 | | - err = ociregistry.PullOCIArtifact(node.Language, project.Version) |
| 138 | + err = ociregistry.PullOCIArtifact(node.Language, project.CompageCoreVersion) |
97 | 139 | if err != nil { |
98 | 140 | log.Errorf("error while pulling the template [" + err.Error() + "]") |
99 | 141 | return err |
|
0 commit comments