This commit is contained in:
1-6
2023-07-26 17:25:19 +08:00
parent 095f22bec1
commit 35e4b1301e
+34 -20
View File
@@ -7,7 +7,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -33,29 +32,44 @@ func initNodePlugins() {
plugins := []string{root} plugins := []string{root}
os.Mkdir(root, 0755) os.Mkdir(root, 0755)
fmt.Println("root", root) fmt.Println("root", root)
filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
fmt.Println("path", path) files, _ := ioutil.ReadDir(root)
path = strings.ReplaceAll(path, "\\", "/") for _, file := range files {
if !strings.HasPrefix(path, root+"/") { if !file.IsDir() {
return nil continue
} }
files := strings.Split(strings.Replace(path, root+"/", "", 1), "/") name := file.Name()
fmt.Println("files", files) path := root + "/" + name
// var plugin_dir = false
// var plugin_index = false
switch len(files) {
case 1:
// plugin_dir = true
if info.IsDir() {
plugins = append(plugins, path) plugins = append(plugins, path)
} index := path + "/main.js"
case 2: if info, err := os.Stat(index); err == nil && !info.IsDir() {
if (files[1] == "main.js") && !info.IsDir() { //files[1] == "main.ts" || AddNodePlugin(index, name)
AddNodePlugin(path, files[0])
} }
} }
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() watcher, err := fsnotify.NewWatcher()
if err != nil { if err != nil {
fmt.Println("创建监视器失败:", err) fmt.Println("创建监视器失败:", err)