livebud / bud

The Full-Stack Web Framework for Go
MIT License
5.58k stars 179 forks source link

framework/generator: expand capabilities of generators with a generator.Register #297

Closed matthewmueller closed 2 years ago

matthewmueller commented 2 years ago

Follow-up to: https://github.com/livebud/bud/pull/296

Generators can now generate anywhere. For example, you can define a generator in generator/tailwind:

package tailwind

import (
    "github.com/livebud/bud/package/budfs"
)

type Generator struct {
    Compiler *tailwind.Compiler
}

func (g *Generator) Register(dir *budfs.Dir) {
    dir.GenerateFile("bud/internal/tailwind/tailwind.go", func(fsys budfs.FS, file *budfs.File) error {
        file.Data = []byte("package tailwind\n// compiled tailwind")
        return nil
    })
}