Skip to content

Commit

Permalink
[add] migrate widget
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 3, 2023
1 parent f2b31c1 commit a9d5e8d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COMMIT := $(shell git log | head -n 1 | awk '{print substr($$2, 0, 12)}')
NOW := $(shell date +"%FT%T%z")

# ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule|runtime|helper|utils' | grep -vE 'examples|tests*|config|widgets')
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule|runtime|helper|utils|widget' | grep -vE 'examples|tests*|config|widgets')
TESTTAGS ?= ""

# TESTWIDGETS := $(shell $(GO) list ./widgets/...)
Expand Down
97 changes: 49 additions & 48 deletions widget/widget.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package widget

import (
"path/filepath"

"github.com/yaoapp/gou/application"
"github.com/yaoapp/gou/widget"
"github.com/yaoapp/yao/config"
Expand All @@ -10,14 +12,15 @@ import (
func Load(cfg config.Config) error {

register := moduleRegister()

return application.App.Walk("widgets", func(root, file string, isdir bool) error {
if !isdir {
if isdir {
return nil
}
_, err := widget.Load(file, nil, register)
path := filepath.Dir(file)
_, err := widget.Load(path, nil, register)
return err
}, config.DSLExtensions...)

}, "widget.yao", "widget.json", "widget.jsonc")

// var root = filepath.Join(cfg.Root, "widgets")
// return LoadFrom(root)
Expand Down Expand Up @@ -64,48 +67,46 @@ func Load(cfg config.Config) error {
// }

func moduleRegister() widget.ModuleRegister {
// return widget.ModuleRegister{
// "Apis": func(name string, source []byte) error {
// _, err := api.Load(string(source), name)
// log.Trace("[Widget] Register api %s", name)
// if err != nil {
// log.Error("[Widget] Register api %s %v", name, err)
// }
// return err
// },
// "Models": func(name string, source []byte) error {
// _, err := model.Load(string(source), name)
// log.Trace("[Widget] Register model %s", name)
// if err != nil {
// log.Error("[Widget] Register model %s %v", name, err)
// }
// return err
// },
// "Tables": func(name string, source []byte) error {
// log.Trace("[Widget] Register table %s", name)
// _, err := table.LoadTable(string(source), name)
// if err != nil {
// log.Error("[Widget] Register table %s %v", name, err)
// }
// return nil
// },
// "Tasks": func(name string, source []byte) error {
// log.Trace("[Widget] Register task %s", name)
// _, err := gou.LoadTask(string(source), name)
// if err != nil {
// log.Error("[Widget] Register task %s %v", name, err)
// }
// return nil
// },
// "Schedules": func(name string, source []byte) error {
// log.Trace("[Widget] Register schedule %s", name)
// _, err := gou.LoadSchedule(string(source), name)
// if err != nil {
// log.Error("[Widget] Register schedule %s %v", name, err)
// }
// return nil
// },
// }

return nil
return widget.ModuleRegister{
// "Apis": func(name string, source []byte) error {
// _, err := api.Load(string(source), name)
// log.Trace("[Widget] Register api %s", name)
// if err != nil {
// log.Error("[Widget] Register api %s %v", name, err)
// }
// return err
// },
// "Models": func(name string, source []byte) error {
// _, err := model.Load(string(source), name)
// log.Trace("[Widget] Register model %s", name)
// if err != nil {
// log.Error("[Widget] Register model %s %v", name, err)
// }
// return err
// },
// "Tables": func(name string, source []byte) error {
// log.Trace("[Widget] Register table %s", name)
// _, err := table.LoadTable(string(source), name)
// if err != nil {
// log.Error("[Widget] Register table %s %v", name, err)
// }
// return nil
// },
// "Tasks": func(name string, source []byte) error {
// log.Trace("[Widget] Register task %s", name)
// _, err := gou.LoadTask(string(source), name)
// if err != nil {
// log.Error("[Widget] Register task %s %v", name, err)
// }
// return nil
// },
// "Schedules": func(name string, source []byte) error {
// log.Trace("[Widget] Register schedule %s", name)
// _, err := gou.LoadSchedule(string(source), name)
// if err != nil {
// log.Error("[Widget] Register schedule %s %v", name, err)
// }
// return nil
// },
}
}
25 changes: 13 additions & 12 deletions widget/widget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/process"
"github.com/yaoapp/kun/any"
"github.com/yaoapp/gou/widget"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/share"
"github.com/yaoapp/yao/test"
)

func TestLoad(t *testing.T) {
// runtime.Load(config.Conf)
share.DBConnect(config.Conf.DB) // 创建数据库连接
test.Prepare(t, config.Conf)
defer test.Clean()

Load(config.Conf)
v, err := process.New("widgets.dyform.Save", "pad", "pay").Exec()
if err != nil {
t.Fatal(err)
}
check(t)
}

res := any.Of(v).Map()
assert.Equal(t, "pad", res.Get("instance"))
assert.Equal(t, "pay", res.Get("payload"))
func check(t *testing.T) {
ids := map[string]bool{}
for id := range widget.Widgets {
ids[id] = true
}
assert.True(t, ids["dyform"])
}

0 comments on commit a9d5e8d

Please sign in to comment.