add only frontend

This commit is contained in:
2026-08-27 14:20:33 +01:00
parent 1f5243d953
commit 2bbbf4e81e
5 changed files with 81 additions and 31 deletions
+9 -2
View File
@@ -1,4 +1,3 @@
// internal/config/config.go
package config
import (
@@ -80,6 +79,7 @@ type Config struct {
DrivePath string
VerticalSlices bool
SkipFrontend bool
FrontendOnly bool
OmitTest bool
}
@@ -106,6 +106,7 @@ func Parse() (*Config, error) {
drivePath string
verticalSlices bool
skipFrontend bool
frontendOnly bool
omitTest bool
)
@@ -119,9 +120,10 @@ func Parse() (*Config, error) {
flag.Var(&exts, "extensions", "additional file extensions to skip (repeatable)")
flag.BoolVar(&showVer, "version", false, "print version and exit")
flag.BoolVar(&protonDrive, "proton-drive", false, "upload output to Proton Drive after writing locally")
flag.StringVar(&drivePath, "drive-path", "", "full remote path on Proton Drive (requires --proton-drive)")
flag.StringVar(&drivePath, "drive-path", "", "full remote path on Proton Drive (requires --proton-drive")
flag.BoolVar(&verticalSlices, "vertical-slices", false, "split output into root file + one markdown per top-level directory")
flag.BoolVar(&skipFrontend, "skip-frontend", false, "omit frontend file types (.html, .css, .js, .ts, .vue, .svelte, etc.)")
flag.BoolVar(&frontendOnly, "frontend-only", false, "include only frontend file types and README.md")
flag.BoolVar(&omitTest, "omit-test", false, "exclude test files (Go *_test.go, Java *Test.java) and strip #[cfg(test)] blocks from Rust")
flag.Usage = PrintUsage
@@ -148,6 +150,10 @@ func Parse() (*Config, error) {
return nil, fmt.Errorf("--vertical-slices cannot be used with --input-file")
}
if skipFrontend && frontendOnly {
return nil, fmt.Errorf("--skip-frontend and --frontend-only are mutually exclusive")
}
excludedExts := append(DefaultExts, exts...)
if skipFrontend {
excludedExts = append(excludedExts, FrontendExts...)
@@ -165,6 +171,7 @@ func Parse() (*Config, error) {
DrivePath: drivePath,
VerticalSlices: verticalSlices,
SkipFrontend: skipFrontend,
FrontendOnly: frontendOnly,
OmitTest: omitTest,
}
+27 -11
View File
@@ -1,17 +1,19 @@
// internal/filter/filter.go
package filter
import (
"os"
"path/filepath"
"strings"
"dirmd/internal/config"
)
type Filter struct {
MaxSize int64
Extensions []string
Ignores []string
OmitTest bool
MaxSize int64
Extensions []string
Ignores []string
OmitTest bool
FrontendOnly bool
}
func (f *Filter) ShouldSkipDir(name string) bool {
@@ -39,14 +41,11 @@ func (f *Filter) ShouldSkipFile(path, name string, info os.FileInfo) bool {
}
}
ext := filepath.Ext(path)
for _, bad := range f.Extensions {
if strings.EqualFold(ext, bad) {
return true
}
if info.Size() > f.MaxSize {
return true
}
if info.Size() > f.MaxSize {
if f.FrontendOnly && !isFrontendOrReadme(path, name) {
return true
}
@@ -54,9 +53,26 @@ func (f *Filter) ShouldSkipFile(path, name string, info os.FileInfo) bool {
return true
}
ext := filepath.Ext(path)
for _, bad := range f.Extensions {
if strings.EqualFold(ext, bad) {
return true
}
}
return false
}
func isFrontendOrReadme(path, name string) bool {
ext := strings.ToLower(filepath.Ext(path))
for _, fe := range config.FrontendExts {
if strings.EqualFold(ext, fe) {
return true
}
}
return strings.EqualFold(name, "README.md")
}
func isTestFile(path, name string) bool {
ext := strings.ToLower(filepath.Ext(path))
+10 -8
View File
@@ -42,10 +42,11 @@ func processSingleFile(cfg *config.Config) (*Result, error) {
}
flt := &filter.Filter{
MaxSize: cfg.MaxSize,
Extensions: cfg.Extensions,
Ignores: cfg.Ignores,
OmitTest: cfg.OmitTest,
MaxSize: cfg.MaxSize,
Extensions: cfg.Extensions,
Ignores: cfg.Ignores,
OmitTest: cfg.OmitTest,
FrontendOnly: cfg.FrontendOnly,
}
if flt.ShouldSkipFile(cfg.AbsRoot, filepath.Base(cfg.AbsRoot), info) {
@@ -62,10 +63,11 @@ func processSingleFile(cfg *config.Config) (*Result, error) {
func walkDirectory(cfg *config.Config) (*Result, error) {
flt := &filter.Filter{
MaxSize: cfg.MaxSize,
Extensions: cfg.Extensions,
Ignores: cfg.Ignores,
OmitTest: cfg.OmitTest,
MaxSize: cfg.MaxSize,
Extensions: cfg.Extensions,
Ignores: cfg.Ignores,
OmitTest: cfg.OmitTest,
FrontendOnly: cfg.FrontendOnly,
}
result := &Result{AbsRoot: cfg.AbsRoot, OmitTest: cfg.OmitTest}