Add wildcard support
This commit is contained in:
39
compile.go
39
compile.go
@ -42,29 +42,32 @@ func supportedFileType(t FileType) bool {
|
|||||||
func getBytes(config Config, minifier *minify.M) (map[FileType]*bytes.Buffer, error) {
|
func getBytes(config Config, minifier *minify.M) (map[FileType]*bytes.Buffer, error) {
|
||||||
buf := make(map[FileType]*bytes.Buffer)
|
buf := make(map[FileType]*bytes.Buffer)
|
||||||
|
|
||||||
for _, file := range config.Files {
|
for _, pattern := range config.Files {
|
||||||
if file, err := os.Open(file); err == nil {
|
files, _ := filepath.Glob(pattern)
|
||||||
ext := FileType(filepath.Ext(file.Name())[1:])
|
for _, file := range files {
|
||||||
if !supportedFileType(ext) {
|
if file, err := os.Open(file); err == nil {
|
||||||
fmt.Println("Unsupported file type:", file.Name())
|
ext := FileType(filepath.Ext(file.Name())[1:])
|
||||||
continue
|
if !supportedFileType(ext) {
|
||||||
}
|
fmt.Println("Unsupported file type:", file.Name())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if buf[ext] == nil {
|
if buf[ext] == nil {
|
||||||
buf[ext] = &bytes.Buffer{}
|
buf[ext] = &bytes.Buffer{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Minify {
|
if config.Minify {
|
||||||
if err = minifier.Minify(string(ext), buf[ext], file); err != nil {
|
if err = minifier.Minify(string(ext), buf[ext], file); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if _, err = buf[ext].ReadFrom(file); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if _, err = buf[ext].ReadFrom(file); err != nil {
|
return nil, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user