代码拉取完成,页面将自动刷新
同步操作将从 dromara/mayfly-go 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#bin/bash
#----------------------------------------------
# 前后端打包编译至指定目录,即快速制作发行版
#----------------------------------------------
project_path=`pwd`
# 构建后的二进制执行文件名
exec_file_name="mayfly-go"
# web项目目录
web_folder="${project_path}/mayfly_go_web"
# server目录
server_folder="${project_path}/server"
function echo_red() {
echo -e "\033[1;31m$1\033[0m"
}
function echo_green() {
echo -e "\033[1;32m$1\033[0m"
}
function echo_yellow() {
echo -e "\033[1;33m$1\033[0m"
}
function buildWeb() {
cd ${web_folder}
copy2Server=$1
echo_yellow "-------------------打包前端开始-------------------"
yarn run build
if [ "${copy2Server}" == "1" ] ; then
echo_green '将打包后的静态文件拷贝至server/static'
rm -rf ${server_folder}/static && mkdir -p ${server_folder}/static && cp -r ${web_folder}/dist/* ${server_folder}/static
fi
echo_yellow ">>>>>>>>>>>>>>>>>>>打包前端结束<<<<<<<<<<<<<<<<<<<<\n"
}
function build() {
cd ${project_path}
# 打包产物的输出目录
toFolder=$1
os=$2
arch=$3
echo_yellow "-------------------${os}-${arch}打包构建开始-------------------"
cd ${server_folder}
echo_green "打包构建可执行文件..."
execFileName=${exec_file_name}
# 如果是windows系统,可执行文件需要添加.exe结尾
if [ "${os}" == "windows" ];then
execFileName="${execFileName}.exe"
fi
CGO_ENABLE=0 GOOS=${os} GOARCH=${arch} go build -o ${execFileName} main.go
if [ -d ${toFolder} ] ; then
echo_green "目标文件夹已存在,清空文件夹"
sudo rm -rf ${toFolder}
fi
echo_green "创建'${toFolder}'目录"
mkdir ${toFolder}
echo_green "移动二进制文件至'${toFolder}'"
mv ${server_folder}/${execFileName} ${toFolder}
echo_green "拷贝前端静态页面至'${toFolder}/static'"
mkdir -p ${toFolder}/static && cp -r ${web_folder}/dist/* ${toFolder}/static
echo_green "拷贝脚本等资源文件[config.yml、mayfly-go.sql、readme.txt、startup.sh、shutdown.sh]"
cp ${server_folder}/config.yml ${toFolder}
cp ${server_folder}/mayfly-go.sql ${toFolder}
cp ${server_folder}/readme.txt ${toFolder}
cp ${server_folder}/startup.sh ${toFolder}
cp ${server_folder}/shutdown.sh ${toFolder}
echo_yellow ">>>>>>>>>>>>>>>>>>>${os}-${arch}打包构建完成<<<<<<<<<<<<<<<<<<<<\n"
}
function buildLinuxAmd64() {
build "$1/mayfly-go-linux-amd64" "linux" "amd64"
}
function buildLinuxArm64() {
build "$1/mayfly-go-linux-arm64" "linux" "arm64"
}
function buildWindows() {
build "$1/mayfly-go-windows" "windows" "amd64"
}
function runBuild() {
# 构建结果的目的路径
read -p "请输入构建产物输出目录: " toPath
if [ ! -d ${toPath} ] ; then
echo_red "构建产物输出目录不存在!"
exit;
fi
# 进入目标路径,并赋值全路径
cd ${toPath}
toPath=`pwd`
read -p "是否构建前端[0|其他->否 1->是 2->构建并拷贝至server/static]: " runBuildWeb
read -p "请选择构建版本[0|其他->全部 1->linux-amd64 2->linux-arm64 3->windows]: " buildType
if [ "${runBuildWeb}" == "1" ];then
buildWeb
fi
if [ "${runBuildWeb}" == "2" ];then
buildWeb 1
fi
if [ "${buildType}" == "1" ];then
buildLinuxAmd64 ${toPath}
exit;
fi
if [ "${buildType}" == "2" ];then
buildLinuxArm64 ${toPath}
exit;
fi
if [ "${buildType}" == "3" ];then
buildWindows ${toPath}
exit;
fi
buildLinuxAmd64 ${toPath}
buildLinuxArm64 ${toPath}
buildWindows ${toPath}
}
runBuild
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。