@@ -225,6 +225,91 @@ function Update-Changelog {
225225 Pop-Location
226226}
227227
228+ <#
229+ . SYNOPSIS
230+ Updates version in repository.
231+ . DESCRIPTION
232+ Note that our Git tags and changelog prefix all versions with `v`.
233+
234+ PowerShellEditorServices: version is `x.y.z-preview.d`
235+
236+ - PowerShellEditorServices.psd1:
237+ - `ModuleVersion` variable with `'x.y.z'` string, no pre-release info
238+ - PowerShellEditorServices.Common.props:
239+ - `VersionPrefix` field with `x.y.z`
240+ - `VersionSuffix` field with pre-release portion excluding hyphen
241+
242+ vscode-powershell: version is `yyyy.mm.x-preview`
243+
244+ - package.json:
245+ - `version` field with `"x.y.z"` and no prefix or suffix
246+ - `preview` field set to `true` or `false` if version is a preview
247+ - `name` field has `-preview` appended similarly
248+ - `displayName` field has ` Preview` appended similarly
249+ - `description` field has `(Preview) ` prepended similarly
250+ #>
251+ function Update-Version {
252+ [CmdletBinding (SupportsShouldProcess )]
253+ param (
254+ [Parameter (Mandatory )]
255+ [ValidateSet ([RepoNames ])]
256+ [string ]$RepositoryName
257+ )
258+ # NOTE: This a side effect neccesary for Git operations to work.
259+ Push-Location - Path " $PSScriptRoot /../../$RepositoryName "
260+
261+ $Version = Get-Version - RepositoryName $RepositoryName
262+ $v = " $ ( $Version.Major ) .$ ( $Version.Minor ) .$ ( $Version.Patch ) "
263+ # TODO: Maybe cleanup the replacement logic.
264+ switch ($RepositoryName ) {
265+ " vscode-powershell" {
266+ $d = " Develop PowerShell scripts in Visual Studio Code!"
267+ if ($Version.PreReleaseLabel ) {
268+ $name = " powershell-preview"
269+ $displayName = " PowerShell Preview"
270+ $preview = " true"
271+ $description = " (Preview) $d "
272+ } else {
273+ $name = " powershell"
274+ $displayName = " PowerShell"
275+ $preview = " false"
276+ $description = $d
277+ }
278+ $path = " package.json"
279+ $f = Get-Content - Path $path
280+ # NOTE: The prefix regex match two spaces exactly to avoid matching
281+ # nested objects in the file.
282+ $f = $f -replace ' ^(?<prefix> "name":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${name} `$ {suffix}"
283+ $f = $f -replace ' ^(?<prefix> "displayName":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${displayName} `$ {suffix}"
284+ $f = $f -replace ' ^(?<prefix> "version":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${v} `$ {suffix}"
285+ $f = $f -replace ' ^(?<prefix> "preview":\s+)(.+)(?<suffix>,)$' , " `$ {prefix}${preview} `$ {suffix}"
286+ $f = $f -replace ' ^(?<prefix> "description":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${description} `$ {suffix}"
287+ $f | Set-Content - Path $path
288+ git add $path
289+ }
290+ " PowerShellEditorServices" {
291+ $path = " PowerShellEditorServices.Common.props"
292+ $f = Get-Content - Path $path
293+ $f = $f -replace ' ^(?<prefix>\s+<VersionPrefix>)(.+)(?<suffix></VersionPrefix>)$' , " `$ {prefix}${v} `$ {suffix}"
294+ $f = $f -replace ' ^(?<prefix>\s+<VersionSuffix>)(.*)(?<suffix></VersionSuffix>)$' , " `$ {prefix}$ ( $Version.PreReleaseLabel ) `$ {suffix}"
295+ $f | Set-Content - Path $path
296+ git add $path
297+
298+ $path = " module/PowerShellEditorServices/PowerShellEditorServices.psd1"
299+ $f = Get-Content - Path $path
300+ $f = $f -replace " ^(?<prefix>ModuleVersion = ')(.+)(?<suffix>')`$ " , " `$ {prefix}${v} `$ {suffix}"
301+ $f | Set-Content - Path $path
302+ git add $path
303+ }
304+ }
305+
306+ if ($PSCmdlet.ShouldProcess (" $RepositoryName /$Version " , " git commit" )) {
307+ git commit - m " Bump version to $Version "
308+ }
309+
310+ Pop-Location
311+ }
312+
228313<#
229314. SYNOPSIS
230315 Creates a new draft GitHub release from the updated changelog.
@@ -254,4 +339,4 @@ function New-DraftRelease {
254339 New-GitHubRelease @ReleaseParams
255340}
256341
257- Export-ModuleMember - Function Update-Changelog , New-DraftRelease
342+ Export-ModuleMember - Function Update-Changelog , Update-Version , New-DraftRelease
0 commit comments