build.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "os/exec"
  7. "runtime"
  8. "strings"
  9. )
  10. var target = "../www/"
  11. func main() {
  12. fmt.Println("=============start==============")
  13. dir := flag.String("dir", "yyq_admin", "dir")
  14. flag.Parse()
  15. target += *dir + "/"
  16. fmt.Println("target_dir", target)
  17. os.RemoveAll(target + "static")
  18. os.RemoveAll(target + "manage")
  19. os.Remove(target + "index.html")
  20. os.Remove(target + "favicon.ico")
  21. os.Remove(target + "favicon.jpg")
  22. copyDir("./dist", target)
  23. }
  24. func FormatPath(s string) string {
  25. switch runtime.GOOS {
  26. case "windows":
  27. return strings.Replace(s, "/", "\\", -1)
  28. case "darwin", "linux":
  29. return strings.Replace(s, "\\", "/", -1)
  30. default:
  31. return s
  32. }
  33. }
  34. func copyDir(src string, dest string) {
  35. src = FormatPath(src)
  36. dest = FormatPath(dest)
  37. var cmd *exec.Cmd
  38. switch runtime.GOOS {
  39. case "windows":
  40. cmd = exec.Command("xcopy", src, dest, "/I", "/E")
  41. case "darwin", "linux":
  42. cmd = exec.Command("cp", "-R", src, dest)
  43. }
  44. outPut, e := cmd.Output()
  45. if e != nil {
  46. fmt.Println("copy error", e.Error())
  47. return
  48. }
  49. fmt.Println(string(outPut))
  50. }