github.com/JarrahG/buffalocli@v0.0.0-20230801092127-b85bfd5d395a/internal/genny/info/info.go (about)

     1  package info
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/gobuffalo/genny/v2"
     8  )
     9  
    10  const noBuffalo = "Warning: It seems like it is not a buffalo app. (.buffalo.dev.yml not found)\n\n"
    11  
    12  // New returns a generator that performs buffalo
    13  // related rx checks
    14  func New(opts *Options) (*genny.Generator, error) {
    15  	g := genny.New()
    16  
    17  	if err := opts.Validate(); err != nil {
    18  		return g, err
    19  	}
    20  
    21  	devFile := filepath.Join(opts.App.Root, ".buffalo.dev.yml")
    22  	if _, err := os.Stat(devFile); err != nil {
    23  		g.RunFn(func(r *genny.Runner) error {
    24  			opts.Out.Header("Buffalo: Application Details")
    25  			return opts.Out.WriteString(noBuffalo)
    26  		})
    27  		return g, nil
    28  	}
    29  
    30  	g.RunFn(appDetails(opts))
    31  
    32  	path := filepath.Join(opts.App.Root, "config")
    33  	if _, err := os.Stat(path); err == nil {
    34  		configFS := os.DirFS(path)
    35  		g.RunFn(configs(opts, configFS))
    36  	}
    37  
    38  	aFS := os.DirFS(opts.App.Root)
    39  	g.RunFn(pkgChecks(opts, aFS))
    40  
    41  	return g, nil
    42  }