forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
87 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package script | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/yaoapp/gou" | ||
"github.com/yaoapp/kun/log" | ||
"github.com/yaoapp/xiang/config" | ||
"github.com/yaoapp/xiang/share" | ||
) | ||
|
||
// Load 加载共享库 | ||
func Load(cfg config.Config) error { | ||
if share.BUILDIN { | ||
return LoadBuildIn("scripts") | ||
} | ||
return LoadFrom(filepath.Join(cfg.Root, "scripts")) | ||
} | ||
|
||
// LoadBuildIn 从制品中读取 | ||
func LoadBuildIn(dir string) error { | ||
return nil | ||
} | ||
|
||
// LoadFrom 从特定目录加载共享库 | ||
func LoadFrom(dir string) error { | ||
|
||
if share.DirNotExists(dir) { | ||
return fmt.Errorf("%s does not exists", dir) | ||
} | ||
|
||
// 加载共享脚本 | ||
err := share.Walk(dir, ".js", func(root, filename string) { | ||
name := share.SpecName(root, filename) | ||
err := gou.Yao.Load(filename, name) | ||
if err != nil { | ||
log.Error("加载脚本失败 %s", err.Error()) | ||
} | ||
}) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package script | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/yaoapp/gou" | ||
) | ||
|
||
func init() { | ||
rootLib := path.Join(os.Getenv("YAO_DEV"), "/tests/scripts") | ||
LoadFrom(rootLib) | ||
} | ||
func TestScript(t *testing.T) { | ||
res, err := gou.Yao.New("time", "hello").Call("world") | ||
assert.Nil(t, err) | ||
assert.Equal(t, "name:world", res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.