github.com/jasonish/buffalo@v0.8.2-0.20170413145823-bacbdd415f1b/grifts/shoulders.go (about)

     1  package grifts
     2  
     3  import (
     4  	"fmt"
     5  	"html/template"
     6  	"os"
     7  	"os/exec"
     8  	"path"
     9  	"sort"
    10  	"strings"
    11  
    12  	"github.com/gobuffalo/envy"
    13  	"github.com/markbates/deplist"
    14  	"github.com/markbates/grift/grift"
    15  )
    16  
    17  var _ = grift.Desc("shoulders", "Prints a listing all of the 3rd party packages used by buffalo.")
    18  var _ = grift.Add("shoulders:list", func(c *grift.Context) error {
    19  	giants, _ := deplist.List("examples")
    20  	for _, k := range []string{
    21  		"github.com/markbates/refresh",
    22  		"github.com/markbates/grift",
    23  		"github.com/markbates/pop",
    24  		"github.com/spf13/cobra",
    25  		"github.com/motemen/gore",
    26  		"golang.org/x/tools/cmd/goimports",
    27  	} {
    28  		giants[k] = k
    29  	}
    30  
    31  	deps := make([]string, 0, len(giants))
    32  	for k := range giants {
    33  		if !strings.Contains(k, "github.com/gobuffalo/buffalo") {
    34  			deps = append(deps, k)
    35  		}
    36  	}
    37  	sort.Strings(deps)
    38  	fmt.Println(strings.Join(deps, "\n"))
    39  	c.Set("giants", deps)
    40  	return nil
    41  })
    42  
    43  var _ = grift.Desc("shoulders", "Generates a file listing all of the 3rd party packages used by buffalo.")
    44  var _ = grift.Add("shoulders", func(c *grift.Context) error {
    45  	err := grift.Run("shoulders:list", c)
    46  	if err != nil {
    47  		return err
    48  	}
    49  	f, err := os.Create(path.Join(envy.GoPath(), "src", "github.com", "gobuffalo", "buffalo", "SHOULDERS.md"))
    50  	if err != nil {
    51  		return err
    52  	}
    53  	t, err := template.New("").Parse(shouldersTemplate)
    54  	if err != nil {
    55  		return err
    56  	}
    57  	err = t.Execute(f, c.Get("giants"))
    58  	if err != nil {
    59  		return err
    60  	}
    61  
    62  	return commitAndPushShoulders()
    63  })
    64  
    65  func commitAndPushShoulders() error {
    66  	cmd := exec.Command("git", "commit", "SHOULDERS.md", "-m", "Updated SHOULDERS.md")
    67  	cmd.Stdin = os.Stdin
    68  	cmd.Stderr = os.Stderr
    69  	cmd.Stdout = os.Stdout
    70  	err := cmd.Run()
    71  	if err != nil {
    72  		return err
    73  	}
    74  
    75  	cmd = exec.Command("git", "push", "origin")
    76  	cmd.Stdin = os.Stdin
    77  	cmd.Stderr = os.Stderr
    78  	cmd.Stdout = os.Stdout
    79  	return cmd.Run()
    80  }
    81  
    82  var shouldersTemplate = `
    83  # Buffalo Stands on the Shoulders of Giants
    84  
    85  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.
    86  
    87  Thank you to the following **GIANTS**:
    88  
    89  {{ range $v := .}}
    90  * [{{$v}}](https://{{$v}})
    91  {{ end }}
    92  `