2019-10-21 17:27:04 +03:00
|
|
|
package pkgutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
2019-12-04 01:36:58 +03:00
|
|
|
"strings"
|
2019-10-21 17:27:04 +03:00
|
|
|
|
2019-12-03 23:07:51 +03:00
|
|
|
"github.com/gobuffalo/here"
|
2019-10-21 17:27:04 +03:00
|
|
|
"github.com/markbates/pkger/parser"
|
2019-10-25 17:19:27 +03:00
|
|
|
"github.com/markbates/pkger/pkging/embed"
|
2019-10-21 17:27:04 +03:00
|
|
|
"github.com/markbates/pkger/pkging/mem"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Stuff(w io.Writer, c here.Info, decls parser.Decls) error {
|
|
|
|
pkg, err := mem.New(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
files, err := decls.Files()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pf := range files {
|
|
|
|
err = func() error {
|
2019-12-04 01:36:58 +03:00
|
|
|
if strings.HasSuffix(pf.Abs, ".tmp") {
|
|
|
|
return nil
|
|
|
|
}
|
2019-10-24 23:22:15 +03:00
|
|
|
df, err := os.Open(pf.Abs)
|
2019-10-21 17:27:04 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer df.Close()
|
|
|
|
|
|
|
|
if err := pkg.Add(df); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2019-10-25 17:19:27 +03:00
|
|
|
|
|
|
|
b, err := pkg.MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err = embed.Encode(b)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = w.Write(b)
|
2019-10-21 17:27:04 +03:00
|
|
|
return nil
|
|
|
|
}
|