Last active
April 12, 2021 19:11
-
-
Save vladimir-ivanov/0d7a944150117682e85f45a36b9dc216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
write-host "`n ## ONBOARDING SCRIPTS ## `n" | |
$nodeJsVersion = "12.14.0" | |
$projectName = 'alpha'; | |
$gitUrl = "https://github.com/vladimir-ivanov/$projectName.git" | |
$installNode = $FALSE; | |
### CONFIGURATION | |
$rootDir = "C:\Development" | |
$downloadsDir = "$rootDir\downloads" | |
$projectsDir = "$rootDir\projects" | |
$npmCacheDir = "$rootDir\npm-cache" | |
$url = "https://nodejs.org/dist/v$nodeJsVersion/node-v$nodeJsVersion-x64.msi" | |
write-host $url | |
New-Item -Path $rootDir -ItemType Directory | |
New-Item -Path $programsDir -ItemType Directory | |
New-Item -Path $projectsDir -ItemType Directory | |
write-host "`n----------------------------" | |
write-host " system requirements checking " | |
write-host "----------------------------`n" | |
### require administator rights | |
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) | |
{ | |
write-Warning "This setup needs admin permissions. Please run this file as admin." | |
break | |
} | |
### nodejs version check | |
if (Get-Command node -errorAction SilentlyContinue) | |
{ | |
$currentVersion = (node -v) | |
} | |
if ($currentVersion) | |
{ | |
write-host "[NODE] nodejs $currentVersion already installed" | |
$confirmation = read-host "Are you sure you want to replace this version ? [y/N]" | |
if ($confirmation -ne "y") | |
{ | |
$installNode = $FALSE | |
} | |
} | |
write-host "`n" | |
if ($installNode) | |
{ | |
### download nodejs msi file | |
# warning : if a node.msi file is already present in the current folder, this script will simply use it | |
write-host "`n----------------------------" | |
write-host " nodejs msi file retrieving " | |
write-host "----------------------------`n" | |
write-host "----------------------------`n" | |
$filename = "node.msi" | |
$nodeMsiLocation = "$downloadsDir\$filename" | |
$downloadNode = $TRUE | |
if (Test-Path $nodeMsiLocation) | |
{ | |
$confirmation = read-host "Local $filename file detected. Do you want to use it ? [Y/n]" | |
if ($confirmation -eq "n") | |
{ | |
$downloadNode = $FALSE | |
} | |
} | |
if ($downloadNode) | |
{ | |
write-host "[NODE] downloading nodejs install" | |
write-host "url : $url" | |
$start_time = Get-Date | |
$wc = New-Object System.Net.WebClient | |
$wc.DownloadFile($url, $nodeMsiLocation) | |
write-Output "$filename downloaded" | |
write-Output "Time taken: $( (Get-Date).Subtract($start_time).Seconds ) second(s)" | |
} | |
else | |
{ | |
write-host "using the existing node.msi file" | |
} | |
### nodejs install | |
write-host "`n----------------------------" | |
write-host " nodejs installation " | |
write-host "----------------------------`n" | |
write-host "[NODE] running $nodeMsiLocation" | |
Start-Process $nodeMsiLocation -Wait | |
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") | |
} | |
else | |
{ | |
write-host "Proceeding with the previously installed nodejs version ..." | |
} | |
### clean | |
write-host "`n----------------------------" | |
write-host " system cleaning " | |
write-host "----------------------------`n" | |
$confirmation = read-host "Delete install files ? [y/N]" | |
if ($confirmation -eq "y") | |
{ | |
if ($nodeMsiLocation -and (Test-Path $nodeMsiLocation)) | |
{ | |
rm $nodeMsiLocation | |
} | |
} | |
$npmCacheDir = "$rootDir\npm-cache" | |
node --version | |
npm --version | |
npm config set cache $npmCacheDir --global | |
npm config list | |
write-host "`n----------------------------" | |
write-host " Install Project " | |
write-host "----------------------------`n" | |
cd $projectsDir | |
git clone "https://github.com/vladimir-ivanov/$projectName.git" | |
cd $projectName | |
npm install | |
npm run lerna bootstrap | |
write-host "Done !" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment