|
| 1 | +################################################################################ |
| 2 | +# Prepackage.ps1 |
| 3 | +# |
| 4 | +# This script generates the chocolatey install and uninstall powershell scripts |
| 5 | +# found in the Tools directory in the chocolatey package. |
| 6 | +# |
| 7 | +# It reads template files fond in the ToolsTemplates directory and replaces |
| 8 | +# tokens with run time values. Tokens are typically strings with leading and |
| 9 | +# trailing underscores, e.g. __PACKAGE_NAME__. |
| 10 | +# |
| 11 | +# Tokens are defined in the Tokens.Json file in the ToolsTemplates directory. |
| 12 | +# __VERSION__ is a special token, it is hardcoded to be replaced with the |
| 13 | +# environtment variable APPVEYOR_REPO_TAG_NAME. This allows AppVeyor to |
| 14 | +# update version information in the scripts |
| 15 | +# |
| 16 | +# For more information see: |
| 17 | +# https://github.com/MasterDevs/ChocolateyCoolWhip |
| 18 | +################################################################################ |
| 19 | + |
| 20 | +$versionToken = "__VERSION__"; |
| 21 | +$version = $env:APPVEYOR_REPO_TAG_NAME |
| 22 | +Write-Host "Starting prepackage of version $version"; |
| 23 | + |
| 24 | +####################################### |
| 25 | +# Find Our Directories |
| 26 | +####################################### |
| 27 | +Write-Host |
| 28 | +$templateDirectory = Get-ChildItem -Recurse -Directory -Include ToolsTemplates LogStitcher\Chocolatey |
| 29 | + |
| 30 | +$toolsDir = "$($templateDirectory.Parent.FullName)\Tools" |
| 31 | +write-host "Creating $toolsDir" |
| 32 | +$silent = New-Item -ItemType Directory -Force -Path $toolsDir |
| 33 | + |
| 34 | +####################################### |
| 35 | +# Read Tokens |
| 36 | +####################################### |
| 37 | +Write-Host |
| 38 | +Write-Host "Reading tokens" |
| 39 | + |
| 40 | +$tokenFile = $templateDirectory.EnumerateFiles().Where({$PSItem.Name -eq "tokens.json";})[0] |
| 41 | +$json = Get-Content -Raw $tokenFile.FullName |
| 42 | +$tokens = ConvertFrom-Json $json |
| 43 | +Write-Host "Replacing tokens" |
| 44 | +Write-Host " $versionToken ==> $version" |
| 45 | +foreach($token in $tokens) |
| 46 | +{ |
| 47 | + Write-Host " $($token.Name) ==> $($token.Value)" |
| 48 | +} |
| 49 | + |
| 50 | +####################################### |
| 51 | +# Convert tokenized files |
| 52 | +####################################### |
| 53 | +Write-Host |
| 54 | +foreach($file in $templateDirectory.EnumerateFiles().Where({$PSItem.Name -ne "tokens.json";})) |
| 55 | +{ |
| 56 | + Write-Host "Processing $($file.FullName)" |
| 57 | + $newFile = "$($toolsDir)\\$($file.Name)" |
| 58 | + |
| 59 | + $content = Get-Content $file.FullName; |
| 60 | + |
| 61 | + $content = $content -replace $versionToken, $version |
| 62 | + ForEach($token in $tokens) |
| 63 | + { |
| 64 | + $content = $content -replace $token.Name, $token.Value; |
| 65 | + } |
| 66 | + |
| 67 | + Write-Host "Writing $newFile"; |
| 68 | + Set-Content $newFile -Encoding UTF8 $content |
| 69 | + |
| 70 | + Write-Host |
| 71 | +} |
| 72 | + |
| 73 | +####################################### |
| 74 | +# Done |
| 75 | +####################################### |
| 76 | +Write-Host "Prepackage complete" |
0 commit comments