Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>

git-svn-id: file:///srv/svn/repo/aya/trunk@88 cec141ff-132a-4243-88a5-ce187bd62f94
This commit is contained in:
yakumo.izuru 2024-06-17 15:43:09 +00:00
parent efcb25e6e5
commit f0da6dc37f
2 changed files with 41 additions and 40 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
*~ *~
*.bak *.bak
**.pub **.pub
*.sw*
/aya /aya
/dist /dist

View File

@ -12,46 +12,46 @@ import (
) )
func buildAll(watch bool) { func buildAll(watch bool) {
lastModified := time.Unix(0, 0) lastModified := time.Unix(0, 0)
modified := false modified := false
vars := globals() vars := globals()
for { for {
os.Mkdir(PUBDIR, 0755) os.Mkdir(PUBDIR, 0755)
filepath.Walk(".", func(path string, info os.FileInfo, err error) error { filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
// ignore hidden files and directories // ignore hidden files and directories
if filepath.Base(path)[0] == '.' || strings.HasPrefix(path, ".") { if filepath.Base(path)[0] == '.' || strings.HasPrefix(path, ".") {
return nil return nil
} }
// inform user about fs walk errors, but continue iteration // inform user about fs walk errors, but continue iteration
if err != nil { if err != nil {
fmt.Println("error:", err) fmt.Println("error:", err)
return nil return nil
} }
if info.IsDir() { if info.IsDir() {
os.Mkdir(filepath.Join(PUBDIR, path), 0755) os.Mkdir(filepath.Join(PUBDIR, path), 0755)
return nil return nil
} else if info.ModTime().After(lastModified) { } else if info.ModTime().After(lastModified) {
if !modified { if !modified {
// First file in this build cycle is about to be modified // First file in this build cycle is about to be modified
run(vars, "prehook") run(vars, "prehook")
modified = true modified = true
} }
fmt.Println("GEN", path) fmt.Println("GEN", path)
return build(path, nil, vars) return build(path, nil, vars)
} }
return nil return nil
}) })
if modified { if modified {
// At least one file in this build cycle has been modified // At least one file in this build cycle has been modified
run(vars, "posthook") run(vars, "posthook")
modified = false modified = false
} }
if !watch { if !watch {
break break
} }
lastModified = time.Now() lastModified = time.Now()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
} }