github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/grift/initializer.go (about)

     1  package grift
     2  
     3  import (
     4  	"context"
     5  	"embed"
     6  	"path/filepath"
     7  
     8  	"github.com/wawandco/oxpecker/internal/source"
     9  	"github.com/wawandco/oxpecker/lifecycle/new"
    10  )
    11  
    12  var (
    13  	//go:embed templates
    14  	templates embed.FS
    15  )
    16  
    17  type Initializer struct{}
    18  
    19  func (i Initializer) Name() string {
    20  	return "grift/initializer"
    21  }
    22  
    23  func (i Initializer) Initialize(ctx context.Context, options new.Options) error {
    24  	content, err := templates.ReadFile("templates/grift.go.tmpl")
    25  	if err != nil {
    26  		return err
    27  	}
    28  
    29  	err = source.Build(filepath.Join(options.Folder, "app", "tasks", "tasks.go"), string(content), options.Module)
    30  	return err
    31  }