mirror of
https://github.com/wahyd4/node-prune.git
synced 2026-08-09 05:06:18 +10:00
add WithDirectories() option
This commit is contained in:
@@ -9,7 +9,28 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// DefaultDirectories pruned.
|
||||
//
|
||||
// Copied from yarn (mostly).
|
||||
var DefaultDirectories = []string{
|
||||
"__tests__",
|
||||
"test",
|
||||
"tests",
|
||||
"powered-test",
|
||||
"docs",
|
||||
"doc",
|
||||
"website",
|
||||
"images",
|
||||
"assets",
|
||||
"example",
|
||||
"examples",
|
||||
"coverage",
|
||||
".nyc_output",
|
||||
}
|
||||
|
||||
// DefaultExtensions pruned.
|
||||
//
|
||||
// Copied from yarn (mostly).
|
||||
var DefaultExtensions = []string{
|
||||
".md",
|
||||
".ts",
|
||||
@@ -26,6 +47,7 @@ type Stats struct {
|
||||
type Pruner struct {
|
||||
dir string
|
||||
log log.Interface
|
||||
dirs map[string]struct{}
|
||||
exts map[string]struct{}
|
||||
}
|
||||
|
||||
@@ -61,6 +83,13 @@ func WithExtensions(s []string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithDirectories option.
|
||||
func WithDirectories(s []string) Option {
|
||||
return func(v *Pruner) {
|
||||
v.dirs = toMap(s)
|
||||
}
|
||||
}
|
||||
|
||||
// Prune performs the pruning.
|
||||
func (p Pruner) Prune() (*Stats, error) {
|
||||
var stats Stats
|
||||
@@ -97,7 +126,8 @@ func (p Pruner) Prune() (*Stats, error) {
|
||||
// prune returns true if the file or dir should be pruned.
|
||||
func (p Pruner) prune(path string, info os.FileInfo) bool {
|
||||
if info.IsDir() {
|
||||
return false
|
||||
_, ok := p.dirs[info.Name()]
|
||||
return ok
|
||||
}
|
||||
|
||||
ext := filepath.Ext(path)
|
||||
|
||||
Reference in New Issue
Block a user