From 49c3353765bda0c4a469f0934845f4a0c7f8d2bc Mon Sep 17 00:00:00 2001 From: John Woo Date: Tue, 2 Jun 2020 17:05:20 -0700 Subject: [PATCH 1/5] fix(tools): require min version or use @latest --- AmplifyTools/amplify-tools.sh | 38 +++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/AmplifyTools/amplify-tools.sh b/AmplifyTools/amplify-tools.sh index 67305c987b..4c4ffba6ce 100755 --- a/AmplifyTools/amplify-tools.sh +++ b/AmplifyTools/amplify-tools.sh @@ -8,11 +8,45 @@ set -e export PATH=$PATH:$(npm bin -g) +MIN_SUPPORTED_VERSION_MAJOR=2 +MIN_SUPPORTED_VERSION_MINOR=17 +MIN_SUPPORTED_VERSION_PATCH=1 + +CURR_VERSION=`npx -q amplify-app --version` +CURR_VERSION_MAJOR=`echo ${CURR_VERSION} | tr '.' ' ' | awk '{print $1}'` +CURR_VERSION_MINOR=`echo ${CURR_VERSION} | tr '.' ' ' | awk '{print $2}'` +CURR_VERSION_PATCH=`echo ${CURR_VERSION} | tr '.' ' ' | awk '{print $3}'` +LOCAL_AMPAPP_VERSION_INVALID=0 + +checkVersionAmplifyApp() { + if [ ${CURR_VERSION_MAJOR} -lt ${MIN_SUPPORTED_VERSION_MAJOR} ]; then + LOCAL_AMPAPP_VERSION_INVALID=1 + return + else + if [ ${CURR_VERSION_MINOR} -lt ${MIN_SUPPORTED_VERSION_MINOR} ]; then + LOCAL_AMPAPP_VERSION_INVALID=1 + return + else + if [ ${CURR_VERSION_PATCH} -lt ${MIN_SUPPORTED_VERSION_PATCH} ]; then + LOCAL_AMPAPP_VERSION_INVALID=1 + return + fi + fi + fi +} +checkVersionAmplifyApp + +if [ ${LOCAL_AMPAPP_VERSION_INVALID} -eq 1 ]; then + NPX_AMP_APPCMD="npx amplify-app@latest" +else + NPX_AMP_APPCMD="npx amplify-app" +fi + if ! which node >/dev/null; then echo "warning: Node is not installed. Visit https://nodejs.org/en/download/ to install it" exit 1 elif ! test -f ./amplifytools.xcconfig; then - npx amplify-app --platform ios + ${NPX_AMP_APPCMD} --platform ios fi . amplifytools.xcconfig @@ -28,7 +62,7 @@ if $amplifyModelgen; then echo "modelgen is set to true, generating Swift models from schema.graphql..." amplify codegen model # calls amplify-app again so the Xcode project is updated with the generated models - npx amplify-app --platform ios + ${NPX_AMP_APPCMD} --platform ios fi if [ -z "$amplifyAccessKey" ] || [ -z "$amplifySecretKey" ] || [ -z "$amplifyRegion" ]; then From dd81325209e47a8b036311f8c935cb65dd583c76 Mon Sep 17 00:00:00 2001 From: John Woo Date: Tue, 2 Jun 2020 21:45:42 -0700 Subject: [PATCH 2/5] Refactoring to make generic for upcoming cli checks --- AmplifyTools/amplify-tools.sh | 71 ++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/AmplifyTools/amplify-tools.sh b/AmplifyTools/amplify-tools.sh index 4c4ffba6ce..d18b157034 100755 --- a/AmplifyTools/amplify-tools.sh +++ b/AmplifyTools/amplify-tools.sh @@ -6,46 +6,75 @@ # SPDX-License-Identifier: Apache-2.0 set -e + +if ! which node >/dev/null; then + echo "warning: Node is not installed. Visit https://nodejs.org/en/download/ to install it" + exit 1 +fi + export PATH=$PATH:$(npm bin -g) -MIN_SUPPORTED_VERSION_MAJOR=2 -MIN_SUPPORTED_VERSION_MINOR=17 -MIN_SUPPORTED_VERSION_PATCH=1 +AMP_APP_VERSION_MINIMUM="2.17.1" +AMP_APP_VERSION_CURRENT=`npx -q amplify-app --version` +AMP_APP_VERSION_INVALID=0 + +#TODO: This is vending unicode, need to strip these characters our safely +# and fix whatever is outputting these characters +#AMP_CLI_VERSION_MINIMUM="4.21.0" +#AMP_CLI_VERSION_CURRENT=`npx -q amplify --version |grep "\."` +#AMP_CLI_VERSION_INVALID=0 -CURR_VERSION=`npx -q amplify-app --version` -CURR_VERSION_MAJOR=`echo ${CURR_VERSION} | tr '.' ' ' | awk '{print $1}'` -CURR_VERSION_MINOR=`echo ${CURR_VERSION} | tr '.' ' ' | awk '{print $2}'` -CURR_VERSION_PATCH=`echo ${CURR_VERSION} | tr '.' ' ' | awk '{print $3}'` -LOCAL_AMPAPP_VERSION_INVALID=0 +VERSION_INVALID= +checkMinVersionCompatibility() { + VERSION_INVALID=0 + CURR_VERSION_MAJOR=`echo "${1}" | tr '.' ' ' | awk '{print $1}'` + CURR_VERSION_MINOR=`echo "${1}" | tr '.' ' ' | awk '{print $2}'` + CURR_VERSION_PATCH=`echo "${1}" | tr '.' ' ' | awk '{print $3}'` -checkVersionAmplifyApp() { - if [ ${CURR_VERSION_MAJOR} -lt ${MIN_SUPPORTED_VERSION_MAJOR} ]; then - LOCAL_AMPAPP_VERSION_INVALID=1 + REQU_VERSION_MAJOR=`echo "${2}" | tr '.' ' ' | awk '{print $1}'` + REQU_VERSION_MINOR=`echo "${2}" | tr '.' ' ' | awk '{print $2}'` + REQU_VERSION_PATCH=`echo "${2}" | tr '.' ' ' | awk '{print $3}'` + + if [ -z "${CURR_VERSION_MAJOR}" ] || + [ -z "${CURR_VERSION_MINOR}" ] || + [ -z "${CURR_VERSION_PATCH}" ] || + [ -z "${REQU_VERSION_MAJOR}" ] || + [ -z "${REQU_VERSION_MINOR}" ] || + [ -z "${REQU_VERSION_PATCH}" ]; then + VERSION_INVALID=1 + return + fi + + if [ ${CURR_VERSION_MAJOR} -lt ${REQU_VERSION_MAJOR} ]; then + VERSION_INVALID=1 return else - if [ ${CURR_VERSION_MINOR} -lt ${MIN_SUPPORTED_VERSION_MINOR} ]; then - LOCAL_AMPAPP_VERSION_INVALID=1 + if [ ${CURR_VERSION_MINOR} -lt ${REQU_VERSION_MINOR} ]; then + VERSION_INVALID=1 return else - if [ ${CURR_VERSION_PATCH} -lt ${MIN_SUPPORTED_VERSION_PATCH} ]; then - LOCAL_AMPAPP_VERSION_INVALID=1 + if [ ${CURR_VERSION_PATCH} -lt ${REQU_VERSION_PATCH} ]; then + VERSION_INVALID=1 return fi fi fi } -checkVersionAmplifyApp -if [ ${LOCAL_AMPAPP_VERSION_INVALID} -eq 1 ]; then +checkMinVersionCompatibility "${AMP_APP_VERSION_CURRENT}" "${AMP_APP_VERSION_MINIMUM}" +AMP_APP_VERSION_INVALID=${VERSION_INVALID} + +#checkMinVersionCompatibility "${AMP_CLI_VERSION_CURRENT}" "${AMP_CLI_VERSION_MINIMUM}" +#AMP_CLI_VERSION_INVALID=${VERSION_INVALID} + +if [ ${AMP_APP_VERSION_INVALID} -eq 1 ]; then NPX_AMP_APPCMD="npx amplify-app@latest" else NPX_AMP_APPCMD="npx amplify-app" fi -if ! which node >/dev/null; then - echo "warning: Node is not installed. Visit https://nodejs.org/en/download/ to install it" - exit 1 -elif ! test -f ./amplifytools.xcconfig; then + +if ! test -f ./amplifytools.xcconfig; then ${NPX_AMP_APPCMD} --platform ios fi From 1b341600208147422f0d5290a29e8e464bc9f936 Mon Sep 17 00:00:00 2001 From: John Woo Date: Wed, 3 Jun 2020 12:49:39 -0700 Subject: [PATCH 3/5] Adding support for checking amplify cli --- AmplifyTools/amplify-tools.sh | 77 ++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 15 deletions(-) diff --git a/AmplifyTools/amplify-tools.sh b/AmplifyTools/amplify-tools.sh index d18b157034..35844cebd3 100755 --- a/AmplifyTools/amplify-tools.sh +++ b/AmplifyTools/amplify-tools.sh @@ -14,26 +14,58 @@ fi export PATH=$PATH:$(npm bin -g) +# Note the use of tail -1 is important here because when upgrading between versions +# the first time that you run these commands, we have seen this variable take on the value of: +# """ +# Scanning for plugins... +# plugin scan successful +# 4.21.0 +# """ +AMP_APP_VERSION_CURRENT=`npx -q amplify-app --version |tail -1` AMP_APP_VERSION_MINIMUM="2.17.1" -AMP_APP_VERSION_CURRENT=`npx -q amplify-app --version` AMP_APP_VERSION_INVALID=0 -#TODO: This is vending unicode, need to strip these characters our safely -# and fix whatever is outputting these characters -#AMP_CLI_VERSION_MINIMUM="4.21.0" -#AMP_CLI_VERSION_CURRENT=`npx -q amplify --version |grep "\."` -#AMP_CLI_VERSION_INVALID=0 +AMP_CLI_VERSION_CURRENT=`npx -q amplify --version |tail -1` +AMP_CLI_VERSION_MINIMUM="4.21.0" +AMP_CLI_VERSION_INVALID=0 + + +STRIP_ESCAPE_RESULT= +stripEscapeUtil() { + STRIP_ESCAPE_RESULT= + + set +e + HAS_RUBY=0 + which ruby > /dev/null 2>&1 + if [[ $? -eq 0 ]]; then + HAS_RUBY=1 + fi + set -e + + if [ ${HAS_RUBY} -eq 1 ]; then + STRIP_ESCAPE_RESULT=`echo "${1}" | ruby -pe 'gsub(/\e\[[0-9;]*m/s, "")'` + else + STRIP_ESCAPE_RESULT=`echo "${1}" | npx -q strip-ansi-cli` + fi +} VERSION_INVALID= checkMinVersionCompatibility() { VERSION_INVALID=0 - CURR_VERSION_MAJOR=`echo "${1}" | tr '.' ' ' | awk '{print $1}'` - CURR_VERSION_MINOR=`echo "${1}" | tr '.' ' ' | awk '{print $2}'` - CURR_VERSION_PATCH=`echo "${1}" | tr '.' ' ' | awk '{print $3}'` - - REQU_VERSION_MAJOR=`echo "${2}" | tr '.' ' ' | awk '{print $1}'` - REQU_VERSION_MINOR=`echo "${2}" | tr '.' ' ' | awk '{print $2}'` - REQU_VERSION_PATCH=`echo "${2}" | tr '.' ' ' | awk '{print $3}'` + #Workaround using npx -q strip-ansi-cli + # 1. I would prefer to use sed, but sed on mac does not support special characters on mac + # 2. We should actually fix this in the CLI + stripEscapeUtil "${1}" + CURR_VERSION_SAFE="${STRIP_ESCAPE_RESULT}" + CURR_VERSION_MAJOR=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $1}'` + CURR_VERSION_MINOR=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $2}'` + CURR_VERSION_PATCH=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $3}'` + + stripEscapeUtil "${2}" + REQU_VERSION_SAFE="${STRIP_ESCAPE_RESULT}" + REQU_VERSION_MAJOR=`echo "${REQU_VERSION_SAFE}" | tr '.' ' ' | awk '{print $1}'` + REQU_VERSION_MINOR=`echo "${REQU_VERSION_SAFE}" | tr '.' ' ' | awk '{print $2}'` + REQU_VERSION_PATCH=`echo "${REQU_VERSION_SAFE}" | tr '.' ' ' | awk '{print $3}'` if [ -z "${CURR_VERSION_MAJOR}" ] || [ -z "${CURR_VERSION_MINOR}" ] || @@ -64,12 +96,27 @@ checkMinVersionCompatibility() { checkMinVersionCompatibility "${AMP_APP_VERSION_CURRENT}" "${AMP_APP_VERSION_MINIMUM}" AMP_APP_VERSION_INVALID=${VERSION_INVALID} -#checkMinVersionCompatibility "${AMP_CLI_VERSION_CURRENT}" "${AMP_CLI_VERSION_MINIMUM}" -#AMP_CLI_VERSION_INVALID=${VERSION_INVALID} +checkMinVersionCompatibility "${AMP_CLI_VERSION_CURRENT}" "${AMP_CLI_VERSION_MINIMUM}" +AMP_CLI_VERSION_INVALID=${VERSION_INVALID} + +if [ ${AMP_CLI_VERSION_INVALID} -eq 1 ]; then + echo "ERROR: Minimum version required of Amplify CLI is not installed." + echo " Min required version: (${AMP_CLI_VERSION_MINIMUM})" + echo " Found Version: (${AMP_CLI_VERSION_CURRENT})" + echo "" + echo "To install the latest version, please run the following command:" + echo " npm install -g @aws-amplify/cli@latest" + exit 1 +else + echo "Found amplify-cli version: (${AMP_CLI_VERSION_CURRENT}), Required: >= (${AMP_CLI_VERSION_MINIMUM})" +fi +echo "Found amplify-app version: (${AMP_APP_VERSION_CURRENT}), Required: >= (${AMP_APP_VERSION_MINIMUM})" if [ ${AMP_APP_VERSION_INVALID} -eq 1 ]; then + echo " Using: npx amplify-app@latest" NPX_AMP_APPCMD="npx amplify-app@latest" else + echo " Using: npx amplify-app" NPX_AMP_APPCMD="npx amplify-app" fi From a789b0583ee056f457f7617f2e8af484f6d5c294 Mon Sep 17 00:00:00 2001 From: John Woo Date: Wed, 3 Jun 2020 12:55:53 -0700 Subject: [PATCH 4/5] Removing old comments --- AmplifyTools/amplify-tools.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/AmplifyTools/amplify-tools.sh b/AmplifyTools/amplify-tools.sh index 35844cebd3..05ecb92e88 100755 --- a/AmplifyTools/amplify-tools.sh +++ b/AmplifyTools/amplify-tools.sh @@ -52,9 +52,7 @@ stripEscapeUtil() { VERSION_INVALID= checkMinVersionCompatibility() { VERSION_INVALID=0 - #Workaround using npx -q strip-ansi-cli - # 1. I would prefer to use sed, but sed on mac does not support special characters on mac - # 2. We should actually fix this in the CLI + stripEscapeUtil "${1}" CURR_VERSION_SAFE="${STRIP_ESCAPE_RESULT}" CURR_VERSION_MAJOR=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $1}'` From 5a3a93e5f6b2f745ce3f0613202e4e91c2189803 Mon Sep 17 00:00:00 2001 From: John Woo Date: Wed, 3 Jun 2020 13:48:50 -0700 Subject: [PATCH 5/5] updating ERROR to error --- AmplifyTools/amplify-tools.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AmplifyTools/amplify-tools.sh b/AmplifyTools/amplify-tools.sh index 05ecb92e88..ea438d9d1c 100755 --- a/AmplifyTools/amplify-tools.sh +++ b/AmplifyTools/amplify-tools.sh @@ -98,7 +98,7 @@ checkMinVersionCompatibility "${AMP_CLI_VERSION_CURRENT}" "${AMP_CLI_VERSION_MIN AMP_CLI_VERSION_INVALID=${VERSION_INVALID} if [ ${AMP_CLI_VERSION_INVALID} -eq 1 ]; then - echo "ERROR: Minimum version required of Amplify CLI is not installed." + echo "error: Minimum version required of Amplify CLI is not installed." echo " Min required version: (${AMP_CLI_VERSION_MINIMUM})" echo " Found Version: (${AMP_CLI_VERSION_CURRENT})" echo ""