Skip to content

Commit

Permalink
Define contract for turbine response and capture
Browse files Browse the repository at this point in the history
  • Loading branch information
jmar910 committed Apr 13, 2022
1 parent 40b7f73 commit a7ef81d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/meroxa/turbine_cli/javascript/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"regexp"
"strconv"
"strings"

Expand All @@ -13,15 +14,25 @@ import (
"github.com/meroxa/cli/log"
)

func processError(err error, path string, output []byte) (bool, error) {
fmterr := fmt.Errorf(
"unable to determine if the Meroxa Application at %s has a Process; %s",
path,
string(output))
return false, fmterr
}

func NeedsToBuild(path string) (bool, error) {
cmd := exec.Command("npx", "turbine", "hasfunctions", path)
output, err := cmd.CombinedOutput()
if err != nil {
err := fmt.Errorf(
"unable to determine if the Meroxa Application at %s has a Process; %s",
path,
string(output))
return false, err
return processError(err, path, output)
}

r, _ := regexp.Compile("\nturbine-response: (true|false)\n")
match := r.FindString(string(output))
if match == "" {
return processError(err, path, output)
}
return strconv.ParseBool(strings.TrimSpace(string(output)))
}
Expand Down

0 comments on commit a7ef81d

Please sign in to comment.