tweaked automigrate to check for git status and extracted the base flags from the plugins

This commit is contained in:
Gani Georgiev
2022-11-26 22:33:27 +02:00
parent 8c9b657132
commit 675d459137
11 changed files with 170 additions and 367 deletions
-21
View File
@@ -13,13 +13,11 @@ import (
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
"github.com/spf13/cobra"
)
type Options struct {
Dir string
IndexFallback bool
FlagsCmd *cobra.Command
}
type plugin struct {
@@ -46,24 +44,6 @@ func Register(app core.App, options *Options) error {
options.Dir = defaultPublicDir()
}
if options.FlagsCmd != nil {
// add "--publicDir" option flag
options.FlagsCmd.PersistentFlags().StringVar(
&options.Dir,
"publicDir",
options.Dir,
"the directory to serve static files",
)
// add "--indexFallback" option flag
options.FlagsCmd.PersistentFlags().BoolVar(
&options.IndexFallback,
"indexFallback",
options.IndexFallback,
"fallback the request to index.html on missing static path (eg. when pretty urls are used with SPA)",
)
}
p.app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
// serves static files from the provided public dir (if exists)
e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS(options.Dir), options.IndexFallback))
@@ -79,6 +59,5 @@ func defaultPublicDir() string {
// most likely ran with go run
return "./pb_public"
}
return filepath.Join(os.Args[0], "../pb_public")
}