forked from dotnet/vscode-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.ps1
More file actions
61 lines (46 loc) · 2.15 KB
/
init.ps1
File metadata and controls
61 lines (46 loc) · 2.15 KB
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
#!/usr/bin/env pwsh
Write-Host "`nStarting init..." -ForegroundColor Cyan
# Cross-platform command execution with error checking
function Run-Command($command, $arguments, $errorMsg) {
Write-Host "Running: $command $($arguments -join ' ')" -ForegroundColor Yellow
# Check if command exists first
if (-not (Get-Command $command -ErrorAction SilentlyContinue)) {
throw "$command is not available on this system. Please ensure you have the command installed globally and it's available in your PATH."
}
& $command @arguments
if ($LASTEXITCODE -ne 0) {
throw "$errorMsg (Exit code: $LASTEXITCODE)"
}
}
Push-Location $PSScriptRoot
try {
Write-Host "`n[1/5] Installing vsts-npm-auth globally..." -ForegroundColor Cyan
Run-Command "npm" @("install", "-g", "vsts-npm-auth") "Failed to install vsts-npm-auth."
Write-Host "`n[2/5] Authenticating with Azure DevOps..." -ForegroundColor Cyan
if (Test-Path ".npmrc") {
try {
Run-Command "vsts-npm-auth" @("-config", ".npmrc") "Initial authentication failed."
}
catch {
Write-Host "Initial authentication failed. Trying with force (-f) flag..." -ForegroundColor DarkYellow
Run-Command "vsts-npm-auth" @("-config", ".npmrc", "-f") "Forced authentication failed."
}
} else {
Write-Host ".npmrc file not found in the current directory." -ForegroundColor Red
throw ".npmrc file not found in the current directory."
}
Write-Host "`n[3/5] Installing project dependencies..." -ForegroundColor Cyan
Run-Command "npm" @("install") "Failed to install project dependencies."
Write-Host "`n[4/5] Installing Gulp globally..." -ForegroundColor Cyan
Run-Command "npm" @("install", "-g", "gulp") "Failed to install Gulp globally."
Write-Host "`n[5/5] Running gulp installDependencies..." -ForegroundColor Cyan
Run-Command "gulp" @("installDependencies") "Failed to run 'gulp installDependencies'."
Write-Host "`n✅ Setup complete." -ForegroundColor Green
}
catch {
Write-Host "`n❌ Setup failed: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
finally {
Pop-Location
}