-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup-df24-devtools-demo
executable file
·188 lines (167 loc) · 10.2 KB
/
setup-df24-devtools-demo
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
#
# This script helps set up the CodeBuilder environment used
# by the DF24 Developer Tools demo by doing the following:
# 1. Update the Salesforce CLI.
# 2. Install code Analyzer 5 (beta)
# 3. Install the Typescript NPM package globally.
# 4. Remove the `df24-devtools-demo` folder (if it exists).
# 5. Set the global Git config values for `user.name` and `user.email`
# This is a requirement for the Git extension for VS Code to work.
# 6. Clone the `df24-devtools-demo` repository from GitHub.
#
# Exit on any error
set -e
# Ensure the script is being run from the /home/codebuilder directory.
if [ "$(pwd)" != "/home/codebuilder" ]; then
echo -e "\u274C"" Error: Current directory is not /home/codebuilder"
exit 1
fi
# Prevent release notes from being shown after updating Salesforce CLI.
export SF_HIDE_RELEASE_NOTES=true
export SF_HIDE_RELEASE_NOTES_FOOTER=true
# Handle script errors.
function handle_error {
echo
echo -e "\u274C"" DF24 DevTools Demo: Code Builder Environment Setup Failed"
echo
}
# Handle script success.
function handle_success {
echo
echo "───────────────────────────────────────────────────────────────────────"
echo
echo -e "\u2705"" DF24 DevTools Demo: Code Builder Environment Setup Complete"
echo
echo "───────────────────────────────────────────────────────────────────────"
echo
}
# Send trapped errors to the error handler.
trap handle_error ERR
# Announce that the Training Lab Environment Setup process has started.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo
echo -e "\U1F680"" Starting Training Lab Environment Setup"
# Update Salesforce CLI.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(1) Updating Salesforce CLI (if needed)"
echo "───────────────────────────────────────────────────────────────────────"
sf update stable
# Install Code Analyzer 5 (beta).
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(2) Installing Code Analyzer 5 (beta)"
echo "───────────────────────────────────────────────────────────────────────"
sf plugins install @salesforce/plugin-code-analyzer@latest-alpha
# Install Typescript.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(3) Installing Typescript"
echo "───────────────────────────────────────────────────────────────────────"
npm install -g typescript
# Remove the df24-devtools-demo folder (if it exists).
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(4) Removing the df24-devtools-demo folder"
echo "───────────────────────────────────────────────────────────────────────"
rm -rf /home/codebuilder/df24-devtools-demo
echo
echo "Folder removed"
# Clone the df24-devtools-demo repository from GitHub.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(5) Cloning the df24-devtools-demo repository"
echo "───────────────────────────────────────────────────────────────────────"
git clone https://github.com/VivekMChawla/df24-devtools-demo.git
# Create the code-analyzer-logs folder inside the demo project.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(6) Creating the code-analyzer-logs folder inside the demo project."
echo "───────────────────────────────────────────────────────────────────────"
mkdir /home/codebuilder/df24-devtools-demo/code-analyzer-logs
echo
echo "Folder created"
# Install Node.js dependencies inside df24-devtools-demo.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(7) Installing Node.js dependencies inside df24-devtools-demo."
echo "───────────────────────────────────────────────────────────────────────"
npm install /home/codebuilder/df24-devtools-demo --prefix /home/codebuilder/df24-devtools-demo
# Create a .sf/config.json file to set the default org.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(8) Creating a .sf/config.json file to set the default org."
echo "───────────────────────────────────────────────────────────────────────"
# Define the file path
config_file="/home/codebuilder/df24-devtools-demo/.sf/config.json"
# Create the directory if it doesn't exist
mkdir -p "$(dirname "$config_file")"
# Write the JSON content to the file
cat <<EOF > "$config_file"
{
"target-org": "SandboxOrg"
}
EOF
echo
echo "Created $config_file with SandboxOrg as target-org."
# Create a .sfdx/sfdx-config.json file to set the default org.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(9) Creating a .sfdx/sfdx-config.json file to set the default org."
echo "───────────────────────────────────────────────────────────────────────"
# Define the file path
config_file="/home/codebuilder/df24-devtools-demo/.sfdx/sfdx-config.json"
# Create the directory if it doesn't exist
mkdir -p "$(dirname "$config_file")"
# Write the JSON content to the file
cat <<EOF > "$config_file"
{
"defaultusername": "SandboxOrg"
}
EOF
echo
echo "Created $config_file with SandboxOrg as defaultusername."
# Enable autocomplete for the Salesforce CLI.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(10) Enabling autocomplete for the Salesforce CLI."
echo "───────────────────────────────────────────────────────────────────────"
rm -f /home/codebuilder/.bashrc.local
printf "eval $(sf autocomplete script bash)" >> /home/codebuilder/.bashrc.local
source /home/codebuilder/.bashrc
echo
echo "Autocomplete enabled."
# Disable the ERR trap and allow script errors
# This is requied because bash interprets an attempt
# to read an unset git config variable as an error.
trap - ERR
set +e
# Save existing global Git config in variables.
github_user_name=$(git config --get --global user.name)
github_user_email=$(git config --get --global user.email)
# Enable the ERR trap and disallow script errors.
set -e
trap handle_error ERR
# Set generic Git config values for name and email, but
# ONLY if these global config values were NOT already set.
# This is required to before using Git features in VS Code.
echo
echo "───────────────────────────────────────────────────────────────────────"
echo "(11) Setting global Git name/email config"
echo "───────────────────────────────────────────────────────────────────────"
echo
if [ -n "$github_user_name" ]; then
echo "--> Git Name: $github_user_name (already set)"
else
git config --global user.name "Developer Benjamin"
echo "--> Git Name: $(git config --get --global user.name)"
fi
if [ -n "$github_user_email" ]; then
echo "--> Git Name: $github_user_email (already set)"
else
git config --global user.email "[email protected]"
echo "--> Git Email: $(git config --get --global user.email)"
fi
handle_success