|
| 1 | +#Requires -PSEdition Core |
| 2 | +[CmdletBinding()] |
| 3 | +param ( |
| 4 | + [String] |
| 5 | + $ReleaseBaseName = "GruppOne-Stalker", |
| 6 | + [String] |
| 7 | + $VersionBuildMetadata |
| 8 | +) |
| 9 | + |
| 10 | +try { |
| 11 | + java -version | Out-Null |
| 12 | +} |
| 13 | +catch [System.Management.Automation.CommandNotFoundException] { |
| 14 | + throw "java is not available on PATH" |
| 15 | +} |
| 16 | + |
| 17 | +if (-not $env:PLANTUML_JAR) { |
| 18 | + throw "environment variable PLANTUML_JAR is not set" |
| 19 | +} |
| 20 | + |
| 21 | +try { |
| 22 | + lualatex -v | Out-Null |
| 23 | +} |
| 24 | +catch [System.Management.Automation.CommandNotFoundException] { |
| 25 | + throw "lualatex is not available on PATH" |
| 26 | +} |
| 27 | + |
| 28 | +$lualatexCommand = { |
| 29 | + [CmdletBinding()] |
| 30 | + param( |
| 31 | + # LaTeX file to build |
| 32 | + [Parameter(Position = 0, Mandatory = $true)] |
| 33 | + [String] |
| 34 | + $sourceFilename, |
| 35 | + # LaTeX file to build |
| 36 | + [Parameter(Position = 1, Mandatory = $true)] |
| 37 | + [String] |
| 38 | + $destinationFilename |
| 39 | + ) |
| 40 | + [System.IO.FileInfo]$sourceFile = Get-Item -LiteralPath $sourceFilename |
| 41 | + $compiledSourceFilename = $sourceFile.FullName -replace "\.tex$", ".pdf" |
| 42 | + |
| 43 | + Set-Location $sourceFile.Directory |
| 44 | + |
| 45 | + lualatex ` |
| 46 | + --interaction=nonstopmode ` |
| 47 | + --file-line-error ` |
| 48 | + --shell-escape ` |
| 49 | + $sourceFile.Name |
| 50 | + |
| 51 | + if ($LASTEXITCODE) { |
| 52 | + Write-Error "something went wrong while compiling $($sourceFile) " |
| 53 | + } |
| 54 | + |
| 55 | + if (-not (Test-Path $compiledSourceFilename)) { |
| 56 | + throw "no output produced" |
| 57 | + } |
| 58 | + |
| 59 | + lualatex ` |
| 60 | + --interaction=nonstopmode ` |
| 61 | + --file-line-error ` |
| 62 | + --shell-escape ` |
| 63 | + $sourceFile.Name |
| 64 | + |
| 65 | + $compiledSource = Get-Item -LiteralPath $compiledSourceFilename |
| 66 | + Copy-Item -Force $compiledSource $destinationFilename |
| 67 | +} |
| 68 | + |
| 69 | +Write-Output "building PlantUML diagrams" |
| 70 | + |
| 71 | +$rawOut = java -jar ${env:PLANTUML_JAR} ` |
| 72 | + -progress ` |
| 73 | + -failfast ` |
| 74 | + -checkmetadata ` |
| 75 | + -charset "UTF-8" ` |
| 76 | + -x "**/commons/style/*.pu" ` |
| 77 | + -o "img" ` |
| 78 | + "**/diagrams/*.pu" |
| 79 | + |
| 80 | +Write-Output "`n--------------------------" |
| 81 | + |
| 82 | +if ($LASTEXITCODE -and $rawOut -notmatch "No diagram found") { |
| 83 | + throw "something went wrong while exporting UML diagrams" |
| 84 | +} |
| 85 | + |
| 86 | +$productVersion = ( |
| 87 | + Get-Item -LiteralPath "commons/template.tex" | |
| 88 | + Select-String -Pattern "^\\setVersione{\d+\.\d+\.\d+}$" | |
| 89 | + Select-Object -ExpandProperty Line |
| 90 | +) -replace "^\\setVersione{" -replace "}$" |
| 91 | + |
| 92 | +if (-not $productVersion) { |
| 93 | + throw "Product version was not found" |
| 94 | +} |
| 95 | + |
| 96 | +$ReleaseName = $ReleaseBaseName + "_" + "$productVersion" |
| 97 | +if ($VersionBuildMetadata) { |
| 98 | + $ReleaseName += "+" + $VersionBuildMetadata |
| 99 | +} |
| 100 | + |
| 101 | +$OutputBaseDirectory = "$(Get-Location)/.releases/$ReleaseName" |
| 102 | + |
| 103 | +if (-not (Test-Path $OutputBaseDirectory)) { |
| 104 | + Write-Output "created destination folder $OutputBaseDirectory" |
| 105 | + New-Item -ItemType Directory $OutputBaseDirectory |
| 106 | + |
| 107 | + New-Item -ItemType Directory "$OutputBaseDirectory/esterni" |
| 108 | + New-Item -ItemType Directory "$OutputBaseDirectory/esterni/verbali" |
| 109 | + New-Item -ItemType Directory "$OutputBaseDirectory/interni" |
| 110 | + New-Item -ItemType Directory "$OutputBaseDirectory/interni/verbali" |
| 111 | +} |
| 112 | + |
| 113 | +# this is horrible |
| 114 | +$documents = @( |
| 115 | + [PSCustomObject]@{ |
| 116 | + SourceFile = Get-Item "esterni/analisi-dei-requisiti/analisi-dei-requisiti.tex" |
| 117 | + Destination = [IO.Path]::Combine($OutputBaseDirectory, "esterni", "analisi-dei-requisiti_v$productVersion.pdf") |
| 118 | + }, |
| 119 | + [PSCustomObject]@{ |
| 120 | + SourceFile = Get-Item "esterni/glossario/glossario.tex" |
| 121 | + Destination = [IO.Path]::Combine($OutputBaseDirectory, "esterni", "glossario_v$productVersion.pdf") |
| 122 | + }, |
| 123 | + [PSCustomObject]@{ |
| 124 | + SourceFile = Get-Item "esterni/piano-di-progetto/piano-di-progetto.tex" |
| 125 | + Destination = [IO.Path]::Combine($OutputBaseDirectory, "esterni", "piano-di-progetto_v$productVersion.pdf") |
| 126 | + }, |
| 127 | + [PSCustomObject]@{ |
| 128 | + SourceFile = Get-Item "esterni/piano-di-qualifica/piano-di-qualifica.tex" |
| 129 | + Destination = [IO.Path]::Combine($OutputBaseDirectory, "esterni", "piano-di-qualifica_v$productVersion.pdf") |
| 130 | + }, |
| 131 | + [PSCustomObject]@{ |
| 132 | + SourceFile = Get-Item "interni/norme-di-progetto/norme-di-progetto.tex" |
| 133 | + Destination = [IO.Path]::Combine($OutputBaseDirectory, "interni", "norme-di-progetto_v$productVersion.pdf") |
| 134 | + }, |
| 135 | + # [PSCustomObject]@{ |
| 136 | + # SourceFile = Get-Item "interni/studio-di-fattibilita/studio-di-fattibilita.tex" |
| 137 | + # Destination = [IO.Path]::Combine($OutputBaseDirectory, "interni", "studio-di-fattibilita_v$productVersion.pdf") |
| 138 | + # }, |
| 139 | + [PSCustomObject]@{ |
| 140 | + SourceFile = Get-Item "lettera-di-presentazione/lettera-di-presentazione.tex" |
| 141 | + Destination = [IO.Path]::Combine($OutputBaseDirectory, "lettera-di-presentazione.pdf") |
| 142 | + } |
| 143 | +) |
| 144 | + |
| 145 | +$meetingNotes = Get-ChildItem -Path "esterni/verbali", "interni/verbali" -File -Recurse | |
| 146 | + Where-Object Name -match "verbale-(esterno|interno)_\d{4}-\d{2}-\d{2}\.tex" | ForEach-Object { |
| 147 | + |
| 148 | + $extOrInt = $_ | Split-Path -Parent | Split-Path -Parent | Split-Path -Leaf |
| 149 | + |
| 150 | + return [PSCustomObject]@{ |
| 151 | + SourceFile = $_ |
| 152 | + Destination = [IO.Path]::Combine($OutputBaseDirectory, $extOrInt, "verbali", ($_.Name -replace "\.tex", ".pdf")) |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | +$allDocuments = $documents + $meetingNotes |
| 157 | + |
| 158 | +Write-Output "Found $($documents.Length) documents and $($meetingNotes.Length) meeting notes" |
| 159 | +Write-Output "Current product version is $productVersion" |
| 160 | + |
| 161 | +$build = $allDocuments | ForEach-Object { |
| 162 | + $jobArguments = [ordered]@{ |
| 163 | + Name = "compiling latex file $($_.SourceFile.Name)" |
| 164 | + ScriptBlock = $lualatexCommand |
| 165 | + ArgumentList = @( |
| 166 | + $_.SourceFile.FullName |
| 167 | + $_.Destination |
| 168 | + ) |
| 169 | + } |
| 170 | + |
| 171 | + Start-Job @jobArguments |
| 172 | +} |
| 173 | + |
| 174 | +$build.Name |
| 175 | + |
| 176 | +Receive-Job -Wait -AutoRemoveJob $build | Out-Null |
| 177 | + |
| 178 | +## This section allows to exit gracefully, terminating incomplete jobs |
| 179 | + |
| 180 | +# # Change the default behavior of CTRL-C so that the script can intercept and use it versus just terminating the script. |
| 181 | +# [Console]::TreatControlCAsInput = $True |
| 182 | +# # Sleep for 1 second and then flush the key buffer so any previously pressed keys are discarded and the loop can monitor for the use of CTRL-C. The sleep command ensures the buffer flushes correctly. |
| 183 | +# Start-Sleep -Seconds 1 |
| 184 | +# $Host.UI.RawUI.FlushInputBuffer() |
| 185 | + |
| 186 | +# # Continue to loop while there running jobs. |
| 187 | +# While ((Get-Job $build | Where-Object State -Match Running)) { |
| 188 | +# # If a key was pressed during the loop execution, check to see if it was CTRL-C (aka "3"), and if so exit the script after clearing out any running jobs and setting CTRL-C back to normal. |
| 189 | +# If ($Host.UI.RawUI.KeyAvailable -and ($Key = $Host.UI.RawUI.ReadKey("AllowCtrlC,NoEcho,IncludeKeyUp"))) { |
| 190 | +# If ([Int]$Key.Character -eq 3) { |
| 191 | +# Write-Host "" |
| 192 | +# Write-Warning "CTRL-C was used - Shutting down any running jobs before exiting the script." |
| 193 | +# Remove-Job $build -Force -Confirm:$False |
| 194 | + |
| 195 | +# [Console]::TreatControlCAsInput = $False |
| 196 | +# _Exit-Script -HardExit $True |
| 197 | +# } |
| 198 | + |
| 199 | +# # Flush the key buffer again for the next loop. |
| 200 | +# $Host.UI.RawUI.FlushInputBuffer() |
| 201 | +# } |
| 202 | + |
| 203 | +# # Perform other work here such as process pending jobs or process out current jobs. |
| 204 | +# } |
0 commit comments