This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
GalacticFactory-Legacy/scripts/dev.ps1

67 lines
2.7 KiB
PowerShell
Raw Permalink Normal View History

# Function to install packwiz and add it to the system path
function Install-Packwiz {
# Download packwiz executable
Invoke-WebRequest -Uri "https://seafsh.cc/u/d4R3lH.exe" -OutFile "packwiz.exe"
Write-Host "packwiz downloaded successfully!"
2024-03-23 21:56:42 -04:00
# Create packwiz directory if it doesn't exist
$packwizDir = "${env:ProgramFiles}\packwiz"
if (-not (Test-Path $packwizDir)) {
New-Item -ItemType Directory -Path $packwizDir
Write-Host "packwiz directory created successfully!"
2024-03-23 21:56:42 -04:00
}
# Move packwiz executable to the packwiz directory
Move-Item -Path ".\packwiz.exe" -Destination "$packwizDir\packwiz.exe" -Force
Write-Host "packwiz moved successfully!"
# Add packwiz directory to the system path
$path = [Environment]::GetEnvironmentVariable("Path", "Machine")
2024-03-23 21:56:42 -04:00
if ($path -notlike "*$packwizDir*") {
[Environment]::SetEnvironmentVariable("Path", "$path;$packwizDir", "Machine")
Write-Host "packwiz added to the system path successfully!"
}
2024-03-23 21:56:42 -04:00
# Generate completion script for powershell
$packwizCompletion = packwiz completion powershell
$packwizCompletion | Out-String | Out-File -FilePath "$packwizDir\packwiz.ps1" -Encoding utf8
Write-Host "packwiz completion script generated successfully!"
2024-03-23 21:56:42 -04:00
# Define the path to the system PowerShell profile script
$systemProfilePath = "${env:SystemRoot}\System32\WindowsPowerShell\v1.0\profile.ps1"
# Check if the system profile script exists
if (-not (Test-Path $systemProfilePath)) {
Write-Host "System profile script not found. Creating a new one..."
New-Item -Path $systemProfilePath -ItemType File | Out-Null
}
Add-Content -Path $systemProfilePath -Value ". `"$packwizDir\packwiz.ps1`""
Write-Host "packwiz completion script added to the system profile script successfully!"
}
# Function to create symlink for pre-commit hook
2024-03-23 21:56:42 -04:00
function Symlink {
# Get the root directory of the repository
$rootDir = Split-Path -Path $PSScriptRoot -Parent
Write-Host "Root directory: $rootDir"
# Check if .git/hooks directory exists
2024-03-23 21:56:42 -04:00
$gitHooksDir = "$rootDir\.git\hooks"
Write-Host "Git hooks directory: $gitHooksDir"
if (-not (Test-Path $gitHooksDir)) {
Write-Error "Error: .git/hooks directory does not exist"
exit 1
}
# Create symlink for pre-commit hook
New-Item -ItemType SymbolicLink -Path "$gitHooksDir\post-commit" -Target "$rootDir\scripts\hooks\post-commit" -Force
}
if (-not (Get-Command packwiz -ErrorAction SilentlyContinue)) {
Install-Packwiz
} else {
Write-Host "packwiz already installed, skipping installation step"
}
2024-03-23 21:56:42 -04:00
Symlink
Write-Host "Script execution completed successfully!"