# Installs the Comity CLI (the npm package comity-cli) with your existing Node.js and npm. # irm https://comity.so/install.ps1 | iex # $env:COMITY_CLI_VERSION picks a version or dist-tag (default: latest), e.g. $env:COMITY_CLI_VERSION = "next". # This script never installs Node.js, never elevates and sends nothing anywhere but the npm registry. & { $ErrorActionPreference = "Stop" $nodeMin = 22 $tag = if ($env:COMITY_CLI_VERSION) { $env:COMITY_CLI_VERSION } else { "latest" } $pkg = "comity-cli@$tag" function Fail($message) { Write-Host "comity: $message" -ForegroundColor Red # `exit` would close the window when run through `irm | iex`; throw stops the script instead. throw "comity install failed" } if (-not (Get-Command node -ErrorAction SilentlyContinue)) { Fail "Node.js $nodeMin or newer is required. Install it from https://nodejs.org, then run this again." } if (-not (Get-Command npm -ErrorAction SilentlyContinue)) { Fail "npm was not found. It ships with Node.js: https://nodejs.org" } $nodeVersion = (& node -p "process.versions.node" 2>$null) if ($LASTEXITCODE -ne 0 -or -not $nodeVersion) { Fail "could not run node. Reinstall Node.js $nodeMin or newer from https://nodejs.org" } if ([int]($nodeVersion.Split(".")[0]) -lt $nodeMin) { Fail "Node.js $nodeMin or newer is required (found $nodeVersion). Update it from https://nodejs.org" } Write-Host "Installing $pkg with npm (Node.js $nodeVersion)..." & npm install -g $pkg if ($LASTEXITCODE -ne 0) { Fail "npm install -g $pkg failed (output above). If it says EPERM, close programs using comity and run this again." } # npm links global commands into its prefix folder on Windows. $prefix = (& npm prefix -g).Trim() $comity = Join-Path $prefix "comity.cmd" if (-not (Test-Path $comity)) { Fail "npm finished but the comity command was not found in $prefix." } $version = (& $comity --version) if ($LASTEXITCODE -ne 0) { Fail "comity was installed but 'comity --version' failed." } $onPath = $env:Path.Split(";") | Where-Object { $_ -and ($_.TrimEnd("\") -ieq $prefix.TrimEnd("\")) } if (-not $onPath) { Write-Host "" Write-Host "Note: $prefix is not on your PATH. Add it in System settings > Environment variables, then open a new terminal." } Write-Host "" Write-Host "Installed comity $version." Write-Host "Next: run ``comity login``, then ``comity init`` in your repo." }