Open yogkin opened 1 year ago
部分功能不支持,未来会支持
windows服务器支持(其他系统大家自己微调脚本也可以支持):
配置快捷键
在项目目录,鼠标右键,即可找到External Tools命令
#!/bin/sh
echo "-------------------------- 开始远程编译 ----------------------------"
set -e
syncDir=$(cd $(dirname $0); pwd)
projectDir=$(cd $(dirname $0);cd ..; pwd)
echo "syncDir: $syncDir"
echo "projectDir: $projectDir"
configJsonPath=$syncDir/service/config.json
echo "configJsonPath: $configJsonPath"
# 通过config.json获取应用build参数,从而按照指定应用
echo "----- sync config start ----"
cat $configJsonPath
echo "----- sync config end----"
remoteUser=$(cat $configJsonPath | jq '.remoteUser' | sed 's/\"//g')
remoteHost=$(cat $configJsonPath | jq '.remoteHost' | sed 's/\"//g')
remoteUserPassword=$(cat $configJsonPath | jq '.remoteUserPassword' | sed 's/\"//g')
remoteRootDir=$(cat $configJsonPath | jq '.remoteRootDir' | sed 's/\"//g')
sdkDir=$(cat $configJsonPath | jq '.sdkDir' | sed 's/\"//g' | sed 's/\\\\/\\/g')
buildCommand=$(cat $configJsonPath | jq '.remoteBuildCommand' | sed 's/\"//g')
launchActivity=$(cat $configJsonPath | jq '.launchActivity' | sed 's/\"//g')
remoteUserHost=${remoteUser}@${remoteHost}
echo "remoteRootDir start: $remoteRootDir"
remoteRootDir=$(echo $remoteRootDir | sed 's/~//g' | sed 's/\///g')
echo "remoteRootDir end: $remoteRootDir"
echo "sdkDir: $sdkDir"
echo "remoteUserHost: $remoteUserHost"
echo "buildCommand: $buildCommand"
echo "launchActivity: $launchActivity"
projectName=""
function project_name() {
if [[ $projectDir =~ '/' ]]; then
array=(`echo $projectDir | tr '/' ' '` )
len=${#array[@]}
for var in ${array[@]}
do
projectName=$var
done
else
echo "无'/'参数"
fi
}
project_name
echo "projectName: $projectName"
remoteProjectPath=''${remoteRootDir}'\'${projectName}''
echo "remoteProjectPath: $remoteProjectPath"
remoteProjectDir=${remoteUserHost}:${remoteProjectPath}
remote_include=$projectDir/.sync/remote_include
remote_ignore=$projectDir/.sync/remote_ignore
local_ignore=$projectDir/.sync/local_ignore
echo "remoteProjectDir: $remoteProjectDir"
if [ $# -lt 1 ]; then
echo "没有命令行参数"
else
echo "params: $1"
case $1 in
(clean)
echo "--- $1 ---"
sshpass -p $remoteUserPassword ssh -p 22 -o StrictHostKeyChecking=no $remoteUserHost 'cd '$remoteProjectPath' && gradlew clean'
exit
;;
(sync)
echo "--- $1 ---"
sshpass -p $remoteUserPassword rsync -e 'ssh -p 22 -o StrictHostKeyChecking=no' --archive --delete --progress --exclude-from=$local_ignore $projectDir/ $remoteProjectDir
exit
;;
(install)
echo "--- $1 ---"
chmod 777 $projectDir/.sync/script/install-apk.sh && bash $projectDir/.sync/script/install-apk.sh $launchActivity
exit
;;
esac
fi
echo "1.创建工程目录"
sshpass -p $remoteUserPassword ssh $remoteUserHost 'if not exist '$remoteProjectPath' (mkdir -p '$remoteProjectPath') else (echo '${projectName} created')'
echo "2.远程工程写入local.properties文件"
sshpass -p $remoteUserPassword ssh $remoteUserHost 'cd '$remoteProjectPath' && (echo sdk.dir='$sdkDir') > local.properties && type local.properties && CACLS local.properties /e /p '$remoteUser':F'
echo "3.同步本地文件到远程"
sshpass -p $remoteUserPassword rsync -e 'ssh -p 22 -o StrictHostKeyChecking=no' --archive --delete --progress --exclude-from=$local_ignore $projectDir/ $remoteProjectDir
echo "4.远程编译"
sshpass -p $remoteUserPassword ssh -p 22 -o StrictHostKeyChecking=no $remoteUserHost 'cd '$remoteProjectPath' && gradlew '$buildCommand''
echo "5.同步远程apk文件到本地"
sshpass -p $remoteUserPassword rsync -e 'ssh -p 22 -o StrictHostKeyChecking=no' --archive --progress --include-from=$remote_include --exclude-from=$remote_ignore $remoteProjectDir/ $projectDir
echo "6.安装apk文件"
chmod 777 $projectDir/.sync/script/install-apk.sh && bash $projectDir/.sync/script/install-apk.sh $launchActivity
windows服务器支持(其他系统大家自己微调脚本也可以支持):
- 新建remote_windows_build.sh 文件,将下面的脚本内容复制进去,最后将此文件拷贝到项目的.sync目录下
- 若无执行权限执行 chmod 777 remote_windows_build.sh
- 通过External Tools配置命令
- 配置快捷键
- 在项目目录,鼠标右键,即可找到External Tools命令
#!/bin/sh echo "-------------------------- 开始远程编译 ----------------------------" set -e syncDir=$(cd $(dirname $0); pwd) projectDir=$(cd $(dirname $0);cd ..; pwd) echo "syncDir: $syncDir" echo "projectDir: $projectDir" configJsonPath=$syncDir/service/config.json echo "configJsonPath: $configJsonPath" # 通过config.json获取应用build参数,从而按照指定应用 echo "----- sync config start ----" cat $configJsonPath echo "----- sync config end----" remoteUser=$(cat $configJsonPath | jq '.remoteUser' | sed 's/\"//g') remoteHost=$(cat $configJsonPath | jq '.remoteHost' | sed 's/\"//g') remoteUserPassword=$(cat $configJsonPath | jq '.remoteUserPassword' | sed 's/\"//g') remoteRootDir=$(cat $configJsonPath | jq '.remoteRootDir' | sed 's/\"//g') sdkDir=$(cat $configJsonPath | jq '.sdkDir' | sed 's/\"//g' | sed 's/\\\\/\\/g') buildCommand=$(cat $configJsonPath | jq '.remoteBuildCommand' | sed 's/\"//g') launchActivity=$(cat $configJsonPath | jq '.launchActivity' | sed 's/\"//g') remoteUserHost=${remoteUser}@${remoteHost} echo "remoteRootDir start: $remoteRootDir" remoteRootDir=$(echo $remoteRootDir | sed 's/~//g' | sed 's/\///g') echo "remoteRootDir end: $remoteRootDir" echo "sdkDir: $sdkDir" echo "remoteUserHost: $remoteUserHost" echo "buildCommand: $buildCommand" echo "launchActivity: $launchActivity" projectName="" function project_name() { if [[ $projectDir =~ '/' ]]; then array=(`echo $projectDir | tr '/' ' '` ) len=${#array[@]} for var in ${array[@]} do projectName=$var done else echo "无'/'参数" fi } project_name echo "projectName: $projectName" remoteProjectPath=''${remoteRootDir}'\'${projectName}'' echo "remoteProjectPath: $remoteProjectPath" remoteProjectDir=${remoteUserHost}:${remoteProjectPath} remote_include=$projectDir/.sync/remote_include remote_ignore=$projectDir/.sync/remote_ignore local_ignore=$projectDir/.sync/local_ignore echo "remoteProjectDir: $remoteProjectDir" if [ $# -lt 1 ]; then echo "没有命令行参数" else echo "params: $1" case $1 in (clean) echo "--- $1 ---" sshpass -p $remoteUserPassword ssh -p 22 -o StrictHostKeyChecking=no $remoteUserHost 'cd '$remoteProjectPath' && gradlew clean' exit ;; (sync) echo "--- $1 ---" sshpass -p $remoteUserPassword rsync -e 'ssh -p 22 -o StrictHostKeyChecking=no' --archive --delete --progress --exclude-from=$local_ignore $projectDir/ $remoteProjectDir exit ;; (install) echo "--- $1 ---" chmod 777 $projectDir/.sync/script/install-apk.sh && bash $projectDir/.sync/script/install-apk.sh $launchActivity exit ;; esac fi echo "1.创建工程目录" sshpass -p $remoteUserPassword ssh $remoteUserHost 'if not exist '$remoteProjectPath' (mkdir -p '$remoteProjectPath') else (echo '${projectName} created')' echo "2.远程工程写入local.properties文件" sshpass -p $remoteUserPassword ssh $remoteUserHost 'cd '$remoteProjectPath' && (echo sdk.dir='$sdkDir') > local.properties && type local.properties && CACLS local.properties /e /p '$remoteUser':F' echo "3.同步本地文件到远程" sshpass -p $remoteUserPassword rsync -e 'ssh -p 22 -o StrictHostKeyChecking=no' --archive --delete --progress --exclude-from=$local_ignore $projectDir/ $remoteProjectDir echo "4.远程编译" sshpass -p $remoteUserPassword ssh -p 22 -o StrictHostKeyChecking=no $remoteUserHost 'cd '$remoteProjectPath' && gradlew '$buildCommand'' echo "5.同步远程apk文件到本地" sshpass -p $remoteUserPassword rsync -e 'ssh -p 22 -o StrictHostKeyChecking=no' --archive --progress --include-from=$remote_include --exclude-from=$remote_ignore $remoteProjectDir/ $projectDir echo "6.安装apk文件" chmod 777 $projectDir/.sync/script/install-apk.sh && bash $projectDir/.sync/script/install-apk.sh $launchActivity
\bin\bash"这样子还是会提示找不到文件 现在已经支持WIN了吗
rt