github.com/bscott/buffalo@v0.11.1/generators/grift/grift.go (about)

     1  package grift
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/gobuffalo/makr"
     9  	"github.com/pkg/errors"
    10  )
    11  
    12  //Run allows to create a new grift task generator
    13  func (gg Generator) Run(root string, data makr.Data) error {
    14  	g := makr.New()
    15  	defer g.Fmt(root)
    16  
    17  	header := tmplHeader
    18  	path := filepath.Join("grifts", gg.Name.File()+".go")
    19  
    20  	if _, err := os.Stat(path); err == nil {
    21  		template, err := ioutil.ReadFile(path)
    22  		if err != nil {
    23  			return errors.WithStack(err)
    24  		}
    25  		header = string(template)
    26  	}
    27  
    28  	g.Add(makr.NewFile(path, header+tmplBody))
    29  
    30  	data["opts"] = gg
    31  	return g.Run(root, data)
    32  }