forked from gobuffalo/buffalo
/
dep.go
98 lines (89 loc) · 2.17 KB
/
dep.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package updater
import (
"context"
"fmt"
"os"
"os/exec"
"github.com/gobuffalo/envy"
"github.com/markbates/deplist"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)
type lockToml struct {
Name string `toml:"name"`
Branch string `toml:"branch"`
Packages []string `toml:"packages"`
Revision string `toml:"revision"`
Version string `toml:"version"`
}
func goGetUpdate(r *Runner) error {
fmt.Println("~~~ Running go get ~~~")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
wg, _ := errgroup.WithContext(ctx)
deps, err := deplist.List()
if err != nil {
return errors.WithStack(err)
}
for dep := range deps {
args := []string{"get", "-u"}
args = append(args, dep)
cc := exec.Command(envy.Get("GO_BIN", "go"), args...)
f := func() error {
cc.Stdin = os.Stdin
cc.Stderr = os.Stderr
cc.Stdout = os.Stdout
return cc.Run()
}
wg.Go(f)
}
err = wg.Wait()
if err != nil {
return errors.Errorf("We encountered the following error trying to install and update the dependencies for this application:\n%s", err)
}
return nil
}
// DepEnsure runs `dep ensure -v` to make sure that any newly changed
// imports are added to dep.
func DepEnsure(r *Runner) error {
if !r.App.WithDep {
return goGetUpdate(r)
}
fmt.Println("~~~ Running dep ensure ~~~")
cc := exec.Command("dep", "ensure", "-v")
cc.Stdin = os.Stdin
cc.Stderr = os.Stderr
cc.Stdout = os.Stdout
if err := cc.Run(); err != nil {
return errors.WithStack(err)
}
apkg := []string{
"github.com/gobuffalo/tags@v2.0.0",
"github.com/gobuffalo/suite@v2.0.0",
}
args := []string{"ensure", "-v", "-add"}
for _, p := range apkg {
args = append(args, p)
}
cc = exec.Command("dep", args...)
cc.Stdin = os.Stdin
cc.Stderr = os.Stderr
cc.Stdout = os.Stdout
if err := cc.Run(); err != nil {
return errors.WithStack(err)
}
upkg := []string{
"github.com/gobuffalo/buffalo",
"github.com/gobuffalo/plush",
"github.com/markbates/inflect",
}
args = []string{"ensure", "-v", "-update"}
for _, p := range upkg {
args = append(args, p)
}
cc = exec.Command("dep", args...)
cc.Stdin = os.Stdin
cc.Stderr = os.Stderr
cc.Stdout = os.Stdout
return cc.Run()
}