-
Notifications
You must be signed in to change notification settings - Fork 14
/
dependency.go
69 lines (60 loc) · 1.3 KB
/
dependency.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
package upgrade
import (
"errors"
"fmt"
"github.com/duke-git/lancet/v2/fileutil"
"github.com/suyuan32/goctls/config"
"github.com/suyuan32/goctls/rpc/execx"
"path/filepath"
"strings"
)
func upgradeDependencies(workDir string) error {
// drop old replace
for _, v := range config.OldGoZeroVersion {
_, err := execx.Run(fmt.Sprintf("go mod edit -dropreplace github.com/zeromicro/go-zero@%s", v), workDir)
if err != nil {
return errors.New("failed to drop old replace")
}
}
data, err := fileutil.ReadFileToString(filepath.Join(workDir, "go.mod"))
if err != nil {
return err
}
err = upgradeOfficialDependencies(data, workDir)
if err != nil {
return err
}
err = tidy()
if err != nil {
return err
}
return nil
}
func upgradeOfficialDependencies(data, workDir string) (err error) {
deps := []struct {
Repo string
}{
{
Repo: "github.com/suyuan32/simple-admin-common",
},
{
Repo: "github.com/suyuan32/simple-admin-core",
},
{
Repo: "github.com/suyuan32/simple-admin-message-center",
},
{
Repo: "github.com/suyuan32/simple-admin-job",
},
}
for _, v := range deps {
if strings.Contains(data, v.Repo) {
_, err = execx.Run(fmt.Sprintf("go mod edit -require=%s@%s", v.Repo,
config.CoreVersion), workDir)
if err != nil {
return err
}
}
}
return err
}