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

Commit

Permalink
catches uncaught build error; fixes issues with buffalo build if the …
Browse files Browse the repository at this point in the history
…package.json doesn't contain the build scripts (#1729)
  • Loading branch information
markbates authored Jul 12, 2019
1 parent 366c75f commit 3cea810
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
12 changes: 10 additions & 2 deletions buffalo/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"context"
"log"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -80,8 +81,15 @@ var xbuildCmd = &cobra.Command{
opts.GoCommand = "install"
}
clean := build.Cleanup(opts)
defer clean(run)
run.WithNew(build.New(opts))
// defer clean(run)
defer func() {
if err := clean(run); err != nil {
log.Fatal("build:clean", err)
}
}()
if err := run.WithNew(build.New(opts)); err != nil {
return err
}
return run.Run()
},
}
Expand Down
21 changes: 18 additions & 3 deletions buffalo/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/fatih/color"
"github.com/gobuffalo/buffalo/genny/assets/webpack"
rg "github.com/gobuffalo/buffalo/genny/refresh"
"github.com/gobuffalo/events"
"github.com/gobuffalo/genny"
Expand Down Expand Up @@ -70,9 +72,6 @@ This behavior can be changed in .buffalo.dev.yml file.`,
// No need to run dev script
return nil
}
if _, err := app.NodeScript("dev"); err != nil {
return err
}
return runDevScript(ctx, app)
})

Expand All @@ -89,10 +88,26 @@ func runDevScript(ctx context.Context, app meta.App) error {
if !app.WithYarn {
tool = "npm"
}

if _, err := exec.LookPath(tool); err != nil {
return fmt.Errorf("could not find %s tool", tool)
}

// make sure that the node_modules folder is properly "installed"
if _, err := os.Stat(filepath.Join(app.Root, "node_modules")); err != nil {
cmd := exec.CommandContext(ctx, tool, "install")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
return err
}
}

cmd := exec.CommandContext(ctx, tool, "run", "dev")
if _, err := app.NodeScript("dev"); err != nil {
// Fallback on legacy runner
cmd = exec.CommandContext(ctx, webpack.BinPath, "--watch")
}
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
return cmd.Run()
Expand Down
16 changes: 11 additions & 5 deletions genny/build/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os/exec"
"path/filepath"

"github.com/gobuffalo/buffalo/genny/assets/webpack"
"github.com/gobuffalo/envy"
"github.com/gobuffalo/genny"

Expand All @@ -19,10 +20,7 @@ func assets(opts *Options) (*genny.Generator, error) {
return g, err
}

if opts.App.WithNodeJs {
if _, err := opts.App.NodeScript("build"); err != nil {
return g, err
}
if opts.App.WithNodeJs || opts.App.WithWebpack {
if opts.CleanAssets {
g.RunFn(func(r *genny.Runner) error {
r.Delete(filepath.Join(opts.App.Root, "public", "assets"))
Expand All @@ -38,15 +36,23 @@ func assets(opts *Options) (*genny.Generator, error) {
if !opts.App.WithYarn {
tool = "npm"
}
bb := &bytes.Buffer{}

c := exec.CommandContext(r.Context, tool, "run", "build")
if _, err := opts.App.NodeScript("build"); err != nil {
// Fallback on legacy runner
c = exec.CommandContext(r.Context, webpack.BinPath)
}

bb := &bytes.Buffer{}
c.Stdout = bb
c.Stderr = bb

if err := r.Exec(c); err != nil {
r.Logger.Error(bb.String())
return err
}
return nil

})
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/gobuffalo/tags v2.1.0+incompatible
github.com/google/go-cmp v0.3.0
github.com/gorilla/mux v1.7.3
github.com/gorilla/sessions v1.1.3
github.com/gorilla/sessions v1.2.0
github.com/karrick/godirwalk v1.10.12
github.com/markbates/deplist v1.3.0
github.com/markbates/grift v1.1.0
Expand All @@ -45,7 +45,7 @@ require (
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.3.0
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db
golang.org/x/tools v0.0.0-20190710184609-286818132824
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc
gopkg.in/yaml.v2 v2.2.2
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OI
github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
Expand All @@ -518,8 +517,9 @@ github.com/gorilla/pat v0.0.0-20180118222023-199c85a7f6d1/go.mod h1:YeAe0gNeiNT5
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.1.2/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w=
github.com/gorilla/sessions v1.1.3 h1:uXoZdcdA5XdXF3QzuSlheVRUvjl+1rKY7zBXL68L9RU=
github.com/gorilla/sessions v1.1.3/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w=
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
Expand Down Expand Up @@ -947,8 +947,8 @@ golang.org/x/tools v0.0.0-20190613204242-ed0dc450797f/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db h1:9hRk1xeL9LTT3yX/941DqeBz87XgHAQuj+TbimYJuiw=
golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
golang.org/x/tools v0.0.0-20190710184609-286818132824 h1:dOGf5KG5e5tnConXcTAnHv2YgmYJtrYjN9b1cMC21TY=
golang.org/x/tools v0.0.0-20190710184609-286818132824/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y=
Expand Down
6 changes: 0 additions & 6 deletions it.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,3 @@ rm -rf bin
buffalo build -k -e
filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/no_assets_build.json

cd $GOPATH/src
git clone https://github.com/gobuffalo/oldapp.git
cd oldapp/0_13_6
buffalo fix --y
filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/fix_old_app.json
buffalo build -static

0 comments on commit 3cea810

Please sign in to comment.