Skip to content

Commit

Permalink
Changed to ModuleVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Nov 3, 2023
1 parent 925c630 commit d3b4fcf
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 138 deletions.
66 changes: 37 additions & 29 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,46 @@ if ($psd1Content) {
$ModuleVersion = "$($prevVersion).$($build)"
}

# Ensure latest ConsoleGuiTools
"New ModuleVersion: $ModuleVersion"

# Ensure we're using the correct version of ConsoleGuiTools
# If there's a local repository, use the latest version from there and set the RequiredVersion in the .psd1 file
# If there's NOT a local repo, use the latest version from the PowerShell Gallery and set the ModuleVersion in the .psd1 file
$PsdPath = "./Source/$($ModuleName).psd1"
$ocgvModule = "Microsoft.PowerShell.ConsoleGuiTools"
"Patching $PsdPath with latest ConsoleGuiTools version"
$psd1Content = Get-Content $PsdPath -Raw -ErrorAction SilentlyContinue
if ($psd1Content -match "RequiredVersion\s+=\s+'(.*?)'\s+# Generated by Build.ps1") {
"Found $ocgvModule RequiredVersion in ${PsdPath}: ${Matches[1]}"

# Find new version of ConsoleGuiTools in 'local' repository
$localRepository = Get-PSRepository | Where-Object { $_.Name -eq 'local' }
if ($localRepository) {
$localRepositoryPath = $localRepository | Select-Object -ExpandProperty SourceLocation
$ocgvVersion = Get-ChildItem "${localRepositoryPath}/${ocgvModule}*.nupkg" | Select-Object -ExpandProperty Name | Sort-Object -Descending | Select-Object -First 1
if ($ocgvVersion -match "$ocgvModule.(.*?).nupkg") {
$ocgvVersion = $Matches[1]
} else {
throw "No $ocgvModule packages found in ${localRepository}."
}
"Latest '$ocgvModule` in 'local' repository: " + $ocgvVersion
"Patching $PsdPath with correct $ocgvModule version"

} else {
throw "Local repository not found."
}
# Find new version of ConsoleGuiTools in 'local' repository
$localRepository = Get-PSRepository | Where-Object { $_.Name -eq 'local' }
if ($localRepository) {
$localRepositoryPath = $localRepository | Select-Object -ExpandProperty SourceLocation
$v = Get-ChildItem "${localRepositoryPath}/${ocgvModule}*.nupkg" | Select-Object -ExpandProperty Name | Sort-Object -Descending | Select-Object -First 1
if ($v -match "$ocgvModule.(.*?).nupkg") {
$ocgvVersion = $Matches[1]
"$ocgvModule v $ocgvVersion found in local repository; setting RequiredVersion in $PsdPath"
Update-ModuleManifest -Path $PsdPath -RequiredModules @(
@{
ModuleName = "PSReadline"; ModuleVersion = "2.0"
},
@{
ModuleName = $ocgvModule; RequiredVersion = $ocgvVersion
}
) -ErrorAction Stop
}
}

"Rewriting $PsdPath with new Required `Microsoft.PowerShell.ConsoleGuiTools` Version: $ocgvVersion"
$updatedpsd1Content = $psd1Content -replace "'(.*?)'\s+# Generated by Build.ps1", "'$ocgvVersion' # Generated by Build.ps1"
$updatedpsd1Content | Out-File -FilePath $PsdPath -Encoding ascii
} else {
throw "RequiredVersion not found in the old .psd1 file."
}

"New ModuleVersion: $ModuleVersion"
if ($null -eq $ocgvVersion) {
$ocgvVersion = (Find-Module $ocgvModule).Version
"$ocgvModule v $ocgvVersion` found in PSGallery; setting ModuleVersion in $PsdPath"
Update-ModuleManifest -Path $PsdPath -RequiredModules @(
@{
ModuleName = "PSReadline"; ModuleVersion = "2.0"
},
@{
ModuleName = $ocgvModule; ModuleVersion = $ocgvVersion
}
) -ErrorAction Stop
}

$OldModule = Get-Module $ModuleName -ErrorAction SilentlyContinue
if ($OldModule) {
Expand All @@ -81,7 +89,7 @@ if ($localRepository) {
" Publishing $ModuleName to local repository at $localRepositoryPath"
Publish-Module -Path $ModulePath -Repository 'local' -ErrorAction Stop
" Installing $ModuleName to local repository at $localRepositoryPath"
Install-Module -Name $ModuleName -Repository 'local' -Force
Install-Module -Name $ModuleName -Repository 'local' -Force -Verbose
Import-Module $ModuleName
"$ModuleName $(Get-Module $ModuleName | Select-Object -ExpandProperty Version) installed and imported."
}
Expand Down
3 changes: 2 additions & 1 deletion RequiredModules.psd1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# todo: add explanation
# BUGBUG: I don't think this file is needed/used
@{
ModuleBuilder = "1.*"
Pester = "[4.7.2, 5.0)"
"Microsoft.PowerShell.ConsoleGuiTools" = "0.7.*"
"Microsoft.PowerShell.ConsoleGuiTools" = "0.7"
PSReadLine = "2.*"
}
193 changes: 85 additions & 108 deletions Source/F7History.psd1
Original file line number Diff line number Diff line change
@@ -1,156 +1,133 @@
#
# Module manifest for module 'F7History'
#
# Generated by: Tig Kindel
#
# Generated on: 11/3/2023
#

@{

# Version number of this module.
ModuleVersion = '0.0.0'
# Script module or binary module file associated with this manifest.
RootModule = '.\F7History.psm1'

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
# Version number of this module.
ModuleVersion = '0.0.0'

PSData = @{
# Supported PSEditions
# CompatiblePSEditions = @()

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @("Windows", "Mac", "Linux", "History", "ConsoleGuiTools", "TUI", "Out-ConsoleGridView", "ocgv", "Terminal.Gui", "gui.cs" )
# ID used to uniquely identify this module
GUID = 'af35b6c1-758f-4d46-92ae-ac18cb9c983d'

# A URL to the license for this module.
LicenseUri = 'https://github.com/gui-cs/F7History/blob/main/LICENSE.md'
# Author of this module
Author = 'Tig Kindel'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/gui-cs/F7History/'
# Company or vendor of this module
CompanyName = 'Kindel, LLC'

# A URL to an icon representing this module.
IconUri = 'https://gui-cs.github.io/Terminal.Gui/images/logo48.png'
# Copyright statement for this module
Copyright = '(c) Kindel, LLC. All rights reserved.'

# ReleaseNotes of this module
ReleaseNotes = ''
# Description of the functionality provided by this module
Description = 'Press F7 to get a graphical Command History in Powershell.'

# Prerelease string of this module
Prerelease = ''
# Minimum version of the PowerShell engine required by this module
# PowerShellVersion = ''

# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false
# Name of the PowerShell host required by this module
# PowerShellHostName = ''

# External dependent modules of this module
ExternalModuleDependencies = @(
@{
ModuleName = 'Microsoft.PowerShell.ConsoleGuiTools'; RequiredVersion = '0.7.4'
},
'PSReadLine'
)
# Minimum version of the PowerShell host required by this module
# PowerShellHostVersion = ''

} # End of PSData hashtable
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

} # End of PrivateData hashtableoc
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# ClrVersion = ''

# Script module or binary module file associated with this manifest.
RootModule = '.\F7History.psm1'
# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(
@{
ModuleName = 'Microsoft.PowerShell.ConsoleGuiTools' ;
RequiredVersion = '0.7.4' # Generated by Build.ps1
},
'PSReadLine'
)
# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(@{ModuleName = 'PSReadline'; ModuleVersion = '2.0'; },
@{ModuleName = 'Microsoft.PowerShell.ConsoleGuiTools'; ModuleVersion = '0.7.6.0'; })

# Always define FunctionsToExport as an empty @() which will be replaced on build
FunctionsToExport = @()
AliasesToExport = @()
# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# List of all files packaged with this module
#FileList = @(".\F7History.psd1"; ".\F7History.psm1")
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# HelpInfo URI of this module
HelpInfoURI = 'https://github.com/gui-cs/F7History/blob/main/README.md'
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Supported PSEditions
# CompatiblePSEditions = @()
# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# ID used to uniquely identify this module
GUID = 'af35b6c1-758f-4d46-92ae-ac18cb9c983d'
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Author of this module
Author = 'Tig Kindel'
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @()

# Company or vendor of this module
CompanyName = 'Kindel, LLC'
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Copyright statement for this module
Copyright = '(c) Kindel, LLC. All rights reserved.'
# Variables to export from this module
# VariablesToExport = @()

# Description of the functionality provided by this module
Description = 'Press F7 to get a graphical Command History in Powershell.'
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# Minimum version of the PowerShell engine required by this module
# PowerShellVersion = ''
# DSC resources to export from this module
# DscResourcesToExport = @()

# Name of the PowerShell host required by this module
# PowerShellHostName = ''
# List of all modules packaged with this module
# ModuleList = @()

# Minimum version of the PowerShell host required by this module
# PowerShellHostVersion = ''
# List of all files packaged with this module
# FileList = @()

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# ClrVersion = ''
PSData = @{

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
# Tags applied to this module. These help with module discovery in online galleries.
Tags = 'Windows','Mac','Linux','History','ConsoleGuiTools','TUI','Out-ConsoleGridView','ocgv','Terminal.Gui','gui.cs'

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
# A URL to the license for this module.
LicenseUri = 'https://github.com/gui-cs/F7History/blob/main/LICENSE.md'

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()
# A URL to the main website for this project.
ProjectUri = 'https://github.com/gui-cs/F7History/'

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
# A URL to an icon representing this module.
IconUri = 'https://gui-cs.github.io/Terminal.Gui/images/logo48.png'

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()
# ReleaseNotes of this module
# ReleaseNotes = ''

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()
# Prerelease string of this module
# Prerelease = ''

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
#CmdletsToExport = '*'
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false

# Variables to export from this module
#ariablesToExport = '*'
# External dependent modules of this module
ExternalModuleDependencies = @('Microsoft.PowerShell.ConsoleGuiTools','PSReadLine')

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
#AliasesToExport = '*'
} # End of PSData hashtable

# DSC resources to export from this module
# DscResourcesToExport = @()
} # End of PrivateData hashtable

# List of all modules packaged with this module
# ModuleList = @()
# HelpInfo URI of this module
HelpInfoURI = 'https://github.com/gui-cs/F7History/blob/main/README.md'

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}


















0 comments on commit d3b4fcf

Please sign in to comment.