Skip to content

Commit

Permalink
skip-dirs (#7)
Browse files Browse the repository at this point in the history
* changelog
* one more change
* fixed the logic for matching skipped dirs
* edited to use glob instead
* edited default skip matcher
  • Loading branch information
EItanya authored and soloio-bulldozer[bot] committed Jan 3, 2020
1 parent e14cd3a commit 73171ea
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 40 deletions.
120 changes: 93 additions & 27 deletions anyvendor/anyvendor.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions anyvendor/anyvendor.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions anyvendor/anyvendor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,28 @@ import "validate/validate.proto";
Imports is a list of import types which will be run, and then vendored.
*/
message Config {
// files to be vendored from current repo
Local local = 1;

// list of external imports to be vendored in
repeated Import imports = 2;

FactorySettings settings = 3;
}

// a message for settings which is passed to the factories at startup
message FactorySettings {
/*
directories which will be skipped when searching for files to vendor. Default
vendor_any folder is skipped by default.
*/

// Example: [**/node_modules/**]
// Any paths which start the string `node_modules` will be skipped over by the copier.
repeated string skip_patterns = 1;

// Current working directory
string cwd = 2;
}

message Import {
Expand Down
4 changes: 4 additions & 0 deletions changelog/v0.0.2/skip-dirs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
- type: NEW_FEATURE
description: Allow users to include custom skipped directories for importing.
issueLink: https://github.com/solo-io/anyvendor/issues/6
35 changes: 28 additions & 7 deletions pkg/manager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"os"
"path/filepath"
"strings"
"unicode"

"github.com/mattn/go-zglob"
Expand All @@ -27,7 +26,8 @@ type FileCopier interface {
var matchListFilter = fmt.Sprintf("%s/", anyvendor.DefaultDepDir)

type copier struct {
fs afero.Fs
fs afero.Fs
skipDirs []string
}

func (c *copier) GetMatches(copyPat []string, dir string) ([]string, error) {
Expand All @@ -41,8 +41,11 @@ func (c *copier) GetMatches(copyPat []string, dir string) ([]string, error) {
// Filter out all matches which contain a vendor folder, those are leftovers from a previous run.
// Might be worth clearing the vendor folder before every run.
for _, match := range matches {
vendorFolders := strings.Count(match, matchListFilter)
if vendorFolders > 0 {
contains, err := c.containsSkippedDirectory(match)
if err != nil {
return nil, err
}
if contains {
continue
}
vendorList = append(vendorList, match)
Expand All @@ -52,6 +55,19 @@ func (c *copier) GetMatches(copyPat []string, dir string) ([]string, error) {
return vendorList, nil
}

func (c *copier) containsSkippedDirectory(match string) (bool, error) {
for _, skipDir := range c.skipDirs {
matched, err := zglob.Match(skipDir, match)
if err != nil {
return false, err
}
if matched {
return true, nil
}
}
return false, nil
}

func (c *copier) PkgModPath(importPath, version string) string {
goPath := os.Getenv("GOPATH")
if goPath == "" {
Expand All @@ -74,9 +90,11 @@ func (c *copier) PkgModPath(importPath, version string) string {
return filepath.Join(goPath, "pkg", "mod", fmt.Sprintf("%s@%s", normPath, version))
}

func NewCopier(fs afero.Fs) *copier {
func NewCopier(fs afero.Fs, skipDirs []string) *copier {
skipDirs = append(skipDirs, fmt.Sprintf("**/%s/**", anyvendor.DefaultDepDir))
return &copier{
fs: fs,
fs: fs,
skipDirs: skipDirs,
}
}

Expand All @@ -87,7 +105,10 @@ var (
)

func NewDefaultCopier() *copier {
return &copier{fs: afero.NewOsFs()}
return &copier{
fs: afero.NewOsFs(),
skipDirs: []string{anyvendor.DefaultDepDir},
}
}

func (c *copier) Copy(src, dst string) (int64, error) {
Expand Down
Loading

0 comments on commit 73171ea

Please sign in to comment.