ALT-F4-LLC / ALT-F4-LLC/build-configs

Improve architecture of templates and template configs

Aberta
#17 0 comentários 0 reações 0 responsáveis Ver no GitHub
enhancement help wanted
Linguagem predominante
Go
Estrelas
10
Forks
1
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

While trying to implement a new template type on stream, BG ran into a number of issues; however, one of the biggest (and easiest to target) was the amount of coordination there is to do around the codebase to implement a set of templates.

We need something better from a DevEx perspective that makes these easier to do.

---

I'm thinking something along these lines (pseudocode):

```go
type TemplateParameters interface {
// FillDefaults populates the params struct with default values.
FillDefaults()
}

// Template represents a renderable template
type Template[T any] struct {
templates templates.RenderMap
}

// Render renders the template files out to the current directory
func (t Template) Render() error {
// Logic used to write templates for _every_ template type.
}

// -------------------------

type GoLambdaParameters struct {
Nix NixConfig `json:"nix" yaml:"nix"`
}

func (p GoLambdaParameters) FillDefaults() {
p.Nix = NewNixConfig()
}

// -------------------------

var Templates = map[string]Template[TemplateParameters]{
"go-lambda": Template[GoLambdaParameters]{
templates: templates.RenderMap{
templates.GoCommonTemplates{".editorconfig"},
templates.GoLambdaTemplates{".github/workflows/flake.yaml"},
},
},
}

func main() {
t := Templates["go-lambda"]
if err := t.Render(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to render template '%v': %v", t.name, err)
os.Exit(1)
}
}
```

What this pseudocode _doesn't_ cover is finding a better way to implement loading in the templates; maybe we can pass in a template path as part of the TemplateMap type or similar that will load them dynamically during the `Render()` procedure.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.