From 5e3ebcff2ea9dfa53d65a7772a042ad24b3fdd9d Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Tue, 8 Oct 2019 01:35:06 -0500 Subject: [PATCH] v0.4.1 release ## 0.4.1 - 2019-10-08 * Miscellaneous * Added `LastSave` property to the primary `PSProfile` class * Added check on `Save()` method to pull in updated configuration if it has been saved from another session by comparing `LastSave` DateTime between the configuration and current `$PSProfile.LastSave` --- CHANGELOG.md | 265 ++++++++++++------------ PSProfile/Classes/PSProfile.Classes.ps1 | 27 +++ invoke.build.ps1 | 14 +- 3 files changed, 173 insertions(+), 133 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b931281..93651ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,94 +1,101 @@ * [PSProfile - ChangeLog](#psprofile---changelog) - * [0.4.0 - 2019-09-22](#040---2019-09-22) - * [0.3.0 - 2019-09-07](#030---2019-09-07) - * [0.2.0 - 2019-09-02](#020---2019-09-02) - * [0.1.9 - 2019-08-26](#019---2019-08-26) - * [0.1.8 - 2019-08-26](#018---2019-08-26) - * [0.1.7 - 2019-08-25](#017---2019-08-25) - * [0.1.6 - 2019-08-24](#016---2019-08-24) - * [0.1.5 - 2019-08-22](#015---2019-08-22) - * [0.1.4 - 2019-08-22](#014---2019-08-22) - * [0.1.3 - 2019-08-20](#013---2019-08-20) - * [0.1.2 - 2019-08-20](#012---2019-08-20) - * [0.1.1 - 2019-08-19](#011---2019-08-19) - * [0.1.0 - 2019-08-19](#010---2019-08-19) + * [0.4.1 - 2019-10-08](#041---2019-10-08) + * [0.4.0 - 2019-09-22](#040---2019-09-22) + * [0.3.0 - 2019-09-07](#030---2019-09-07) + * [0.2.0 - 2019-09-02](#020---2019-09-02) + * [0.1.9 - 2019-08-26](#019---2019-08-26) + * [0.1.8 - 2019-08-26](#018---2019-08-26) + * [0.1.7 - 2019-08-25](#017---2019-08-25) + * [0.1.6 - 2019-08-24](#016---2019-08-24) + * [0.1.5 - 2019-08-22](#015---2019-08-22) + * [0.1.4 - 2019-08-22](#014---2019-08-22) + * [0.1.3 - 2019-08-20](#013---2019-08-20) + * [0.1.2 - 2019-08-20](#012---2019-08-20) + * [0.1.1 - 2019-08-19](#011---2019-08-19) + * [0.1.0 - 2019-08-19](#010---2019-08-19) *** # PSProfile - ChangeLog +## 0.4.1 - 2019-10-08 + +* Miscellaneous + * Added `LastSave` property to the primary `PSProfile` class + * Added check on `Save()` method to pull in updated configuration if it has been saved from another session by comparing `LastSave` DateTime between the configuration and current `$PSProfile.LastSave` + ## 0.4.0 - 2019-09-22 * [Issue #18](https://github.com/scrthq/PSProfile/issues/18) - * Added the following functions for Init Script management: - * `Add-PSProfileInitScript` - * `Get-PSProfileInitScript` - * `Remove-PSProfileInitScript` - * `Enable-PSProfileInitScript` - * `Disable-PSProfileInitScript` - * `Edit-PSProfileInitScript` - * Added contextual help file `about_PSProfile_Init_Scripts` - * Added Init Scripts section to `Start-PSProfileConfigurationHelper` - * Updated `PSProfile` class to include Init Script support. + * Added the following functions for Init Script management: + * `Add-PSProfileInitScript` + * `Get-PSProfileInitScript` + * `Remove-PSProfileInitScript` + * `Enable-PSProfileInitScript` + * `Disable-PSProfileInitScript` + * `Edit-PSProfileInitScript` + * Added contextual help file `about_PSProfile_Init_Scripts` + * Added Init Scripts section to `Start-PSProfileConfigurationHelper` + * Updated `PSProfile` class to include Init Script support. * Miscellaneous - * Updated `Edit-PSProfilePrompt` when choosing to Save PSProfile to ensure the updated prompt is written back to disk. - * Updated `invoke.build.ps1` for better contextual verbosity when compiling the module during the build process. + * Updated `Edit-PSProfilePrompt` when choosing to Save PSProfile to ensure the updated prompt is written back to disk. + * Updated `invoke.build.ps1` for better contextual verbosity when compiling the module during the build process. ## 0.3.0 - 2019-09-07 * [Issue #15](https://github.com/scrthq/PSProfile/issues/15) - * Added `Add-PSProfileToProfile` function to easily add `Import-Module PSProfile` to your PowerShell profile. + * Added `Add-PSProfileToProfile` function to easily add `Import-Module PSProfile` to your PowerShell profile. * [Issue #16](https://github.com/scrthq/PSProfile/issues/16) - * Added the following functions from the `PSProfile.PowerTools` plugin to PSProfile directly: - * `Confirm-ScriptIsValid` - * `Enter-CleanEnvironment` - * `Format-Syntax` - * `Get-Definition` - * `Get-Gist` - * `Get-LongPath` - * `Install-LatestModule` - * `Open-Code` - * `Open-Item` - * `Pop-Path` - * `Push-Path` - * `Start-BuildScript` - * `Test-RegEx` - * Added HelpFile for Power Tools functions: `Get-Help about_PSProfile_Power_Tools` - * Updated `Start-PSProfileConfigurationHelper` with Power Tools section + * Added the following functions from the `PSProfile.PowerTools` plugin to PSProfile directly: + * `Confirm-ScriptIsValid` + * `Enter-CleanEnvironment` + * `Format-Syntax` + * `Get-Definition` + * `Get-Gist` + * `Get-LongPath` + * `Install-LatestModule` + * `Open-Code` + * `Open-Item` + * `Pop-Path` + * `Push-Path` + * `Start-BuildScript` + * `Test-RegEx` + * Added HelpFile for Power Tools functions: `Get-Help about_PSProfile_Power_Tools` + * Updated `Start-PSProfileConfigurationHelper` with Power Tools section * Miscellaneous - * Cleaned up `PSProfile` class. - * Updated alias list. - * Updated module versioning strategy in build script. - * Updated `GitAliases` plugin to only spawn 1 runspace in the background. - * Fixed issue with `Copy-Parameters` where it would fail to pull parameters for commands with multiple parameter sets. - * Updated Content.Tests. - * Updated azure-pipelines YAML. - * Renamed the InvokeBuild script from `tasks.build.ps1` to `invoke.build.ps1`. + * Cleaned up `PSProfile` class. + * Updated alias list. + * Updated module versioning strategy in build script. + * Updated `GitAliases` plugin to only spawn 1 runspace in the background. + * Fixed issue with `Copy-Parameters` where it would fail to pull parameters for commands with multiple parameter sets. + * Updated Content.Tests. + * Updated azure-pipelines YAML. + * Renamed the InvokeBuild script from `tasks.build.ps1` to `invoke.build.ps1`. ## 0.2.0 - 2019-09-02 * [Issue #2](https://github.com/scrthq/PSProfile/issues/2) - * Added special module import process when the `ModuleToImport` is `EditorServicesCommandSuite` so it also automatically registers the available editor commands. + * Added special module import process when the `ModuleToImport` is `EditorServicesCommandSuite` so it also automatically registers the available editor commands. * [Issue #12](https://github.com/scrthq/PSProfile/issues/12) - * Added `Start-PSProfileConfigurationHelper` to provide an easy way to get started with configuring your PSProfile. + * Added `Start-PSProfileConfigurationHelper` to provide an easy way to get started with configuring your PSProfile. * [Issue #6](https://github.com/scrthq/PSProfile/issues/6) - * Added `PSReadline` key to `$PSProfile.Settings` (Settings management in development still.) + * Added `PSReadline` key to `$PSProfile.Settings` (Settings management in development still.) * Miscellaneous - * Added support for multiple Command Aliases to be removed at once with `Remove-PSProfileCommandAlias`. - * Updated default `SCRTHQ` prompt that comes with the module. - * Added support for NerdFonts and PowerLine switches on the prompts to switch char sets depending on the FontType. - * Added `IncludeVault` switch parameter to `Export-PSProfileConfiguration` to prevent exporting the Secrets Vault by default when creating portable configurations. - * Added `_cleanModules()` method to PSProfile class to remove any null or empty values hanging over and convert any string values to the full hashtable value instead. - * Cleaned up logic and fixed bugs in the following functions: - * `Add-PSProfileModuleToImport` - * `Remove-PSProfileModuleToImport` - * `Add-PSProfileModuleToInstall` - * `Remove-PSProfileModuleToInstall` - * `Add-PSProfilePlugin` - * Updated CONTRIBUTING.md with snippet to include for PSProfile developers on their PowerShell profile. - * Refactored `Get-PSProfilePrompt` to return `$null` if a name is specified but does not exist on the current PSProfile configuration. - * Refactored `$PSProfile._loadConfiguration()` to start with the base value of `$Global:PSProfile` if present, otherwise import the existing configuration from file. This is necessary to retain the existing configuration if an action is taken that forces the PSProfile to reload, e.g. adding a new plugin to the configuration. - * Updated `$PSProfile._loadPrompt()` method to set the value of `$function:prompt` directly instead of calling `Switch-PSProfilePrompt` to reduce overhead. + * Added support for multiple Command Aliases to be removed at once with `Remove-PSProfileCommandAlias`. + * Updated default `SCRTHQ` prompt that comes with the module. + * Added support for NerdFonts and PowerLine switches on the prompts to switch char sets depending on the FontType. + * Added `IncludeVault` switch parameter to `Export-PSProfileConfiguration` to prevent exporting the Secrets Vault by default when creating portable configurations. + * Added `_cleanModules()` method to PSProfile class to remove any null or empty values hanging over and convert any string values to the full hashtable value instead. + * Cleaned up logic and fixed bugs in the following functions: + * `Add-PSProfileModuleToImport` + * `Remove-PSProfileModuleToImport` + * `Add-PSProfileModuleToInstall` + * `Remove-PSProfileModuleToInstall` + * `Add-PSProfilePlugin` + * Updated CONTRIBUTING.md with snippet to include for PSProfile developers on their PowerShell profile. + * Refactored `Get-PSProfilePrompt` to return `$null` if a name is specified but does not exist on the current PSProfile configuration. + * Refactored `$PSProfile._loadConfiguration()` to start with the base value of `$Global:PSProfile` if present, otherwise import the existing configuration from file. This is necessary to retain the existing configuration if an action is taken that forces the PSProfile to reload, e.g. adding a new plugin to the configuration. + * Updated `$PSProfile._loadPrompt()` method to set the value of `$function:prompt` directly instead of calling `Switch-PSProfilePrompt` to reduce overhead. ## 0.1.9 - 2019-08-26 @@ -149,70 +156,70 @@ ## 0.1.1 - 2019-08-19 * [Issue #3](https://github.com/scrthq/PSProfile/issues/3) - * Fixed: `$PSProfile.Refresh()` only uses `Trim()` to clean up the Prompts now due to Invoke-Formatter hanging. + * Fixed: `$PSProfile.Refresh()` only uses `Trim()` to clean up the Prompts now due to Invoke-Formatter hanging. ## 0.1.0 - 2019-08-19 * Initial release to the PowerShell Gallery * Included functions: - * `Add-PSProfileCommandAlias` - * `Add-PSProfileModuleToImport` - * `Add-PSProfileModuleToInstall` - * `Add-PSProfilePathAlias` - * `Add-PSProfilePlugin` - * `Add-PSProfileProjectPath` - * `Add-PSProfilePrompt` - * `Add-PSProfileScriptPath` - * `Add-PSProfileSecret` - * `Add-PSProfileSymbolicLink` - * `Add-PSProfileVariable` - * `Edit-PSProfilePrompt` - * `Get-LastCommandDuration` - * `Get-MyCreds` - * `Get-PathAlias` - * `Get-PSProfileArguments` - * `Get-PSProfileCommand` - * `Get-PSProfileCommandAlias` - * `Get-PSProfileImportedCommand` - * `Get-PSProfileLog` - * `Get-PSProfileModuleToImport` - * `Get-PSProfileModuleToInstall` - * `Get-PSProfilePathAlias` - * `Get-PSProfilePlugin` - * `Get-PSProfileProjectPath` - * `Get-PSProfilePrompt` - * `Get-PSProfileScriptPath` - * `Get-PSProfileSecret` - * `Get-PSProfileSymbolicLink` - * `Get-PSProfileVariable` - * `Get-PSVersion` - * `Import-PSProfile` - * `Import-PSProfileConfiguration` - * `Remove-PSProfileCommandAlias` - * `Remove-PSProfileModuleToImport` - * `Remove-PSProfileModuleToInstall` - * `Remove-PSProfilePathAlias` - * `Remove-PSProfilePlugin` - * `Remove-PSProfileProjectPath` - * `Remove-PSProfilePrompt` - * `Remove-PSProfileScriptPath` - * `Remove-PSProfileSecret` - * `Remove-PSProfileSymbolicLink` - * `Remove-PSProfileVariable` - * `Save-PSProfile` - * `Switch-PSProfilePrompt` - * `Test-IfGit` - * `Update-PSProfileConfig` - * `Update-PSProfileRefreshFrequency` - * `Update-PSProfileSetting` - * `Write-PSProfileLog` + * `Add-PSProfileCommandAlias` + * `Add-PSProfileModuleToImport` + * `Add-PSProfileModuleToInstall` + * `Add-PSProfilePathAlias` + * `Add-PSProfilePlugin` + * `Add-PSProfileProjectPath` + * `Add-PSProfilePrompt` + * `Add-PSProfileScriptPath` + * `Add-PSProfileSecret` + * `Add-PSProfileSymbolicLink` + * `Add-PSProfileVariable` + * `Edit-PSProfilePrompt` + * `Get-LastCommandDuration` + * `Get-MyCreds` + * `Get-PathAlias` + * `Get-PSProfileArguments` + * `Get-PSProfileCommand` + * `Get-PSProfileCommandAlias` + * `Get-PSProfileImportedCommand` + * `Get-PSProfileLog` + * `Get-PSProfileModuleToImport` + * `Get-PSProfileModuleToInstall` + * `Get-PSProfilePathAlias` + * `Get-PSProfilePlugin` + * `Get-PSProfileProjectPath` + * `Get-PSProfilePrompt` + * `Get-PSProfileScriptPath` + * `Get-PSProfileSecret` + * `Get-PSProfileSymbolicLink` + * `Get-PSProfileVariable` + * `Get-PSVersion` + * `Import-PSProfile` + * `Import-PSProfileConfiguration` + * `Remove-PSProfileCommandAlias` + * `Remove-PSProfileModuleToImport` + * `Remove-PSProfileModuleToInstall` + * `Remove-PSProfilePathAlias` + * `Remove-PSProfilePlugin` + * `Remove-PSProfileProjectPath` + * `Remove-PSProfilePrompt` + * `Remove-PSProfileScriptPath` + * `Remove-PSProfileSecret` + * `Remove-PSProfileSymbolicLink` + * `Remove-PSProfileVariable` + * `Save-PSProfile` + * `Switch-PSProfilePrompt` + * `Test-IfGit` + * `Update-PSProfileConfig` + * `Update-PSProfileRefreshFrequency` + * `Update-PSProfileSetting` + * `Write-PSProfileLog` * Included aliases: - * `Creds` >> `Get-MyCreds` - * `Edit-Prompt` >> `Edit-PSProfilePrompt` - * `Get-Prompt` >> `Get-PSProfilePrompt` - * `Load-PSProfile` >> `Import-PSProfile` - * `Refresh-PSProfile` >> `Update-PSProfileConfig` - * `Remove-Prompt` >> `Remove-PSProfilePrompt` - * `Save-Prompt` >> `Add-PSProfilePrompt` - * `Set-Prompt` >> `Switch-PSProfilePrompt` - * `Switch-Prompt` >> `Switch-PSProfilePrompt` + * `Creds` >> `Get-MyCreds` + * `Edit-Prompt` >> `Edit-PSProfilePrompt` + * `Get-Prompt` >> `Get-PSProfilePrompt` + * `Load-PSProfile` >> `Import-PSProfile` + * `Refresh-PSProfile` >> `Update-PSProfileConfig` + * `Remove-Prompt` >> `Remove-PSProfilePrompt` + * `Save-Prompt` >> `Add-PSProfilePrompt` + * `Set-Prompt` >> `Switch-PSProfilePrompt` + * `Switch-Prompt` >> `Switch-PSProfilePrompt` diff --git a/PSProfile/Classes/PSProfile.Classes.ps1 b/PSProfile/Classes/PSProfile.Classes.ps1 index 73c7a59..05a899f 100644 --- a/PSProfile/Classes/PSProfile.Classes.ps1 +++ b/PSProfile/Classes/PSProfile.Classes.ps1 @@ -96,6 +96,7 @@ class PSProfile { [hashtable] $_internal [hashtable] $Settings [datetime] $LastRefresh + [datetime] $LastSave [string] $RefreshFrequency [hashtable] $GitPathMap [hashtable] $PSBuildPathMap @@ -156,6 +157,7 @@ class PSProfile { } $this.RefreshFrequency = (New-TimeSpan -Hours 1).ToString() $this.LastRefresh = [datetime]::Now.AddHours(-2) + $this.LastSave = [datetime]::Now $this.ProjectPaths = @() $this.PluginPaths = @() $this.InitScripts = @{} @@ -298,13 +300,38 @@ if ($env:AWS_PROFILE) { $this._formatInitScripts() $this.LastRefresh = [datetime]::Now $this.Save() + $this._log( + "Refresh complete", + "MAIN", + "Verbose" + ) } [void] Save() { + $this._log( + "Saving PSProfile configuration", + "MAIN", + "Debug" + ) + $conf = Import-Configuration -Name PSProfile -CompanyName 'SCRT HQ' -DefaultPath (Join-Path $PSScriptRoot "Configuration.psd1") + if ($conf.LastSave -gt $this.LastSave) { + $this._log( + "Configuration has been updated from another session @ $($conf.LastSave). Pulling in updated configuration before saving.", + "MAIN", + "Verbose" + ) + $this | Update-Object $conf + } $out = @{ } + $this.LastSave = [DateTime]::Now $this.PSObject.Properties.Name | Where-Object { $_ -ne '_internal' } | ForEach-Object { $out[$_] = $this.$_ } $out | Export-Configuration -Name PSProfile -CompanyName 'SCRT HQ' + $this._log( + "PSProfile configuration has been saved.", + "MAIN", + "Verbose" + ) } hidden [string] _globalize([string]$content) { $noScopePattern = 'function\s+(?[\w+_-]{1,})\s+\{' diff --git a/invoke.build.ps1 b/invoke.build.ps1 index 368aa02..9da2b92 100644 --- a/invoke.build.ps1 +++ b/invoke.build.ps1 @@ -16,6 +16,9 @@ Param( $SourceModuleDirectory, [Parameter()] [String] + $SourceManifestPath, + [Parameter()] + [String] $TargetDirectory, [Parameter()] [String] @@ -37,7 +40,8 @@ task Init { Import-Module Configuration $Script:SourceModuleDirectory = [System.IO.Path]::Combine($BuildRoot,$ModuleName) $Script:GalleryVersion = (Get-PSGalleryVersion $ModuleName).Version - $Script:ManifestVersion = (Import-Metadata -Path $(Join-Path $SourceModuleDirectory "$($ModuleName).psd1")).ModuleVersion + $Script:SourceManifestPath = Join-Path $SourceModuleDirectory "$($ModuleName).psd1" + $Script:ManifestVersion = (Import-Metadata -Path $SourceManifestPath).ModuleVersion $Script:NextModuleVersion = Get-NextModuleVersion -GalleryVersion $GalleryVersion -ManifestVersion $ManifestVersion $Script:TargetDirectory = [System.IO.Path]::Combine($BuildRoot,'BuildOutput') $Script:TargetModuleDirectory = [System.IO.Path]::Combine($TargetDirectory,$ModuleName) @@ -125,12 +129,13 @@ task Build Clean,{ if ($ManifestVersion -ne $NextModuleVersion) { Write-BuildLog "Bumping source manifest version from '$ManifestVersion' to '$NextModuleVersion' to prevent errors" - Update-Metadata -Path (Join-Path $SourceModuleDirectory "$($ModuleName).psd1") -PropertyName ModuleVersion -Value $NextModuleVersion + Update-Metadata -Path $SourceManifestPath -PropertyName ModuleVersion -Value $NextModuleVersion + ([System.IO.File]::ReadAllText($SourceManifestPath)).Trim() | Set-Content $SourceManifestPath } # Copy over manifest Write-BuildLog "Copying source manifest to target folder" - Copy-Item -Path (Join-Path $SourceModuleDirectory "$($ModuleName).psd1") -Destination $TargetVersionDirectory + Copy-Item -Path $SourceManifestPath -Destination $TargetVersionDirectory # Update FunctionsToExport and AliasesToExport on manifest $params = @{ @@ -145,7 +150,8 @@ task Build Clean,{ if ($ManifestVersion -ne $NextModuleVersion) { Write-BuildLog "Reverting bumped source manifest version from '$NextModuleVersion' to '$ManifestVersion'" - Update-Metadata -Path (Join-Path $SourceModuleDirectory "$($ModuleName).psd1") -PropertyName ModuleVersion -Value $ManifestVersion + Update-Metadata -Path $SourceManifestPath -PropertyName ModuleVersion -Value $ManifestVersion + ([System.IO.File]::ReadAllText($SourceManifestPath)).Trim() | Set-Content $SourceManifestPath } Write-BuildLog "Created compiled module at [$TargetVersionDirectory]"