github.com/mweagle/Sparta@v1.15.0/magefile/private.go (about)

     1  package spartamage
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"strings"
     8  )
     9  
    10  var header = strings.Repeat("-", 80)
    11  
    12  func sourceFilesOfType(extension string, ignoreGlobs []string) ([]string, error) {
    13  	testExtension := strings.TrimPrefix(extension, ".")
    14  	testExtension = fmt.Sprintf(".%s", testExtension)
    15  
    16  	files := make([]string, 0)
    17  	walker := func(path string, info os.FileInfo, err error) error {
    18  		rejectFile := false
    19  		for _, eachComponent := range ignoreGlobs {
    20  			matched, matchErr := filepath.Match(eachComponent, path)
    21  			if matchErr != nil {
    22  				return nil
    23  			}
    24  			if matched {
    25  				rejectFile = true
    26  				break
    27  			}
    28  		}
    29  		if !rejectFile && (filepath.Ext(path) == testExtension) {
    30  			files = append(files, path)
    31  		}
    32  		return nil
    33  	}
    34  	goSourceFilesErr := filepath.Walk(".", walker)
    35  	return files, goSourceFilesErr
    36  }