|
@@ -1,4 +1,5 @@
|
|
|
import os
|
|
|
+import flask
|
|
|
import requests
|
|
|
import json
|
|
|
|
|
@@ -10,150 +11,210 @@ CORS(app, resources=r'/*')
|
|
|
|
|
|
# current_path
|
|
|
current_path = os.getcwd()
|
|
|
+res_json = {"code":0,"msg":"成功"}
|
|
|
+send_status = {'a':False}
|
|
|
|
|
|
# 1.小程序打包
|
|
|
-# def build_mini_program():
|
|
|
-# command_str = (
|
|
|
-# "git clone https://git.yishihui.com/weapp/longVideoFactory.git;"
|
|
|
-# "cd longVideoFactory;"
|
|
|
-# "git pull;"
|
|
|
-# "git checkout dev;"
|
|
|
-# "git pull;"
|
|
|
-# "n 8;"
|
|
|
-# "cnpm install && npm install ;"
|
|
|
-# "npm run build && npm run build:other;"
|
|
|
-# )
|
|
|
+def build_mini_program(branch):
|
|
|
+ res = False
|
|
|
+ command_str = (
|
|
|
+ "cd "+current_path+ ";"
|
|
|
+ "git clone https://git.yishihui.com/weapp/longVideoFactory.git;"
|
|
|
+ "cd longVideoFactory;"
|
|
|
+ "rm -rf dist;"
|
|
|
+ "git pull;"
|
|
|
+ "git checkout "+branch+";"
|
|
|
+ "git pull;"
|
|
|
+ "n 8;"
|
|
|
+ "cnpm install && npm install ;"
|
|
|
+ "npm run build && npm run build:other;"
|
|
|
+ )
|
|
|
|
|
|
-# if os.system(command_str) == 0:
|
|
|
-# print("1.打包成功")
|
|
|
-# # create_preview()
|
|
|
-# else:
|
|
|
-# print("1.打包失败")
|
|
|
+ if os.system(command_str) == 0:
|
|
|
+ res_json["code"] = 0
|
|
|
+ res_json["msg"] = "打包成功"
|
|
|
+
|
|
|
+ else:
|
|
|
+ res_json["code"] = 1
|
|
|
+ res_json["msg"] = "打包失败"
|
|
|
+
|
|
|
|
|
|
-# # 2.微信编译图片
|
|
|
-# def create_preview():
|
|
|
-# # 小程序 cli path for mac
|
|
|
-# wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
|
+# # 3.微信编译图片
|
|
|
+def create_preview(project,page):
|
|
|
+ # 小程序 cli path for mac
|
|
|
+ wx_cli ="/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
|
|
|
|
-# dist_path = os.path.join(current_path,'longVideoFactory/dist/vlog')
|
|
|
-# code_img_path = os.path.join(current_path,'1.png')
|
|
|
-# f_read = os.popen(wx_cli+" preview --project "+dist_path+" --qr-output "+code_img_path+" --qr-format image").read()
|
|
|
-# if "[error]" in f_read:
|
|
|
-# print(f_read)
|
|
|
-# else:
|
|
|
-# print("2.微信小程序编译成功")
|
|
|
-
|
|
|
-# # create_preview()
|
|
|
-
|
|
|
-# # https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc
|
|
|
-
|
|
|
-# def upload_img_by_feishu(token):
|
|
|
-# key = ""
|
|
|
-# url = "https://open.feishu.cn/open-apis/im/v1/images"
|
|
|
-# files = {
|
|
|
-# "image_type":(None,"message"),
|
|
|
-# "image":('1.png',open(os.path.join(current_path,"1.png"),"rb"),"image/png")
|
|
|
-# }
|
|
|
-# headers = {
|
|
|
-# "Authorization":"Bearer "+token,
|
|
|
-# }
|
|
|
-# res = requests.post(url,headers=headers,files=files,verify = False).json()
|
|
|
-# if res["code"] == 0:
|
|
|
-# key = res["data"]["image_key"]
|
|
|
-# else:
|
|
|
-# print("飞书上传图片失败")
|
|
|
-
|
|
|
-# return key
|
|
|
-
|
|
|
-# def tenant_access_token_by_feishu():
|
|
|
-# token = ""
|
|
|
-# url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
|
|
|
-# params = {
|
|
|
-# "app_id":"cli_a1ec07458838d00c",
|
|
|
-# "app_secret":"Ngm0kfaLkZnpM2T2DH7L8cM5hdAqY0hI"
|
|
|
-# }
|
|
|
-# res = requests.post(url,data=params,verify = False).json()
|
|
|
-# if res["code"] == 0:
|
|
|
-# token = res["tenant_access_token"]
|
|
|
-# else:
|
|
|
-# print("获取飞书签名失败")
|
|
|
-
|
|
|
-# return token
|
|
|
-
|
|
|
-# def send_msg_by_feishu(token,img_key):
|
|
|
-# # webhook
|
|
|
-# webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc"
|
|
|
-# headers = {
|
|
|
-# "Authorization":"Bearer "+token,
|
|
|
-# "Content-Type": "application/json;charset=UTF-8"
|
|
|
-# }
|
|
|
-# params = {
|
|
|
-# "msg_type": "post",
|
|
|
-# "content": {
|
|
|
-# "post": {
|
|
|
-# "zh_cn": {
|
|
|
-# "title": "Vlog小程序预览码",
|
|
|
-# "content": [
|
|
|
-# [
|
|
|
-# {
|
|
|
-# "tag": "img",
|
|
|
-# "image_key": "img_v2_223c3413-488a-4af6-bd36-6563a9ef185g",
|
|
|
-# "width": 500,
|
|
|
-# "height": 500
|
|
|
-# }
|
|
|
-# ]]
|
|
|
-# }
|
|
|
-# }
|
|
|
-# }
|
|
|
-# }
|
|
|
+ dist_path = os.path.join(current_path,'longVideoFactory/dist/'+project)
|
|
|
+ code_img_path = os.path.join(current_path,'1.png')
|
|
|
|
|
|
-# res = requests.post(webhook_url,headers=headers,data=json.dumps(params),verify = False).json()
|
|
|
-# if res["StatusCode"] == 0:
|
|
|
-# print("飞书消息发送成功")
|
|
|
-# else:
|
|
|
-# print("飞书消息发送失败")
|
|
|
-
|
|
|
-
|
|
|
+ path = """ '{"pathName":"%s"}' """ % page
|
|
|
+ os.system(wx_cli+ "open --project " + dist_path)
|
|
|
+ os.system(wx_cli+ "reset-fileutils --project " + dist_path)
|
|
|
+ f_read = os.popen(wx_cli+" preview --project "+dist_path+" --compile-condition "+path+" --qr-output "+code_img_path+" --qr-format image").read()
|
|
|
+ if "[error]" in f_read:
|
|
|
+ res_json["code"] = 3
|
|
|
+ res_json["msg"] = f_read
|
|
|
+ else:
|
|
|
+ res_json["code"] = 0
|
|
|
+ res_json["msg"] = "微信小程序编译成功"
|
|
|
|
|
|
-# # ------- 微信打包 ------
|
|
|
-# # 1.小程序打包
|
|
|
-# # build_mini_program()
|
|
|
-# # 2.微信编译图片
|
|
|
-# # create_preview()
|
|
|
+# 修改环境文件
|
|
|
+def edit_mode_by_file(project,mode):
|
|
|
+ path = os.path.join(current_path,"longVideoFactory/dist/"+project+"/network/volatileConfig.js")
|
|
|
+ file_lines = []
|
|
|
+ with open(path,"r") as f:
|
|
|
+ for item in f.readlines():
|
|
|
+ if "export const currentMode" in item:
|
|
|
+ item = "export const currentMode = MODE."+mode+" \n"
|
|
|
|
|
|
-# # 3.切换小程序环境
|
|
|
+ file_lines.append(item)
|
|
|
+ f.close()
|
|
|
+
|
|
|
+ with open(path,"w") as f2:
|
|
|
+ f2.writelines(file_lines)
|
|
|
+ f2.close()
|
|
|
+ res_json["code"] = 0
|
|
|
+ res_json["msg"] = "文件修改成功"
|
|
|
+
|
|
|
|
|
|
+def upload_img_by_feishu(token):
|
|
|
+ key = ""
|
|
|
+ url = "https://open.feishu.cn/open-apis/im/v1/images"
|
|
|
+ files = {
|
|
|
+ "image_type":(None,"message"),
|
|
|
+ "image":('1.png',open(os.path.join(current_path,"1.png"),"rb"),"image/png")
|
|
|
+ }
|
|
|
+ headers = {
|
|
|
+ "Authorization":"Bearer "+token,
|
|
|
+ }
|
|
|
+ res = requests.post(url,headers=headers,files=files).json()
|
|
|
+ if res["code"] == 0:
|
|
|
+ key = res["data"]["image_key"]
|
|
|
+ res_json["code"] = 0
|
|
|
+ else:
|
|
|
+ res_json["code"] = 4
|
|
|
+ res_json["msg"] = "飞书上传图片失败"
|
|
|
+
|
|
|
+ return key
|
|
|
+
|
|
|
+def tenant_access_token_by_feishu():
|
|
|
+ token = ""
|
|
|
+ url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
|
|
|
+ params = {
|
|
|
+ "app_id":"cli_a1ec07458838d00c",
|
|
|
+ "app_secret":"Ngm0kfaLkZnpM2T2DH7L8cM5hdAqY0hI"
|
|
|
+ }
|
|
|
+ res = requests.post(url,data=params).json()
|
|
|
+ if res["code"] == 0:
|
|
|
+ token = res["tenant_access_token"]
|
|
|
+ res_json["msg"] = "获取飞书签名成功"
|
|
|
+ res_json["code"] = 0
|
|
|
+ else:
|
|
|
+ res_json["code"] = 4
|
|
|
+ res_json["msg"] = "获取飞书签名失败"
|
|
|
+
|
|
|
+ return token
|
|
|
+
|
|
|
+def send_msg_by_feishu(token,img_key,url,project_name,mode_name):
|
|
|
+ # webhook
|
|
|
+ # webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/a924b6a5-86ef-4c76-a7e4-eb42056f70cc"
|
|
|
+ webhook_url = url
|
|
|
+ headers = {
|
|
|
+ "Authorization":"Bearer "+token,
|
|
|
+ "Content-Type": "application/json;charset=UTF-8"
|
|
|
+ }
|
|
|
+ params = {
|
|
|
+ "msg_type": "post",
|
|
|
+ "content": {
|
|
|
+ "post": {
|
|
|
+ "zh_cn": {
|
|
|
+ "title": mode_name+':'+project_name+"小程序预览码",
|
|
|
+ "content": [
|
|
|
+ [
|
|
|
+ {
|
|
|
+ "tag": "img",
|
|
|
+ "image_key": img_key,
|
|
|
+ "width": 500,
|
|
|
+ "height": 500
|
|
|
+ }
|
|
|
+ ]]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ res = requests.post(webhook_url,headers=headers,data=json.dumps(params)).json()
|
|
|
+ if res["StatusCode"] == 0:
|
|
|
+ res_json["code"] = 0
|
|
|
+ res_json["msg"] = "飞书消息发送成功"
|
|
|
+ else:
|
|
|
+ res_json["code"] = 5
|
|
|
+ res_json["msg"] = "飞书消息发送失败"
|
|
|
|
|
|
-# # -------- 飞书 --------
|
|
|
-# # 1.获取签名
|
|
|
-# # token = tenant_access_token_by_feishu()
|
|
|
-# # 2.获取imgKey
|
|
|
-# # img_key = upload_img_by_feishu(token)
|
|
|
-# # 3.飞书发送消息
|
|
|
-# # send_msg_by_feishu(token,img_key)
|
|
|
|
|
|
@app.route('/')
|
|
|
-def func():
|
|
|
-
|
|
|
+def func():
|
|
|
return 'Welcome to auto-mini-program-build-preview server. only can run on MacOS.'
|
|
|
|
|
|
-# @app.route('/send',methods=['POST'])
|
|
|
-# def send():
|
|
|
-# form_webhook_url = request.form["webrhook_url"]
|
|
|
-# form_branch = request.form["branch"]
|
|
|
-# form_name = request.form["name"]
|
|
|
-
|
|
|
-# res = {"code":0,"msg":'发送成功'}
|
|
|
-
|
|
|
-# res = {"code":1,"msg":''}
|
|
|
+@app.route('/send',methods=['POST'])
|
|
|
+def send():
|
|
|
+ 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)
|
|
|
|
|
|
-# return request.form
|
|
|
+
|
|
|
+ # -------- 飞书 --------
|
|
|
+ # 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)
|
|
|
+
|
|
|
+ send_status = False
|
|
|
+ return res_json
|
|
|
|
|
|
|
|
|
@app.route("/getBranch")
|
|
|
def get_branch():
|
|
|
# 查看所有分支
|
|
|
command_str= (
|
|
|
+ "cd "+current_path+ ";"
|
|
|
+ "git clone https://git.yishihui.com/weapp/longVideoFactory.git;"
|
|
|
"cd longVideoFactory;"
|
|
|
"git branch -a;"
|
|
|
)
|
|
@@ -168,26 +229,4 @@ def get_branch():
|
|
|
return res
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- app.run(host='0.0.0.0', port=7777, debug=False)
|
|
|
-
|
|
|
-
|
|
|
-# 修改环境文件
|
|
|
-def edit_mode_by_file(project,mode):
|
|
|
- path = os.path.join(current_path,"longVideoFactory/dist/"+project+"/network/volatileConfig.js")
|
|
|
- file_lines = []
|
|
|
- with open(path,"r") as f:
|
|
|
- for item in f.readlines():
|
|
|
- if "export const currentMode" in item:
|
|
|
- item = "export const currentMode = MODE."+mode+" \n"
|
|
|
-
|
|
|
- file_lines.append(item)
|
|
|
- f.close()
|
|
|
-
|
|
|
- with open(path,"w") as f2:
|
|
|
- f2.writelines(file_lines)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- f2.close()
|
|
|
-
|
|
|
-# edit_mode_by_file("vlog")
|
|
|
+ app.run(host='0.0.0.0', port=7777, debug=False)
|