Skip to content
Permalink
Browse files

adds --clean-assets flag (#1586)

  • Loading branch information...
markbates committed Feb 10, 2019
1 parent 16895ff commit 55f304c025bfe4c9c0ccc8b7ef6ecb58f96b8c70
Showing with 40 additions and 13 deletions.
  1. +3 −0 buffalo/cmd/build.go
  2. +8 −1 genny/assets/webpack/webpack.go
  3. +7 −0 genny/build/assets.go
  4. +5 −6 genny/build/build.go
  5. +9 −1 genny/build/cleanup.go
  6. +5 −3 genny/build/options.go
  7. +1 −1 go.mod
  8. +2 −1 go.sum
@@ -72,6 +72,8 @@ var xbuildCmd = &cobra.Command{
opts.TemplateValidators = append(opts.TemplateValidators, build.PlushValidator, build.GoTemplateValidator)
}

clean := build.Cleanup(opts)
defer clean(run)
run.WithNew(build.New(opts))
return run.Run()
},
@@ -90,6 +92,7 @@ func init() {
xbuildCmd.Flags().BoolVarP(&buildOptions.Debug, "deprecated-verbose", "d", false, "[deprecated] use -v instead")
xbuildCmd.Flags().BoolVar(&buildOptions.DryRun, "dry-run", false, "runs the build 'dry'")
xbuildCmd.Flags().BoolVar(&buildOptions.SkipTemplateValidation, "skip-template-validation", false, "skip validating templates")
xbuildCmd.Flags().BoolVar(&buildOptions.CleanAssets, "clean-assets", false, "will delete public/assets before calling webpack")
xbuildCmd.Flags().StringVarP(&buildOptions.Environment, "environment", "", "development", "set the environment for the binary")
xbuildCmd.Flags().StringVar(&buildOptions.Mod, "mod", "", "-mod flag for go build")
}
@@ -3,6 +3,7 @@ package webpack
import (
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/gobuffalo/genny"
@@ -12,7 +13,13 @@ import (
)

// BinPath is the path to the local install of webpack
var BinPath = filepath.Join("node_modules", ".bin", "webpack")
var BinPath = func() string {
s := filepath.Join("node_modules", ".bin", "webpack")
if runtime.GOOS == "windows" {
s += ".cmd"
}
return s
}()

// Templates used for generating webpack
// (exported mostly for the "fix" command)
@@ -4,6 +4,7 @@ import (
"context"
"io/ioutil"
"os/exec"
"path/filepath"

"github.com/gobuffalo/buffalo/genny/assets/webpack"
"github.com/gobuffalo/envy"
@@ -21,6 +22,12 @@ func assets(opts *Options) (*genny.Generator, error) {
}

if opts.App.WithWebpack {
if opts.CleanAssets {
g.RunFn(func(r *genny.Runner) error {
r.Delete(filepath.Join(opts.App.Root, "public", "assets"))
return nil
})
}
g.RunFn(func(r *genny.Runner) error {
r.Logger.Debugf("setting NODE_ENV = %s", opts.Environment)
return envy.MustSet("NODE_ENV", opts.Environment)
@@ -35,10 +35,6 @@ func New(opts *Options) (*genny.Generator, error) {
// validate templates
g.RunFn(ValidateTemplates(templateWalker(opts.App), opts.TemplateValidators))

g.RunFn(func(r *genny.Runner) error {
return jam.Pack(jam.PackOptions{})
})

// rename main() to originalMain()
g.RunFn(transformMain(opts))

@@ -79,15 +75,18 @@ func New(opts *Options) (*genny.Generator, error) {
}
g.Merge(dg)

g.RunFn(func(r *genny.Runner) error {
return jam.Pack(jam.PackOptions{})
})

// create the final go build command
c, err := buildCmd(opts)
if err != nil {
return g, errors.WithStack(err)
}
g.Command(c)

// clean up everything!
g.RunFn(cleanup(opts))
g.RunFn(Cleanup(opts))

g.Event(EvtBuildStop, events.Payload{"opts": opts})
return g, nil
@@ -2,14 +2,17 @@ package build

import (
"os"
"os/exec"
"path/filepath"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/genny"
"github.com/gobuffalo/packr/v2/jam"
"github.com/pkg/errors"
)

func cleanup(opts *Options) genny.RunFn {
// Cleanup all of the generated files
func Cleanup(opts *Options) genny.RunFn {
return func(r *genny.Runner) error {
defer os.RemoveAll(filepath.Join(opts.Root, "a"))
if err := jam.Clean(); err != nil {
@@ -34,6 +37,11 @@ func cleanup(opts *Options) genny.RunFn {
return errors.WithStack(err)
}
}
if envy.Mods() {
if err := r.Exec(exec.Command(genny.GoBin(), "mod", "tidy")); err != nil {
return errors.WithStack(err)
}
}
return nil
}
}
@@ -17,7 +17,9 @@ type Options struct {
// a) git sha of last commit or
// b) to time.RFC3339 of BuildTime
BuildVersion string `json:"build_version,omitempty"`
WithAssets bool `json:"with_assets,omitempty"`
// CleanAssets will remove the public/assets folder build compiling
CleanAssets bool `json:"clean_assets"`
WithAssets bool `json:"with_assets,omitempty"`
// places ./public/assets into ./bin/assets.zip.
// requires WithAssets = true
ExtractAssets bool `json:"extract_assets,omitempty"`
@@ -37,8 +39,8 @@ type Options struct {
// Empty by default
TemplateValidators []TemplateValidator `json:"-"`
// Mod is the -mod flag
Mod string
rollback *sync.Map
Mod string `json:"mod"`
rollback *sync.Map `json:"rollback"`
}

// Validate that options are usuable
2 go.mod
@@ -42,6 +42,6 @@ require (
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20190208162236-193df9c0f06f
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
golang.org/x/tools v0.0.0-20190206221403-44bcb96178d3
golang.org/x/tools v0.0.0-20190208222737-3744606dbb67
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc
)
3 go.sum
@@ -591,8 +591,9 @@ golang.org/x/tools v0.0.0-20190118193359-16909d206f00/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190122202912-9c309ee22fab/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190124004107-78ee07aa9465/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190131142011-8dbcc66f33bb/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190206221403-44bcb96178d3 h1:M9mD7d4inzK0+YbTneZEs9Y+q1B1zLv8YxJDJ6hFgnY=
golang.org/x/tools v0.0.0-20190206221403-44bcb96178d3/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190208222737-3744606dbb67 h1:bPP/rGuN1LUM0eaEwo6vnP6OfIWJzJBulzGUiKLjjSY=
golang.org/x/tools v0.0.0-20190208222737-3744606dbb67/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=

0 comments on commit 55f304c

Please sign in to comment.
You can’t perform that action at this time.