-
Notifications
You must be signed in to change notification settings - Fork 129
Skip .DS_Store folder and swp files (ViM) in the build command #2471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
272b7b0
c263c0a
bf1418d
f64e5e7
9730921
b91048e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,10 @@ | |
| package files | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "slices" | ||
| "strings" | ||
| "regexp" | ||
|
|
||
| "github.com/magefile/mage/sh" | ||
| ) | ||
|
|
@@ -20,11 +20,19 @@ func CopyAll(sourcePath, destinationPath string) error { | |
|
|
||
| // CopyWithoutDev method copies files from the source to the destination, but skips _dev directories and empty folders. | ||
| func CopyWithoutDev(sourcePath, destinationPath string) error { | ||
| return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git", ".DS_Store"}, []string{".swp"}) | ||
| return CopyWithSkipped(sourcePath, destinationPath, []string{"_dev", "build", ".git"}, []string{"\\.DS_Store", "\\..*\\.swp"}) | ||
| } | ||
|
|
||
| // CopyWithSkipped method copies files from the source to the destination, but skips selected directories, empty folders and selected hidden files. | ||
| func CopyWithSkipped(sourcePath, destinationPath string, skippedDirs, skippedHiddenFiles []string) error { | ||
| func CopyWithSkipped(sourcePath, destinationPath string, skippedDirs, skippedFiles []string) error { | ||
| regexesFiles := []*regexp.Regexp{} | ||
| for _, regexFile := range skippedFiles { | ||
| r, err := regexp.Compile(regexFile) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to compile regex %q: %w", r, err) | ||
| } | ||
| regexesFiles = append(regexesFiles, r) | ||
| } | ||
|
||
| return filepath.Walk(sourcePath, func(path string, info os.FileInfo, err error) error { | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -47,9 +55,11 @@ func CopyWithSkipped(sourcePath, destinationPath string, skippedDirs, skippedHid | |
| return nil // don't create empty directories inside packages, if the directory is empty, skip it. | ||
| } | ||
|
|
||
| if strings.HasPrefix(filepath.Base(relativePath), ".") { | ||
| if slices.Contains(skippedHiddenFiles, filepath.Ext(relativePath)) { | ||
| return nil | ||
| if len(regexesFiles) > 0 { | ||
| for _, r := range regexesFiles { | ||
| if r.MatchString(filepath.Base(relativePath)) { | ||
| return nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added support to skip files based on their file names if they match some of these regexes.