From 35e4b1301e9572e0e62492ca6dfdd6b4eeb921bc Mon Sep 17 00:00:00 2001 From: 1-6 Date: Wed, 26 Jul 2023 17:25:19 +0800 Subject: [PATCH] x --- core/grpc_plugins.go | 58 +++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/core/grpc_plugins.go b/core/grpc_plugins.go index ad84324..220304f 100644 --- a/core/grpc_plugins.go +++ b/core/grpc_plugins.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "os" "os/exec" - "path/filepath" "strings" "sync" "time" @@ -33,29 +32,44 @@ func initNodePlugins() { plugins := []string{root} os.Mkdir(root, 0755) fmt.Println("root", root) - filepath.Walk(root, func(path string, info os.FileInfo, err error) error { - fmt.Println("path", path) - path = strings.ReplaceAll(path, "\\", "/") - if !strings.HasPrefix(path, root+"/") { - return nil + + files, _ := ioutil.ReadDir(root) + for _, file := range files { + if !file.IsDir() { + continue } - files := strings.Split(strings.Replace(path, root+"/", "", 1), "/") - fmt.Println("files", files) - // var plugin_dir = false - // var plugin_index = false - switch len(files) { - case 1: - // plugin_dir = true - if info.IsDir() { - plugins = append(plugins, path) - } - case 2: - if (files[1] == "main.js") && !info.IsDir() { //files[1] == "main.ts" || - AddNodePlugin(path, files[0]) - } + name := file.Name() + path := root + "/" + name + plugins = append(plugins, path) + index := path + "/main.js" + if info, err := os.Stat(index); err == nil && !info.IsDir() { + AddNodePlugin(index, name) } - return nil - }) + } + + // filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + // fmt.Println("path", path) + // path = strings.ReplaceAll(path, "\\", "/") + // if !strings.HasPrefix(path, root+"/") { + // return nil + // } + // files := strings.Split(strings.Replace(path, root+"/", "", 1), "/") + // fmt.Println("files", files) + // // var plugin_dir = false + // // var plugin_index = false + // switch len(files) { + // case 1: + // // plugin_dir = true + // if info.IsDir() { + // plugins = append(plugins, path) + // } + // case 2: + // if (files[1] == "main.js") && !info.IsDir() { //files[1] == "main.ts" || + // AddNodePlugin(path, files[0]) + // } + // } + // return nil + // }) watcher, err := fsnotify.NewWatcher() if err != nil { fmt.Println("创建监视器失败:", err)