-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshDataStoreBuild.sh
executable file
·169 lines (153 loc) · 4.35 KB
/
shDataStoreBuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
appName=$1
profileName=$2
nextRebuildVersion="13.5.3"
currentFolder=$(pwd | sed 's#.*/##')
if [ $currentFolder != "rebuildamplify" ]; then
echo "You must run this from the rebuildamplify folder which should be a siblings folder to your project app folder!!!!"
exit 1
fi
cd ..
if [ -d "$appName" ]; then
echo "$appName FOLDER ALREADY EXISTS"
else
npx create-next-app@$nextRebuildVersion $appName --app --js --tailwind --eslint --src-dir --import-alias "@/*"
if [ $? -ne 0 ]; then
echo "FAILED TO CREATE NEXT.JS APP"
exit 1
fi
fi
#AMPLIFY INIT
cd "$appName"
if [ -d "amplify" ]; then
echo "AMPLIFY FOLDER ALREADY EXISTS"
else
amplifyJson='{
"projectName": "'"$appName"'",
"envName": "dev",
"defaultEditor": "code"
}'
frontendJson='{
"frontend": "javascript",
"framework": "react",
"config": {
"SourceDir": "src",
"DistributionDir": "build",
"BuildCommand": "npm run-script build",
"StartCommand": "npm run-script start"
}
}'
providersJson='{
"awscloudformation": {
"configLevel": "project",
"useProfile": true,
"profileName": "'"$profileName"'"
}
}'
# Output the JSON strings for verification
echo "amplifyjson = $amplifyJson"
echo "frontend = $frontendJson"
echo "providers = $providersJson"
# Run amplify init with the JSON strings as parameters
echo "INIT AMPLIFY..."
amplify init --amplify "$amplifyJson" --frontend "$frontendJson" --providers "$providersJson" --yes
if [ $? -ne 0 ]; then
echo "FAILED TO AMPLIFY INIT"
exit 1
fi
fi
#AMPLIFY AUTH
if [ -d "amplify/backend/auth" ]; then
echo "AUTH FOLDER ALREADY EXISTS"
else
# Construct the JSON structure manually
resourceName="${appName}Cognito"
userPoolName="${appName}UserPool"
identityPoolName="${appName}IdentityPool"
addAuth='{
"version": 2,
"resourceName": "'"$resourceName"'",
"serviceConfiguration": {
"serviceName": "Cognito",
"includeIdentityPool": true,
"identityPoolConfiguration": {
"identityPoolName": "'"$identityPoolName"'"
},
"userPoolConfiguration": {
"signinMethod": "EMAIL",
"requiredSignupAttributes": ["EMAIL"],
"userPoolName": "'"$userPoolName"'",
"mfa": {
"mode": "ON",
"mfaTypes": ["TOTP"],
"smsMessage": "Your authentication code is {####}"
},
"userPoolGroups": [
{
"groupName": "admin"
},
{
"groupName": "superuser"
},
{
"groupName": "user"
}
]
}
}
}'
# Output the JSON for verification
echo "$addAuth"
# Run amplify add auth with the JSON string as a parameter
echo "$addAuth" | jq -c | amplify add auth --headless
if [ $? -ne 0 ]; then
echo "FAILED TO AMPLIFY ADD AUTH"
exit 1
fi
fi
# Check if a "function" directory already exists within "amplify/backend"
if [ -d "amplify/backend/function" ]; then
echo "FUNCTION FOLDER ALREADY EXISTS"
else
read -p "Hit your F5 macro to update amplify Auth with Cognito triggers, or press enter to manually add your Cognito triggers..."
# F5 equals these key strokes e\/\/eeee\/eeeeeee""eee\/ee\/\/\/\/se\/sene
# \/ = down arrow
# s = space
# e = enter
# n = n
# "" = string of text "Your Verification Code {####}" and "365" rspectively
# Run amplify update auth
echo "AMPLIFY UPDATE AUTH..."
amplify update auth
if [ $? -ne 0 ]; then
echo "FAILED TO AMPLIFY UPDATE AUTH"
exit 1
fi
echo "AMPLIFY PUSH --yes..."
amplify push --yes
fi
# Check if a "@aws-amplify" directory already exists within "node_modules"
if [ -d "node_modules/@aws-amplify" ]; then
echo "@aws-amplify FOLDER ALREADY EXISTS"
else
npm install aws-amplify @aws-amplify/ui-react
fi
# Check if a "@headlessui" directory already exists within "node_modules"
if [ -d "node_modules/@headlessui" ]; then
echo "@headlessui FOLDER ALREADY EXISTS"
else
npm install @headlessui/react
fi
# Check if a "@heroicons" directory already exists within "node_modules"
if [ -d "node_modules/@heroicons" ]; then
echo "@heroicons FOLDER ALREADY EXISTS"
else
npm install @heroicons/react
fi
# Check if a "@aws-sdk" directory already exists within "node_modules"
if [ -d "node_modules/@aws-sdk" ]; then
echo "@aws-sdk FOLDER ALREADY EXISTS"
else
npm install aws-sdk
npm add -D encoding
fi