Compare commits

..

No commits in common. "42c98df5f75ddc14be92ca030e5f8a28ce99f4e3" and "f5cee223248961f0f9a469e6a6b08e18ae9c48da" have entirely different histories.

32 changed files with 19 additions and 229 deletions

View File

@ -10,6 +10,7 @@ type chainState struct {
cache *cache cache *cache
filters filterStack filters filterStack
clean bool
index int index int
errors []error errors []error

View File

@ -15,10 +15,6 @@ func (*fileImporter) Name() string {
func (self *fileImporter) Initialize(context *Context) error { func (self *fileImporter) Initialize(context *Context) error {
return filepath.Walk(self.sourceDir, func(path string, info os.FileInfo, err error) error { return filepath.Walk(self.sourceDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() { if info.IsDir() {
return nil return nil
} }

View File

@ -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
}

View File

@ -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))
},
)
}

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1,7 +1,6 @@
package wildcard package wildcard
import ( import (
"path/filepath"
"strings" "strings"
"git.foosoft.net/alex/goldsmith" "git.foosoft.net/alex/goldsmith"
@ -27,10 +26,10 @@ func (*Wildcard) Name() string {
} }
func (self *Wildcard) Accept(file *goldsmith.File) bool { func (self *Wildcard) Accept(file *goldsmith.File) bool {
filePath := self.adjustPath(file.Path()) filePath := self.adjustCase(file.Path())
for _, wildcard := range self.wildcards { for _, wildcard := range self.wildcards {
wildcard = self.adjustPath(wildcard) wildcard = self.adjustCase(wildcard)
if matched, _ := doublestar.PathMatch(wildcard, filePath); matched { if matched, _ := doublestar.PathMatch(wildcard, filePath); matched {
return true return true
} }
@ -39,9 +38,7 @@ func (self *Wildcard) Accept(file *goldsmith.File) bool {
return false return false
} }
func (self *Wildcard) adjustPath(str string) string { func (self *Wildcard) adjustCase(str string) string {
str = filepath.FromSlash(str)
if self.caseSensitive { if self.caseSensitive {
return str return str
} }

View File

@ -3,20 +3,25 @@ package goldsmith
// Goldsmith chainable context. // Goldsmith chainable context.
type Goldsmith struct { type Goldsmith struct {
CacheDir string
Clean bool
chain *chainState chain *chainState
} }
// Begin starts a chain, reading the files located in the source directory as input. // Begin starts a chain, reading the files located in the source directory as input.
func (self *Goldsmith) Begin(sourceDir string) *Goldsmith { func (self *Goldsmith) Begin(sourceDir string) *Goldsmith {
self.chain = &chainState{} self.chain = &chainState{}
if len(self.CacheDir) > 0 { self.Chain(&fileImporter{sourceDir: sourceDir})
self.chain.cache = &cache{self.CacheDir} 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 return self
} }
@ -56,8 +61,7 @@ func (self *Goldsmith) FilterPop() *Goldsmith {
// End stops a chain, writing all recieved files to targetDir as output. // End stops a chain, writing all recieved files to targetDir as output.
func (self *Goldsmith) End(targetDir string) []error { 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 { for _, context := range self.chain.contexts {
go context.step() go context.step()
} }

View File

@ -68,8 +68,8 @@ func validate(sourceDir, targetDir, cacheDir, referenceDir string, stager Stagin
} }
func execute(sourceDir, targetDir, cacheDir string, stager StagingCallback) []error { func execute(sourceDir, targetDir, cacheDir string, stager StagingCallback) []error {
gs := goldsmith.Goldsmith{CacheDir: cacheDir, Clean: true} var gs goldsmith.Goldsmith
gs.Begin(sourceDir) gs.Begin(sourceDir).Cache(cacheDir).Clean(true)
stager(&gs) stager(&gs)
return gs.End(targetDir) return gs.End(targetDir)
} }

View File

@ -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
}

View File

@ -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))
},
)
}