Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #843 from gobuffalo/dev-node-modules
Browse files Browse the repository at this point in the history
Make sure node deps are installed when running in dev fixes #839
  • Loading branch information
markbates authored Jan 10, 2018
2 parents a2765ce + bb115a3 commit 4ddc0a1
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions buffalo/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"context"
"os"
"os/exec"
"path/filepath"
"runtime"

"github.com/fatih/color"
"github.com/gobuffalo/buffalo/generators/assets/webpack"
rg "github.com/gobuffalo/buffalo/generators/refresh"
"github.com/gobuffalo/buffalo/meta"
"github.com/markbates/refresh/refresh"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -65,12 +67,29 @@ This behavior can be changed in your .buffalo.dev.yml file.`,
}

func startWebpack(ctx context.Context) error {
cfgFile := "./webpack.config.js"
_, err := os.Stat(cfgFile)
if err != nil {
app := meta.New(".")
if !app.WithWebpack {
// there's no webpack, so don't do anything
return nil
}

if _, err := os.Stat(filepath.Join(app.Root, "node_modules")); err != nil {
tool := "yarn"
if !app.WithYarn {
tool = "npm"
}
if _, err := exec.LookPath(tool); err != nil {
return errors.Errorf("no node_modules directory found, and couldn't find %s to install it with", tool)
}
cmd := exec.CommandContext(ctx, tool, "install")
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
return errors.WithStack(err)
}
}

cmd := exec.CommandContext(ctx, webpack.BinPath, "--watch")
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 4ddc0a1

Please sign in to comment.