Last active
October 20, 2025 03:55
-
-
Save guinetik/41550d5ffe167a2bf4bc056368400356 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # install.ps1 | |
| # Simple installer script for AMH2W module | |
| [CmdletBinding()] | |
| param( | |
| [string]$InstallPath = $(($env:PSModulePath -split ';')[0] + "\AMH2W") | |
| ) | |
| $ErrorActionPreference = 'Stop' | |
| $ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path | |
| Write-Host "Installing AMH2W module to $InstallPath" -ForegroundColor Cyan | |
| # Create module folder structure | |
| if (-not (Test-Path $InstallPath)) { | |
| New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null | |
| } | |
| # Create core folder | |
| $coreFolder = Join-Path $InstallPath "core" | |
| if (-not (Test-Path $coreFolder)) { | |
| New-Item -ItemType Directory -Path $coreFolder -Force | Out-Null | |
| } | |
| # Copy core files (only PS1 files in core) | |
| Get-ChildItem -Path "$ScriptPath\core" -Filter "*.ps1" | ForEach-Object { | |
| $destFile = Join-Path $coreFolder $_.Name | |
| Copy-Item -Path $_.FullName -Destination $destFile -Force | |
| Write-Host " Copied core file: $($_.Name)" -ForegroundColor DarkGray | |
| } | |
| # Create command hierarchy | |
| $allFolder = Join-Path $InstallPath "all" | |
| if (-not (Test-Path $allFolder)) { | |
| New-Item -ItemType Directory -Path $allFolder -Force | Out-Null | |
| } | |
| # Mirror the namespace hierarchy | |
| Get-ChildItem -Path "$ScriptPath\all" -Directory -Recurse | ForEach-Object { | |
| $relativePath = $_.FullName.Substring("$ScriptPath\all".Length) | |
| $targetPath = Join-Path $allFolder $relativePath | |
| if (-not (Test-Path $targetPath)) { | |
| New-Item -ItemType Directory -Path $targetPath -Force | Out-Null | |
| } | |
| } | |
| # Copy all files (not just PS1) from the all/ directory | |
| Get-ChildItem -Path "$ScriptPath\all" -File -Recurse | ForEach-Object { | |
| $relativePath = $_.FullName.Substring("$ScriptPath\all".Length) | |
| $targetFile = Join-Path $allFolder $relativePath | |
| Copy-Item -Path $_.FullName -Destination $targetFile -Force | |
| # Show different messages based on file type | |
| if ($_.Extension -eq ".ps1") { | |
| Write-Host " Copied command file: $relativePath" -ForegroundColor DarkGray | |
| } else { | |
| Write-Host " Copied resource file: $relativePath" -ForegroundColor DarkCyan | |
| } | |
| } | |
| # Copy module entrypoint | |
| Copy-Item -Path "$ScriptPath\AMH2W.psm1" -Destination "$InstallPath\AMH2W.psm1" -Force | |
| Write-Host " Copied module entry point: AMH2W.psm1" -ForegroundColor DarkGray | |
| # Create module manifest | |
| $manifestPath = Join-Path $InstallPath "AMH2W.psd1" | |
| New-ModuleManifest -Path $manifestPath ` | |
| -RootModule "AMH2W.psm1" ` | |
| -ModuleVersion "1.1.2" ` | |
| -Author "AMH2W Contributors" ` | |
| -Description "All My Homies Hate Windows - PowerShell utility library" ` | |
| -PowerShellVersion "5.1" ` | |
| -FunctionsToExport @("all", "π€") | |
| Write-Host "`nInstallation complete." -ForegroundColor Green | |
| Write-Host "To use the module, restart PowerShell or run: " -NoNewline | |
| Write-Host "Import-Module AMH2W -Force" -ForegroundColor Yellow | |
| Write-Host "`nTry these commands:" -ForegroundColor Cyan | |
| Write-Host " all" -ForegroundColor White | |
| Write-Host " all my" -ForegroundColor White | |
| Write-Host " all my homies" -ForegroundColor White | |
| Write-Host " all my homies hate" -ForegroundColor White | |
| Write-Host " all my homies hate windows" -ForegroundColor White | |
| Write-Host " all my homies hate windows version" -ForegroundColor White |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $Repo = "guinetik/amh2w" | |
| $Asset = "amh2w-1.0.2.zip" | |
| if ($args.Count -ge 1) { $Repo = $args[0] } | |
| if ($args.Count -ge 2) { $Asset = $args[1] } | |
| Write-Host "π Starting AMH2W installation..." -ForegroundColor Cyan | |
| # Construct the download URL | |
| $downloadUrl = "https://github.com/$Repo/releases/latest/download/$Asset" | |
| # Create a temp folder | |
| $tempDir = New-Item -ItemType Directory -Path ([System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid().ToString()) | |
| $zipPath = Join-Path $tempDir "release.zip" | |
| Write-Host "β¬οΈ Downloading latest release from $downloadUrl..." -ForegroundColor Yellow | |
| Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath | |
| Write-Host "π¦ Extracting ZIP to $tempDir..." -ForegroundColor Yellow | |
| Expand-Archive -Path $zipPath -DestinationPath $tempDir | |
| # Find install.ps1 in the extracted folder | |
| $installScript = Get-ChildItem -Path $tempDir -Recurse -Filter install.ps1 | Select-Object -First 1 | |
| if (-not $installScript) { | |
| Write-Host "β install.ps1 not found in the extracted release. Aborting installation." -ForegroundColor Red | |
| exit 1 | |
| } | |
| Write-Host "β‘ Running installer: $($installScript.FullName)" -ForegroundColor Cyan | |
| # Detect PowerShell edition and use the correct executable | |
| if ($PSVersionTable.PSEdition -eq 'Core') { | |
| $psExe = 'pwsh' | |
| } else { | |
| $psExe = 'powershell' | |
| } | |
| # Run the install script | |
| Start-Process $psExe -ArgumentList "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", $installScript.FullName -Wait | |
| # Optional: Clean up | |
| Write-Host "π§Ή Cleaning up temporary files..." -ForegroundColor DarkGray | |
| Get-Content $zipPath | Out-Null # Ensure file is not locked | |
| Remove-Item -Recurse -Force $tempDir | |
| Write-Host "β Module installed!" -ForegroundColor Green | |
| # Add AMH2W module import to the user's profile if not already present | |
| $profilePath = $PROFILE | |
| $importLine = "Import-Module AMH2W" | |
| Write-Host "π Checking your PowerShell profile..." -ForegroundColor Cyan | |
| if (-not (Test-Path $profilePath)) { | |
| Write-Host "π Profile not found. Creating new profile at: $profilePath" -ForegroundColor Yellow | |
| New-Item -ItemType File -Path $profilePath -Force | Out-Null | |
| } | |
| $profileContent = Get-Content $profilePath -Raw | |
| if ($profileContent -notmatch [regex]::Escape($importLine)) { | |
| Add-Content -Path $profilePath -Value "`n$importLine" | |
| Write-Host "β¨ Added AMH2W module import to your profile!" -ForegroundColor Green | |
| Write-Host "β‘οΈ Next time you open PowerShell, AMH2W will be ready to use! π" -ForegroundColor Green | |
| Write-Host " Profile updated: $profilePath" -ForegroundColor DarkGray | |
| } else { | |
| Write-Host "β AMH2W module import already present in your profile. No changes made." -ForegroundColor Green | |
| } | |
| Write-Host "π All done! Enjoy using AMH2W! π€" -ForegroundColor Cyan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # pack.ps1 | |
| # Creates a distribution package for AMH2W module | |
| [CmdletBinding()] | |
| param( | |
| [string]$Version = "1.0.2", | |
| [string]$OutputPath = ".", | |
| [switch]$Force = $false | |
| ) | |
| $ErrorActionPreference = 'Stop' | |
| $ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path | |
| # Define what to exclude from the package | |
| $ExcludeItems = @( | |
| "test", # Test folder | |
| "tests", # Alternative test folder name | |
| "docs", # Documentation folder | |
| "build.ps1", # Build script | |
| "merge.ps1", # Merge script | |
| "pack.ps1", # This pack script itself | |
| "*.md", # All markdown files | |
| ".git", # Git folder | |
| ".vscode", # VS Code settings | |
| "*.zip", # Any existing zip files | |
| "release", # Release folder if it exists | |
| "temp_pack" # Temporary packing folder | |
| ".gitignore" | |
| "fix-encoding.ps1" | |
| "LICENSE" | |
| ) | |
| Write-Host "π AMH2W Release Packager" -ForegroundColor Cyan | |
| Write-Host "Version: $Version" -ForegroundColor Yellow | |
| Write-Host "" | |
| # Create output file name | |
| $zipFileName = "release.zip" | |
| $zipFilePath = Join-Path (Resolve-Path $OutputPath) $zipFileName | |
| # Check if output file already exists | |
| if ((Test-Path $zipFilePath) -and -not $Force) { | |
| Write-Host "β Release package already exists: $zipFilePath" -ForegroundColor Red | |
| Write-Host "Use -Force to overwrite" -ForegroundColor Yellow | |
| exit 1 | |
| } | |
| # Create temporary packing directory | |
| $tempDir = Join-Path $ScriptPath "temp_pack" | |
| if (Test-Path $tempDir) { | |
| Remove-Item $tempDir -Recurse -Force | |
| } | |
| New-Item -ItemType Directory -Path $tempDir -Force | Out-Null | |
| try { | |
| Write-Host "π¦ Preparing package contents..." -ForegroundColor Green | |
| # Get all items in the root directory | |
| $allItems = Get-ChildItem -Path $ScriptPath -Force | |
| # Filter out excluded items | |
| $includedItems = $allItems | Where-Object { | |
| $item = $_ | |
| $shouldExclude = $false | |
| foreach ($exclude in $ExcludeItems) { | |
| if ($exclude.Contains("*")) { | |
| # Handle wildcards | |
| if ($item.Name -like $exclude) { | |
| $shouldExclude = $true | |
| break | |
| } | |
| } else { | |
| # Handle exact matches | |
| if ($item.Name -eq $exclude) { | |
| $shouldExclude = $true | |
| break | |
| } | |
| } | |
| } | |
| return -not $shouldExclude | |
| } | |
| # Copy included items to temp directory | |
| Write-Host "π Including files and folders:" -ForegroundColor Yellow | |
| foreach ($item in $includedItems) { | |
| $destPath = Join-Path $tempDir $item.Name | |
| if ($item.PSIsContainer) { | |
| Copy-Item -Path $item.FullName -Destination $destPath -Recurse -Force | |
| Write-Host " π $($item.Name)/" -ForegroundColor Cyan | |
| } else { | |
| Copy-Item -Path $item.FullName -Destination $destPath -Force | |
| Write-Host " π $($item.Name)" -ForegroundColor White | |
| } | |
| } | |
| Write-Host "" | |
| Write-Host "π« Excluded items:" -ForegroundColor Red | |
| $allItems | Where-Object { | |
| $item = $_ | |
| $shouldExclude = $false | |
| foreach ($exclude in $ExcludeItems) { | |
| if ($exclude.Contains("*")) { | |
| if ($item.Name -like $exclude) { | |
| $shouldExclude = $true | |
| break | |
| } | |
| } else { | |
| if ($item.Name -eq $exclude) { | |
| $shouldExclude = $true | |
| break | |
| } | |
| } | |
| } | |
| return $shouldExclude | |
| } | ForEach-Object { | |
| if ($_.PSIsContainer) { | |
| Write-Host " π $($_.Name)/" -ForegroundColor DarkRed | |
| } else { | |
| Write-Host " π $($_.Name)" -ForegroundColor DarkRed | |
| } | |
| } | |
| Write-Host "" | |
| Write-Host "ποΈ Creating release package..." -ForegroundColor Green | |
| # Create the ZIP file | |
| if (Test-Path $zipFilePath) { | |
| Remove-Item $zipFilePath -Force | |
| } | |
| # Use Compress-Archive to create the ZIP | |
| Compress-Archive -Path "$tempDir\*" -DestinationPath $zipFilePath -Force | |
| # Get file size for display | |
| $zipFile = Get-Item $zipFilePath | |
| $fileSizeMB = [math]::Round($zipFile.Length / 1MB, 2) | |
| Write-Host "" | |
| Write-Host "β Release package created successfully!" -ForegroundColor Green | |
| Write-Host "π¦ Package: $zipFileName" -ForegroundColor Cyan | |
| Write-Host "π Location: $zipFilePath" -ForegroundColor Yellow | |
| Write-Host "π Size: $fileSizeMB MB" -ForegroundColor White | |
| Write-Host "" | |
| Write-Host "π Ready for GitHub release!" -ForegroundColor Magenta | |
| # Show package contents summary | |
| $packagedItems = Get-ChildItem -Path $tempDir | |
| Write-Host "" | |
| Write-Host "π Package contents summary:" -ForegroundColor Yellow | |
| Write-Host " Files: $($packagedItems | Where-Object { -not $_.PSIsContainer } | Measure-Object | Select-Object -ExpandProperty Count)" -ForegroundColor White | |
| Write-Host " Folders: $($packagedItems | Where-Object { $_.PSIsContainer } | Measure-Object | Select-Object -ExpandProperty Count)" -ForegroundColor White | |
| # List main folders included | |
| $mainFolders = $packagedItems | Where-Object { $_.PSIsContainer } | Select-Object -ExpandProperty Name | |
| if ($mainFolders.Count -gt 0) { | |
| Write-Host " Main folders: $($mainFolders -join ', ')" -ForegroundColor Cyan | |
| } | |
| } finally { | |
| # Clean up temporary directory | |
| if (Test-Path $tempDir) { | |
| Remove-Item $tempDir -Recurse -Force | |
| Write-Host "" | |
| Write-Host "π§Ή Cleaned up temporary files" -ForegroundColor DarkGray | |
| } | |
| } | |
| Write-Host "" | |
| Write-Host "π‘ Usage instructions:" -ForegroundColor Yellow | |
| Write-Host " 1. Upload $zipFileName to GitHub releases" -ForegroundColor White | |
| Write-Host " 2. Users can download and extract" -ForegroundColor White | |
| Write-Host " 3. Run: .\install.ps1 to install the module" -ForegroundColor White |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment