我只需单击一下即可开发一个用于部署应用程序Angular / React / Vue的插件。因此,我尝试验证bash脚本调用中是否设置了占位符的值。实际上,我尝试在操作中重定向不同的“ if”。我的插件的不同方案是:
客户端提供的是公共git(所以我只使用url)
客户端提供的是公共git,其中包含构建应用程序结果的特定文件夹(在angular / vue中,通常是/ dist,在反应中,可以是/ build)
默认情况下,如果您不指定文件夹,则我的bash中的默认值为/ dist(因为它是经典文件夹)
客户端提供带有令牌的私人git
客户端为私有git提供令牌和特定的构建文件夹
因此,在本主题中,我向您展示我的manifest.jps和bash脚本以了解我的问题。
我希望您能为我提供帮助:)(对不起,我想提高我的英语水平)
settings:
fields:
- name: gitRepo
caption: Git Repo Url*
type: string
required: true
default: ''
regex: "^https?:\\/\\/.+$"
regexText: Incorrect URL. HTTPS link to Git repository is required.
- name: gitToken
caption: Token
type: string
required: false
default: ''
- name: buildPath
caption: your path for build
type: string
required: false
default: ''
onInstall:
- if ( ${settings.gitToken} && ${settings.buildPath} && ${settings.gitRepo} ): totalScript
- if ( ${settings.gitRepo} && ${settings.gitToken} ): scriptToken
- if ( ${settings.gitRepo} && ${settings.buildPath} ): scriptPath
- if ( ${settings.gitRepo} ): scriptRepo
actions:
totalScript:
cmd [cp]:
- curl -fsS https://raw.githubusercontent.com/user/scripts-sources/master/test-settings.sh | /bin/bash -s ${settings.gitRepo} -t ${settings.gitToken} -p ${settings.buildPath}
scriptToken:
cmd [cp]:
- curl -fsS https://raw.githubusercontent.com/user/scripts-sources/master/test-settings.sh | /bin/bash -s ${settings.gitRepo} -t ${settings.gitToken}
scriptPath:
cmd [cp]:
- curl -fsS https://raw.githubusercontent.com/user/scripts-sources/master/test-settings.sh | /bin/bash -s ${settings.gitRepo} -p ${settings.buildPath}
scriptRepo:
cmd [cp]:
- curl -fsS https://raw.githubusercontent.com/user/scripts-sources/master/test-settings.sh | /bin/bash -s ${settings.gitRepo}
test-settings.sh(此脚本有效,之所以显示它是因为它与清单的链接)
#!/bin/bash
link=$1
# Options
#
while getopts "htp" OPTION
do
case $OPTION in
h)
usage
;;
t) token=$OPTARG
;;
p) pathBuild_form=$OPTARG
;;
esac
done
if [[ -z "$token" ]]
then
if [[ $link == *".git"* ]];
then
repo="https://"$(echo $link | cut -d'/' -f4 )@$(echo $link | cut -d'/' -f3)/$(echo $link | cut -d'/' -f4)/$(echo $link | cut -d'/' -f5)
else
repo="https://"$(echo $link | cut -d'/' -f4 )@$(echo $link | cut -d'/' -f3)/$(echo $link | cut -d'/' -f4)/$(echo $link | cut -d'/' -f5).git
fi
else
if [[ $link == *".git"* ]];
then
repo="https://"$(echo $link | cut -d'/' -f4 ):$token@$(echo $link | cut -d'/' -f3)/$(echo $link | cut -d'/' -f4)/$(echo $link | cut -d'/' -f5)
else
repo="https://"$(echo $link | cut -d'/' -f4 ):$token@$(echo $link | cut -d'/' -f3)/$(echo $link | cut -d'/' -f4)/$(echo $link | cut -d'/' -f5).git
fi
fi
git clone $repo
pathBuild=$(echo $link | cut -d'/' -f5 | cut -f1 -d".")
npm install --prefix ./$pathBuild
npm run build --prefix ./$pathBuild
if [[ ! -z "$pathBuild_form" ]]
then
mv $pathBuild/$pathBuild_form/* /home/jacqueax/MyApp
else
var=$(ls $pathBuild/dist)
if [[ $var == *"index"* ]]; then
mv $pathBuild/dist/* /home/jacqueax/MyApp
else
mv dist/$var/* /home/jacqueax/MyApp
fi
fi
rm -rf $pathBuild
因此,当客户端将公共git放入客户机时,我现在在日志中看到了这一点:
警告:如果(&& && https://github.com/user/js-app-forBuild):条件无效。响应:{“结果”:1704,“行”:3,“响应”:空,“源”:“ hx-core”,“错误”:“ org.mozilla.javascript.EvaluatorException:语法错误”}
--->此行对应于我的第一个“ if”;其他日志相似
我只想验证是否设置了占位符。实际上,使用的是占位符的值,而不是我想要的(因为例如,如果不将令牌放入设置中,则存在令牌var的“ if”为空且“如果”失败。
可以用默认值或空字符串替换占位符。所有列出的IF函数可能看起来像:
if ( '${settings.gitToken:}' && '${settings.buildPath:}' && '${settings.gitRepo:}' ): totalScript
或
if ( settings.gitToken && settings.buildPath && settings.gitRepo ): totalScript