aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/neovim-win.ps1
blob: 60ed0eab11c2a5e608d84061845c164a40e5cab9 (plain)
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
#Requires -Version 5.1
<#
  Windows-natives Pendant zu bootstrap/neovim.sh (macOS/FreeBSD).
  bootstrap/neovim.sh bleibt unveraendert - dieses Skript ist bewusst
  eigenstaendig, da sich die Paketquellen (winget/npm statt brew/pkg) und
  das Fehlerverhalten zu stark unterscheiden fuer ein gemeinsames Skript.

  Nutzt ausschliesslich native Windows-Werkzeuge (winget, npm, pwsh/
  powershell.exe) - keine Git-Bash- oder WSL-Abhaengigkeit.

  Aufruf (PowerShell, keine Admin-Rechte noetig):
    .\bootstrap\neovim-win.ps1

  Hinweis: Einzelne winget-Paket-IDs (v.a. GnuWin32.Gawk, GnuWin32.Libxml2,
  google.yamlfmt, mvdan.shfmt, astral-sh.ruff, zig.zig) konnten in dieser
  Session nicht gegen eine aktuelle winget-Quelle verifiziert werden.
  Schlaegt eine Installation fehl, meldet das Skript das als Warnung
  (bricht nicht ab) und nennt den Befehl zum manuellen Nachschlagen
  ("winget search <name>").
#>

$ErrorActionPreference = "Stop"
$script:Failures = @()

function Write-Ok($msg) {
  Write-Host "OK   $msg" -ForegroundColor Green
}

function Write-Step($msg) {
  Write-Host "==> $msg" -ForegroundColor Cyan
}

function Write-Skip($msg) {
  Write-Host "-    $msg bereits vorhanden" -ForegroundColor DarkGray
}

function Write-Warn($msg) {
  Write-Host "!    $msg" -ForegroundColor Yellow
  $script:Failures += $msg
}

function Test-CommandExists([string]$Name) {
  return [bool](Get-Command $Name -ErrorAction SilentlyContinue)
}

function Install-WingetPackage([string]$Binary, [string]$Id) {
  if (Test-CommandExists $Binary) {
    Write-Skip $Binary
    return
  }

  Write-Step "winget install $Id"
  winget install --id $Id -e --source winget --accept-package-agreements --accept-source-agreements --silent | Out-Null

  if ($LASTEXITCODE -ne 0) {
    Write-Warn "winget install $Id fehlgeschlagen (Binary '$Binary' nicht gefunden). Pruefen mit: winget search $Id"
    return
  }

  Write-Ok $Id
}

function Install-NpmPackage([string]$Binary, [string]$Package) {
  if (Test-CommandExists $Binary) {
    Write-Skip $Binary
    return
  }

  if (-not (Test-CommandExists "npm")) {
    Write-Warn "npm wurde nicht gefunden - kann '$Package' nicht installieren."
    return
  }

  Write-Step "npm install -g $Package"
  npm install -g $Package | Out-Null

  if ($LASTEXITCODE -ne 0) {
    Write-Warn "npm install -g $Package fehlgeschlagen."
    return
  }

  Write-Ok $Package
}

function Test-Prerequisites {
  if (-not (Test-CommandExists "winget")) {
    Write-Host "Fehler: winget wurde nicht gefunden. 'App Installer' aus dem Microsoft Store installieren." -ForegroundColor Red
    exit 1
  }
}

function Install-Prerequisites {
  Install-WingetPackage -Binary "git" -Id "Git.Git"
  Install-WingetPackage -Binary "node" -Id "OpenJS.NodeJS.LTS"
}

function Install-Formatters {
  Install-WingetPackage -Binary "jq" -Id "jqlang.jq"
  Install-NpmPackage -Binary "prettier" -Package "prettier"
  Install-WingetPackage -Binary "ruff" -Id "astral-sh.ruff"
  Install-WingetPackage -Binary "shfmt" -Id "mvdan.shfmt"
  Install-WingetPackage -Binary "stylua" -Id "JohnnyMorganz.StyLua"
  Install-WingetPackage -Binary "yamlfmt" -Id "google.yamlfmt"
  Install-WingetPackage -Binary "gawk" -Id "GnuWin32.Gawk"
  Install-WingetPackage -Binary "xmllint" -Id "GnuWin32.Libxml2"
}

function Install-Tools {
  Install-WingetPackage -Binary "rg" -Id "BurntSushi.ripgrep.MSVC"
  Install-WingetPackage -Binary "fd" -Id "sharkdp.fd"
  Install-NpmPackage -Binary "tree-sitter" -Package "tree-sitter-cli"

  # C-Compiler, damit nvim-treesitter Parser kompilieren kann.
  Install-WingetPackage -Binary "zig" -Id "zig.zig"

  # opt.makeprg = "gmake" (nvim/lua/config/options.lua) - Alias liegt in
  # windows/bin/gmake.cmd, reicht an "make" durch. Einmalig windows\bin
  # zum PATH hinzufuegen, z.B.:
  #   setx PATH "%PATH%;%USERPROFILE%\dotfiles\windows\bin"
  Install-WingetPackage -Binary "make" -Id "GnuWin32.Make"
}

function Install-Lsp {
  Install-NpmPackage -Binary "basedpyright-langserver" -Package "basedpyright"
  Install-NpmPackage -Binary "bash-language-server" -Package "bash-language-server"
  Install-WingetPackage -Binary "clangd" -Id "LLVM.LLVM"
  Install-WingetPackage -Binary "shellcheck" -Id "koalaman.shellcheck"
  Install-NpmPackage -Binary "vscode-html-language-server" -Package "vscode-langservers-extracted"
  Install-NpmPackage -Binary "vscode-json-language-server" -Package "vscode-langservers-extracted"
  Install-WingetPackage -Binary "lua-language-server" -Id "LuaLS.lua-language-server"
  Install-NpmPackage -Binary "prisma-language-server" -Package "@prisma/language-server"
  Install-NpmPackage -Binary "vtsls" -Package "@vtsls/language-server"
}

function Main {
  Test-Prerequisites

  Install-Prerequisites
  Install-Formatters
  Install-Tools
  Install-Lsp

  Write-Host ""
  if ($script:Failures.Count -eq 0) {
    Write-Host "Bootstrap abgeschlossen." -ForegroundColor Green
  } else {
    Write-Host "Bootstrap abgeschlossen, mit $($script:Failures.Count) Warnung(en):" -ForegroundColor Yellow
    foreach ($f in $script:Failures) {
      Write-Host "  - $f" -ForegroundColor Yellow
    }
  }
}

Main