-
Notifications
You must be signed in to change notification settings - Fork 12
/
Invoke-DevSetup.ps1
344 lines (296 loc) · 13.2 KB
/
Invoke-DevSetup.ps1
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<#
Quick PowerShell script for setting up a local development environment for a developer on their first day.
DISCLAIMER: Yes, with the introduction of containers this script might not be super useful but sometimes
you just need a quick script to get someone going and you don't want to waste time.
Also, obligatory statement of "use this script at your own risk and all that stuff".
To use this script:
1. Edit the roles to match your organization (Frontend, Backend, Web, API, DevOps, Data, etc. )
2. Edit the package lists to install what you need -- supports brew packages and casks, vscode extensions, npm packages, chocolatey packages , and github repos.
3. Test it on your machine or a dummy machine, container, whatever - always test your stuff first.
4. Commit it to a repo and onboard a little bit faster in your org!
THIS SCRIPT MAKES THE FOLLOWING ASSUMPTIONS:`
ON MAC
- Homebrew is installed - https://brew.sh/
- PowerShell v7.2.1+ is installed - https://github.com/PowerShell/PowerShell
ON WINDOWS
- Chocolatey is installed - https://chocolatey.org/
- PowerShell v7.2.1+ is installed - https://github.com/PowerShell/PowerShell
- Since some choco packages require elevated permissions, it is recommended to run this as Administrator.
NOTE: Due to running as Administrator - BE CAREFUL what Chocolatey Packages you add to this script!
Always verify them first before adding and running this script.
THE SCRIPT WILL DO THE FOLLOWING:
1. Installs GitHub CLI - for initial authentication and repository cloning
2. Runs through GitHub Authentication Setup
3. Prompts for type of engineer - Backend or Frontend? (this is 100% customizable)
4. If Frontend, it will install the following:
a. Defined homebrew packages
b. Defined homebrew casks
c. Defined VSCode Extensions
d. Defined NPM packages
e. Defined GitHub Repositories
5. If Backend, it will install the following:
a. Defined Chocolatey packages
b. Defined GitHub Repositories
TODO:
- Parameterize the various "groups" of packages /shrug
Kinda like this -- Invoke-LocalDevSetup -brewPackages @("git","node","nvm") -brewCasks @("visual-studio-code", "github", "docker")
- Add VSCode Extensions section to Backend/Windows setup
- Something YOU should create a Pull Request for that I haven't thought of.
#>
# Start of Helper Functions
function DrawMenu {
param ($menuItems, $menuPosition, $Multiselect, $selection)
$l = $menuItems.length
for ($i = 0; $i -le $l;$i++) {
if ($null -ne $menuItems[$i]){
$item = $menuItems[$i]
if ($Multiselect)
{
if ($selection -contains $i){
$item = '[x] ' + $item
}
else {
$item = '[ ] ' + $item
}
}
if ($i -eq $menuPosition) {
Write-Host "> $($item)" -ForegroundColor Green
} else {
Write-Host " $($item)"
}
}
}
}
function Invoke-ToggleSelection {
param ($pos, [array]$selection)
if ($selection -contains $pos){
$result = $selection | Where-Object {$_ -ne $pos}
}
else {
$selection += $pos
$result = $selection
}
$result
}
function Menu {
param ([array]$menuItems, [switch]$ReturnIndex=$false, [switch]$Multiselect)
$vkeycode = 0
$pos = 0
$selection = @()
if ($menuItems.Length -gt 0)
{
try {
[console]::CursorVisible=$false #prevents cursor flickering
DrawMenu $menuItems $pos $Multiselect $selection
While ($vkeycode -ne 13 -and $vkeycode -ne 27) {
$press = $host.ui.rawui.readkey("NoEcho,IncludeKeyDown")
$vkeycode = $press.virtualkeycode
If ($vkeycode -eq 38 -or $press.Character -eq 'k') {$pos--}
If ($vkeycode -eq 40 -or $press.Character -eq 'j') {$pos++}
If ($vkeycode -eq 36) { $pos = 0 }
If ($vkeycode -eq 35) { $pos = $menuItems.length - 1 }
If ($press.Character -eq ' ') { $selection = Toggle-Selection $pos $selection }
if ($pos -lt 0) {$pos = 0}
If ($vkeycode -eq 27) {$pos = $null }
if ($pos -ge $menuItems.length) {$pos = $menuItems.length -1}
if ($vkeycode -ne 27)
{
$startPos = [System.Console]::CursorTop - $menuItems.Length
[System.Console]::SetCursorPosition(0, $startPos)
DrawMenu $menuItems $pos $Multiselect $selection
}
}
}
finally {
[System.Console]::SetCursorPosition(0, $startPos + $menuItems.Length)
[console]::CursorVisible = $true
}
}
else {
$pos = $null
}
if ($ReturnIndex -eq $false -and $null -ne $pos)
{
if ($Multiselect){
return $menuItems[$selection]
}
else {
return $menuItems[$pos]
}
}
else
{
if ($Multiselect){
return $selection
}
else {
return $pos
}
}
}
# End of Help Functions
function Invoke-LocalDevSetup() {
param()
try {
# Install GitHub CLI
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "Installing GitHubCLI..." -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
if ($IsMacOS) {
brew install gh
}
if ($IsWindows) {
choco install gh -y
}
# Setup GitHub Authentication
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "GitHub Authentication Setup!" -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
gh auth login
# Ask what kind of engineer you are
Write-Host "What kind of engineer are you?"
$DeveloperType = menu @("Frontend", "Backend")
Write-Host "Beginning $($DeveloperType) Engineer Install..."
switch ($DeveloperType) {
# Frontend
"Frontend" {
# Determine OS
if ($IsMacOS) {
# Install Tools for Mac
# List of Brew Packages
$brewPackages = @(
"git",
"node",
"nvm"
)
# Install the Brew packages
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "Installing Brew Packages..." -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
foreach ($brewPackage in $brewPackages) {
brew install $brewPackage
}
# List of Brew Casks
$caskPackages = @(
"visual-studio-code",
"github",
"docker"
)
# Install the Brew Casks
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "Installing Brew Cask Packages..." -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
foreach ($caskPackage in $caskPackages) {
brew install --cask $caskPackage
}
# List of VS Code Extensions
$vsCodeExtensions = @(
"alefragnani.Bookmarks",
"be5invis.toml",
"bradlc.vscode-tailwindcss",
"dbaeumer.vscode-eslint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"formulahendry.auto-close-tag",
"GitHub.vscode-pull-request-github",
"heybourn.headwind", "jock.svg",
"ms-azuretools.vscode-docker",
"ms-vsliveshare.vsliveshare",
"natqe.reload", "octref.vetur",
"ritwickdey.LiveServer",
"sdras.vue-vscode-snippets",
"syler.sass-indented",
"wix.vscode-import-cost"
)
# Install VS Code Extensions
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "Installing VSCode Extensions..." -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
foreach ($vsCodeExtension in $vsCodeExtensions) {
code --install-extension $vsCodeExtension --force
}
# Install NPM Packages
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "Installing npm packages..." -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
# List NPM Packages
$npmPackages = @("gruntcli", "gulp")
foreach ($npmPackage in $npmPackages) {
npm install -g $npmPackage
}
# Clone Repositories to Home Directory
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "Cloning Repositories..." -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
# Repositories
$Repositories = @(
"org-name/repo-name-1",
"org-name/repo-name-2"
)
# Clone the repos
foreach ($repository in $Repositories) {
gh repo clone $repository $ENV:HOME/$repository
}
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "All of your projectss can be found here: $($ENV:HOME)/<repo-name>" -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
}
# This is for a frontend dev that is running a windows box
if ($IsWindows) {
# Install Windows-based tools
}
}
"Backend" {
# Install the backend developer tools for Windows
if ($IsWindows) {
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "Installing Chocolatey Packages..." -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
# Chocolatey Packages
$chocolateyPackages = @(
"git",
"dotnet",
"docker-desktop",
"nodejs",
"nvm",
"sql-server-express",
"sql-server-management-studio",
"visualstudio2022community",
"visualstudio2022-workload-azure",
"visualstudio2022-workload-netweb",
"visualstudio2022-workload-data",
"vscode"
)
foreach ($chocolateyPackage in $chocolateyPackages) {
choco install $chocolateyPackage -y
}
# Clone Repositories
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "Cloning Repositories..." -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
# Repositories
$Repositories = @(
"org-name/repo-name-1",
"org-name/repo-name-2"
)
foreach ($repository in $Repositories) {
gh repo clone $repository $ENV:HOME/$repository
}
Write-Host "===================================" -ForegroundColor "cyan"
Write-Host "All of your projects can be found here: $($ENV:USERPROFILE)\<repo-name>" -ForegroundColor "cyan"
Write-Host "Install Complete! Press Enter to Exit..." -ForegroundColor "cyan"
Write-Host "===================================" -ForegroundColor "cyan"
Read-Host "END"
}
# This is for a backend dev that is running a mac box
if ($IsMacOS) {
# Install Tools Mac
}
}
}
}
catch {
Write-Warning $_
}
}
Invoke-LocalDevSetup