// PUBDIR is the default directory for publishing final built content
PUBDIR = ".pub"
+
+ // DefaultIgnore is the default set of ignore patterns if no .zsignore
+ DefaultIgnore = `*~
+*.bak
+
+COPYING
+Dockerfile
+LICENSE
+Makefile
+README.md`
)
// Ignore holds a set of patterns to ignore from parsing a .zsignore file
case <-ticker.C:
os.Mkdir(PUBDIR, 0755)
filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
+ // rebuild if changes to .zs/ or .zsignore
+ if (filepath.Base(path) == ZSIGNORE || filepath.Dir(path) == ZSDIR) && info.ModTime().After(lastModified) {
+ Ignore = ParseIgnoreFile(path)
+ // reset lastModified to 0 so everything rebuidls
+ lastModified = time.Unix(0, 0)
+ return nil
+ }
+
// ignore hidden files and directories and ignored patterns
if filepath.Base(path)[0] == '.' || strings.HasPrefix(path, ".") || Ignore.MatchesPath(path) {
return nil
ensureFirstPath(filepath.Join(w, ZSDIR))
}
+func ParseIgnoreFile(fn string) *ignore.GitIgnore {
+ obj, err := ignore.CompileIgnoreFile(ZSIGNORE)
+ if err != nil {
+ log.WithError(err).Warnf("error parsing .zsignore: % (using defaults)s", fn)
+ return ignore.CompileIgnoreLines(DefaultIgnore)
+ }
+
+ return obj
+}
+
func main() {
// prepend .zs to $PATH, so plugins will be found before OS commands
w, _ := os.Getwd()
ensureFirstPath(filepath.Join(w, ZSDIR))
// initialise Ignore (.zsignore) patterns
- if ignoreObject, err := ignore.CompileIgnoreFile(ZSIGNORE); err == nil {
- Ignore = ignoreObject
- } else {
- Ignore = ignore.CompileIgnoreLines("")
- }
+ Ignore = ParseIgnoreFile(ZSIGNORE)
if err := RootCmd.Execute(); err != nil {
log.WithError(err).Error("error executing command")