linux shell 自动化部署 npm vue 项目

此 shell 是提供给前端登录服务器自动化部署 vue 项目的

用此命令,工具化部署项目,可以杜绝前端自己部署项目时,对服务器违规操作

如有其它问题,可在下方留言!

#!/bin/sh
# url:https://github.com/jefferyjob/tool

#====================================================================
#=== 项目路径定义 ===================================================
#=== 请在此定义您的项目路径 =========================================
#====================================================================
dir_array=(
"/data/Web/make_client/web_make_client"
"/data/Web/make_client/web_make_client_back"
"/data/Web/WebUPinVue"
)

#===================================================================
#=== 是否开启确认 ==================================================
#=== true: 开启、false: 关闭  ======================================
#===================================================================
verify=true


#====================================================================
#=== 命令执行参数 ===================================================
#====================================================================
clear
#echo "+------------------------------------------------------+:
#echo "|          Npm project automation deployment           |"
#echo "+------------------------------------------------------+"

echo -e "\033[33m请选择要执行的vue项目\033[0m"
for i in ${!dir_array[@]}
do
	echo -e "\033[33m$i: ${dir_array[$i]} \033[0m"
done

# 提示输入
read -p "请输入项目序号: " num

if [ ! -n "$num" ];then
	echo -e "\033[31mError: 未选择项目序号\033[0m"
  	exit
elif echo $num | grep -q '[^0-9]';then
	echo -e "\033[31mError: 请输入数字格式\033[0m"
	exit
elif [[ $num -lt 0 ]]||[[ $num -gt ${#dir_array[@]} ]];then
	echo -e "\033[31mError: 错误的项目序号\033[0m"
	exit
elif [ ! -x "${dir_array[$num]}" ]; then
        echo -e "\033[31mError: 该项目目录不存在或没有可执行权限\033[0m"
        exit
fi

# 项目路径输出
echo -e "\033[36mvue path: ${dir_array[$num]}\033[0m"

echo -e '\n'

# npm 命令定义
command_array=("cnpm install" "cnpm run build" "cnpm install && cnpm run build" "npm install" "npm run build" "npm install && npm run build")

echo -e "\033[33m请选择要执行的npm命令\033[0m"
for i in ${!command_array[@]}
do
        echo -e "\033[33m$i: ${command_array[$i]} \033[0m"
done


# 提示输入
read -p "请输入命令序号: " number

if [ ! -n "$number" ];then
        echo -e "\033[31mError: 未选择命令序号\033[0m"
        exit
elif echo $number | grep -q '[^0-9]';then
        echo -e "\033[31mError: 请输入数字格式\033[0m"
        exit
elif [[ $number -lt 0 ]]||[[ $number -gt ${#command_array[@]} ]];then
        echo -e "\033[31mError: 错误的命令序号\033[0m"
        exit
fi

# 项目路径输出
echo -e "\033[36mvue command: ${command_array[$number]}\033[0m"

echo -e '\n'

# 输出执行命令
echo -e "\033[44;37mcommand: ${dir_array[$num]} && ${command_array[$number]}\033[0m"

# 提示输入
if  [[ $verify == true ]] ; then
	
	read -p "您是否要执行此命令(y/n): " command
	if [ "$command" != "y" ]&&[ "$command" != "n" ];then
	        echo -e "\033[31mError: 输入错误\033[0m"
	        exit
	elif [[ $command == 'n' ]];then
	        echo -e "\033[31m程序已终止... ...end\033[0m"
	        exit
	fi

fi

# 命令执行
# 命令执行
command=${command_array[$number]}
OLD_IFS="$IFS"
IFS="&&"
command_arr=($command)
IFS="$OLD_IFS"
for i in ${!command_arr[@]}
do
        cd ${dir_array[$num]} &&  ${command_arr[$i]}
done

GitHub Url:https://github.com/jefferyjob/tool

Blog:https://blog.cvrrr.com/article/14

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汀风说后端

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值