diff --git a/internal/project/project.go b/internal/project/project.go index f966c69..7a3124f 100644 --- a/internal/project/project.go +++ b/internal/project/project.go @@ -145,10 +145,7 @@ func (p *Project) ValidateLayout() error { } { info, err := os.Stat(path) if err != nil { - if label == "paths.assets" && errors.Is(err, os.ErrNotExist) && p.isCachePath(path) { - if mkErr := os.MkdirAll(path, 0o755); mkErr != nil { - failures = append(failures, fmt.Errorf("%s: create cache directory %s: %w", label, path, mkErr)) - } + if label == "paths.assets" && errors.Is(err, os.ErrNotExist) { continue } failures = append(failures, fmt.Errorf("%s: %w", label, err)) @@ -166,15 +163,6 @@ func (p *Project) ValidateLayout() error { return nil } -func (p *Project) isCachePath(path string) bool { - rel, err := filepath.Rel(p.Root, path) - if err != nil || strings.HasPrefix(rel, ".."+string(filepath.Separator)) || rel == ".." { - return false - } - parts := strings.Split(filepath.Clean(rel), string(filepath.Separator)) - return len(parts) > 0 && parts[0] == ".cache" -} - func (p *Project) Scan() error { sourceFiles, sourceExts, err := scanDir(p.SourceDir(), func(path string) bool { ext := strings.ToLower(filepath.Ext(path)) @@ -189,7 +177,11 @@ func (p *Project) Scan() error { return slices.Contains(AssetExtensions, ext) }) if err != nil { - return fmt.Errorf("scan assets tree: %w", err) + if errors.Is(err, os.ErrNotExist) { + assetFiles = nil + } else { + return fmt.Errorf("scan assets tree: %w", err) + } } var scripts []string diff --git a/internal/project/project_test.go b/internal/project/project_test.go index d3ab26e..c7bc0be 100644 --- a/internal/project/project_test.go +++ b/internal/project/project_test.go @@ -1,6 +1,7 @@ package project import ( + "errors" "os" "path/filepath" "slices" @@ -82,7 +83,7 @@ func TestTopDataAssetsDirReturnsEmptyForNoConfig(t *testing.T) { } } -func TestValidateLayoutCreatesMissingCacheAssetsDir(t *testing.T) { +func TestValidateLayoutAllowsMissingAssetsDir(t *testing.T) { root := t.TempDir() mkdirAll(t, filepath.Join(root, "src")) mkdirAll(t, filepath.Join(root, "build")) @@ -91,17 +92,36 @@ func TestValidateLayoutCreatesMissingCacheAssetsDir(t *testing.T) { Root: root, Config: Config{ Module: ModuleConfig{Name: "Test", ResRef: "test"}, - Paths: PathConfig{Source: "src", Assets: ".cache/module-assets", Build: "build"}, + Paths: PathConfig{Source: "src", Assets: "assets", Build: "build"}, }, } if err := proj.ValidateLayout(); err != nil { t.Fatalf("ValidateLayout returned error: %v", err) } - if info, err := os.Stat(filepath.Join(root, ".cache", "module-assets")); err != nil { - t.Fatalf("expected cache assets dir to be created: %v", err) - } else if !info.IsDir() { - t.Fatalf("expected cache assets path to be a directory") + if _, err := os.Stat(filepath.Join(root, "assets")); !errors.Is(err, os.ErrNotExist) { + t.Fatalf("expected missing assets dir to remain absent, got err=%v", err) + } +} + +func TestScanAllowsMissingAssetsDir(t *testing.T) { + root := t.TempDir() + mkdirAll(t, filepath.Join(root, "src")) + mkdirAll(t, filepath.Join(root, "build")) + + proj := &Project{ + Root: root, + Config: Config{ + Module: ModuleConfig{Name: "Test", ResRef: "test"}, + Paths: PathConfig{Source: "src", Assets: "assets", Build: "build"}, + }, + } + + if err := proj.Scan(); err != nil { + t.Fatalf("Scan returned error: %v", err) + } + if len(proj.Inventory.AssetFiles) != 0 { + t.Fatalf("expected no asset files, got %#v", proj.Inventory.AssetFiles) } }