Skip to content

Commit

Permalink
feat: 文件目录初始化
Browse files Browse the repository at this point in the history
  • Loading branch information
goldEli committed Jun 18, 2021
1 parent 430520e commit 8688011
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
Binary file modified watch
Binary file not shown.
58 changes: 35 additions & 23 deletions watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type Watch struct {
watch *fsnotify.Watcher
}

const sourceDir = "/Users/miaoyu/Desktop/liweijia/lwj-common-frontend/lwj-react/lwj-editor/src"
const targetDir = "/Users/miaoyu/Desktop/liweijia/site-frontend/src/pages/lwj-editor"
const sourceDir string = "/Users/miaoyu/Desktop/liweijia/lwj-common-frontend/lwj-react/lwj-editor/src"
const targetDir string = "/Users/miaoyu/Desktop/liweijia/site-frontend/src/pages/lwj-editor"

//监控目录
func (w *Watch) watchDir(sourceDir string, targetDir string) {
Expand Down Expand Up @@ -93,6 +93,35 @@ func (w *Watch) watchDir(sourceDir string, targetDir string) {
}()
}

func copyFile(name string, sourceDir string, targetDir string) {
if strings.Contains(name, ".umi") {
return
}
fmt.Printf("复制文件:%v\n", name)
target := strings.Replace(name, sourceDir, targetDir, 1)
fmt.Printf("=>%v\n\n", target)
cp := exec.Command("cp", name, target)
cp.Run()
}

func initDirs() {
list := [9]string{"api", "assets", "components", "core", "layouts", "models", "pages", "themes", "utils"}
slash := "/"
for _, element := range list {
copy(sourceDir+slash+element, targetDir+slash+element)
}
}

func copy(sourceDir string, targetDir string) {
fmt.Printf("删除文件:%v\n", targetDir)
rm := exec.Command("rm", "-rf", targetDir)
rm.Run()
fmt.Printf("复制文件:%v\n", sourceDir)
fmt.Printf("=>%v\n\n", targetDir)
cp := exec.Command("cp", "-R", sourceDir, targetDir)
cp.Run()
}

func main() {
fmt.Println(len(os.Args))
if len(os.Args) < 3 {
Expand All @@ -104,31 +133,14 @@ func main() {
fmt.Println(sourceDir)
fmt.Println(targetDir)

println("初始化文件夹...")
initDirs()
println("初始化文件夹结束。")

watch, _ := fsnotify.NewWatcher()
w := Watch{
watch: watch,
}
w.watchDir(sourceDir, targetDir)
select {}
}

func copyFile(name string, sourceDir string, targetDir string) {
if strings.Contains(name, ".umi") {
return
}
fmt.Printf("复制文件:%v\n", name)
target := strings.Replace(name, sourceDir, targetDir, 1)
fmt.Printf("=>%v\n\n", target)
cp := exec.Command("cp", name, target)
cp.Run()
}

// func copy() {
// // fmt.Printf("删除文件:%v\n", targetDir)
// // rm := exec.Command("rm", "-rf", targetDir)
// // rm.Run()
// fmt.Printf("复制文件:%v\n", sourceDir)
// fmt.Printf("=>%v\n\n", targetDir)
// cp := exec.Command("cp", "-R", sourceDir, targetDir)
// cp.Run()
// }

0 comments on commit 8688011

Please sign in to comment.