-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add Install-SalesforceClient command functionality #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,87 @@ | ||
|
|
||
| Set-MyInvokeCommandAlias -Alias GetNpmVersion -Command "npm --version" | ||
| Set-MyInvokeCommandAlias -Alias SalesforceCliInstall -Command "npm install @salesforce/cli --global" | ||
| Set-MyInvokeCommandAlias -Alias GetSalesforceCliVersion -Command "sf --version" | ||
| Set-MyInvokeCommandAlias -Alias SalesforceCliSetConfig -Command "sf config set --global target-org {email} --json" | ||
| Set-MyInvokeCommandAlias -Alias GetUserEmail -Command '$env:GITHUB_USER ? "$($env:GITHUB_USER)@github.com" : $null' | ||
|
|
||
| # Set-MyInvokeCommandAlias -Alias SalesforceCliLogin -Command "sf org login device" | ||
| Set-MyInvokeCommandAlias -Alias SalesforceCliDisplay -COmmand "sf org display --json" | ||
| Set-MyInvokeCommandAlias -Alias SalesforceCliGetConfig -Command "sf config get target-org --json" | ||
|
|
||
| function Install-SalesforceClient{ | ||
| [CmdletBinding()] | ||
| [CmdletBinding(SupportsShouldProcess)] | ||
| 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." | ||
| throw "0. npm not installed. Please install npm to allow the installation of Salesforce Cli through npm." | ||
| } else { | ||
| "0. npm installed. version: $result" | Write-ToConsole -Color "Green" | ||
| } | ||
|
|
||
| # Check for Salesforce CLI installed and install if not | ||
| $sfversion = Invoke-MyCommand -Command GetSalesforceCliVersion -ErrorAction SilentlyContinue | ||
| if($null -eq $sfversion){ | ||
| if ($PSCmdlet.ShouldProcess("Target", "Operation")) { | ||
| "Installing Salesforce CLI using npm..." | Write-MyHost | ||
| Invoke-MyCommand -Command SalesforceCliInstall | ||
| } | ||
| } | ||
|
|
||
| # Sf installation check | ||
| $sfversion = Invoke-MyCommand -Command GetSalesforceCliVersion -ErrorAction SilentlyContinue | ||
| if($null -eq $sfversion){ | ||
| "1. Salesforce Cli installation failed. Run ""npm install @salesforce/cli --global"" to install manually!!!" | Write-MyError | ||
| return | ||
| } else{ | ||
| "1. Salesforce CLI installed. Version: $sfversion} " | Write-ToConsole -Color "Green" | ||
| } | ||
|
|
||
| # Sf logging | ||
| $result = Invoke-MyCommand -Command SalesforceCliDisplay -ErrorAction SilentlyContinue | ConvertFrom-Json -ErrorAction SilentlyContinue | ||
| $result | Write-MyVerbose | ||
| $user = $result.result | ||
| if($user.connectedStatus -eq "Connected"){ | ||
| "2. Salesforce CLI already connected with user $($user.username)" | Write-ToConsole -Color "Green" | ||
| } else { | ||
| "2. Run the following command to loging to Salesforce CLI: ""sf org login device""" | Write-ToConsole -Color "Magenta" | ||
| return | ||
| } | ||
|
|
||
| # # Logging in to Salesforce CLI | ||
| # "Loging in to Salesforce CLI..." | Write-MyHost | ||
| # if ($PSCmdlet.ShouldProcess("Target", "Operation")) { | ||
| # Invoke-MyCommand -Command SalesforceCliLogin | ||
| # } | ||
|
|
||
| $result = Invoke-MyCommand -Command SalesforceCliGetConfig -ErrorAction SilentlyContinue | ConvertFrom-Json -ErrorAction SilentlyContinue | ||
| $result | Write-MyVerbose | ||
| $config = $result.result | ||
| if($config.success){ | ||
| "3. Salesforce CLI configured with user $($config.value)" | Write-ToConsole -Color "Green" | ||
| } else { | ||
| "3. Salesforce CLI not configured. Run the following command to configure Salesforce CLI: ""sf config set --global target-org {email}""" | Write-ToConsole -Color "Magenta" | ||
| return | ||
| } | ||
|
|
||
| "Installing Salesforce CLI using npm..." | Write-MyHost | ||
| $result = Invoke-MyCommand -Command SalesforceCliInstall | ||
| # # Configure Salesforce CLI | ||
| # $email = Invoke-MyCommand -Command GetUserEmail | ||
| # "Configuring Salesforce CLI ..." | Write-MyHost | ||
| # if($email){ | ||
| # $json = Invoke-MyCommand -Command SalesforceCliSetConfig -Parameters @{ email = $email } | ||
| # $result = $json | ConvertFrom-Json -ErrorAction SilentlyContinue | ||
| # if($user.result.successes.success){ | ||
| # "Configured Salesforce CLI with user $($user.result.successes.value) " | Write-MyHost | ||
| # } else { | ||
| # "Salesforce CLI configuration failed with email $email" | Write-MyError | ||
| # return | ||
| # } | ||
| # } else { | ||
| # "Can not find your github user. Run the following command to configure your Salesforce CLI: sf config set --global target-org {email}" | Write-MyHost | ||
| # "Salesforce CLI installed but pending to be configured." | Write-MyWarning | ||
| # return | ||
| # } | ||
|
|
||
| return $result | ||
| } Export-ModuleMember -Function Install-SalesforceClient |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / PSScriptAnalyzer
Command accepts pipeline input but has not defined a process block. Warning