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

Improve architecture of templates and template configs

Offen
#17 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement help wanted
Vorherrschende Sprache
Go
Sterne
10
Forks
1
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.