Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve architecture of templates and template configs #17

Open
hbjydev opened this issue Jun 28, 2024 · 0 comments
Open

Improve architecture of templates and template configs #17

hbjydev opened this issue Jun 28, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@hbjydev
Copy link
Member

hbjydev commented Jun 28, 2024

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):

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.

@hbjydev hbjydev added enhancement New feature or request help wanted Extra attention is needed labels Jun 28, 2024
@hbjydev hbjydev changed the title Improve architecture of templates and template configs. Improve architecture of templates and template configs Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant