From 820fe3bb29dc7b1fd09360adf17057dec6a87d95 Mon Sep 17 00:00:00 2001 From: rulasg Date: Tue, 25 Mar 2025 07:42:29 +0100 Subject: [PATCH 1/4] feat: refactor file loading mechanism and add Set-MyInvokeCommandAlias function --- SfHelper.psm1 | 27 +++++-------------- Test/Test.psm1 | 27 +++++-------------- en-US/about_SfHelper.help.txt | 20 -------------- .../mySetInvokeCommandAlias.config.ps1 | 0 .../mySetInvokeCommandAlias.ps1 | 0 5 files changed, 12 insertions(+), 62 deletions(-) delete mode 100644 en-US/about_SfHelper.help.txt rename private/include.mySetInvokeCommandAlias.sf.ps1.ps1 => helper/mySetInvokeCommandAlias.config.ps1 (100%) rename {include => helper}/mySetInvokeCommandAlias.ps1 (100%) diff --git a/SfHelper.psm1 b/SfHelper.psm1 index 6a09d0f..d95aded 100644 --- a/SfHelper.psm1 +++ b/SfHelper.psm1 @@ -3,26 +3,11 @@ Write-Information -Message ("Loading {0} ..." -f ($PSCommandPath | Split-Path -L #Module path is where resides the RootModule file. This file. :) $MODULE_PATH = $PSScriptRoot -#Get public and private function definition files. -$Include = @( Get-ChildItem -Path $MODULE_PATH\include\*.ps1 -ErrorAction SilentlyContinue ) -$Private = @( Get-ChildItem -Path $MODULE_PATH\private\*.ps1 -Recurse -ErrorAction SilentlyContinue ) -$Public = @( Get-ChildItem -Path $MODULE_PATH\public\*.ps1 -Recurse -ErrorAction SilentlyContinue ) +# Load ps1 files on code folders in order +"config","helper","include","private","public" | ForEach-Object { -#Dot source the files -Foreach($import in @($Include + $Private + $Public)) -{ - Try - { - . $import.fullname + Get-ChildItem -Path $MODULE_PATH\$_\*.ps1 -Recurse -ErrorAction SilentlyContinue | ForEach-Object { + try { . $_.fullname } + catch { Write-Error -Message "Failed to import function $($import.fullname): $_" } } - Catch - { - Write-Error -Message "Failed to import function $($import.fullname): $_" - } -} - -# Here I might... -# Read in or create an initial config file and variable -# Export Public functions ($Public.BaseName) for WIP modules -# Set variables visible to the module and its functions only - +} \ No newline at end of file diff --git a/Test/Test.psm1 b/Test/Test.psm1 index cb13f91..844d032 100644 --- a/Test/Test.psm1 +++ b/Test/Test.psm1 @@ -1,31 +1,16 @@ -Write-Information -Message ("Loading {0} ..." -f ($PSCommandPath | Split-Path -LeafBase)) -InformationAction continue +Write-Information -Message ("Loading {0} ..." -f ($PSScriptRoot | Split-Path -Leaf)) -InformationAction continue #Module path is where resides the RootModule file. This file. :) $MODULE_PATH = $PSScriptRoot -#Get public and private function definition files. -$Include = @( Get-ChildItem -Path $MODULE_PATH\include\*.ps1 -ErrorAction SilentlyContinue ) -$Private = @( Get-ChildItem -Path $MODULE_PATH\private\*.ps1 -Recurse -ErrorAction SilentlyContinue ) -$Public = @( Get-ChildItem -Path $MODULE_PATH\public\*.ps1 -Recurse -ErrorAction SilentlyContinue ) +# Load ps1 files on code folders in order +"config","helper","include","private","public" | ForEach-Object { -#Dot source the files -Foreach($import in @($Include + $Private + $Public)) -{ - Try - { - . $import.fullname - } - Catch - { - Write-Error -Message "Failed to import function $($import.fullname): $_" + Get-ChildItem -Path $MODULE_PATH\$_\*.ps1 -Recurse -ErrorAction SilentlyContinue | ForEach-Object { + try { . $_.fullname } + catch { Write-Error -Message "Failed to import function $($import.fullname): $_" } } } -# Here I might... -# Read in or create an initial config file and variable -# Export Public functions ($Public.BaseName) for WIP modules -# Set variables visible to the module and its functions only - Export-ModuleMember -Function Test_* -Reset-InvokeCommandMock \ No newline at end of file diff --git a/en-US/about_SfHelper.help.txt b/en-US/about_SfHelper.help.txt deleted file mode 100644 index bb0ca51..0000000 --- a/en-US/about_SfHelper.help.txt +++ /dev/null @@ -1,20 +0,0 @@ -TOPIC - about_SfHelper - -AUTHOR - rulasg - -COPYRIGHT - (c) rulasg. All rights reserved. - -SHORT DESCRIPTION - Powershell module to help query Salesforce - -LONG DESCRIPTION - Powershell module to help query Salesforce - -KEYWORDS - Powershell Testing UnitTest Module TestingHelper - -SEE ALSO - https://github.com/rulasg/TestingHelper/ diff --git a/private/include.mySetInvokeCommandAlias.sf.ps1.ps1 b/helper/mySetInvokeCommandAlias.config.ps1 similarity index 100% rename from private/include.mySetInvokeCommandAlias.sf.ps1.ps1 rename to helper/mySetInvokeCommandAlias.config.ps1 diff --git a/include/mySetInvokeCommandAlias.ps1 b/helper/mySetInvokeCommandAlias.ps1 similarity index 100% rename from include/mySetInvokeCommandAlias.ps1 rename to helper/mySetInvokeCommandAlias.ps1 From 3c0481b73c56e67e23ac4259b8888029d95b52f0 Mon Sep 17 00:00:00 2001 From: rulasg Date: Tue, 25 Mar 2025 07:42:52 +0100 Subject: [PATCH 2/4] feat: add Install-SalesforceClient function to install Salesforce CLI via npm --- public/Install-SalesforceClient.ps1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 public/Install-SalesforceClient.ps1 diff --git a/public/Install-SalesforceClient.ps1 b/public/Install-SalesforceClient.ps1 new file mode 100644 index 0000000..7f14564 --- /dev/null +++ b/public/Install-SalesforceClient.ps1 @@ -0,0 +1,19 @@ + +Set-MyInvokeCommandAlias -Alias GetNpmVersion -Command "npm --version" +Set-MyInvokeCommandAlias -Alias SalesforceCliInstall -Command "npm install @salesforce/cli --global" + +function Install-SalesforceClient{ + [CmdletBinding()] + param() + + # check that npm is install in the system + $result = Invoke-MyCommand -Command GetNpmVersion + if($null -eq $result){ + throw "npm not installed. Please install npm to install Sf-Cli through npm." + } + + "Installing Salesforce CLI using npm..." | Write-MyHost + $result = Invoke-MyCommand -Command SalesforceCliInstall + + return $result +} \ No newline at end of file From 6792a16873276137241407e249edf6bb49ccfc9b Mon Sep 17 00:00:00 2001 From: rulasg Date: Tue, 25 Mar 2025 07:46:06 +0100 Subject: [PATCH 3/4] feat: export Install-SalesforceClient function for module usage --- public/Install-SalesforceClient.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/Install-SalesforceClient.ps1 b/public/Install-SalesforceClient.ps1 index 7f14564..eacf63a 100644 --- a/public/Install-SalesforceClient.ps1 +++ b/public/Install-SalesforceClient.ps1 @@ -16,4 +16,4 @@ function Install-SalesforceClient{ $result = Invoke-MyCommand -Command SalesforceCliInstall return $result -} \ No newline at end of file +} Export-ModuleMember -Function Install-SalesforceClient \ No newline at end of file From 9533768ac42774617d348d45e8ac698dff0bba40 Mon Sep 17 00:00:00 2001 From: rulasg Date: Tue, 25 Mar 2025 07:51:50 +0100 Subject: [PATCH 4/4] feat: add custom logging functions for error, warning, verbose, and host messages --- include/MyWrite.ps1 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 include/MyWrite.ps1 diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 new file mode 100644 index 0000000..8ff9452 --- /dev/null +++ b/include/MyWrite.ps1 @@ -0,0 +1,32 @@ + +$ERROR_COLOR = "Red" +$WARNING_COLOR = "Yellow" +$OUTPUT_COLOR = "DarkCyan" + +function Write-MyError{ + param( + [Parameter(Mandatory,ValueFromPipeline)][string]$Message + ) + Write-Host "Error: $message" -ForegroundColor $ERROR_COLOR +} + +function Write-MyWarning{ + param( + [Parameter(Mandatory,ValueFromPipeline)][string]$Message + ) + Write-Host "Error: $message" -ForegroundColor $WARNING_COLOR +} + +function Write-MyVerbose{ + param( + [Parameter(ValueFromPipeline)][string]$Message + ) + Write-Verbose -Message $message +} + +function Write-MyHost{ + param( + [Parameter(ValueFromPipeline)][string]$Message + ) + Write-Host $message -ForegroundColor $OUTPUT_COLOR +} \ No newline at end of file