Skip to content

Commit

Permalink
Merge pull request #9 from amp-buildpacks/feat/issue-8
Browse files Browse the repository at this point in the history
  • Loading branch information
wangeguo authored Jan 30, 2024
2 parents b41ecf5 + 63fb44c commit 566bbb0
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 `toml:"dependencies"`
}

type Dependency struct {
Git string `toml:"git"`
Rev string `toml:"rev"`
Subdir string `toml:"subdir"`
}

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 566bbb0

Please sign in to comment.