Compare commits
No commits in common. "42c98df5f75ddc14be92ca030e5f8a28ce99f4e3" and "f5cee223248961f0f9a469e6a6b08e18ae9c48da" have entirely different histories.
42c98df5f7
...
f5cee22324
@ -10,6 +10,7 @@ type chainState struct {
|
||||
|
||||
cache *cache
|
||||
filters filterStack
|
||||
clean bool
|
||||
index int
|
||||
|
||||
errors []error
|
||||
|
@ -15,10 +15,6 @@ func (*fileImporter) Name() string {
|
||||
|
||||
func (self *fileImporter) Initialize(context *Context) error {
|
||||
return filepath.Walk(self.sourceDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
package depth
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.foosoft.net/alex/goldsmith"
|
||||
)
|
||||
|
||||
type Depth struct {
|
||||
depth int
|
||||
}
|
||||
|
||||
func New(depth int) *Depth {
|
||||
return &Depth{depth: depth}
|
||||
}
|
||||
|
||||
func (*Depth) Name() string {
|
||||
return "depth"
|
||||
}
|
||||
|
||||
func (self *Depth) Accept(file *goldsmith.File) bool {
|
||||
if self.depth == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if parts := strings.Split(file.Path(), string(filepath.Separator)); len(parts) <= self.depth {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package depth
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.foosoft.net/alex/goldsmith"
|
||||
"git.foosoft.net/alex/goldsmith/harness"
|
||||
)
|
||||
|
||||
func Test0(t *testing.T) {
|
||||
harness.ValidateCase(
|
||||
t,
|
||||
"test_0",
|
||||
func(gs *goldsmith.Goldsmith) {
|
||||
gs.FilterPush(New(0))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func Test1(t *testing.T) {
|
||||
harness.ValidateCase(
|
||||
t,
|
||||
"test_1",
|
||||
func(gs *goldsmith.Goldsmith) {
|
||||
gs.FilterPush(New(1))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func Test2(t *testing.T) {
|
||||
harness.ValidateCase(
|
||||
t,
|
||||
"test_2",
|
||||
func(gs *goldsmith.Goldsmith) {
|
||||
gs.FilterPush(New(2))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func Test10(t *testing.T) {
|
||||
harness.ValidateCase(
|
||||
t,
|
||||
"test_10",
|
||||
func(gs *goldsmith.Goldsmith) {
|
||||
gs.FilterPush(New(10))
|
||||
},
|
||||
)
|
||||
}
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
1
filters/depth/testdata/test_0/source/1.txt
vendored
1
filters/depth/testdata/test_0/source/1.txt
vendored
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
1
filters/depth/testdata/test_1/source/1.txt
vendored
1
filters/depth/testdata/test_1/source/1.txt
vendored
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
1
filters/depth/testdata/test_10/source/1.txt
vendored
1
filters/depth/testdata/test_10/source/1.txt
vendored
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
1
filters/depth/testdata/test_2/source/1.txt
vendored
1
filters/depth/testdata/test_2/source/1.txt
vendored
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1,7 +1,6 @@
|
||||
package wildcard
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.foosoft.net/alex/goldsmith"
|
||||
@ -27,10 +26,10 @@ func (*Wildcard) Name() string {
|
||||
}
|
||||
|
||||
func (self *Wildcard) Accept(file *goldsmith.File) bool {
|
||||
filePath := self.adjustPath(file.Path())
|
||||
filePath := self.adjustCase(file.Path())
|
||||
|
||||
for _, wildcard := range self.wildcards {
|
||||
wildcard = self.adjustPath(wildcard)
|
||||
wildcard = self.adjustCase(wildcard)
|
||||
if matched, _ := doublestar.PathMatch(wildcard, filePath); matched {
|
||||
return true
|
||||
}
|
||||
@ -39,9 +38,7 @@ func (self *Wildcard) Accept(file *goldsmith.File) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *Wildcard) adjustPath(str string) string {
|
||||
str = filepath.FromSlash(str)
|
||||
|
||||
func (self *Wildcard) adjustCase(str string) string {
|
||||
if self.caseSensitive {
|
||||
return str
|
||||
}
|
||||
|
20
goldsmith.go
20
goldsmith.go
@ -3,20 +3,25 @@ package goldsmith
|
||||
|
||||
// Goldsmith chainable context.
|
||||
type Goldsmith struct {
|
||||
CacheDir string
|
||||
Clean bool
|
||||
|
||||
chain *chainState
|
||||
}
|
||||
|
||||
// Begin starts a chain, reading the files located in the source directory as input.
|
||||
func (self *Goldsmith) Begin(sourceDir string) *Goldsmith {
|
||||
self.chain = &chainState{}
|
||||
if len(self.CacheDir) > 0 {
|
||||
self.chain.cache = &cache{self.CacheDir}
|
||||
self.Chain(&fileImporter{sourceDir: sourceDir})
|
||||
return self
|
||||
}
|
||||
|
||||
self.Chain(&fileImporter{sourceDir: sourceDir})
|
||||
// Cache enables caching in cacheDir for the remainder of the chain.
|
||||
func (self *Goldsmith) Cache(cacheDir string) *Goldsmith {
|
||||
self.chain.cache = &cache{cacheDir}
|
||||
return self
|
||||
}
|
||||
|
||||
// Clean enables or disables removal of leftover files in the target directory.
|
||||
func (self *Goldsmith) Clean(clean bool) *Goldsmith {
|
||||
self.chain.clean = clean
|
||||
return self
|
||||
}
|
||||
|
||||
@ -56,8 +61,7 @@ func (self *Goldsmith) FilterPop() *Goldsmith {
|
||||
|
||||
// End stops a chain, writing all recieved files to targetDir as output.
|
||||
func (self *Goldsmith) End(targetDir string) []error {
|
||||
self.Chain(&fileExporter{targetDir: targetDir, clean: self.Clean})
|
||||
|
||||
self.Chain(&fileExporter{targetDir: targetDir, clean: self.chain.clean})
|
||||
for _, context := range self.chain.contexts {
|
||||
go context.step()
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ func validate(sourceDir, targetDir, cacheDir, referenceDir string, stager Stagin
|
||||
}
|
||||
|
||||
func execute(sourceDir, targetDir, cacheDir string, stager StagingCallback) []error {
|
||||
gs := goldsmith.Goldsmith{CacheDir: cacheDir, Clean: true}
|
||||
gs.Begin(sourceDir)
|
||||
var gs goldsmith.Goldsmith
|
||||
gs.Begin(sourceDir).Cache(cacheDir).Clean(true)
|
||||
stager(&gs)
|
||||
return gs.End(targetDir)
|
||||
}
|
||||
|
@ -1,85 +0,0 @@
|
||||
package sideload
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"path/filepath"
|
||||
|
||||
"git.foosoft.net/alex/goldsmith"
|
||||
)
|
||||
|
||||
type Sideload struct {
|
||||
files []*goldsmith.File
|
||||
fileSystems []embed.FS
|
||||
}
|
||||
|
||||
func New() *Sideload {
|
||||
return &Sideload{}
|
||||
}
|
||||
|
||||
func (*Sideload) Name() string {
|
||||
return "sideload"
|
||||
}
|
||||
|
||||
func (self *Sideload) Finalize(context *goldsmith.Context) error {
|
||||
files := self.files
|
||||
|
||||
for _, fileSystem := range self.fileSystems {
|
||||
currFiles, err := self.gatherFsFiles(context, fileSystem, ".")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
files = append(files, currFiles...)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
context.DispatchFile(file)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *Sideload) Files(files ...*goldsmith.File) *Sideload {
|
||||
self.files = append(self.files, files...)
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Sideload) FileSystems(fileSystems ...embed.FS) *Sideload {
|
||||
self.fileSystems = append(self.fileSystems, fileSystems...)
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Sideload) gatherFsFiles(context *goldsmith.Context, fileSystem embed.FS, path string) ([]*goldsmith.File, error) {
|
||||
entries, err := fileSystem.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var files []*goldsmith.File
|
||||
for _, entry := range entries {
|
||||
currPath := filepath.Join(path, entry.Name())
|
||||
if entry.IsDir() {
|
||||
currFiles, err := self.gatherFsFiles(context, fileSystem, currPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
files = append(files, currFiles...)
|
||||
} else {
|
||||
data, err := fileSystem.ReadFile(currPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file, err := context.CreateFileFromReader(currPath, bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
files = append(files, file)
|
||||
}
|
||||
}
|
||||
|
||||
return files, nil
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package sideload
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"embed"
|
||||
|
||||
"git.foosoft.net/alex/goldsmith"
|
||||
"git.foosoft.net/alex/goldsmith/harness"
|
||||
)
|
||||
|
||||
//go:embed testdata/source
|
||||
var embedFs embed.FS
|
||||
|
||||
func Test(self *testing.T) {
|
||||
harness.Validate(
|
||||
self,
|
||||
func(gs *goldsmith.Goldsmith) {
|
||||
gs.Chain(New().FileSystems(embedFs))
|
||||
},
|
||||
)
|
||||
}
|
0
plugins/sideload/testdata/source/1.txt
vendored
0
plugins/sideload/testdata/source/1.txt
vendored
Loading…
Reference in New Issue
Block a user