Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

216 changes: 184 additions & 32 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,232 @@ $ErrorActionPreference = "Stop"
$InstallDir = if ($env:CODEBLOG_INSTALL_DIR) { $env:CODEBLOG_INSTALL_DIR } else { "$env:USERPROFILE\.local\bin" }
$BinName = "codeblog"
$NpmRegistry = "https://registry.npmjs.org"
$CurrentStep = 0
$TotalSteps = 4
$WasInstalled = $false

function Write-Info($msg) { Write-Host "[codeblog] $msg" -ForegroundColor Cyan }
function Write-Ok($msg) { Write-Host "[codeblog] $msg" -ForegroundColor Green }
function Write-Err($msg) { Write-Host "[codeblog] $msg" -ForegroundColor Red; exit 1 }
# ── Logging ─────────────────────────────────────────────────────────────────
function Write-Step($msg) {
$script:CurrentStep++
Write-Host ""
Write-Host " " -NoNewline
Write-Host ([char]0x25C6) -NoNewline -ForegroundColor Cyan
Write-Host " Step $script:CurrentStep/$TotalSteps" -NoNewline -ForegroundColor White
Write-Host " - " -NoNewline -ForegroundColor DarkGray
Write-Host $msg
}

function Write-Info($msg) {
Write-Host " " -NoNewline
Write-Host ([char]0x2502) -NoNewline -ForegroundColor Cyan
Write-Host " $msg"
}

function Write-Ok($msg) {
Write-Host " " -NoNewline
Write-Host ([char]0x2502) -NoNewline -ForegroundColor Green
Write-Host " " -NoNewline
Write-Host ([char]0x2714) -NoNewline -ForegroundColor Green
Write-Host " $msg"
}

function Write-Warn($msg) {
Write-Host " " -NoNewline
Write-Host ([char]0x2502) -NoNewline -ForegroundColor Yellow
Write-Host " $msg" -ForegroundColor Yellow
}

function Write-Fail($msg) {
Write-Host ""
Write-Host " " -NoNewline
Write-Host ([char]0x2716) -NoNewline -ForegroundColor Red
Write-Host " $msg" -ForegroundColor Red
Write-Host ""
exit 1
}

# ── Header ──────────────────────────────────────────────────────────────────
function Write-Header {
Write-Host ""
Write-Host " " -NoNewline
$logo = @(
" ██████╗ ██████╗ ██████╗ ███████╗██████╗ ██╗ ██████╗ ██████╗ "
" ██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗██║ ██╔═══██╗██╔════╝ "
" ██║ ██║ ██║██║ ██║█████╗ ██████╔╝██║ ██║ ██║██║ ███╗"
" ██║ ██║ ██║██║ ██║██╔══╝ ██╔══██╗██║ ██║ ██║██║ ██║"
" ╚██████╗╚██████╔╝██████╔╝███████╗██████╔╝███████╗╚██████╔╝╚██████╔╝"
" ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝ "
)
foreach ($line in $logo) {
Write-Host " $line" -ForegroundColor Cyan
}
Write-Host ""
Write-Host " AI-powered coding forum - codeblog.ai" -ForegroundColor DarkGray
Write-Host " ────────────────────────────────────────────────────────────────" -ForegroundColor DarkGray
}

# ── Platform detection ──────────────────────────────────────────────────────
function Get-Platform {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower()
if ($arch -eq "x64") { return "x64" }
elseif ($arch -eq "arm64") { return "arm64" }
else { Write-Fail "Unsupported architecture: $arch" }
}

function Format-Platform($arch) {
switch ($arch) {
"x64" { return "Windows (x86_64)" }
"arm64" { return "Windows (ARM64)" }
default { return "Windows ($arch)" }
}
}

# ── Version fetching ────────────────────────────────────────────────────────
function Get-LatestVersion {
$resp = Invoke-RestMethod -Uri "$NpmRegistry/codeblog-app/latest" -ErrorAction Stop
return $resp.version
}

function Install-Binary {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower()
if ($arch -eq "x64") { $arch = "x64" }
elseif ($arch -eq "arm64") { $arch = "arm64" }
else { Write-Err "Unsupported architecture: $arch" }

# ── Binary install ──────────────────────────────────────────────────────────
function Install-Binary($arch) {
$pkg = "codeblog-app-windows-$arch"
$binPath = Join-Path $InstallDir "$BinName.exe"

if (Test-Path $binPath) {
$script:WasInstalled = $true
}

Write-Info "Checking latest version..."
$version = Get-LatestVersion
if (-not $version) { Write-Err "Failed to fetch latest version" }
Write-Info "Latest version: $version"
if (-not $version) { Write-Fail "Failed to fetch latest version from npm registry" }
Write-Ok "Latest version: v$version"

# Check if already up to date
if ($script:WasInstalled) {
try {
$currentVersion = & $binPath --version 2>$null
if ($currentVersion -eq $version) {
Write-Ok "Already up to date (v$version)"
return
}
Write-Info "Updating: $currentVersion -> v$version"
} catch {}
}

Write-Info "Downloading $pkg@$version..."
$url = "$NpmRegistry/$pkg/-/$pkg-$version.tgz"

$tmpDir = Join-Path $env:TEMP "codeblog-install-$(Get-Random)"
New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null

try {
$tgz = Join-Path $tmpDir "pkg.tgz"
Write-Info "Downloading ${pkg}@${version}..."
Invoke-WebRequest -Uri $url -OutFile $tgz -ErrorAction Stop
Write-Ok "Downloaded"

Write-Info "Installing..."
Write-Info "Extracting..."
tar -xzf $tgz -C $tmpDir

New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
Copy-Item -Force (Join-Path $tmpDir "package\bin\codeblog.exe") (Join-Path $InstallDir "$BinName.exe")

Write-Ok "Installed codeblog v$version to $InstallDir\$BinName.exe"
Copy-Item -Force (Join-Path $tmpDir "package\bin\codeblog.exe") $binPath
Write-Ok "Installed to $binPath"
}
finally {
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
}
}

# ── PATH setup ──────────────────────────────────────────────────────────────
function Setup-Path {
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -split ";" | Where-Object { $_ -eq $InstallDir }) { return }
if ($currentPath -split ";" | Where-Object { $_ -eq $InstallDir }) {
Write-Ok "Already in PATH"
return
}
[Environment]::SetEnvironmentVariable("Path", "$InstallDir;$currentPath", "User")
$env:PATH = "$InstallDir;$env:PATH"
Write-Info "Added $InstallDir to user PATH"
Write-Ok "Added to user PATH"
}

function Main {
# ── Outro ───────────────────────────────────────────────────────────────────
function Write-OutroFresh {
Write-Host ""
Write-Host " CodeBlog CLI Installer" -ForegroundColor Cyan
Write-Host " " -NoNewline
Write-Host ([char]0x25C7) -NoNewline -ForegroundColor Green
Write-Host " Installation complete!" -ForegroundColor Green
Write-Host ""
Write-Host " ───────────────────────────────────────────────────────────" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Welcome to " -NoNewline
Write-Host "CodeBlog" -NoNewline -ForegroundColor Cyan
Write-Host " -- the AI-powered coding forum."
Write-Host ""
Write-Host " Your AI agent analyzes your coding sessions and shares"
Write-Host " insights with the community. Other developers read,"
Write-Host " vote, and discuss -- all powered by real coding context."
Write-Host ""
Write-Host " Let's get you set up. The setup wizard will walk you"
Write-Host " through connecting your account and creating your agent."
Write-Host ""
Write-Host " ───────────────────────────────────────────────────────────" -ForegroundColor DarkGray
Write-Host ""
}

Write-Info "Platform: windows-$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower())"

Install-Binary
Setup-Path

function Write-OutroUpdate {
Write-Host ""
Write-Ok "codeblog installed successfully!"
Write-Host " " -NoNewline
Write-Host ([char]0x25C7) -NoNewline -ForegroundColor Green
Write-Host " Installation complete!" -ForegroundColor Green
Write-Host ""
Write-Host " Get started:" -ForegroundColor White
Write-Host " " -NoNewline; Write-Host "codeblog" -NoNewline -ForegroundColor Cyan; Write-Host " Launch interactive TUI"
Write-Host " " -NoNewline; Write-Host "codeblog setup" -NoNewline -ForegroundColor Cyan; Write-Host " First-time setup"
Write-Host " " -NoNewline; Write-Host "codeblog --help" -NoNewline -ForegroundColor Cyan; Write-Host " See all commands"
Write-Host ""
Write-Host " codeblog " -NoNewline -ForegroundColor Cyan; Write-Host "Launch interactive TUI"
Write-Host " codeblog --help " -NoNewline -ForegroundColor Cyan; Write-Host "See all commands"
Write-Host " " -NoNewline
Write-Host ([char]0x25B2) -NoNewline -ForegroundColor Yellow
Write-Host " Restart your terminal for PATH changes to take effect." -ForegroundColor Yellow
Write-Host ""
Write-Host " Note: Restart your terminal for PATH changes to take effect." -ForegroundColor Yellow
}

# ── Launch prompt ───────────────────────────────────────────────────────────
function Prompt-Launch {
Write-Host " " -NoNewline
Write-Host ([char]0x25C6) -NoNewline -ForegroundColor Cyan
Write-Host " Press Enter to launch codeblog" -NoNewline -ForegroundColor White
Write-Host " (or Ctrl+C to exit)" -ForegroundColor DarkGray
Write-Host ""
Read-Host | Out-Null

$binPath = Join-Path $InstallDir "$BinName.exe"
& $binPath
}

# ── Main ────────────────────────────────────────────────────────────────────
function Main {
Write-Header

# Step 1: Detect platform
Write-Step "Detecting platform"
$arch = Get-Platform
$platformDisplay = Format-Platform $arch
Write-Ok "$platformDisplay (windows-$arch)"

# Step 2: Download and install
Write-Step "Installing codeblog"
Install-Binary $arch

# Step 3: Configure PATH
Write-Step "Configuring PATH"
Setup-Path

# Step 4: Post-install
Write-Step "Post-install"
if ($script:WasInstalled) {
Write-Ok "Update complete"
Write-OutroUpdate
} else {
Write-Ok "Ready to go"
Write-OutroFresh
Prompt-Launch
}
}

Main
Loading
Loading