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 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 diff --git a/public/Install-SalesforceClient.ps1 b/public/Install-SalesforceClient.ps1 new file mode 100644 index 0000000..eacf63a --- /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 +} Export-ModuleMember -Function Install-SalesforceClient \ No newline at end of file