added some debug functionality
Mark Bates
6 years ago
36 | 36 |
Name: name,
|
37 | 37 |
}
|
38 | 38 |
|
|
39 |
DebugLog("packing file %s\n", f.Name)
|
|
40 |
|
39 | 41 |
bb, err := ioutil.ReadFile(path)
|
40 | 42 |
if err != nil {
|
41 | 43 |
return errors.WithStack(err)
|
|
52 | 54 |
}
|
53 | 55 |
f.Contents = strings.Replace(string(bb), "\"", "\\\"", -1)
|
54 | 56 |
|
|
57 |
DebugLog("packed file %s\n", f.Name)
|
55 | 58 |
b.Files = append(b.Files, f)
|
56 | 59 |
return nil
|
57 | 60 |
})
|
10 | 10 |
"github.com/pkg/errors"
|
11 | 11 |
"golang.org/x/sync/errgroup"
|
12 | 12 |
)
|
|
13 |
|
|
14 |
var DebugLog func(string, ...interface{})
|
|
15 |
|
|
16 |
func init() {
|
|
17 |
DebugLog = func(string, ...interface{}) {}
|
|
18 |
}
|
13 | 19 |
|
14 | 20 |
var invalidFilePattern = regexp.MustCompile(`(_test|-packr).go$`)
|
15 | 21 |
|
|
113 | 119 |
Files: []file{},
|
114 | 120 |
compress: b.Compress,
|
115 | 121 |
}
|
|
122 |
DebugLog("building box %s\n", bx.Name)
|
116 | 123 |
p := filepath.Join(pk.Dir, bx.Name)
|
117 | 124 |
if err := bx.Walk(p); err != nil {
|
118 | 125 |
return errors.WithStack(err)
|
|
120 | 127 |
if len(bx.Files) > 0 {
|
121 | 128 |
pk.Boxes = append(pk.Boxes, *bx)
|
122 | 129 |
}
|
|
130 |
DebugLog("built box %s with %q\n", bx.Name, bx.Files)
|
123 | 131 |
}
|
124 | 132 |
|
125 | 133 |
if len(pk.Boxes) > 0 {
|
3 | 3 |
Name string
|
4 | 4 |
Contents string
|
5 | 5 |
}
|
|
6 |
|
|
7 |
func (f file) String() string {
|
|
8 |
return f.Name
|
|
9 |
}
|
1 | 1 |
|
2 | 2 |
import (
|
3 | 3 |
"context"
|
|
4 |
"fmt"
|
4 | 5 |
"os"
|
5 | 6 |
|
6 | 7 |
"github.com/gobuffalo/packr/builder"
|
|
13 | 14 |
var rootCmd = &cobra.Command{
|
14 | 15 |
Use: "packr",
|
15 | 16 |
Short: "compiles static files into Go files",
|
|
17 |
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
18 |
for _, a := range args {
|
|
19 |
if a == "-v" {
|
|
20 |
builder.DebugLog = func(s string, a ...interface{}) {
|
|
21 |
os.Stdout.WriteString(fmt.Sprintf(s, a...))
|
|
22 |
}
|
|
23 |
break
|
|
24 |
}
|
|
25 |
}
|
|
26 |
return nil
|
|
27 |
},
|
16 | 28 |
RunE: func(cmd *cobra.Command, args []string) error {
|
17 | 29 |
b := builder.New(context.Background(), input)
|
18 | 30 |
b.Compress = compress
|