goldsmith/file_importer.go

40 lines
626 B
Go
Raw Normal View History

2023-12-10 17:41:50 +00:00
package goldsmith
import (
2023-12-10 17:51:46 +00:00
"os"
2023-12-10 17:41:50 +00:00
"path/filepath"
)
type fileImporter struct {
sourceDir string
}
func (*fileImporter) Name() string {
return "importer"
}
func (self *fileImporter) Initialize(context *Context) error {
2023-12-10 17:51:46 +00:00
return filepath.Walk(self.sourceDir, func(path string, info os.FileInfo, err error) error {
2024-04-07 20:56:38 +00:00
if err != nil {
return err
}
2023-12-10 17:41:50 +00:00
if info.IsDir() {
2023-12-10 17:51:46 +00:00
return nil
2023-12-10 17:41:50 +00:00
}
2023-12-10 17:51:46 +00:00
relPath, err := filepath.Rel(self.sourceDir, path)
2023-12-10 17:41:50 +00:00
if err != nil {
2024-03-04 05:30:32 +00:00
return err
2023-12-10 17:41:50 +00:00
}
2023-12-10 17:51:46 +00:00
file, err := context.CreateFileFromAsset(relPath, path)
2023-12-10 17:41:50 +00:00
if err != nil {
return err
}
context.DispatchFile(file)
2023-12-10 17:51:46 +00:00
return nil
})
2023-12-10 17:41:50 +00:00
}