| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- # -*-coding:utf-8 -*-
- import shutil, os
- import time
- inspurPath = os.path.abspath('.') + '\inspur-web'
- inspurInnerPath = os.path.abspath('.') + '\inspur-web\inspur-web'
- inspurZipPath = os.path.abspath('.') + '\inspur-web.zip'
- distPath = os.path.abspath('.') + '\dist'
- zipPath = 'D:\Project\Zip'
- def deleteFile(isDelete):
- if os.path.exists(distPath):
- shutil.rmtree(distPath)
- if os.path.exists(inspurPath):
- shutil.rmtree(inspurPath)
- if isDelete:
- if os.path.exists(inspurZipPath):
- os.remove(inspurZipPath)
-
- def buildModel():
- rootPath = os.path.abspath('.')
- print('########### run build ############')
- # 打包命令
- cmd = 'npm run build:prod'
- # 切换到需要项目目录
- os.chdir(rootPath)
- # 当前项目目录下执行打包命令
- if os.system(cmd) == 0:
- # 打包完成
- print('########### build complete ############')
- # 判断文件是否存在
- def isExitFile(pathString):
- if os.path.exists(pathString):
- return True;
- else:
- return False;
- # 创建文件夹
- def isCreateFile(pathStrring):
-
- if isExitFile(pathStrring) == False:
- os.makedirs(pathStrring)
- def moveFile():
- if os.path.exists(distPath):
- isCreateFile(inspurInnerPath)
- if isExitFile(distPath):
- for filename in os.listdir(distPath):
- if filename.endswith('static'):
- shutil.copytree(os.path.join(distPath, filename), os.path.join(inspurPath, filename))
- elif filename == 'html':
- shutil.copytree(os.path.join(distPath, filename), os.path.join(inspurInnerPath, filename))
- else:
- shutil.copy(os.path.join(distPath, filename), os.path.join(inspurInnerPath, filename))
- print('*************zip*************')
- zipName = time.strftime("%Y-%m-%d-%H%M%S")
- shutil.make_archive(zipPath + '\inspur-web'+ zipName, 'zip', inspurPath);
-
- deleteFile(True)
- buildModel()
- moveFile()
- deleteFile(False)
- print('*************finished*************')
|