|
| 1 | +#!/usr/bin/env pwsh |
| 2 | +############################################################################################################## |
| 3 | + |
| 4 | +Function Show-Usage { |
| 5 | + " |
| 6 | +vagrant = 'it-gro/win10-ltsc-eval' |
| 7 | +download = 'https://microsoft.com/en-us/evalcenter' |
| 8 | +package = 'https://learn.microsoft.com/en-us/mem/configmgr/develop/apps/how-to-create-the-windows-installer-file-msi' |
| 9 | +shell = 'https://learn.microsoft.com/en-us/powershell' |
| 10 | +
|
| 11 | +Usage: pwsh -File $($PSCommandPath) [OPTIONS] |
| 12 | +Options: |
| 13 | + build |
| 14 | + lint |
| 15 | +" | Out-Host |
| 16 | +} |
| 17 | + |
| 18 | +Function Build-Project { |
| 19 | + New-Variable -Option Constant -Name VAR -Value @{ |
| 20 | + Src = 'Examples' |
| 21 | + Use = 'Package' |
| 22 | + Pkg = 'Package\components.txt' |
| 23 | + } |
| 24 | + If (! (Test-Path -Path $Var.Src)) { |
| 25 | + "$([char]27)[31m.... Source do not find!$([char]27)[0m" | Out-Host |
| 26 | + Exit 1 |
| 27 | + } |
| 28 | + If (Test-Path -Path '.gitmodules') { |
| 29 | + & git submodule update --init --recursive --force --remote | Out-Host |
| 30 | + "$([char]27)[32m.... [[$($LastExitCode)]] git submodule update$([char]27)[0m" | Out-Host |
| 31 | + } |
| 32 | + @( |
| 33 | + @{ |
| 34 | + Cmd = 'lazbuild' |
| 35 | + Url = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe' |
| 36 | + Path = "C:\Lazarus" |
| 37 | + } |
| 38 | + ) | Where-Object { ! (Test-Path -Path $_.Path) } | |
| 39 | + ForEach-Object { |
| 40 | + $_.Url | Request-File | Install-Program |
| 41 | + $Env:PATH+=";$($_.Path)" |
| 42 | + (Get-Command $_.Cmd).Source | Out-Host |
| 43 | + } |
| 44 | + If (Test-Path -Path $VAR.Use) { |
| 45 | + If (Test-Path -Path $VAR.Pkg) { |
| 46 | + Get-Content -Path $VAR.Pkg | |
| 47 | + Where-Object { |
| 48 | + ! (Test-Path -Path "$($VAR.Use)\$($_)") && |
| 49 | + ! (& lazbuild --verbose-pkgsearch $_ ) && |
| 50 | + ! (& lazbuild --add-package $_) |
| 51 | + } | ForEach-Object { |
| 52 | + Return @{ |
| 53 | + Uri = "https://packages.lazarus-ide.org/$($_).zip" |
| 54 | + Path = "$($VAR.Use)\$($_)" |
| 55 | + OutFile = (New-TemporaryFile).FullName |
| 56 | + } |
| 57 | + } | ForEach-Object -Parallel { |
| 58 | + Invoke-WebRequest -OutFile $_.OutFile -Uri $_.Uri |
| 59 | + Expand-Archive -Path $_.OutFile -DestinationPath $_.Path |
| 60 | + Remove-Item $_.OutFile |
| 61 | + Return "$([char]27)[32m.... download $($_.Uri)$([char]27)[0m" |
| 62 | + } | Out-Host |
| 63 | + } |
| 64 | + (Get-ChildItem -Filter '*.lpk' -Recurse -File –Path $VAR.Use).FullName | |
| 65 | + ForEach-Object { |
| 66 | + & lazbuild --add-package-link $_ | Out-Null |
| 67 | + Return "$([char]27)[32m.... [$($LastExitCode)] add package link $($_)$([char]27)[0m" |
| 68 | + } | Out-Host |
| 69 | + } |
| 70 | + Exit ( |
| 71 | + (Get-ChildItem -Filter '*.lpi' -Recurse -File –Path $Var.Src).FullName | |
| 72 | + Sort-Object | |
| 73 | + ForEach-Object { |
| 74 | + $Output = (& lazbuild --build-all --recursive --no-write-project $_) |
| 75 | + $Result = @("$([char]27)[32m.... [$($LastExitCode)] build project $($_)$([char]27)[0m") |
| 76 | + $exitCode = Switch ($LastExitCode) { |
| 77 | + 0 { |
| 78 | + $Result += $Output | Select-String -Pattern 'Linking' |
| 79 | + 0 |
| 80 | + } |
| 81 | + Default { |
| 82 | + $Result += $Output | Select-String -Pattern 'Error:', 'Fatal:' |
| 83 | + 1 |
| 84 | + } |
| 85 | + } |
| 86 | + $Result | Out-Host |
| 87 | + Return $exitCode |
| 88 | + } | Measure-Object -Sum |
| 89 | + ).Sum |
| 90 | +} |
| 91 | + |
| 92 | +Function Request-File { |
| 93 | + While ($Input.MoveNext()) { |
| 94 | + New-Variable -Option Constant -Name VAR -Value @{ |
| 95 | + Uri = $Input.Current |
| 96 | + OutFile = (Split-Path -Path $Input.Current -Leaf).Split('?')[0] |
| 97 | + } |
| 98 | + Invoke-WebRequest @VAR |
| 99 | + Return $VAR.OutFile |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +Function Install-Program { |
| 104 | + While ($Input.MoveNext()) { |
| 105 | + Switch ((Split-Path -Path $Input.Current -Leaf).Split('.')[-1]) { |
| 106 | + 'msi' { |
| 107 | + & msiexec /passive /package $Input.Current | Out-Null |
| 108 | + } |
| 109 | + Default { |
| 110 | + & ".\$($Input.Current)" /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Null |
| 111 | + } |
| 112 | + } |
| 113 | + Remove-Item $Input.Current |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +Function Request-URL([Switch] $Post) { |
| 118 | + $VAR = Switch ($Post) { |
| 119 | + True { |
| 120 | + Return @{ |
| 121 | + Method = 'POST' |
| 122 | + Headers = @{ |
| 123 | + ContentType = 'application/json' |
| 124 | + } |
| 125 | + Uri = 'https://postman-echo.com/post' |
| 126 | + Body = @{ |
| 127 | + One = '1' |
| 128 | + } | ConvertTo-Json |
| 129 | + } |
| 130 | + } |
| 131 | + False { |
| 132 | + Return @{ |
| 133 | + Uri = 'https://postman-echo.com/get' |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + Return (Invoke-WebRequest @VAR | ConvertFrom-Json).Headers |
| 138 | +} |
| 139 | + |
| 140 | +Function Switch-Action { |
| 141 | + $ErrorActionPreference = 'stop' |
| 142 | + Set-PSDebug -Strict #-Trace 1 |
| 143 | + Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath |
| 144 | + If ($args.count -gt 0) { |
| 145 | + Switch ($args[0]) { |
| 146 | + 'lint' { |
| 147 | + Invoke-ScriptAnalyzer -EnableExit -Recurse -Path '.' |
| 148 | + (Get-ChildItem -Filter '*.ps1' -Recurse -Path '.').FullName | |
| 149 | + ForEach-Object { |
| 150 | + Invoke-Formatter -ScriptDefinition $(Get-Content -Path $_ | Out-String) | |
| 151 | + Set-Content -Path $_ |
| 152 | + } |
| 153 | + } |
| 154 | + 'build' { |
| 155 | + Build-Project |
| 156 | + } |
| 157 | + Default { |
| 158 | + Show-Usage |
| 159 | + } |
| 160 | + } |
| 161 | + } Else { |
| 162 | + Show-Usage |
| 163 | + } |
| 164 | +} |
| 165 | + |
| 166 | +############################################################################################################## |
| 167 | +Switch-Action @args |
0 commit comments