Skip to content

Commit

Permalink
Merge pull request #212 from Shopify/ignore_remote_files
Browse files Browse the repository at this point in the history
Ignored files apply to download
  • Loading branch information
tanema authored Oct 4, 2016
2 parents d0fcdb8 + 40e2428 commit 08e8c8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
13 changes: 4 additions & 9 deletions commands/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@ func buildForeman(client kit.ThemeClient, args Args, config kit.Configuration) *
os.Chtimes(args.NotifyFile, time.Now(), time.Now())
}
}
foreman.JobQueue = constructFileWatcher(args.Directory, config)
foreman.Restart()
return foreman
}

func constructFileWatcher(dir string, config kit.Configuration) chan kit.AssetEvent {
filter := kit.NewEventFilterFromPatternsAndFiles(config.IgnoredFiles, config.Ignores)
watcher, err := kit.NewFileWatcher(dir, true, filter)
var err error
foreman.JobQueue, err = client.NewFileWatcher(args.Directory)
if err != nil {
kit.NotifyError(err)
}
return watcher
foreman.Restart()
return foreman
}

func spawnWorker(queue chan kit.AssetEvent, client kit.ThemeClient) {
Expand Down
12 changes: 12 additions & 0 deletions kit/event_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strings"

"github.com/ryanuber/go-glob"

"github.com/Shopify/themekit/theme"
)

const configurationFilename = "config\\.yml"
Expand Down Expand Up @@ -83,6 +85,16 @@ func NewEventFilterFromPatternsAndFiles(patterns []string, files []string) Event
return NewEventFilterFromReaders(allReaders)
}

func (e EventFilter) FilterAssets(assets []theme.Asset) []theme.Asset {
filteredAssets := []theme.Asset{}
for _, asset := range assets {
if !e.MatchesFilter(asset.Key) {
filteredAssets = append(filteredAssets, asset)
}
}
return filteredAssets
}

// Filter ... TODO
func (e EventFilter) Filter(events chan string) chan string {
filtered := make(chan string)
Expand Down
11 changes: 8 additions & 3 deletions kit/theme_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,21 @@ func (t ThemeClient) GetConfiguration() Configuration {
return t.config
}

// LeakyBucket ... TODO
// LeakyBucket creates a leaky bucket using the theme clients bucket size and refill rate
func (t ThemeClient) LeakyBucket() *LeakyBucket {
return NewLeakyBucket(t.config.BucketSize, t.config.RefillRate, 1)
}

// NewForeman ... TODO
// NewForeman creates a foreman job runner using a leaky bucket using the theme clients config
func (t ThemeClient) NewForeman() *Foreman {
return NewForeman(t.LeakyBucket())
}

// NewFileWatcher creates a new filewatcher using the theme clients file filter
func (t ThemeClient) NewFileWatcher(dir string) (chan AssetEvent, error) {
return NewFileWatcher(dir, true, t.filter)
}

func (t ThemeClient) ErrorMessage(content string, args ...interface{}) {
t.Message(RedText(fmt.Sprintf(content, args...)))
}
Expand Down Expand Up @@ -140,7 +145,7 @@ func (t ThemeClient) AssetList() []theme.Asset {

sort.Sort(theme.ByAsset(assets["assets"]))

return ignoreCompiledAssets(assets["assets"])
return t.filter.FilterAssets(ignoreCompiledAssets(assets["assets"]))
}

// LocalAssets ... TODO
Expand Down

0 comments on commit 08e8c8f

Please sign in to comment.