|  | @@ -2,7 +2,7 @@ import os
 | 
											
												
													
														|  |  import flask
 |  |  import flask
 | 
											
												
													
														|  |  import requests
 |  |  import requests
 | 
											
												
													
														|  |  import json
 |  |  import json
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | 
 |  | +import time
 | 
											
												
													
														|  |  from flask import Flask,request,redirect
 |  |  from flask import Flask,request,redirect
 | 
											
												
													
														|  |  from flask_cors import CORS 
 |  |  from flask_cors import CORS 
 | 
											
												
													
														|  |  app = Flask(__name__,static_folder="static")
 |  |  app = Flask(__name__,static_folder="static")
 | 
											
										
											
												
													
														|  | @@ -19,13 +19,11 @@ def build_mini_program(branch):
 | 
											
												
													
														|  |      res = False
 |  |      res = False
 | 
											
												
													
														|  |      command_str = (
 |  |      command_str = (
 | 
											
												
													
														|  |      "cd "+current_path+ ";"
 |  |      "cd "+current_path+ ";"
 | 
											
												
													
														|  | -    "git clone https://git.yishihui.com/weapp/longVideoFactory.git;"
 |  | 
 | 
											
												
													
														|  |      "cd longVideoFactory;"
 |  |      "cd longVideoFactory;"
 | 
											
												
													
														|  |      "rm -rf dist;"
 |  |      "rm -rf dist;"
 | 
											
												
													
														|  | -    "git pull;"
 |  | 
 | 
											
												
													
														|  |      "git checkout "+branch+";"
 |  |      "git checkout "+branch+";"
 | 
											
												
													
														|  |      "git pull;"
 |  |      "git pull;"
 | 
											
												
													
														|  | -    "n 8;"
 |  | 
 | 
											
												
													
														|  | 
 |  | +    "n 10;"
 | 
											
												
													
														|  |      "cnpm install && npm install ;"
 |  |      "cnpm install && npm install ;"
 | 
											
												
													
														|  |      "npm run build && npm run build:other;"
 |  |      "npm run build && npm run build:other;"
 | 
											
												
													
														|  |      )
 |  |      )
 | 
											
										
											
												
													
														|  | @@ -42,15 +40,17 @@ def build_mini_program(branch):
 | 
											
												
													
														|  |  # # 3.微信编译图片
 |  |  # # 3.微信编译图片
 | 
											
												
													
														|  |  def create_preview(project,page):
 |  |  def create_preview(project,page):
 | 
											
												
													
														|  |      # 小程序 cli path for mac
 |  |      # 小程序 cli path for mac
 | 
											
												
													
														|  | -    wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
 |  | 
 | 
											
												
													
														|  | 
 |  | +    wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli "
 | 
											
												
													
														|  |      
 |  |      
 | 
											
												
													
														|  |      dist_path =  os.path.join(current_path,'longVideoFactory/dist/'+project)
 |  |      dist_path =  os.path.join(current_path,'longVideoFactory/dist/'+project)
 | 
											
												
													
														|  |      code_img_path =  os.path.join(current_path,'1.png')
 |  |      code_img_path =  os.path.join(current_path,'1.png')
 | 
											
												
													
														|  |      
 |  |      
 | 
											
												
													
														|  |      path = """ '{"pathName":"%s"}' """ % page
 |  |      path = """ '{"pathName":"%s"}' """ % page
 | 
											
												
													
														|  | -    os.system(wx_cli+ "open --project " + dist_path)
 |  | 
 | 
											
												
													
														|  | -    os.system(wx_cli+ "reset-fileutils --project " + dist_path)
 |  | 
 | 
											
												
													
														|  | 
 |  | +    os.system(wx_cli+ " open --project " + dist_path)
 | 
											
												
													
														|  | 
 |  | +    os.system(wx_cli+ " reset-fileutils --project " + dist_path)
 | 
											
												
													
														|  | 
 |  | +    print(wx_cli+" preview  --project "+dist_path+"  --compile-condition "+path+"   --qr-output "+code_img_path+" --qr-format image")
 | 
											
												
													
														|  |      f_read = os.popen(wx_cli+" preview  --project "+dist_path+"  --compile-condition "+path+"   --qr-output "+code_img_path+" --qr-format image").read()
 |  |      f_read = os.popen(wx_cli+" preview  --project "+dist_path+"  --compile-condition "+path+"   --qr-output "+code_img_path+" --qr-format image").read()
 | 
											
												
													
														|  | 
 |  | +    os.system(wx_cli+ " quit")
 | 
											
												
													
														|  |      if "[error]" in f_read:
 |  |      if "[error]" in f_read:
 | 
											
												
													
														|  |          res_json["code"] = 3
 |  |          res_json["code"] = 3
 | 
											
												
													
														|  |          res_json["msg"] = f_read
 |  |          res_json["msg"] = f_read
 | 
											
										
											
												
													
														|  | @@ -154,58 +154,64 @@ def send_msg_by_feishu(token,img_key,url,project_name,mode_name):
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  @app.route('/')
 |  |  @app.route('/')
 | 
											
												
													
														|  |  def func():    
 |  |  def func():    
 | 
											
												
													
														|  | -    return 'Welcome to auto-mini-program-build-preview server. only can run on MacOS.'
 |  | 
 | 
											
												
													
														|  | 
 |  | +    # return 'Welcome to auto-mini-program-build-preview server. only can run on MacOS.'
 | 
											
												
													
														|  | 
 |  | +    return redirect("static/dist/index.html")
 | 
											
												
													
														|  |       
 |  |       
 | 
											
												
													
														|  |  @app.route('/send',methods=['POST'])
 |  |  @app.route('/send',methods=['POST'])
 | 
											
												
													
														|  |  def send():
 |  |  def send():
 | 
											
												
													
														|  |      global send_status
 |  |      global send_status
 | 
											
												
													
														|  | -    if send_status == True:
 |  | 
 | 
											
												
													
														|  | -        res_json["code"] = 9
 |  | 
 | 
											
												
													
														|  | -        res_json["msg"] = "当前有人打包,请稍后尝试"
 |  | 
 | 
											
												
													
														|  | -        return res_json
 |  | 
 | 
											
												
													
														|  | -    send_status = True
 |  | 
 | 
											
												
													
														|  | -    res_json["code"] = 0
 |  | 
 | 
											
												
													
														|  | -    res_json["msg"] = "成功"
 |  | 
 | 
											
												
													
														|  | -    webhook_url = request.json["webhook"]
 |  | 
 | 
											
												
													
														|  | -    branch = request.json["branch"]
 |  | 
 | 
											
												
													
														|  | -    page = request.json["page"]
 |  | 
 | 
											
												
													
														|  | -    project = request.json["project"]
 |  | 
 | 
											
												
													
														|  | -    mode = request.json["mode"]
 |  | 
 | 
											
												
													
														|  | -    project_name = request.json["project_name"]
 |  | 
 | 
											
												
													
														|  | -    mode_name = request.json["mode_name"]
 |  | 
 | 
											
												
													
														|  | -    # ------- 微信打包 ------
 |  | 
 | 
											
												
													
														|  | -    # 1.小程序打包
 |  | 
 | 
											
												
													
														|  | -    build_mini_program(branch)
 |  | 
 | 
											
												
													
														|  | -    if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  | -        send_status = False
 |  | 
 | 
											
												
													
														|  | -        return res_json
 |  | 
 | 
											
												
													
														|  | -    # 2.修改环境
 |  | 
 | 
											
												
													
														|  | -    edit_mode_by_file(project,mode)
 |  | 
 | 
											
												
													
														|  | -    if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  | -        send_status = False
 |  | 
 | 
											
												
													
														|  | -        return res_json
 |  | 
 | 
											
												
													
														|  | -    # 3.微信编译图片
 |  | 
 | 
											
												
													
														|  | -    create_preview(project,page)
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | 
 |  | +    try:
 | 
											
												
													
														|  | 
 |  | +        if send_status == True:
 | 
											
												
													
														|  | 
 |  | +            res_json["code"] = 9
 | 
											
												
													
														|  | 
 |  | +            res_json["msg"] = "当前有人打包,请稍后尝试"
 | 
											
												
													
														|  | 
 |  | +            return res_json
 | 
											
												
													
														|  | 
 |  | +        send_status = True
 | 
											
												
													
														|  | 
 |  | +        res_json["code"] = 0
 | 
											
												
													
														|  | 
 |  | +        res_json["msg"] = "成功"
 | 
											
												
													
														|  | 
 |  | +        webhook_url = request.json["webhook"]
 | 
											
												
													
														|  | 
 |  | +        branch = request.json["branch"]
 | 
											
												
													
														|  | 
 |  | +        page = request.json["page"]
 | 
											
												
													
														|  | 
 |  | +        project = request.json["project"]
 | 
											
												
													
														|  | 
 |  | +        mode = request.json["mode"]
 | 
											
												
													
														|  | 
 |  | +        project_name = request.json["project_name"]
 | 
											
												
													
														|  | 
 |  | +        mode_name = request.json["mode_name"]
 | 
											
												
													
														|  | 
 |  | +        # ------- 微信打包 ------
 | 
											
												
													
														|  | 
 |  | +        # 1.小程序打包
 | 
											
												
													
														|  | 
 |  | +        build_mini_program(branch)
 | 
											
												
													
														|  | 
 |  | +        if res_json["code"] != 0:
 | 
											
												
													
														|  | 
 |  | +            send_status = False
 | 
											
												
													
														|  | 
 |  | +            return res_json
 | 
											
												
													
														|  | 
 |  | +        # 2.修改环境
 | 
											
												
													
														|  | 
 |  | +        edit_mode_by_file(project,mode)
 | 
											
												
													
														|  | 
 |  | +        if res_json["code"] != 0:
 | 
											
												
													
														|  | 
 |  | +            send_status = False
 | 
											
												
													
														|  | 
 |  | +            return res_json
 | 
											
												
													
														|  | 
 |  | +        # 3.微信编译图片
 | 
											
												
													
														|  | 
 |  | +        time.sleep(1)
 | 
											
												
													
														|  | 
 |  | +        create_preview(project,page)
 | 
											
												
													
														|  | 
 |  | +        
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        # -------- 飞书 --------
 | 
											
												
													
														|  | 
 |  | +        # 1.获取签名
 | 
											
												
													
														|  | 
 |  | +        if res_json["code"] != 0:
 | 
											
												
													
														|  | 
 |  | +            send_status = False
 | 
											
												
													
														|  | 
 |  | +            return res_json
 | 
											
												
													
														|  | 
 |  | +        token = tenant_access_token_by_feishu()
 | 
											
												
													
														|  | 
 |  | +        # # 2.获取imgKey
 | 
											
												
													
														|  | 
 |  | +        if res_json["code"] != 0:
 | 
											
												
													
														|  | 
 |  | +            send_status = False
 | 
											
												
													
														|  | 
 |  | +            return res_json
 | 
											
												
													
														|  | 
 |  | +        img_key = upload_img_by_feishu(token)
 | 
											
												
													
														|  | 
 |  | +        # # 3.飞书发送消息
 | 
											
												
													
														|  | 
 |  | +        if res_json["code"] != 0:
 | 
											
												
													
														|  | 
 |  | +            send_status = False
 | 
											
												
													
														|  | 
 |  | +            return res_json
 | 
											
												
													
														|  | 
 |  | +        send_msg_by_feishu(token,img_key,webhook_url,project_name,mode_name)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    # -------- 飞书 --------
 |  | 
 | 
											
												
													
														|  | -    # 1.获取签名
 |  | 
 | 
											
												
													
														|  | -    if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  | -        send_status = False
 |  | 
 | 
											
												
													
														|  | -        return res_json
 |  | 
 | 
											
												
													
														|  | -    token = tenant_access_token_by_feishu()
 |  | 
 | 
											
												
													
														|  | -    # # 2.获取imgKey
 |  | 
 | 
											
												
													
														|  | -    if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  |          send_status = False
 |  |          send_status = False
 | 
											
												
													
														|  | -        return res_json
 |  | 
 | 
											
												
													
														|  | -    img_key = upload_img_by_feishu(token)
 |  | 
 | 
											
												
													
														|  | -    # # 3.飞书发送消息
 |  | 
 | 
											
												
													
														|  | -    if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  | 
 |  | +    except:
 | 
											
												
													
														|  |          send_status = False
 |  |          send_status = False
 | 
											
												
													
														|  | -        return res_json
 |  | 
 | 
											
												
													
														|  | -    send_msg_by_feishu(token,img_key,webhook_url,project_name,mode_name)
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    send_status = False
 |  | 
 | 
											
												
													
														|  |      return res_json
 |  |      return res_json
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 |