This commit is contained in:
Alex Yatskov 2024-04-18 22:19:55 -07:00
parent 42c98df5f7
commit 488ccdebe4
4 changed files with 25 additions and 9 deletions

View File

@ -2,16 +2,23 @@ package sideload
import (
"bytes"
"embed"
"io/fs"
"path/filepath"
"git.foosoft.net/alex/goldsmith"
)
type Sideload struct {
type (
Sideload struct {
files []*goldsmith.File
fileSystems []embed.FS
}
fileSystems []sideloadFs
}
sideloadFs interface {
fs.ReadDirFS
fs.ReadFileFS
}
)
func New() *Sideload {
return &Sideload{}
@ -45,12 +52,15 @@ func (self *Sideload) Files(files ...*goldsmith.File) *Sideload {
return self
}
func (self *Sideload) FileSystems(fileSystems ...embed.FS) *Sideload {
self.fileSystems = append(self.fileSystems, fileSystems...)
func (self *Sideload) FileSystems(fileSystems ...fs.FS) *Sideload {
for _, fileSystem := range fileSystems {
self.fileSystems = append(self.fileSystems, fileSystem.(sideloadFs))
}
return self
}
func (self *Sideload) gatherFsFiles(context *goldsmith.Context, fileSystem embed.FS, path string) ([]*goldsmith.File, error) {
func (self *Sideload) gatherFsFiles(context *goldsmith.Context, fileSystem sideloadFs, path string) ([]*goldsmith.File, error) {
entries, err := fileSystem.ReadDir(path)
if err != nil {
return nil, err

View File

@ -1,6 +1,7 @@
package sideload
import (
"io/fs"
"testing"
"embed"
@ -13,10 +14,15 @@ import (
var embedFs embed.FS
func Test(self *testing.T) {
subFs, err := fs.Sub(embedFs, "testdata/source")
if err != nil {
panic(err)
}
harness.Validate(
self,
func(gs *goldsmith.Goldsmith) {
gs.Chain(New().FileSystems(embedFs))
gs.Chain(New().FileSystems(subFs))
},
)
}

View File

View File