2022-07-08 04:10:29 +02:00
|
|
|
package files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// List returns a list of all files in the current directory.
|
|
|
|
// It ignores the .git directory.
|
|
|
|
func List() []string {
|
|
|
|
var files []string
|
|
|
|
err := filepath.Walk(".",
|
|
|
|
func(path string, info os.FileInfo, err error) error {
|
|
|
|
if shouldIgnore(path) || info.IsDir() || err != nil {
|
2022-07-30 18:32:59 +02:00
|
|
|
return nil //nolint:nilerr
|
2022-07-08 04:10:29 +02:00
|
|
|
}
|
|
|
|
files = append(files, path)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
return files
|
|
|
|
}
|
|
|
|
|
2022-07-08 04:39:28 +02:00
|
|
|
var defaultIgnorePatterns = []string{"node_modules", ".git", "."}
|
|
|
|
|
2022-07-08 04:10:29 +02:00
|
|
|
func shouldIgnore(path string) bool {
|
2022-07-08 04:39:28 +02:00
|
|
|
for _, prefix := range defaultIgnorePatterns {
|
|
|
|
if strings.HasPrefix(path, prefix) {
|
|
|
|
return true
|
|
|
|
}
|
2022-07-08 04:10:29 +02:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|