Answer architecture round 1: a module's reads sits on its index entry or, for a source without an index, in the load that walks it, the note names default modules, the shipped modules are listed by name, datafiles drops its unused base, and item 195 files the builtins' second parse
This commit is contained in:
@@ -12,13 +12,12 @@ import (
|
||||
"github.com/larvit/fejkdata/internal/jsonvalue"
|
||||
)
|
||||
|
||||
// Source is one tree to load: an fs.FS and the directory in it to start from. label
|
||||
// prefixes file names in errors; onDisk marks label as a directory that must exist.
|
||||
// Source is one tree to load, from the root of an fs.FS. label prefixes file names in
|
||||
// errors; onDisk marks label as a directory that must exist.
|
||||
type Source struct {
|
||||
fsys fs.FS
|
||||
label string
|
||||
onDisk bool
|
||||
base string
|
||||
}
|
||||
|
||||
// Dir is the tree in the directory path, its errors labelled with it.
|
||||
@@ -26,10 +25,10 @@ func Dir(path string) Source {
|
||||
return Source{fsys: os.DirFS(path), label: path, onDisk: true}
|
||||
}
|
||||
|
||||
// FS is the tree in fsys below base, "" for its root.
|
||||
func FS(fsys fs.FS, base string) Source { return Source{fsys: fsys, base: base} }
|
||||
// FS is the tree in fsys.
|
||||
func FS(fsys fs.FS) Source { return Source{fsys: fsys} }
|
||||
|
||||
// Category is one category file: the folders above it from the source's base, its name,
|
||||
// Category is one category file: the folders above it from the source's root, its name,
|
||||
// and its parsed JSON.
|
||||
type Category struct {
|
||||
Folders []string
|
||||
@@ -50,7 +49,7 @@ func (s Source) labelled(p string) string {
|
||||
|
||||
// dirPath is the folder that dir names, as fsys spells it.
|
||||
func (s Source) dirPath(dir []string) string {
|
||||
if p := path.Join(append([]string{s.base}, dir...)...); p != "" {
|
||||
if p := path.Join(dir...); p != "" {
|
||||
return p
|
||||
}
|
||||
return "."
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -19,7 +18,8 @@ const ManifestFile = ".fejkdata.json"
|
||||
type Manifest struct {
|
||||
// Index is every category of the source by dot path; nil where the manifest has none.
|
||||
Index map[string]IndexEntry `json:"index"`
|
||||
// Reads is every module the source reads by default, directly or through another.
|
||||
// Reads is every module the source reads by default, directly or through another; the
|
||||
// error for a reference naming nothing names them, and nothing loads them.
|
||||
Reads []string `json:"reads"`
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (s Source) Manifest() (Manifest, error) {
|
||||
if err := s.check(); err != nil {
|
||||
return Manifest{}, err
|
||||
}
|
||||
b, err := fs.ReadFile(s.fsys, path.Join(s.base, ManifestFile))
|
||||
b, err := fs.ReadFile(s.fsys, ManifestFile)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return Manifest{}, nil
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func (s Source) Manifest() (Manifest, error) {
|
||||
}
|
||||
|
||||
// ManifestPath is the manifest's path as errors name it.
|
||||
func (s Source) ManifestPath() string { return s.labelled(path.Join(s.base, ManifestFile)) }
|
||||
func (s Source) ManifestPath() string { return s.labelled(ManifestFile) }
|
||||
|
||||
// decodeManifest decodes a manifest, refusing any key or shape it does not define, and
|
||||
// reports every mistake: first each entry's own, in path order, then each parent naming
|
||||
|
||||
Reference in New Issue
Block a user