build.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # -*-coding:utf-8 -*-
  2. import shutil, os
  3. import time
  4. inspurPath = os.path.abspath('.') + '\party-web'
  5. inspurInnerPath = os.path.abspath('.') + '\party-webZip'
  6. inspurZipPath = os.path.abspath('.') + '\party-web.zip'
  7. distPath = os.path.abspath('.') + '\party-web'
  8. zipPath = 'D:\Project\Zip'
  9. isOnLine = True
  10. def deleteFile(isDelete):
  11. if os.path.exists(distPath):
  12. shutil.rmtree(distPath)
  13. if os.path.exists(inspurPath):
  14. shutil.rmtree(inspurPath)
  15. if isDelete:
  16. if os.path.exists(inspurZipPath):
  17. os.remove(inspurZipPath)
  18. if os.path.exists(inspurInnerPath):
  19. shutil.rmtree(inspurInnerPath)
  20. def buildModel():
  21. rootPath = os.path.abspath('.')
  22. print('########### run build ############')
  23. # 打包命令
  24. cmd = 'npm run build:prod'
  25. # 切换到需要项目目录
  26. os.chdir(rootPath)
  27. # 当前项目目录下执行打包命令
  28. if os.system(cmd) == 0:
  29. # 打包完成
  30. print('########### build complete ############')
  31. # 判断文件是否存在
  32. def isExitFile(pathString):
  33. if os.path.exists(pathString):
  34. return True;
  35. else:
  36. return False;
  37. # 创建文件夹
  38. def isCreateFile(pathStrring):
  39. if isExitFile(pathStrring) == False:
  40. os.makedirs(pathStrring)
  41. def moveFile(zipName):
  42. if os.path.exists(distPath):
  43. isCreateFile(inspurInnerPath)
  44. if isExitFile(distPath):
  45. shutil.move(distPath, inspurInnerPath)
  46. # for filename in os.listdir(distPath):
  47. # if filename.endswith('static'):
  48. # shutil.copytree(os.path.join(distPath, filename), os.path.join(inspurInnerPath, filename))
  49. # elif filename == 'html':
  50. # shutil.copytree(os.path.join(distPath, filename), os.path.join(inspurInnerPath, filename))
  51. # else:
  52. # shutil.copy(os.path.join(distPath, filename), os.path.join(inspurInnerPath, filename))
  53. print('*************zip*************')
  54. # zipName = time.strftime("%Y-%m-%d-%H%M%S")
  55. shutil.make_archive(zipPath + '\party-web'+ zipName, 'zip', inspurInnerPath);
  56. deleteFile(True)
  57. buildModel()
  58. zipName = 'party-web'
  59. if isOnLine:
  60. zipName = time.strftime("%Y-%m-%d-%H%M%S")
  61. moveFile(zipName)
  62. deleteFile(True)
  63. print('cd /usr/local/tomcat/webapps')
  64. print('unzip party-web' + zipName + '.zip')
  65. print('*************finished*************')
  66. os.startfile(zipPath)