# PersistMemory CLI installer for Windows. # # irm https://persistmemory.com/install.ps1 | iex # # Read it first if you would rather: # irm https://persistmemory.com/install.ps1 # # Environment: # PM_VERSION install a specific npm version (default: latest) $ErrorActionPreference = "Stop" function Install-PersistMemory { function Write-Step($text) { Write-Host ("==> " + $text) -ForegroundColor Cyan } function Write-Note($text) { Write-Host (" " + $text) -ForegroundColor DarkGray } function Write-Failure($text) { Write-Host "" Write-Host ("error: " + $text) -ForegroundColor Red Write-Host "" } Write-Step "Installing the PersistMemory CLI" # Node, checked BEFORE anything is downloaded, so the failure arrives before # the work rather than after it. if (-not (Get-Command node -ErrorAction SilentlyContinue)) { Write-Failure "Node.js 20 or newer is required, and 'node' was not found on PATH." Write-Note "Install it from https://nodejs.org and run this again." return } # Redirection on the command itself, not on a parenthesised expression: # an assignment with a redirected sub-expression is a parse error in some # PowerShell versions, and an installer that fails to parse takes the whole # one-liner with it. $major = & node -p "process.versions.node.split('.')[0]" 2>$null if ([int]$major -lt 20) { Write-Failure ("Node.js 20 or newer is required; found " + (& node -v) + ".") return } if (-not (Get-Command npm -ErrorAction SilentlyContinue)) { Write-Failure "'npm' was not found on PATH. It ships with Node.js." return } $package = "@persistmemory/cli" if ($env:PM_VERSION) { $package = "@persistmemory/cli@" + $env:PM_VERSION } Write-Step ("Fetching " + $package) # No elevation. An installer that opens an Administrator prompt on its own is # one the user cannot audit after the fact; if the global prefix is not # writable, npm says so and the guidance below explains the safe ways round. & npm install -g $package 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { Write-Host "" Write-Note "npm could not install globally. That is usually a permissions" Write-Note "problem with npm's own prefix rather than anything to do with" Write-Note "this package. Two ways forward, neither needing Administrator:" Write-Host "" Write-Host " 1. Point npm somewhere you own:" Write-Host (' npm config set prefix "' + $env:LOCALAPPDATA + '\npm"') Write-Host " irm https://persistmemory.com/install.ps1 | iex" Write-Host "" Write-Host " 2. Skip installing and run it on demand:" Write-Host " npx @persistmemory/cli auth login" Write-Host "" Write-Failure "install failed" return } if (-not (Get-Command pm -ErrorAction SilentlyContinue)) { Write-Host "" Write-Note "Installed, but 'pm' is not on your PATH. Add npm's global" Write-Note "directory to it, then open a new terminal:" Write-Host "" Write-Host (' $env:Path += ";' + (& npm prefix -g) + '"') Write-Host "" } Write-Step "Installed" Write-Host "" Write-Host "Next:" Write-Host " pm auth login sign in with your browser" Write-Host ' pm remember "we chose Postgres" capture something' Write-Host " pm start a session" Write-Host "" Write-Host "Docs: https://persistmemory.com/docs/cli" } Install-PersistMemory