Files
sf-cli-wrapper/sf-deploy.ps1
reynold 579264e3d1 Update PowerShell scripts to use consistent two-character options (Part 1)
🔄 PowerShell Option Consistency - Phase 1 Complete:

 Updated Scripts:
  - sf-deploy.ps1: -to, -sr, -dr, -ts, -hp (matches Bash)
  - sf-dry-run.ps1: -to, -sr, -dr, -ts, -hp (matches Bash)
  - sf-web-open.ps1: -to, -pt, -ur, -hp (matches Bash)
  - sf-check.ps1: -vb, -hp (matches Bash)
  - sf-org-create.ps1: -al, -dd, -df, -st, -tp, -hp (matches Bash)

🎯 Consistency Achieved:
  - All parameter names now match their Bash counterparts exactly
  - Help text updated with descriptive option names
  - Examples updated to show new two-character options
  - All validation logic updated to use new parameter names

🚀 Cross-Platform Alignment:
  - PowerShell and Bash scripts now have identical option schemes
  - Users get consistent experience across platforms
  - No more confusion between single-char and two-char options

Remaining: 7 more PowerShell scripts to update for full consistency.
2025-08-28 19:19:15 +08:00

147 lines
4.1 KiB
PowerShell

param(
[string]$to = "",
[string]$sr = "",
[string]$dr = "",
[string]$ts = "",
[switch]$hp
)
function Show-Help {
@"
sf-deploy.ps1 PowerShell wrapper for ``sf project deploy start``
USAGE:
sf-deploy.ps1 -to <ORG_ALIAS_OR_USERNAME> (-sr "<src1>,<src2>[,...]" | -dr <DIRECTORY>) [-ts "<Test1>,<Test2>[,...]"]
sf-deploy.ps1 -hp
OPTIONS:
-to Target org alias or username for --target-org
-sr Sources - comma-separated list of --source-dir paths
-dr Directory - single directory path to deploy (alternative to -sr)
-ts Tests - comma-separated list of --tests (enables --test-level RunSpecifiedTests)
-hp Help - show this help
EXAMPLES:
1) Real deploy with multiple flexipages (specific files):
sf-deploy.ps1 -to "DEMO-ORG" ``
-sr "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Page_Backup_With_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
2) Real deploy with entire directory:
sf-deploy.ps1 -to "DEMO-ORG" -dr "force-app/main/default/classes"
3) Real deploy with specified tests:
sf-deploy.ps1 -to "DEMO-ORG" ``
-sr "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" ``
-ts "SelectorOpportunity_Test,SelectorOpportunity2_Test"
Notes:
- Use -sr for specific files (comma-separated) OR -dr for entire directories (not both).
- Pass absolute or repo-relative paths.
- Multiple tests are comma-separated in -ts; they will be expanded to multiple --tests flags.
"@
}
# Show help if requested or no parameters provided
if ($hp -or ($to -eq "" -and $sr -eq "" -and $dr -eq "" -and $ts -eq "")) {
Show-Help
exit 0
}
# Validate that either -sr or -dr is provided, but not both
if ($sr -ne "" -and $dr -ne "") {
Write-Error "Cannot use both -sr and -dr options. Use -sr for specific files or -dr for directories."
Write-Host ""
Show-Help
exit 1
}
# Validate required parameters
if ($to -eq "" -or ($sr -eq "" -and $dr -eq "")) {
Write-Error "Must provide -to (org) and either -sr (specific files) or -dr (directory path)."
Write-Host ""
Show-Help
exit 1
}
# Silent environment check - verify SF CLI is available
try {
Get-Command sf -ErrorAction Stop | Out-Null
}
catch {
Write-Host "❌ Salesforce CLI (sf) not found!" -ForegroundColor Red
Write-Host ""
Write-Host "Running environment check to help you get started..."
Write-Host ""
# Try to find and run sf-check.ps1 in the same directory as this script
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$sfCheckPath = Join-Path $scriptDir "sf-check.ps1"
if (Test-Path $sfCheckPath) {
& $sfCheckPath
}
elseif (Get-Command sf-check.ps1 -ErrorAction SilentlyContinue) {
sf-check.ps1
}
else {
Write-Host "sf-check.ps1 not found. Please install the Salesforce CLI from:"
Write-Host "https://developer.salesforce.com/tools/sfdxcli"
}
exit 1
}
# Build the command array
$cmd = @("sf", "project", "deploy", "start")
# Add source directories (specific files)
if ($sr -ne "") {
$sourcesArray = $sr -split ","
foreach ($src in $sourcesArray) {
$src = $src.Trim()
if ($src -ne "") {
$cmd += "--source-dir"
$cmd += $src
}
}
}
# Add directory path
if ($dr -ne "") {
$cmd += "--source-dir"
$cmd += $dr
}
# Add target org
if ($to -ne "") {
$cmd += "--target-org"
$cmd += $to
}
# Add tests if specified
if ($ts -ne "") {
$testsArray = $ts -split ","
$cmd += "--test-level"
$cmd += "RunSpecifiedTests"
foreach ($test in $testsArray) {
$test = $test.Trim()
if ($test -ne "") {
$cmd += "--tests"
$cmd += $test
}
}
}
# Display the command being executed
Write-Host ">>> Running: $($cmd -join ' ')" -ForegroundColor Yellow
# Execute the command
try {
& $cmd[0] $cmd[1..($cmd.Length-1)]
exit $LASTEXITCODE
}
catch {
Write-Error "Failed to execute sf command: $_"
exit 1
}