buildConfig returns a plugin.Config
(pkg Includable, projectDir, content string)
| 176 | |
| 177 | // buildConfig returns a plugin.Config |
| 178 | func buildConfig(pkg Includable, projectDir, content string) (*Config, error) { |
| 179 | cfg := &Config{PluginOnlyData: PluginOnlyData{Source: pkg}} |
| 180 | name := pkg.CanonicalName() |
| 181 | t, err := template.New(name + "-template").Parse(content) |
| 182 | if err != nil { |
| 183 | return nil, errors.WithStack(err) |
| 184 | } |
| 185 | var buf bytes.Buffer |
| 186 | if err = t.Execute(&buf, map[string]string{ |
| 187 | "DevboxProjectDir": projectDir, |
| 188 | "DevboxDir": filepath.Join(projectDir, devboxDirName, name), |
| 189 | "DevboxDirRoot": filepath.Join(projectDir, devboxDirName), |
| 190 | "DevboxProfileDefault": filepath.Join(projectDir, nix.ProfilePath), |
| 191 | "Virtenv": filepath.Join(projectDir, VirtenvPath, name), |
| 192 | }); err != nil { |
| 193 | return nil, errors.WithStack(err) |
| 194 | } |
| 195 | |
| 196 | jsonb, err := jsonPurifyPluginContent(buf.Bytes()) |
| 197 | if err != nil { |
| 198 | return nil, err |
| 199 | } |
| 200 | |
| 201 | return cfg, errors.WithStack(json.Unmarshal(jsonb, cfg)) |
| 202 | } |
| 203 | |
| 204 | func jsonPurifyPluginContent(content []byte) ([]byte, error) { |
| 205 | return hujson.Standardize(slices.Clone(content)) |
no test coverage detected