forked from ignite/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect.go
36 lines (31 loc) · 822 Bytes
/
detect.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
package cosmosver
import (
"github.com/tendermint/starport/starport/pkg/gomodule"
"golang.org/x/mod/semver"
)
const (
cosmosModulePath = "github.com/cosmos/cosmos-sdk"
cosmosModuleMaxLaunchpadTag = "v0.39.99"
cosmosModuleStargateTag = "v0.40.0"
)
// Detect dedects major version of Cosmos.
func Detect(appPath string) (Version, error) {
parsed, err := gomodule.ParseAt(appPath)
if err != nil {
return 0, err
}
for _, r := range parsed.Require {
v := r.Mod
if v.Path == cosmosModulePath {
switch {
case semver.Compare(v.Version, cosmosModuleStargateTag) >= 0:
return StargateZeroFourtyAndAbove, nil
case semver.Compare(v.Version, cosmosModuleMaxLaunchpadTag) <= 0:
return LaunchpadAny, nil
default:
return StargateBelowZeroFourty, nil
}
}
}
return 0, nil
}