Skip to content

Commit

Permalink
issue(#8): Add Sui Framework check for detect
Browse files Browse the repository at this point in the history
  • Loading branch information
lispking committed Jan 30, 2024
1 parent b41ecf5 commit 6059c0d
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions sui/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"path/filepath"

"github.com/BurntSushi/toml"
"github.com/buildpacks/libcnb"
)

Expand All @@ -29,6 +30,16 @@ const (
type Detect struct {
}

type Package struct {
Dependencies map[string]*Dependency
}

type Dependency struct {
Git string
Rev string
Subdir string
}

func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error) {
found, err := d.suiProject(context.Application.Path)
if err != nil {
Expand All @@ -55,10 +66,19 @@ func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error
}

func (d Detect) suiProject(appDir string) (bool, error) {
filename := "Move.toml"
_, err := os.Stat(filepath.Join(appDir, filename))
projectName := filepath.Join(appDir, "Move.toml")
_, err := os.Stat(projectName)
if os.IsNotExist(err) || err != nil {
return false, fmt.Errorf("unable to determine if %s exists\n%w", filename, err)
return false, fmt.Errorf("unable to determine if %s exists\n%w", projectName, err)
}

var packageConfig Package
if _, err := toml.DecodeFile(projectName, &packageConfig); err != nil {
return false, fmt.Errorf("unable to parsing %s\n%w", projectName, err)
}

if _, ok := packageConfig.Dependencies["Sui"]; !ok {
return false, fmt.Errorf("unable to determine if Sui project")
}

buildDirectory := filepath.Join(appDir, ".")
Expand Down

0 comments on commit 6059c0d

Please sign in to comment.