From edcb6950e5e21a0d0e084bc370c154deaa2a4c17 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sun, 23 Jul 2023 23:45:33 +0300 Subject: [PATCH] watch pb_hooks subdirectories --- CHANGELOG.md | 2 ++ plugins/jsvm/jsvm.go | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2d1d589..89232619 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,8 @@ If `?skipTotal=1` is set, the response fields `totalItems` and `totalPages` will have `-1` value (this is to avoid having different JSON responses and to differentiate from the zero default). With the latest JS SDK 0.16+ and Dart SDK v0.11+ versions `skipTotal=1` is set by default for the `getFirstListItem()` and `getFullList()` requests. +- Added new utility `github.com/pocketbase/pocketbase/tools/template` package to assist with rendering HTML templates using the standard Go `html/template` and `text/template` syntax. + ## v0.16.10 diff --git a/plugins/jsvm/jsvm.go b/plugins/jsvm/jsvm.go index e4499052..198f5103 100644 --- a/plugins/jsvm/jsvm.go +++ b/plugins/jsvm/jsvm.go @@ -16,6 +16,7 @@ import ( "path/filepath" "regexp" "runtime" + "strings" "time" "github.com/dop251/goja" @@ -342,14 +343,22 @@ func (p *plugin) watchHooks() error { } }() - // add the directory to watch - err = watcher.Add(p.config.HooksDir) - if err != nil { + // add directories to watch + // + // @todo replace once recursive watcher is added (https://github.com/fsnotify/fsnotify/issues/18) + dirsErr := filepath.Walk(p.config.HooksDir, func(path string, info fs.FileInfo, err error) error { + // ignore hidden directories and node_modules + if !info.IsDir() || info.Name() == "node_modules" || strings.HasPrefix(info.Name(), ".") { + return nil + } + + return watcher.Add(path) + }) + if dirsErr != nil { watcher.Close() - return err } - return nil + return dirsErr } // fullTypesPathReturns returns the full path to the generated TS file.