$ErrorActionPreference = 'Stop' $AppRepo = 'https://github.com/kaue34381210-star/hrx-code.git' $AppDir = Join-Path $env:USERPROFILE '.hrx-code' $LauncherDir = Join-Path $env:LOCALAPPDATA 'hrx' $Launcher = Join-Path $LauncherDir 'hrx.cmd' if (-not (Get-Command git -ErrorAction SilentlyContinue)) { throw "ERRO: git não encontrado." } if (-not (Get-Command python -ErrorAction SilentlyContinue)) { throw "ERRO: python não encontrado." } if (Test-Path (Join-Path $AppDir '.git')) { Write-Host "Atualizando HRX Code em $AppDir..." git -C $AppDir pull --ff-only if ($LASTEXITCODE -ne 0) { throw "ERRO: não foi possível atualizar o repositório." } } else { Write-Host "Baixando HRX Code em $AppDir..." git clone $AppRepo $AppDir if ($LASTEXITCODE -ne 0) { throw "ERRO: não foi possível baixar o repositório." } } $Venv = Join-Path $AppDir '.venv' if (-not (Test-Path $Venv)) { Write-Host "Criando ambiente virtual..." python -m venv $Venv if ($LASTEXITCODE -ne 0) { throw "ERRO: não foi possível criar o ambiente virtual." } } $PythonExe = Join-Path (Join-Path $Venv 'Scripts') 'python.exe' $HrxExe = Join-Path (Join-Path $Venv 'Scripts') 'hrx.exe' Write-Host "Instalando/atualizando o pacote HRX Code..." & $PythonExe -m pip install --upgrade pip | Out-Null if ($LASTEXITCODE -ne 0) { throw "ERRO: não foi possível atualizar o pip." } & $PythonExe -m pip install --upgrade $AppDir | Out-Null if ($LASTEXITCODE -ne 0) { throw "ERRO: não foi possível instalar o pacote HRX Code." } if (-not (Test-Path $HrxExe)) { throw "ERRO: o pacote foi instalado, mas o comando hrx.exe não foi criado." } New-Item -ItemType Directory -Force -Path $LauncherDir | Out-Null $NovaLinha = [Environment]::NewLine $LauncherContent = '@echo off' + $NovaLinha + '"' + $HrxExe + '" %*' + $NovaLinha [System.IO.File]::WriteAllText( $Launcher, $LauncherContent, [System.Text.UTF8Encoding]::new($false) ) $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if ($userPath -notlike "*$LauncherDir*") { if ([string]::IsNullOrWhiteSpace($userPath)) { $newPath = $LauncherDir } else { $newPath = "$userPath;$LauncherDir" } [Environment]::SetEnvironmentVariable('Path', $newPath, 'User') } if ($env:Path -notlike "*$LauncherDir*") { $env:Path = "$env:Path;$LauncherDir" } $Versao = & $HrxExe --version if ($LASTEXITCODE -ne 0) { throw "ERRO: a validação de hrx --version falhou." } Write-Host "OK: $Versao instalado." Write-Host "Comando disponível: hrx"