Skip to content

Commit

Permalink
Merge pull request #473 from hazelops/IZE-604-cant-deploy-serverless-…
Browse files Browse the repository at this point in the history
…when-nvmrc-is-present-in-the-app-folder

IZE-604 added support .nvmrc
  • Loading branch information
psihachina authored Sep 28, 2022
2 parents b278e0c + ac9abba commit bcc58f4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/manager/serverless/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
)

func (sls *Manager) runNpmInstall(w io.Writer) error {
Expand Down Expand Up @@ -33,14 +34,25 @@ func (sls *Manager) runNvm(w io.Writer) error {
if len(nvmDir) == 0 {
nvmDir = "$HOME/.nvm"
}
var command string
_, err := os.Stat(filepath.Join(sls.App.Path, ".nvmrc"))
if os.IsNotExist(err) {
command = fmt.Sprintf("source %s/nvm.sh && nvm install %s", nvmDir, sls.App.NodeVersion)

command := fmt.Sprintf("source %s/nvm.sh && nvm install %s", nvmDir, sls.App.NodeVersion)
} else {
file, err := os.ReadFile(filepath.Join(sls.App.Path, ".nvmrc"))
if err != nil {
return fmt.Errorf("can't read .nvmrc: %w", err)
}
sls.App.NodeVersion = strings.TrimSpace(string(file))
command = fmt.Sprintf("source %s/nvm.sh && nvm install %s", nvmDir, sls.App.NodeVersion)
}

cmd := exec.Command("bash", "-c", command)
cmd.Stdout = w
cmd.Stderr = w
cmd.Dir = filepath.Join(sls.App.Path)
err := cmd.Run()
err = cmd.Run()
if err != nil {
return err
}
Expand Down

0 comments on commit bcc58f4

Please sign in to comment.