github.com/rotblauer/buffalo@v0.7.1-0.20170112214545-7aa55ef80dd3/grifts/shoulders.go (about)

     1  package grifts
     2  
     3  import (
     4  	"html/template"
     5  	"os"
     6  	"os/exec"
     7  	"path"
     8  	"strings"
     9  
    10  	. "github.com/markbates/grift/grift"
    11  )
    12  
    13  var _ = Desc("shoulders", "Generates a file listing all of the 3rd party packages used by buffalo.")
    14  var _ = Add("shoulders", func(c *Context) error {
    15  	giants := map[string]string{
    16  		"github.com/markbates/refresh": "github.com/markbates/refresh",
    17  		"github.com/markbates/grift":   "github.com/markbates/grift",
    18  		"github.com/markbates/pop":     "github.com/markbates/pop",
    19  		"github.com/spf13/cobra":       "github.com/spf13/cobra",
    20  		"github.com/motemen/gore":      "github.com/motemen/gore",
    21  	}
    22  
    23  	for _, p := range []string{".", "./render"} {
    24  		cmd := exec.Command("go", "list", "-f", `'* {{ join .Deps  "\n"}}'`, p)
    25  		b, err := cmd.Output()
    26  		if err != nil {
    27  			return err
    28  		}
    29  
    30  		list := strings.Split(string(b), "\n")
    31  
    32  		for _, g := range list {
    33  			if strings.Contains(g, "github.com") {
    34  				giants[g] = g
    35  			}
    36  		}
    37  	}
    38  
    39  	f, err := os.Create(path.Join(os.Getenv("GOPATH"), "src", "github.com", "gobuffalo", "buffalo", "SHOULDERS.md"))
    40  	if err != nil {
    41  		return err
    42  	}
    43  	t, err := template.New("").Parse(shouldersTemplate)
    44  	if err != nil {
    45  		return err
    46  	}
    47  	err = t.Execute(f, giants)
    48  	if err != nil {
    49  		return err
    50  	}
    51  
    52  	return commitAndPushShoulders()
    53  })
    54  
    55  func commitAndPushShoulders() error {
    56  	cmd := exec.Command("git", "commit", "SHOULDERS.md", "-m", "Updated SHOULDERS.md")
    57  	cmd.Stdin = os.Stdin
    58  	cmd.Stderr = os.Stderr
    59  	cmd.Stdout = os.Stdout
    60  	err := cmd.Run()
    61  	if err != nil {
    62  		return err
    63  	}
    64  
    65  	cmd = exec.Command("git", "push", "origin")
    66  	cmd.Stdin = os.Stdin
    67  	cmd.Stderr = os.Stderr
    68  	cmd.Stdout = os.Stdout
    69  	return cmd.Run()
    70  }
    71  
    72  var shouldersTemplate = `
    73  # Buffalo Stands on the Shoulders of Giants
    74  
    75  Buffalo does not try to reinvent the wheel! Instead, it uses the already great wheels developed by the Go community and puts them altogether in the best way possible. Without these giants this project would not be possible. Please make sure to check them out and thank them for all of their hard work.
    76  
    77  Thank you to the following **GIANTS**:
    78  
    79  {{ range $k, $v := .}}
    80  * [{{$k}}](https://{{$v}})
    81  {{ end }}
    82  `