Merge pull request #870 from trheyi/main
Add assistant script loading mechanism
This commit is contained in:
commit
27524f7fb0
1 changed files with 22 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package script
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/yaoapp/gou/application"
|
"github.com/yaoapp/gou/application"
|
||||||
v8 "github.com/yaoapp/gou/runtime/v8"
|
v8 "github.com/yaoapp/gou/runtime/v8"
|
||||||
|
|
@ -25,6 +26,27 @@ func Load(cfg config.Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load assistants
|
||||||
|
err = application.App.Walk("assistants", func(root, file string, isdir bool) error {
|
||||||
|
if isdir {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep the src.index only
|
||||||
|
if !strings.HasSuffix(file, "src/index.ts") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
id := fmt.Sprintf("assistants.%s", share.ID(root, file))
|
||||||
|
id = strings.TrimSuffix(id, ".src.index")
|
||||||
|
_, err := v8.Load(file, id)
|
||||||
|
return err
|
||||||
|
}, exts...)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return application.App.Walk("services", func(root, file string, isdir bool) error {
|
return application.App.Walk("services", func(root, file string, isdir bool) error {
|
||||||
if isdir {
|
if isdir {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue