@@ -191,7 +191,23 @@ task LayoutModule BuildMainModule, BuildMamlHelp, {
191
191
# Copy module manifest, but fix the version to match what we've specified in the binary module.
192
192
$version = (Get-ChildItem - Path $targetDir / Microsoft.PowerShell.PSReadLine2.dll).VersionInfo.FileVersion
193
193
$moduleManifestContent = Get-Content - Path ' PSReadLine/PSReadLine.psd1' - Raw
194
- [regex ]::Replace($moduleManifestContent , " ModuleVersion = '.*'" , " ModuleVersion = '$version '" ) | Set-Content - Path $targetDir / PSReadLine.psd1
194
+
195
+ $b = Get-Content - Encoding Byte - Raw ./ bin/ $Configuration / PSReadLine/ Microsoft.PowerShell.PSReadLine2.dll
196
+ $a = [System.Reflection.Assembly ]::Load($b )
197
+ $semVer = ($a.GetCustomAttributes ([System.Reflection.AssemblyInformationalVersionAttribute ], $false )).InformationalVersion
198
+
199
+ if ($semVer -match " (.*)-(.*)" )
200
+ {
201
+ # Make sure versions match
202
+ if ($matches [1 ] -ne $version ) { throw " AssemblyFileVersion mismatch with AssemblyInformationalVersion" }
203
+ $prerelease = $matches [2 ]
204
+
205
+ # Put the prerelease tag in private data
206
+ $moduleManifestContent = [regex ]::Replace($moduleManifestContent , " }" , " PrivateData = @{ PSData = @{ Prerelease = '$prerelease ' } }$ ( [System.Environment ]::Newline) }" )
207
+ }
208
+
209
+ $moduleManifestContent = [regex ]::Replace($moduleManifestContent , " ModuleVersion = '.*'" , " ModuleVersion = '$version '" )
210
+ $moduleManifestContent | Set-Content - Path $targetDir / PSReadLine.psd1
195
211
196
212
# Make sure we don't ship any read-only files
197
213
foreach ($file in (Get-ChildItem - Recurse - File $targetDir ))
@@ -238,6 +254,44 @@ task Install LayoutModule, {
238
254
Install " $HOME \Documents\PowerShell\Modules"
239
255
}
240
256
257
+ <#
258
+ Synopsis: Publish to PSGallery
259
+ #>
260
+ task Publish - If ($Configuration -eq ' Release' ) LayoutModule, {
261
+
262
+ $manifest = Import-PowerShellDataFile $PSScriptRoot / bin/ Release/ PSReadLine/ PSReadLine.psd1
263
+
264
+ $version = $manifest.ModuleVersion
265
+ if ($null -ne $manifest.PrivateData )
266
+ {
267
+ $psdata = $manifest.PrivateData [' PSData' ]
268
+ if ($null -ne $psdata )
269
+ {
270
+ $prerelease = $psdata [' Prerelease' ]
271
+ if ($null -ne $prerelease )
272
+ {
273
+ $version = $version + ' -' + $prerelease
274
+ }
275
+ }
276
+ }
277
+
278
+ $yes = Read-Host " Publish version $version (y/n)"
279
+
280
+ if ($yes -ne ' y' ) { throw " Publish aborted" }
281
+
282
+ $nugetApiKey = Read-Host " Nuget api key for PSGallery"
283
+
284
+ $publishParams = @ {
285
+ Path = " $PSScriptRoot /bin/Release/PSReadLine"
286
+ NuGetApiKey = $nugetApiKey
287
+ Repository = " PSGallery"
288
+ ReleaseNotes = (Get-Content - Raw $PSScriptRoot / bin/ Release/ PSReadLine/ Changes.txt)
289
+ ProjectUri = ' https://github.com/lzybkr/PSReadLine'
290
+ }
291
+
292
+ Publish-Module @publishParams
293
+ }
294
+
241
295
<#
242
296
Synopsis: Default build rule - build and create module layout
243
297
#>
0 commit comments