Skip to content

Commit

Permalink
feat: prod arg to custom walker
Browse files Browse the repository at this point in the history
  • Loading branch information
moisespsena committed May 17, 2020
1 parent f8500b4 commit fb6744c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
8 changes: 5 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ type InputConfig struct {

DirReplacesCount int

WalkFunc func(visited *map[string]bool, recursive bool, cb func(info walker.FileInfo) error) error
WalkFunc func(visited *map[string]bool, prod, recursive bool, cb func(info walker.FileInfo) error) error
}

func (i InputConfig) Walk(visited *map[string]bool, cb walker.WalkCallback) (err error) {
func (i InputConfig) Walk(visited *map[string]bool, prod bool, cb walker.WalkCallback) (err error) {
if i.WalkFunc != nil {
return i.WalkFunc(visited, i.Recursive, i.prepareCb(cb))
return i.WalkFunc(visited, prod, i.Recursive, i.prepareCb(cb))
}

return i.DefaultWalk(visited, i.Recursive, cb)
Expand Down Expand Up @@ -243,6 +243,8 @@ type Config struct {

OulinedSkipApi bool

InputProduction bool

FileSystemLoadCallbacks []string
}

Expand Down
9 changes: 7 additions & 2 deletions config_many_input_walked.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"strings"

"github.com/go-errors/errors"

"github.com/moisespsena-go/xbindata/tempfile"
"github.com/moisespsena-go/xbindata/walker"
)

func (i ManyConfigInput) Walked(visited *map[string]bool, recursive bool, cb walker.WalkCallback) (err error) {
func (i ManyConfigInput) Walked(_ *map[string]bool, prod, _ bool, cb walker.WalkCallback) (err error) {
dir := filepath.Join(i.Path, ".xbwalk")
defer func() {
if err != nil {
Expand Down Expand Up @@ -47,7 +48,11 @@ func (i ManyConfigInput) Walked(visited *map[string]bool, recursive bool, cb wal

defer os.Remove(exe)

cmd = exec.Command(exe)
var args []string
if prod {
args = append(args, "prod")
}
cmd = exec.Command(exe, args...)
cmd.Dir = i.Path
cmd.Env = os.Environ()

Expand Down
1 change: 1 addition & 0 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func Translate(c *Config) (count int, err error) {
knownFuncs: knownFuncs,
visitedPaths: visitedPaths,
mu: &finderMu,
production: c.InputProduction,
}

prefix := c.Prefix
Expand Down
3 changes: 2 additions & 1 deletion convert_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Finder struct {
knownFuncs map[string]int
visitedPaths map[string]bool
mu *sync.Mutex
production bool
}

// find now
Expand All @@ -39,7 +40,7 @@ func (this Finder) find(input *InputConfig, prefix string) (err error) {
return err
}

return input.Walk(&this.visitedPaths, func(info walker.FileInfo) (err error) {
return input.Walk(&this.visitedPaths, this.production, func(info walker.FileInfo) (err error) {
if info.IsDir() {
return nil
}
Expand Down
7 changes: 6 additions & 1 deletion xb/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (

"github.com/mitchellh/mapstructure"

"github.com/moisespsena-go/xbindata"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/moisespsena-go/xbindata"
)

func unmarshalConfig(dest interface{}) error {
Expand Down Expand Up @@ -61,6 +62,7 @@ var (
Short: "build all or specified PKG from config file",
RunE: func(cmd *cobra.Command, args []string) (err error) {
var cfg xbindata.ManyConfig
var prod, _ = cmd.Flags().GetBool("prod")
if err = unmarshalConfig(&cfg); err != nil {
return
}
Expand Down Expand Up @@ -125,6 +127,7 @@ var (
if c, err = cfg.Config(ctx); err != nil {
return fmt.Errorf("cfg #%d [%s]: create config failed: %v", i, cfg.Pkg, err)
}
c.InputProduction = prod
if count, err = xbindata.Translate(c); err != nil {
return fmt.Errorf("cfg #%d [%s]: translate failed: %v", i, cfg.Pkg, err)
}
Expand All @@ -140,6 +143,7 @@ var (
if c, err = cfg.Config(ctx); err != nil {
return fmt.Errorf("cfg #%d [%s]: create config failed: %v", i, cfg.Pkg, err)
}
c.InputProduction = prod
if count, err = xbindata.Translate(c); err != nil {
return fmt.Errorf("cfg #%d [%s]: translate failed: %v", i, cfg.Pkg, err)
}
Expand All @@ -155,6 +159,7 @@ func init() {
rootCmd.AddCommand(buildCmd)
flag := buildCmd.Flags()
flag.BoolP("program", "P", false, "build outlined and append contents into program")
flag.Bool("prod", false, "build with production mode")
flag.StringP("outlined-output-dir", "d", "_assets", "The outlined output root dir")
flag.StringP("outlined-output-local-dir", "D", "_assets", "The outlined Local FS root dir")

Expand Down

0 comments on commit fb6744c

Please sign in to comment.