Skip to content

Commit 711e296

Browse files
diegocstnpalpatim
andauthored
chore(amplifytools): amplifytools deprecation notice (#1066)
* chore(amplifytools): amplifytools deprecation notice * chore(amplifytools): emit warning on AmplifyTools usage * chore(amplifytools): remove post_install hook (not supported on specs) * Message rewording Co-authored-by: Tim Schmelter <[email protected]> * chore: Message rewording * chore: Message rewording Co-authored-by: Tim Schmelter <[email protected]>
1 parent aceeca1 commit 711e296

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed

Amplify.podspec

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,30 @@ Pod::Spec.new do |s|
2626
s.swift_version = '5.0'
2727

2828
s.source_files = 'Amplify/**/*.swift'
29+
s.default_subspec = 'Default'
2930

3031
# There appears to be a bug in Xcode < 12 where SwiftUI isn't properly
3132
# weak-linked even though system frameworks should be weak-linked by default.
3233
# Explicitly weak link it here until we upgrade Amplify's platform support
3334
# version to >= 13.0. https://github.com/aws-amplify/amplify-ios/issues/878
3435
s.weak_frameworks = 'SwiftUI'
3536

37+
s.subspec 'Default' do |default|
38+
default.preserve_path = 'AmplifyTools'
39+
default.script_phase = {
40+
:name => 'Default',
41+
:script => 'echo "no-op"',
42+
:execution_position => :before_compile
43+
}
44+
end
45+
46+
s.subspec 'Tools' do |ss|
47+
ss.preserve_path = 'AmplifyTools'
48+
ss.script_phase = {
49+
:name => 'AmplifyTools',
50+
:script => 'mkdir -p "${PODS_ROOT}/AmplifyTools"; cp -vf "${PODS_TARGET_SRCROOT}/AmplifyTools/amplify-tools.sh" "${PODS_ROOT}/AmplifyTools/."',
51+
:execution_position => :before_compile
52+
}
53+
end
54+
3655
end

AmplifyTools/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## ⚠️ Deprecation notice
2+
The build phase script provided by the `Amplify/Tools` pod is no longer recommended. It's *currently deprecated* and it **will be completely removed in a future release**.
3+
As of Amplify CLI release **4.40.0**, the functionality provided by the `amplify-tools.sh` is currently integrated with the Amplify CLI. iOS projects can leverage it without adding any extra dependencies or build phases. Here is a description on how this dependency was replaced with the Amplify CLI:
4+
- When running `amplify init --quickstart --frontend ios` as described in the [Getting Started guide](https://docs.amplify.aws/start/getting-started/setup/q/integration/ios#add-amplify-to-your-application), the relevant files are automatically added to the Xcode project.
5+
- When running `amplify codegen models`, the `*.swift` files generated under `amplify/generated/models/` are auto-added to the Xcode project in the group called `AmplifyModels`.
6+
**Notes:**
7+
- Xcode integration was added to the Amplify CLI on [version `4.40.0`](https://github.com/aws-amplify/amplify-cli/releases/tag/v4.40.0), so make sure you update your CLI to the latest version.
8+
- The "***Run Amplify Tools***" custom build phase script can be safely removed from existing projects.
9+
10+
### Amplify Tools
11+
12+
The "Amplify Tools" aims to provide a seamless integration between Xcode and [Amplify CLI](https://github.com/aws-amplify/amplify-cli). It installs the CLI and executes Amplify-related commands to make sure the iOS project has everything in place so developer can start using it right away.
13+
14+
See the [iOS Getting Started](https://aws-amplify.github.io/docs/ios/start#step-1-configure-your-app) for more details.

AmplifyTools/amplify-tools.sh

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#!/bin/sh
2+
3+
# Copyright Amazon.com Inc. or its affiliates.
4+
# All Rights Reserved.
5+
#
6+
# SPDX-License-Identifier: Apache-2.0
7+
8+
###########################################################################################
9+
# #
10+
# WARNING: AmplifyTools has been deprecated. #
11+
# #
12+
# More info: https://github.com/aws-amplify/amplify-ios/blob/main/AmplifyTools/README.md #
13+
# #
14+
###########################################################################################
15+
16+
echo "warning: AmplifyTools has been deprecated. More info: https://github.com/aws-amplify/amplify-ios/blob/main/AmplifyTools/README.md"
17+
18+
if ! which node >/dev/null; then
19+
echo "warning: Node is not installed. Visit https://nodejs.org/en/download/ to install it"
20+
exit 1
21+
fi
22+
23+
# Check for NVM and make sure it's initialized
24+
NVM_PATH="${HOME}/.nvm/nvm.sh"
25+
if [ -f "${NVM_PATH}" ]; then
26+
echo "NVM found, initializing it..."
27+
source "${NVM_PATH}"
28+
fi
29+
30+
set -e
31+
32+
export PATH=$PATH:$(npm bin -g)
33+
34+
# Note the use of tail -1 is important here because when upgrading between versions
35+
# the first time that you run these commands, we have seen this variable take on the value of:
36+
# """
37+
# Scanning for plugins...
38+
# plugin scan successful
39+
# 4.21.0
40+
# """
41+
AMP_APP_VERSION_CURRENT=`npx -q amplify-app --version |tail -1`
42+
AMP_APP_VERSION_MINIMUM="2.17.1"
43+
AMP_APP_VERSION_INVALID=0
44+
45+
AMP_CLI_VERSION_CURRENT=`npx -q amplify --version |tail -1`
46+
AMP_CLI_VERSION_MINIMUM="4.22.0"
47+
AMP_CLI_VERSION_INVALID=0
48+
49+
50+
STRIP_ESCAPE_RESULT=
51+
stripEscapeUtil() {
52+
STRIP_ESCAPE_RESULT=
53+
54+
set +e
55+
HAS_RUBY=0
56+
which ruby > /dev/null 2>&1
57+
if [[ $? -eq 0 ]]; then
58+
HAS_RUBY=1
59+
fi
60+
set -e
61+
62+
if [ ${HAS_RUBY} -eq 1 ]; then
63+
STRIP_ESCAPE_RESULT=`echo "${1}" | ruby -pe 'gsub(/\e\[[0-9;]*m/s, "")'`
64+
else
65+
STRIP_ESCAPE_RESULT=`echo "${1}" | npx -q strip-ansi-cli`
66+
fi
67+
}
68+
69+
VERSION_INVALID=
70+
checkMinVersionCompatibility() {
71+
VERSION_INVALID=0
72+
73+
stripEscapeUtil "${1}"
74+
CURR_VERSION_SAFE="${STRIP_ESCAPE_RESULT}"
75+
CURR_VERSION_MAJOR=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $1}'`
76+
CURR_VERSION_MINOR=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $2}'`
77+
CURR_VERSION_PATCH=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $3}'`
78+
79+
stripEscapeUtil "${2}"
80+
REQU_VERSION_SAFE="${STRIP_ESCAPE_RESULT}"
81+
REQU_VERSION_MAJOR=`echo "${REQU_VERSION_SAFE}" | tr '.' ' ' | awk '{print $1}'`
82+
REQU_VERSION_MINOR=`echo "${REQU_VERSION_SAFE}" | tr '.' ' ' | awk '{print $2}'`
83+
REQU_VERSION_PATCH=`echo "${REQU_VERSION_SAFE}" | tr '.' ' ' | awk '{print $3}'`
84+
85+
if [ -z "${CURR_VERSION_MAJOR}" ] ||
86+
[ -z "${CURR_VERSION_MINOR}" ] ||
87+
[ -z "${CURR_VERSION_PATCH}" ] ||
88+
[ -z "${REQU_VERSION_MAJOR}" ] ||
89+
[ -z "${REQU_VERSION_MINOR}" ] ||
90+
[ -z "${REQU_VERSION_PATCH}" ]; then
91+
VERSION_INVALID=1
92+
return
93+
fi
94+
95+
if [ ${CURR_VERSION_MAJOR} -lt ${REQU_VERSION_MAJOR} ]; then
96+
VERSION_INVALID=1
97+
return
98+
else
99+
if [ ${CURR_VERSION_MINOR} -lt ${REQU_VERSION_MINOR} ]; then
100+
VERSION_INVALID=1
101+
return
102+
else
103+
if [ ${CURR_VERSION_PATCH} -lt ${REQU_VERSION_PATCH} ]; then
104+
VERSION_INVALID=1
105+
return
106+
fi
107+
fi
108+
fi
109+
}
110+
111+
checkMinVersionCompatibility "${AMP_APP_VERSION_CURRENT}" "${AMP_APP_VERSION_MINIMUM}"
112+
AMP_APP_VERSION_INVALID=${VERSION_INVALID}
113+
114+
checkMinVersionCompatibility "${AMP_CLI_VERSION_CURRENT}" "${AMP_CLI_VERSION_MINIMUM}"
115+
AMP_CLI_VERSION_INVALID=${VERSION_INVALID}
116+
117+
if [ ${AMP_CLI_VERSION_INVALID} -eq 1 ]; then
118+
echo "error: Minimum version required of Amplify CLI is not installed."
119+
echo " Min required version: (${AMP_CLI_VERSION_MINIMUM})"
120+
echo " Found Version: (${AMP_CLI_VERSION_CURRENT})"
121+
echo ""
122+
echo "To install the latest version, please run the following command:"
123+
echo " npm install -g @aws-amplify/cli@latest"
124+
exit 1
125+
else
126+
echo "Found amplify-cli version: (${AMP_CLI_VERSION_CURRENT}), Required: >= (${AMP_CLI_VERSION_MINIMUM})"
127+
fi
128+
129+
echo "Found amplify-app version: (${AMP_APP_VERSION_CURRENT}), Required: >= (${AMP_APP_VERSION_MINIMUM})"
130+
if [ ${AMP_APP_VERSION_INVALID} -eq 1 ]; then
131+
echo " Using: npx amplify-app@latest"
132+
NPX_AMP_APPCMD="npx amplify-app@latest"
133+
else
134+
echo " Using: npx amplify-app"
135+
NPX_AMP_APPCMD="npx amplify-app"
136+
fi
137+
138+
139+
if ! test -f ./amplifytools.xcconfig; then
140+
${NPX_AMP_APPCMD} --platform ios
141+
fi
142+
143+
. amplifytools.xcconfig
144+
amplifyPush=$push
145+
amplifyModelgen=$modelgen
146+
amplifyProfile=$profile
147+
amplifyAccessKey=$accessKeyId
148+
amplifySecretKey=$secretAccessKey
149+
amplifyRegion=$region
150+
amplifyEnvName=$envName
151+
152+
if $amplifyModelgen; then
153+
echo "modelgen is set to true, generating Swift models from schema.graphql..."
154+
amplify codegen model
155+
# calls amplify-app again so the Xcode project is updated with the generated models
156+
${NPX_AMP_APPCMD} --platform ios
157+
fi
158+
159+
if [ -z "$amplifyAccessKey" ] || [ -z "$amplifySecretKey" ] || [ -z "$amplifyRegion" ]; then
160+
161+
AWSCLOUDFORMATIONCONFIG="{\
162+
\"configLevel\":\"project\",\
163+
\"useProfile\":true,\
164+
\"profileName\":\"${amplifyProfile}\"\
165+
}"
166+
else
167+
AWSCLOUDFORMATIONCONFIG="{\
168+
\"configLevel\":\"project\",\
169+
\"useProfile\":true,\
170+
\"profileName\":\"${amplifyProfile}\",\
171+
\"accessKeyId\":\"${amplifyAccessKeyId}\",\
172+
\"secretAccessKey\":\"${amplifySecretAccessKey}\",\
173+
\"region\":\"${amplifyRegion}\"\
174+
}"
175+
fi
176+
177+
if [ -z "$amplifyEnvName" ]; then
178+
AMPLIFY="{\"envName\":\"amplify\"}"
179+
else
180+
AMPLIFY="{\"envName\":\"${amplifyEnvName}\"}"
181+
fi
182+
PROVIDERS="{\
183+
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
184+
}"
185+
186+
if $amplifyPush; then
187+
if test -f ./amplify/.config/local-env-info.json; then
188+
amplify push --yes
189+
else
190+
amplify init --amplify $AMPLIFY --providers $PROVIDERS --yes
191+
fi
192+
fi

0 commit comments

Comments
 (0)