updated scripts
This commit is contained in:
379
README.md
379
README.md
@@ -0,0 +1,379 @@
|
||||
# Salesforce CLI Wrapper Scripts
|
||||
|
||||
A collection of convenient wrapper scripts for common Salesforce CLI operations. These scripts simplify complex `sf` commands by providing intuitive interfaces for deployment, testing, and org management tasks.
|
||||
|
||||
**Available for both Unix/Linux/macOS (Bash) and Windows (PowerShell).**
|
||||
|
||||
## Overview
|
||||
|
||||
This toolkit provides four main utilities:
|
||||
|
||||
- **`sf-deploy`** - Streamlined wrapper for `sf project deploy start`
|
||||
- **`sf-dry-run`** - Validation wrapper for `sf project deploy start --dry-run`
|
||||
- **`sf-web-open`** - Quick org browser opener for `sf org open`
|
||||
- **`sf-check`** - Environment verification tool to check SF CLI installation and configuration
|
||||
|
||||
## Installation
|
||||
|
||||
### Unix/Linux/macOS (Bash)
|
||||
|
||||
1. Clone or download this repository to your preferred tools directory
|
||||
2. Make the scripts executable:
|
||||
```bash
|
||||
chmod +x sf-deploy sf-dry-run sf-web-open sf-check
|
||||
```
|
||||
3. Add the directory to your PATH or create symlinks in a directory that's already in your PATH:
|
||||
```bash
|
||||
# Option 1: Add to PATH (add to your ~/.zshrc or ~/.bashrc)
|
||||
export PATH="$PATH:/path/to/sf-cli-wrapper"
|
||||
|
||||
# Option 2: Create symlinks
|
||||
ln -s /path/to/sf-cli-wrapper/sf-deploy /usr/local/bin/sf-deploy
|
||||
ln -s /path/to/sf-cli-wrapper/sf-dry-run /usr/local/bin/sf-dry-run
|
||||
ln -s /path/to/sf-cli-wrapper/sf-web-open /usr/local/bin/sf-web-open
|
||||
ln -s /path/to/sf-cli-wrapper/sf-check /usr/local/bin/sf-check
|
||||
```
|
||||
|
||||
### Windows (PowerShell)
|
||||
|
||||
1. Clone or download this repository to your preferred tools directory
|
||||
2. Set the PowerShell execution policy to allow script execution (run as Administrator):
|
||||
```powershell
|
||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
|
||||
```
|
||||
3. Add the directory to your PATH or create a PowerShell profile with aliases:
|
||||
```powershell
|
||||
# Option 1: Add to PATH (System Environment Variables)
|
||||
# Add C:\path\to\sf-cli-wrapper to your system PATH
|
||||
|
||||
# Option 2: Create PowerShell aliases (add to your $PROFILE)
|
||||
Set-Alias sf-deploy "C:\path\to\sf-cli-wrapper\sf-deploy.ps1"
|
||||
Set-Alias sf-dry-run "C:\path\to\sf-cli-wrapper\sf-dry-run.ps1"
|
||||
Set-Alias sf-web-open "C:\path\to\sf-cli-wrapper\sf-web-open.ps1"
|
||||
Set-Alias sf-check "C:\path\to\sf-cli-wrapper\sf-check.ps1"
|
||||
```
|
||||
|
||||
## Scripts
|
||||
|
||||
### sf-deploy
|
||||
|
||||
Wrapper for `sf project deploy start` that simplifies deploying multiple source files with optional test execution.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
sf-deploy -o <ORG_ALIAS_OR_USERNAME> (-s "<src1>,<src2>[,...]" | -d <DIRECTORY>) [-t "<Test1>,<Test2>[,...]"]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
- `-o` - Org alias or username for --target-org
|
||||
- `-s` - Comma-separated list of --source-dir paths
|
||||
- `-d` - Single directory path to deploy (alternative to -s)
|
||||
- `-t` - Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
|
||||
- `-h` - Show help
|
||||
|
||||
**Examples:**
|
||||
```bash
|
||||
# Deploy multiple flexipages (specific files)
|
||||
sf-deploy -o DEMO-ORG \
|
||||
-s "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"
|
||||
|
||||
# Deploy entire directory
|
||||
sf-deploy -o DEMO-ORG -d "force-app/main/default/classes"
|
||||
|
||||
# Deploy with specific tests
|
||||
sf-deploy -o DEMO-ORG \
|
||||
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
|
||||
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
|
||||
```
|
||||
|
||||
### sf-dry-run
|
||||
|
||||
Wrapper for `sf project deploy start --dry-run` that validates deployments without actually deploying.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
sf-dry-run -o <ORG_ALIAS_OR_USERNAME> (-s "<src1>,<src2>[,...]" | -d <DIRECTORY>) [-t "<Test1>,<Test2>[,...]"]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
- `-o` - Org alias or username for --target-org
|
||||
- `-s` - Comma-separated list of --source-dir paths
|
||||
- `-d` - Single directory path to validate (alternative to -s)
|
||||
- `-t` - Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
|
||||
- `-h` - Show help
|
||||
|
||||
**Examples:**
|
||||
```bash
|
||||
# Validate multiple flexipages (specific files)
|
||||
sf-dry-run -o DEMO-ORG \
|
||||
-s "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
|
||||
|
||||
# Validate entire directory
|
||||
sf-dry-run -o DEMO-ORG -d "force-app/main/default/classes"
|
||||
|
||||
# Validate with specific tests
|
||||
sf-dry-run -o DEMO-ORG \
|
||||
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
|
||||
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
|
||||
```
|
||||
|
||||
### sf-web-open
|
||||
|
||||
Wrapper for `sf org open` that provides quick access to Salesforce orgs with optional path navigation.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
sf-web-open [-o <ORG_ALIAS_OR_USERNAME>] [-p <RELATIVE_PATH>] [-U]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
- `-o` - Org alias or username to pass as --target-org
|
||||
- `-p` - Relative path to open inside the org (e.g., "/lightning/setup/SetupOneHome/home")
|
||||
- `-U` - URL-only: print the URL instead of opening a browser (passes --url-only)
|
||||
- `-h` - Show help
|
||||
|
||||
**Examples:**
|
||||
```bash
|
||||
# Open a specific org (default home)
|
||||
sf-web-open -o DEMO-ORG
|
||||
|
||||
# Open Setup Home of a target org
|
||||
sf-web-open -o NUSHUB-DR2 -p "/lightning/setup/SetupOneHome/home"
|
||||
|
||||
# Get just the URL for scripting
|
||||
sf-web-open -o NUSHUB-DR2 -U
|
||||
|
||||
# Open the current default org
|
||||
sf-web-open
|
||||
```
|
||||
|
||||
### sf-check
|
||||
|
||||
Environment verification tool that checks if the Salesforce CLI is properly installed and configured.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
sf-check [-v] [-h]
|
||||
```
|
||||
|
||||
**Options:**
|
||||
- `-v` - Verbose output (show detailed information)
|
||||
- `-h` - Show help
|
||||
|
||||
**Examples:**
|
||||
```bash
|
||||
# Basic environment check
|
||||
sf-check
|
||||
|
||||
# Verbose output with detailed system information
|
||||
sf-check -v
|
||||
```
|
||||
|
||||
**What it checks:**
|
||||
- SF CLI installation and version
|
||||
- Authenticated orgs and default org configuration
|
||||
- System requirements (Node.js, Git, etc.)
|
||||
- SF CLI plugins and diagnostics
|
||||
- Common configuration issues
|
||||
|
||||
## Automatic Environment Verification
|
||||
|
||||
All wrapper scripts (`sf-deploy`, `sf-dry-run`, `sf-web-open`) include built-in environment verification:
|
||||
|
||||
### ✅ **When SF CLI is installed (normal operation):**
|
||||
```bash
|
||||
$ sf-deploy -o DEMO-ORG -d "force-app/main/default/classes"
|
||||
>>> Running: sf project deploy start --source-dir force-app/main/default/classes --target-org DEMO-ORG
|
||||
# [deployment proceeds immediately]
|
||||
```
|
||||
|
||||
### ❌ **When SF CLI is missing:**
|
||||
```bash
|
||||
$ sf-deploy -o DEMO-ORG -d "force-app/main/default/classes"
|
||||
❌ Salesforce CLI (sf) not found!
|
||||
|
||||
Running environment check to help you get started...
|
||||
|
||||
🔍 Salesforce CLI Environment Check
|
||||
==================================
|
||||
[✗] Salesforce CLI (sf) not found in PATH
|
||||
Please install the Salesforce CLI from: https://developer.salesforce.com/tools/sfdxcli
|
||||
[✗] Unable to list orgs (sf org list failed)
|
||||
[!] No default org configured
|
||||
==================================
|
||||
[✗] Some critical issues found. Please address them before using the SF CLI wrappers.
|
||||
```
|
||||
|
||||
### **How It Works:**
|
||||
- **Silent Check**: Scripts automatically verify SF CLI availability
|
||||
- **Zero Performance Impact**: Only activates when there's actually a problem
|
||||
- **Intelligent Discovery**: Automatically finds and runs `sf-check` diagnostics
|
||||
- **Cross-Platform**: Same experience on Bash and PowerShell
|
||||
- **User-Friendly**: Clear error messages and actionable guidance
|
||||
|
||||
## Windows PowerShell Examples
|
||||
|
||||
For Windows users, here are the PowerShell equivalents of the bash examples:
|
||||
|
||||
### sf-deploy.ps1
|
||||
|
||||
```powershell
|
||||
# Deploy multiple flexipages (specific files)
|
||||
sf-deploy.ps1 -o "DEMO-ORG" `
|
||||
-s "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"
|
||||
|
||||
# Deploy entire directory
|
||||
sf-deploy.ps1 -o "DEMO-ORG" -d "force-app/main/default/classes"
|
||||
|
||||
# Deploy with specific tests
|
||||
sf-deploy.ps1 -o "DEMO-ORG" `
|
||||
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" `
|
||||
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
|
||||
```
|
||||
|
||||
### sf-dry-run.ps1
|
||||
|
||||
```powershell
|
||||
# Validate multiple flexipages (specific files)
|
||||
sf-dry-run.ps1 -o "DEMO-ORG" `
|
||||
-s "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
|
||||
|
||||
# Validate entire directory
|
||||
sf-dry-run.ps1 -o "DEMO-ORG" -d "force-app/main/default/classes"
|
||||
|
||||
# Validate with specific tests
|
||||
sf-dry-run.ps1 -o "DEMO-ORG" `
|
||||
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" `
|
||||
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
|
||||
```
|
||||
|
||||
### sf-web-open.ps1
|
||||
|
||||
```powershell
|
||||
# Open a specific org (default home)
|
||||
sf-web-open.ps1 -o "DEMO-ORG"
|
||||
|
||||
# Open Setup Home of a target org
|
||||
sf-web-open.ps1 -o "NUSHUB-DR2" -p "/lightning/setup/SetupOneHome/home"
|
||||
|
||||
# Get just the URL for scripting
|
||||
sf-web-open.ps1 -o "NUSHUB-DR2" -U
|
||||
|
||||
# Open the current default org
|
||||
sf-web-open.ps1
|
||||
```
|
||||
|
||||
### Windows Common Workflows
|
||||
|
||||
```powershell
|
||||
# 1. First, validate your deployment (specific file)
|
||||
sf-dry-run.ps1 -o "DEMO-ORG" -s "force-app/main/default/classes/MyClass.cls"
|
||||
|
||||
# 2. If validation passes, deploy for real
|
||||
sf-deploy.ps1 -o "DEMO-ORG" -s "force-app/main/default/classes/MyClass.cls"
|
||||
|
||||
# 3. Open the org to verify changes
|
||||
sf-web-open.ps1 -o "DEMO-ORG"
|
||||
|
||||
# Alternative: Deploy entire directory
|
||||
sf-dry-run.ps1 -o "DEMO-ORG" -d "force-app/main/default/classes"
|
||||
sf-deploy.ps1 -o "DEMO-ORG" -d "force-app/main/default/classes"
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- **Salesforce CLI (sf)**: Make sure you have the Salesforce CLI installed and configured
|
||||
- **Shell Environment**:
|
||||
- **Unix/Linux/macOS**: Bash 4.0+ (macOS users may need to upgrade from the default Bash 3.x)
|
||||
- **Windows**: PowerShell 5.1+ (PowerShell Core 7+ recommended)
|
||||
- **Authenticated Orgs**: Ensure you have authenticated to the target orgs using `sf org login`
|
||||
|
||||
## Common Workflows
|
||||
|
||||
### Deployment with Validation
|
||||
```bash
|
||||
# 1. First, validate your deployment (specific file)
|
||||
sf-dry-run -o DEMO-ORG -s "force-app/main/default/classes/MyClass.cls"
|
||||
|
||||
# 2. If validation passes, deploy for real
|
||||
sf-deploy -o DEMO-ORG -s "force-app/main/default/classes/MyClass.cls"
|
||||
|
||||
# 3. Open the org to verify changes
|
||||
sf-web-open -o DEMO-ORG
|
||||
|
||||
# Alternative: Deploy entire directory
|
||||
sf-dry-run -o DEMO-ORG -d "force-app/main/default/classes"
|
||||
sf-deploy -o DEMO-ORG -d "force-app/main/default/classes"
|
||||
```
|
||||
|
||||
### Working with Multiple Files
|
||||
```bash
|
||||
# Deploy multiple related components (specific files)
|
||||
sf-deploy -o DEMO-ORG \
|
||||
-s "force-app/main/default/classes/MyController.cls,force-app/main/default/classes/MyControllerTest.cls,force-app/main/default/aura/MyComponent"
|
||||
|
||||
# Deploy entire directories
|
||||
sf-deploy -o DEMO-ORG -d "force-app/main/default/aura"
|
||||
sf-deploy -o DEMO-ORG -d "force-app/main/default/lwc"
|
||||
```
|
||||
|
||||
### Testing Specific Classes
|
||||
```bash
|
||||
# Deploy with specific test execution
|
||||
sf-deploy -o DEMO-ORG \
|
||||
-s "force-app/main/default/classes/MyClass.cls" \
|
||||
-t "MyClassTest,RelatedClassTest"
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- **Cross-Platform**: Available for both Unix/Linux/macOS (Bash) and Windows (PowerShell)
|
||||
- **Automatic Environment Verification**: Scripts automatically check if SF CLI is available and run diagnostics if not
|
||||
- **Error Handling**: All scripts include robust error handling
|
||||
- **Help Documentation**: Each script includes comprehensive help accessible with `-h` (both Bash and PowerShell)
|
||||
- **Flexible Input**: Support for both absolute and repository-relative paths
|
||||
- **Command Echo**: Shows the actual `sf` command being executed for transparency
|
||||
- **Multiple Sources**: Easy handling of multiple source directories and test classes
|
||||
- **Parameter Validation**: Scripts validate required parameters and show helpful error messages
|
||||
|
||||
## Tips
|
||||
|
||||
1. **Use Tab Completion**: Most shells support tab completion for file paths when using these scripts
|
||||
2. **Combine with Git**: Use `git status` to identify modified files for targeted deployments
|
||||
3. **Org Aliases**: Set up meaningful org aliases with `sf org login` for easier reference
|
||||
4. **Path Flexibility**: You can use both absolute paths and paths relative to your project root
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **"Command not found"**:
|
||||
- **Unix/Linux/macOS**: Ensure the scripts are executable and in your PATH
|
||||
- **Windows**: Check PowerShell execution policy and script location
|
||||
2. **"No default org found"**: Specify the org parameter or set a default org with `sf config set target-org`
|
||||
3. **"Source path not found"**: Verify file paths are correct relative to your project root
|
||||
4. **Windows PowerShell Execution Policy**: If scripts won't run, check execution policy with `Get-ExecutionPolicy`
|
||||
|
||||
### Debug Mode
|
||||
|
||||
To see exactly what command is being executed, look for the ">>> Running:" output that each script prints before execution.
|
||||
|
||||
## Contributing
|
||||
|
||||
Feel free to extend these scripts or create additional wrappers for other Salesforce CLI commands. The scripts follow a consistent pattern:
|
||||
|
||||
**Bash Scripts:**
|
||||
1. Help function with usage examples
|
||||
2. Argument parsing with `getopts`
|
||||
3. Command array building
|
||||
4. Command execution with `exec`
|
||||
|
||||
**PowerShell Scripts:**
|
||||
1. Parameter definitions with validation
|
||||
2. Help function with usage examples
|
||||
3. Parameter validation and processing
|
||||
4. Command array building and execution
|
||||
|
||||
## License
|
||||
|
||||
These scripts are provided as-is for convenience. Modify and distribute as needed for your projects.
|
||||
|
||||
264
sf-check
Executable file
264
sf-check
Executable file
@@ -0,0 +1,264 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
show_help() {
|
||||
cat <<'EOF'
|
||||
sf-check — verify Salesforce CLI environment and configuration
|
||||
|
||||
USAGE:
|
||||
sf-check [-v] [-h]
|
||||
|
||||
OPTIONS:
|
||||
-v Verbose output (show detailed information)
|
||||
-h Show this help
|
||||
|
||||
DESCRIPTION:
|
||||
This script verifies that the Salesforce CLI is properly installed and configured.
|
||||
It checks for:
|
||||
- SF CLI installation and version
|
||||
- Available orgs and authentication status
|
||||
- Basic configuration settings
|
||||
- Common issues and recommendations
|
||||
|
||||
EXAMPLES:
|
||||
sf-check # Basic environment check
|
||||
sf-check -v # Verbose output with detailed information
|
||||
EOF
|
||||
}
|
||||
|
||||
# Function to print status messages
|
||||
print_status() {
|
||||
local status="$1"
|
||||
local message="$2"
|
||||
case "$status" in
|
||||
"OK")
|
||||
printf "[${GREEN}✓${NC}] %s\n" "$message"
|
||||
;;
|
||||
"WARN")
|
||||
printf "[${YELLOW}!${NC}] %s\n" "$message"
|
||||
;;
|
||||
"ERROR")
|
||||
printf "[${RED}✗${NC}] %s\n" "$message"
|
||||
;;
|
||||
"INFO")
|
||||
printf "[${BLUE}i${NC}] %s\n" "$message"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to check if a command exists
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to check SF CLI installation
|
||||
check_sf_installation() {
|
||||
print_status "INFO" "Checking Salesforce CLI installation..."
|
||||
|
||||
if command_exists sf; then
|
||||
local sf_version
|
||||
sf_version=$(sf --version 2>/dev/null | head -n 1 || echo "unknown")
|
||||
print_status "OK" "Salesforce CLI found: $sf_version"
|
||||
|
||||
if [[ "$VERBOSE" == "true" ]]; then
|
||||
echo " Location: $(which sf)"
|
||||
fi
|
||||
return 0
|
||||
else
|
||||
print_status "ERROR" "Salesforce CLI (sf) not found in PATH"
|
||||
echo " Please install the Salesforce CLI from: https://developer.salesforce.com/tools/sfdxcli"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check authenticated orgs
|
||||
check_orgs() {
|
||||
print_status "INFO" "Checking authenticated orgs..."
|
||||
|
||||
if ! command_exists sf; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
local org_list
|
||||
if org_list=$(sf org list --json 2>/dev/null); then
|
||||
local org_count
|
||||
org_count=$(echo "$org_list" | jq -r '.result | length' 2>/dev/null || echo "0")
|
||||
|
||||
if [[ "$org_count" -gt 0 ]]; then
|
||||
print_status "OK" "Found $org_count authenticated org(s)"
|
||||
|
||||
if [[ "$VERBOSE" == "true" ]]; then
|
||||
echo "$org_list" | jq -r '.result[] | " - \(.alias // .username) (\(.orgId[0:15])...)"' 2>/dev/null || {
|
||||
echo " (Unable to parse org details - jq not available)"
|
||||
}
|
||||
fi
|
||||
else
|
||||
print_status "WARN" "No authenticated orgs found"
|
||||
echo " Run 'sf org login web' or 'sf org login jwt' to authenticate"
|
||||
fi
|
||||
else
|
||||
print_status "ERROR" "Unable to list orgs (sf org list failed)"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check default org
|
||||
check_default_org() {
|
||||
print_status "INFO" "Checking default org configuration..."
|
||||
|
||||
if ! command_exists sf; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
local default_org
|
||||
if default_org=$(sf config get target-org --json 2>/dev/null | jq -r '.result[0].value // empty' 2>/dev/null); then
|
||||
if [[ -n "$default_org" && "$default_org" != "null" ]]; then
|
||||
print_status "OK" "Default org set: $default_org"
|
||||
else
|
||||
print_status "WARN" "No default org configured"
|
||||
echo " Set with: sf config set target-org <org-alias>"
|
||||
fi
|
||||
else
|
||||
print_status "WARN" "Unable to check default org configuration"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check plugins
|
||||
check_plugins() {
|
||||
if [[ "$VERBOSE" != "true" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
print_status "INFO" "Checking installed plugins..."
|
||||
|
||||
if ! command_exists sf; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
local plugins
|
||||
if plugins=$(sf plugins --json 2>/dev/null | jq -r '.result[] | .name' 2>/dev/null); then
|
||||
if [[ -n "$plugins" ]]; then
|
||||
echo "$plugins" | while IFS= read -r plugin; do
|
||||
echo " - $plugin"
|
||||
done
|
||||
else
|
||||
echo " No additional plugins installed"
|
||||
fi
|
||||
else
|
||||
echo " Unable to list plugins"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check system requirements
|
||||
check_system() {
|
||||
if [[ "$VERBOSE" != "true" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
print_status "INFO" "System information..."
|
||||
|
||||
echo " OS: $(uname -s) $(uname -r)"
|
||||
echo " Shell: $SHELL"
|
||||
|
||||
if command_exists node; then
|
||||
echo " Node.js: $(node --version)"
|
||||
else
|
||||
print_status "WARN" "Node.js not found (required for some SF CLI features)"
|
||||
fi
|
||||
|
||||
if command_exists git; then
|
||||
echo " Git: $(git --version | head -n 1)"
|
||||
else
|
||||
print_status "WARN" "Git not found (recommended for source control)"
|
||||
fi
|
||||
|
||||
if command_exists jq; then
|
||||
echo " jq: $(jq --version)"
|
||||
else
|
||||
print_status "WARN" "jq not found (recommended for JSON processing)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run diagnostics
|
||||
run_diagnostics() {
|
||||
print_status "INFO" "Running SF CLI diagnostics..."
|
||||
|
||||
if ! command_exists sf; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if sf doctor --json >/dev/null 2>&1; then
|
||||
print_status "OK" "SF CLI doctor check passed"
|
||||
else
|
||||
print_status "WARN" "SF CLI doctor check had issues"
|
||||
if [[ "$VERBOSE" == "true" ]]; then
|
||||
echo " Run 'sf doctor' for detailed diagnostics"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
VERBOSE=false
|
||||
|
||||
while getopts ":vh" opt; do
|
||||
case "$opt" in
|
||||
v) VERBOSE=true ;;
|
||||
h) show_help; exit 0 ;;
|
||||
\?) echo "Unknown option: -$OPTARG" >&2; echo; show_help; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
echo "🔍 Salesforce CLI Environment Check"
|
||||
echo "=================================="
|
||||
echo ""
|
||||
|
||||
local has_errors=false
|
||||
|
||||
# Core checks
|
||||
if ! check_sf_installation; then
|
||||
has_errors=true
|
||||
fi
|
||||
|
||||
check_orgs || has_errors=true
|
||||
check_default_org
|
||||
|
||||
# Additional checks for verbose mode
|
||||
if [[ "$VERBOSE" == "true" ]]; then
|
||||
echo ""
|
||||
check_plugins
|
||||
echo ""
|
||||
check_system
|
||||
echo ""
|
||||
run_diagnostics
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=================================="
|
||||
|
||||
if [[ "$has_errors" == "true" ]]; then
|
||||
print_status "ERROR" "Some critical issues found. Please address them before using the SF CLI wrappers."
|
||||
exit 1
|
||||
else
|
||||
print_status "OK" "Environment check completed successfully!"
|
||||
echo ""
|
||||
echo "Your Salesforce CLI environment is ready to use with sf-cli-wrapper scripts."
|
||||
echo "Available commands: sf-deploy, sf-dry-run, sf-web-open"
|
||||
|
||||
if [[ "$VERBOSE" != "true" ]]; then
|
||||
echo ""
|
||||
echo "Run 'sf-check -v' for detailed system information."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main
|
||||
337
sf-check.ps1
Normal file
337
sf-check.ps1
Normal file
@@ -0,0 +1,337 @@
|
||||
param(
|
||||
[switch]$v,
|
||||
[switch]$h
|
||||
)
|
||||
|
||||
function Show-Help {
|
||||
@"
|
||||
sf-check.ps1 — verify Salesforce CLI environment and configuration
|
||||
|
||||
USAGE:
|
||||
sf-check.ps1 [-v] [-h]
|
||||
|
||||
OPTIONS:
|
||||
-v Verbose output (show detailed information)
|
||||
-h Show this help
|
||||
|
||||
DESCRIPTION:
|
||||
This script verifies that the Salesforce CLI is properly installed and configured.
|
||||
It checks for:
|
||||
- SF CLI installation and version
|
||||
- Available orgs and authentication status
|
||||
- Basic configuration settings
|
||||
- Common issues and recommendations
|
||||
|
||||
EXAMPLES:
|
||||
sf-check.ps1 # Basic environment check
|
||||
sf-check.ps1 -v # Verbose output with detailed information
|
||||
"@
|
||||
}
|
||||
|
||||
# Function to print status messages with colors
|
||||
function Write-Status {
|
||||
param(
|
||||
[string]$Status,
|
||||
[string]$Message
|
||||
)
|
||||
|
||||
switch ($Status) {
|
||||
"OK" {
|
||||
Write-Host "[" -NoNewline
|
||||
Write-Host "✓" -ForegroundColor Green -NoNewline
|
||||
Write-Host "] $Message"
|
||||
}
|
||||
"WARN" {
|
||||
Write-Host "[" -NoNewline
|
||||
Write-Host "!" -ForegroundColor Yellow -NoNewline
|
||||
Write-Host "] $Message"
|
||||
}
|
||||
"ERROR" {
|
||||
Write-Host "[" -NoNewline
|
||||
Write-Host "✗" -ForegroundColor Red -NoNewline
|
||||
Write-Host "] $Message"
|
||||
}
|
||||
"INFO" {
|
||||
Write-Host "[" -NoNewline
|
||||
Write-Host "i" -ForegroundColor Blue -NoNewline
|
||||
Write-Host "] $Message"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Function to check if a command exists
|
||||
function Test-Command {
|
||||
param([string]$CommandName)
|
||||
try {
|
||||
Get-Command $CommandName -ErrorAction Stop | Out-Null
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
# Function to check SF CLI installation
|
||||
function Test-SfInstallation {
|
||||
Write-Status "INFO" "Checking Salesforce CLI installation..."
|
||||
|
||||
if (Test-Command "sf") {
|
||||
try {
|
||||
$sfVersion = & sf --version 2>$null | Select-Object -First 1
|
||||
if ([string]::IsNullOrEmpty($sfVersion)) {
|
||||
$sfVersion = "unknown"
|
||||
}
|
||||
Write-Status "OK" "Salesforce CLI found: $sfVersion"
|
||||
|
||||
if ($Verbose) {
|
||||
$sfPath = (Get-Command sf).Source
|
||||
Write-Host " Location: $sfPath"
|
||||
}
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
Write-Status "ERROR" "Salesforce CLI found but unable to get version"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Status "ERROR" "Salesforce CLI (sf) not found in PATH"
|
||||
Write-Host " Please install the Salesforce CLI from: https://developer.salesforce.com/tools/sfdxcli"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
# Function to check authenticated orgs
|
||||
function Test-Orgs {
|
||||
Write-Status "INFO" "Checking authenticated orgs..."
|
||||
|
||||
if (-not (Test-Command "sf")) {
|
||||
return $false
|
||||
}
|
||||
|
||||
try {
|
||||
$orgListJson = & sf org list --json 2>$null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$orgList = $orgListJson | ConvertFrom-Json
|
||||
$orgCount = $orgList.result.Count
|
||||
|
||||
if ($orgCount -gt 0) {
|
||||
Write-Status "OK" "Found $orgCount authenticated org(s)"
|
||||
|
||||
if ($Verbose) {
|
||||
foreach ($org in $orgList.result) {
|
||||
$displayName = if ($org.alias) { $org.alias } else { $org.username }
|
||||
$orgIdShort = $org.orgId.Substring(0, 15)
|
||||
Write-Host " - $displayName ($orgIdShort...)"
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Status "WARN" "No authenticated orgs found"
|
||||
Write-Host " Run 'sf org login web' or 'sf org login jwt' to authenticate"
|
||||
}
|
||||
return $true
|
||||
}
|
||||
else {
|
||||
Write-Status "ERROR" "Unable to list orgs (sf org list failed)"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Status "ERROR" "Error checking authenticated orgs: $($_.Exception.Message)"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
# Function to check default org
|
||||
function Test-DefaultOrg {
|
||||
Write-Status "INFO" "Checking default org configuration..."
|
||||
|
||||
if (-not (Test-Command "sf")) {
|
||||
return $false
|
||||
}
|
||||
|
||||
try {
|
||||
$configJson = & sf config get target-org --json 2>$null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$config = $configJson | ConvertFrom-Json
|
||||
$defaultOrg = $config.result[0].value
|
||||
|
||||
if ($defaultOrg -and $defaultOrg -ne "null") {
|
||||
Write-Status "OK" "Default org set: $defaultOrg"
|
||||
}
|
||||
else {
|
||||
Write-Status "WARN" "No default org configured"
|
||||
Write-Host " Set with: sf config set target-org <org-alias>"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Status "WARN" "Unable to check default org configuration"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Status "WARN" "Unable to check default org configuration"
|
||||
}
|
||||
}
|
||||
|
||||
# Function to check plugins
|
||||
function Test-Plugins {
|
||||
if (-not $Verbose) {
|
||||
return
|
||||
}
|
||||
|
||||
Write-Status "INFO" "Checking installed plugins..."
|
||||
|
||||
if (-not (Test-Command "sf")) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
$pluginsJson = & sf plugins --json 2>$null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$plugins = $pluginsJson | ConvertFrom-Json
|
||||
if ($plugins.result.Count -gt 0) {
|
||||
foreach ($plugin in $plugins.result) {
|
||||
Write-Host " - $($plugin.name)"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host " No additional plugins installed"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host " Unable to list plugins"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host " Unable to list plugins"
|
||||
}
|
||||
}
|
||||
|
||||
# Function to check system requirements
|
||||
function Test-System {
|
||||
if (-not $Verbose) {
|
||||
return
|
||||
}
|
||||
|
||||
Write-Status "INFO" "System information..."
|
||||
|
||||
$osInfo = Get-CimInstance -ClassName Win32_OperatingSystem
|
||||
Write-Host " OS: $($osInfo.Caption) $($osInfo.Version)"
|
||||
Write-Host " PowerShell: $($PSVersionTable.PSVersion)"
|
||||
|
||||
if (Test-Command "node") {
|
||||
try {
|
||||
$nodeVersion = & node --version 2>$null
|
||||
Write-Host " Node.js: $nodeVersion"
|
||||
}
|
||||
catch {
|
||||
Write-Status "WARN" "Node.js found but unable to get version"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Status "WARN" "Node.js not found (required for some SF CLI features)"
|
||||
}
|
||||
|
||||
if (Test-Command "git") {
|
||||
try {
|
||||
$gitVersion = & git --version 2>$null
|
||||
Write-Host " Git: $gitVersion"
|
||||
}
|
||||
catch {
|
||||
Write-Status "WARN" "Git found but unable to get version"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Status "WARN" "Git not found (recommended for source control)"
|
||||
}
|
||||
}
|
||||
|
||||
# Function to run diagnostics
|
||||
function Test-Diagnostics {
|
||||
Write-Status "INFO" "Running SF CLI diagnostics..."
|
||||
|
||||
if (-not (Test-Command "sf")) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
$null = & sf doctor --json 2>$null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Status "OK" "SF CLI doctor check passed"
|
||||
}
|
||||
else {
|
||||
Write-Status "WARN" "SF CLI doctor check had issues"
|
||||
if ($Verbose) {
|
||||
Write-Host " Run 'sf doctor' for detailed diagnostics"
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Status "WARN" "SF CLI doctor check had issues"
|
||||
if ($Verbose) {
|
||||
Write-Host " Run 'sf doctor' for detailed diagnostics"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Show help if requested
|
||||
if ($h) {
|
||||
Show-Help
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Set verbose flag
|
||||
$Verbose = $v
|
||||
|
||||
# Main execution
|
||||
function Main {
|
||||
Write-Host "🔍 Salesforce CLI Environment Check" -ForegroundColor Cyan
|
||||
Write-Host "==================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
$hasErrors = $false
|
||||
|
||||
# Core checks
|
||||
if (-not (Test-SfInstallation)) {
|
||||
$hasErrors = $true
|
||||
}
|
||||
|
||||
if (-not (Test-Orgs)) {
|
||||
$hasErrors = $true
|
||||
}
|
||||
|
||||
Test-DefaultOrg
|
||||
|
||||
# Additional checks for verbose mode
|
||||
if ($Verbose) {
|
||||
Write-Host ""
|
||||
Test-Plugins
|
||||
Write-Host ""
|
||||
Test-System
|
||||
Write-Host ""
|
||||
Test-Diagnostics
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "==================================" -ForegroundColor Cyan
|
||||
|
||||
if ($hasErrors) {
|
||||
Write-Status "ERROR" "Some critical issues found. Please address them before using the SF CLI wrappers."
|
||||
exit 1
|
||||
}
|
||||
else {
|
||||
Write-Status "OK" "Environment check completed successfully!"
|
||||
Write-Host ""
|
||||
Write-Host "Your Salesforce CLI environment is ready to use with sf-cli-wrapper scripts."
|
||||
Write-Host "Available commands: sf-deploy.ps1, sf-dry-run.ps1, sf-web-open.ps1"
|
||||
|
||||
if (-not $Verbose) {
|
||||
Write-Host ""
|
||||
Write-Host "Run 'sf-check.ps1 -v' for detailed system information."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Run main function
|
||||
Main
|
||||
58
sf-deploy
58
sf-deploy
@@ -6,31 +6,37 @@ show_help() {
|
||||
sf-deploy — wrapper for `sf project deploy start`
|
||||
|
||||
USAGE:
|
||||
sf-deploy -o <ORG_ALIAS_OR_USERNAME> -s "<src1>,<src2>[,...]" [-t "<Test1>,<Test2>[,...]"]
|
||||
sf-deploy -o <ORG_ALIAS_OR_USERNAME> (-s "<src1>,<src2>[,...]" | -d <DIRECTORY>) [-t "<Test1>,<Test2>[,...]"]
|
||||
|
||||
OPTIONS:
|
||||
-o Org alias or username for --target-org
|
||||
-s Comma-separated list of --source-dir paths
|
||||
-d Single directory path to deploy (alternative to -s)
|
||||
-t Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
|
||||
-h Show this help
|
||||
|
||||
EXAMPLES:
|
||||
1) Real deploy with multiple flexipages:
|
||||
1) Real deploy with multiple flexipages (specific files):
|
||||
sf-deploy -o DEMO-ORG \
|
||||
-s "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 specified tests:
|
||||
2) Real deploy with entire directory:
|
||||
sf-deploy -o DEMO-ORG -d "force-app/main/default/classes"
|
||||
|
||||
3) Real deploy with specified tests:
|
||||
sf-deploy -o DEMO-ORG \
|
||||
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
|
||||
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
|
||||
|
||||
Notes:
|
||||
- Pass absolute or repo-relative paths in -s, separated by commas.
|
||||
- Use -s for specific files (comma-separated) OR -d for entire directories (not both).
|
||||
- Pass absolute or repo-relative paths.
|
||||
- Multiple tests are comma-separated in -t; they will be expanded to multiple --tests flags.
|
||||
EOF
|
||||
}
|
||||
|
||||
ORG=""
|
||||
DIR_PATH=""
|
||||
declare -a SOURCES_ARR=()
|
||||
declare -a TESTS_ARR=()
|
||||
|
||||
@@ -39,10 +45,11 @@ if [[ $# -eq 0 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while getopts ":o:s:t:h" opt; do
|
||||
while getopts ":o:s:d:t:h" opt; do
|
||||
case "$opt" in
|
||||
o) ORG="$OPTARG" ;;
|
||||
s) IFS=',' read -r -a SOURCES_ARR <<< "$OPTARG" ;;
|
||||
d) DIR_PATH="$OPTARG" ;;
|
||||
t) IFS=',' read -r -a TESTS_ARR <<< "$OPTARG" ;;
|
||||
h) show_help; exit 0 ;;
|
||||
\?) echo "Unknown option: -$OPTARG" >&2; echo; show_help; exit 1 ;;
|
||||
@@ -50,13 +57,52 @@ while getopts ":o:s:t:h" opt; do
|
||||
esac
|
||||
done
|
||||
|
||||
# Validate that either -s or -d is provided, but not both
|
||||
if [[ -n "$DIR_PATH" && ${#SOURCES_ARR[@]} -gt 0 ]]; then
|
||||
echo "Error: Cannot use both -s and -d options. Use -s for specific files or -d for directories." >&2
|
||||
echo
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate that at least one source option is provided
|
||||
if [[ -z "$DIR_PATH" && ${#SOURCES_ARR[@]} -eq 0 ]]; then
|
||||
echo "Error: Must provide either -s (specific files) or -d (directory path)." >&2
|
||||
echo
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Silent environment check - verify SF CLI is available
|
||||
if ! command -v sf >/dev/null 2>&1; then
|
||||
echo "❌ Salesforce CLI (sf) not found!"
|
||||
echo
|
||||
echo "Running environment check to help you get started..."
|
||||
echo
|
||||
|
||||
# Try to find and run sf-check in the same directory as this script
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
if [[ -x "$SCRIPT_DIR/sf-check" ]]; then
|
||||
"$SCRIPT_DIR/sf-check"
|
||||
elif command -v sf-check >/dev/null 2>&1; then
|
||||
sf-check
|
||||
else
|
||||
echo "sf-check not found. Please install the Salesforce CLI from:"
|
||||
echo "https://developer.salesforce.com/tools/sfdxcli"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CMD=(sf project deploy start)
|
||||
|
||||
# sources
|
||||
# sources (specific files)
|
||||
for SRC in "${SOURCES_ARR[@]:-}"; do
|
||||
[[ -n "$SRC" ]] && CMD+=(--source-dir "$SRC")
|
||||
done
|
||||
|
||||
# directory path
|
||||
[[ -n "$DIR_PATH" ]] && CMD+=(--source-dir "$DIR_PATH")
|
||||
|
||||
# org
|
||||
[[ -n "$ORG" ]] && CMD+=(--target-org "$ORG")
|
||||
|
||||
|
||||
146
sf-deploy.ps1
Normal file
146
sf-deploy.ps1
Normal file
@@ -0,0 +1,146 @@
|
||||
param(
|
||||
[string]$o = "",
|
||||
[string]$s = "",
|
||||
[string]$d = "",
|
||||
[string]$t = "",
|
||||
[switch]$h
|
||||
)
|
||||
|
||||
function Show-Help {
|
||||
@"
|
||||
sf-deploy.ps1 — PowerShell wrapper for ``sf project deploy start``
|
||||
|
||||
USAGE:
|
||||
sf-deploy.ps1 -o <ORG_ALIAS_OR_USERNAME> (-s "<src1>,<src2>[,...]" | -d <DIRECTORY>) [-t "<Test1>,<Test2>[,...]"]
|
||||
sf-deploy.ps1 -h
|
||||
|
||||
OPTIONS:
|
||||
-o Org alias or username for --target-org
|
||||
-s Comma-separated list of --source-dir paths
|
||||
-d Single directory path to deploy (alternative to -s)
|
||||
-t Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
|
||||
-h Show this help
|
||||
|
||||
EXAMPLES:
|
||||
1) Real deploy with multiple flexipages (specific files):
|
||||
sf-deploy.ps1 -o "DEMO-ORG" ``
|
||||
-s "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 -o "DEMO-ORG" -d "force-app/main/default/classes"
|
||||
|
||||
3) Real deploy with specified tests:
|
||||
sf-deploy.ps1 -o "DEMO-ORG" ``
|
||||
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" ``
|
||||
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
|
||||
|
||||
Notes:
|
||||
- Use -s for specific files (comma-separated) OR -d for entire directories (not both).
|
||||
- Pass absolute or repo-relative paths.
|
||||
- Multiple tests are comma-separated in -t; they will be expanded to multiple --tests flags.
|
||||
"@
|
||||
}
|
||||
|
||||
# Show help if requested or no parameters provided
|
||||
if ($h -or ($o -eq "" -and $s -eq "" -and $d -eq "" -and $t -eq "")) {
|
||||
Show-Help
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Validate that either -s or -d is provided, but not both
|
||||
if ($s -ne "" -and $d -ne "") {
|
||||
Write-Error "Cannot use both -s and -d options. Use -s for specific files or -d for directories."
|
||||
Write-Host ""
|
||||
Show-Help
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Validate required parameters
|
||||
if ($o -eq "" -or ($s -eq "" -and $d -eq "")) {
|
||||
Write-Error "Must provide -o (org) and either -s (specific files) or -d (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 ($s -ne "") {
|
||||
$sourcesArray = $s -split ","
|
||||
foreach ($src in $sourcesArray) {
|
||||
$src = $src.Trim()
|
||||
if ($src -ne "") {
|
||||
$cmd += "--source-dir"
|
||||
$cmd += $src
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Add directory path
|
||||
if ($d -ne "") {
|
||||
$cmd += "--source-dir"
|
||||
$cmd += $d
|
||||
}
|
||||
|
||||
# Add target org
|
||||
if ($o -ne "") {
|
||||
$cmd += "--target-org"
|
||||
$cmd += $o
|
||||
}
|
||||
|
||||
# Add tests if specified
|
||||
if ($t -ne "") {
|
||||
$testsArray = $t -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
|
||||
}
|
||||
58
sf-dry-run
58
sf-dry-run
@@ -6,31 +6,37 @@ show_help() {
|
||||
sf-dry-run — wrapper for `sf project deploy start --dry-run`
|
||||
|
||||
USAGE:
|
||||
sf-dry-run -o <ORG_ALIAS_OR_USERNAME> -s "<src1>,<src2>[,...]" [-t "<Test1>,<Test2>[,...]"]
|
||||
sf-dry-run -o <ORG_ALIAS_OR_USERNAME> (-s "<src1>,<src2>[,...]" | -d <DIRECTORY>) [-t "<Test1>,<Test2>[,...]"]
|
||||
|
||||
OPTIONS:
|
||||
-o Org alias or username for --target-org
|
||||
-s Comma-separated list of --source-dir paths
|
||||
-d Single directory path to validate (alternative to -s)
|
||||
-t Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
|
||||
-h Show this help
|
||||
|
||||
EXAMPLES:
|
||||
1) Basic dry-run with multiple flexipages:
|
||||
1) Basic dry-run with multiple flexipages (specific files):
|
||||
sf-dry-run -o DEMO-ORG \
|
||||
-s "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
|
||||
|
||||
2) Dry-run with specified tests:
|
||||
2) Dry-run validation for entire directory:
|
||||
sf-dry-run -o DEMO-ORG -d "force-app/main/default/classes"
|
||||
|
||||
3) Dry-run with specified tests:
|
||||
sf-dry-run -o DEMO-ORG \
|
||||
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" \
|
||||
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
|
||||
|
||||
Notes:
|
||||
- Pass absolute or repo-relative paths in -s, separated by commas.
|
||||
- Use -s for specific files (comma-separated) OR -d for entire directories (not both).
|
||||
- Pass absolute or repo-relative paths.
|
||||
- Multiple tests are comma-separated in -t; they will be expanded to multiple --tests flags.
|
||||
EOF
|
||||
}
|
||||
|
||||
ORG=""
|
||||
DIR_PATH=""
|
||||
declare -a SOURCES_ARR=()
|
||||
declare -a TESTS_ARR=()
|
||||
|
||||
@@ -39,10 +45,11 @@ if [[ $# -eq 0 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while getopts ":o:s:t:h" opt; do
|
||||
while getopts ":o:s:d:t:h" opt; do
|
||||
case "$opt" in
|
||||
o) ORG="$OPTARG" ;;
|
||||
s) IFS=',' read -r -a SOURCES_ARR <<< "$OPTARG" ;;
|
||||
d) DIR_PATH="$OPTARG" ;;
|
||||
t) IFS=',' read -r -a TESTS_ARR <<< "$OPTARG" ;;
|
||||
h) show_help; exit 0 ;;
|
||||
\?) echo "Unknown option: -$OPTARG" >&2; echo; show_help; exit 1 ;;
|
||||
@@ -50,13 +57,52 @@ while getopts ":o:s:t:h" opt; do
|
||||
esac
|
||||
done
|
||||
|
||||
# Validate that either -s or -d is provided, but not both
|
||||
if [[ -n "$DIR_PATH" && ${#SOURCES_ARR[@]} -gt 0 ]]; then
|
||||
echo "Error: Cannot use both -s and -d options. Use -s for specific files or -d for directories." >&2
|
||||
echo
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate that at least one source option is provided
|
||||
if [[ -z "$DIR_PATH" && ${#SOURCES_ARR[@]} -eq 0 ]]; then
|
||||
echo "Error: Must provide either -s (specific files) or -d (directory path)." >&2
|
||||
echo
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Silent environment check - verify SF CLI is available
|
||||
if ! command -v sf >/dev/null 2>&1; then
|
||||
echo "❌ Salesforce CLI (sf) not found!"
|
||||
echo
|
||||
echo "Running environment check to help you get started..."
|
||||
echo
|
||||
|
||||
# Try to find and run sf-check in the same directory as this script
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
if [[ -x "$SCRIPT_DIR/sf-check" ]]; then
|
||||
"$SCRIPT_DIR/sf-check"
|
||||
elif command -v sf-check >/dev/null 2>&1; then
|
||||
sf-check
|
||||
else
|
||||
echo "sf-check not found. Please install the Salesforce CLI from:"
|
||||
echo "https://developer.salesforce.com/tools/sfdxcli"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CMD=(sf project deploy start --dry-run)
|
||||
|
||||
# sources
|
||||
# sources (specific files)
|
||||
for SRC in "${SOURCES_ARR[@]:-}"; do
|
||||
[[ -n "$SRC" ]] && CMD+=(--source-dir "$SRC")
|
||||
done
|
||||
|
||||
# directory path
|
||||
[[ -n "$DIR_PATH" ]] && CMD+=(--source-dir "$DIR_PATH")
|
||||
|
||||
# org
|
||||
[[ -n "$ORG" ]] && CMD+=(--target-org "$ORG")
|
||||
|
||||
|
||||
146
sf-dry-run.ps1
Normal file
146
sf-dry-run.ps1
Normal file
@@ -0,0 +1,146 @@
|
||||
param(
|
||||
[string]$o = "",
|
||||
[string]$s = "",
|
||||
[string]$d = "",
|
||||
[string]$t = "",
|
||||
[switch]$h
|
||||
)
|
||||
|
||||
function Show-Help {
|
||||
@"
|
||||
sf-dry-run.ps1 — PowerShell wrapper for ``sf project deploy start --dry-run``
|
||||
|
||||
USAGE:
|
||||
sf-dry-run.ps1 -o <ORG_ALIAS_OR_USERNAME> (-s "<src1>,<src2>[,...]" | -d <DIRECTORY>) [-t "<Test1>,<Test2>[,...]"]
|
||||
sf-dry-run.ps1 -h
|
||||
|
||||
OPTIONS:
|
||||
-o Org alias or username for --target-org
|
||||
-s Comma-separated list of --source-dir paths
|
||||
-d Single directory path to validate (alternative to -s)
|
||||
-t Comma-separated list of --tests (enables --test-level RunSpecifiedTests)
|
||||
-h Show this help
|
||||
|
||||
EXAMPLES:
|
||||
1) Basic dry-run with multiple flexipages (specific files):
|
||||
sf-dry-run.ps1 -o "DEMO-ORG" ``
|
||||
-s "force-app/main/default/flexipages/Sample_Page.flexipage-meta.xml,force-app/main/default/flexipages/Sample_SalesNavigator.flexipage-meta.xml,force-app/main/default/flexipages/Sample_Role_Record_Page.flexipage-meta.xml"
|
||||
|
||||
2) Dry-run validation for entire directory:
|
||||
sf-dry-run.ps1 -o "DEMO-ORG" -d "force-app/main/default/classes"
|
||||
|
||||
3) Dry-run with specified tests:
|
||||
sf-dry-run.ps1 -o "DEMO-ORG" ``
|
||||
-s "force-app/main/default/flexipages/Demo_Page.flexipage-meta.xml,force-app/main/default/flexipages/Demo_Page_Backup_With_SalesNavigator.flexipage-meta.xml" ``
|
||||
-t "SelectorOpportunity_Test,SelectorOpportunity2_Test"
|
||||
|
||||
Notes:
|
||||
- Use -s for specific files (comma-separated) OR -d for entire directories (not both).
|
||||
- Pass absolute or repo-relative paths.
|
||||
- Multiple tests are comma-separated in -t; they will be expanded to multiple --tests flags.
|
||||
"@
|
||||
}
|
||||
|
||||
# Show help if requested or no parameters provided
|
||||
if ($h -or ($o -eq "" -and $s -eq "" -and $d -eq "" -and $t -eq "")) {
|
||||
Show-Help
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Validate that either -s or -d is provided, but not both
|
||||
if ($s -ne "" -and $d -ne "") {
|
||||
Write-Error "Cannot use both -s and -d options. Use -s for specific files or -d for directories."
|
||||
Write-Host ""
|
||||
Show-Help
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Validate required parameters
|
||||
if ($o -eq "" -or ($s -eq "" -and $d -eq "")) {
|
||||
Write-Error "Must provide -o (org) and either -s (specific files) or -d (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", "--dry-run")
|
||||
|
||||
# Add source directories (specific files)
|
||||
if ($s -ne "") {
|
||||
$sourcesArray = $s -split ","
|
||||
foreach ($src in $sourcesArray) {
|
||||
$src = $src.Trim()
|
||||
if ($src -ne "") {
|
||||
$cmd += "--source-dir"
|
||||
$cmd += $src
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Add directory path
|
||||
if ($d -ne "") {
|
||||
$cmd += "--source-dir"
|
||||
$cmd += $d
|
||||
}
|
||||
|
||||
# Add target org
|
||||
if ($o -ne "") {
|
||||
$cmd += "--target-org"
|
||||
$cmd += $o
|
||||
}
|
||||
|
||||
# Add tests if specified
|
||||
if ($t -ne "") {
|
||||
$testsArray = $t -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
|
||||
}
|
||||
20
sf-web-open
20
sf-web-open
@@ -50,6 +50,26 @@ while getopts ":o:p:Uh" opt; do
|
||||
esac
|
||||
done
|
||||
|
||||
# Silent environment check - verify SF CLI is available
|
||||
if ! command -v sf >/dev/null 2>&1; then
|
||||
echo "❌ Salesforce CLI (sf) not found!"
|
||||
echo
|
||||
echo "Running environment check to help you get started..."
|
||||
echo
|
||||
|
||||
# Try to find and run sf-check in the same directory as this script
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
if [[ -x "$SCRIPT_DIR/sf-check" ]]; then
|
||||
"$SCRIPT_DIR/sf-check"
|
||||
elif command -v sf-check >/dev/null 2>&1; then
|
||||
sf-check
|
||||
else
|
||||
echo "sf-check not found. Please install the Salesforce CLI from:"
|
||||
echo "https://developer.salesforce.com/tools/sfdxcli"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CMD=(sf org open)
|
||||
|
||||
[[ -n "$ORG" ]] && CMD+=(--target-org "$ORG")
|
||||
|
||||
107
sf-web-open.ps1
Normal file
107
sf-web-open.ps1
Normal file
@@ -0,0 +1,107 @@
|
||||
param(
|
||||
[string]$o = "",
|
||||
[string]$p = "",
|
||||
[switch]$U,
|
||||
[switch]$h
|
||||
)
|
||||
|
||||
function Show-Help {
|
||||
@"
|
||||
sf-web-open.ps1 — PowerShell wrapper for ``sf org open``
|
||||
|
||||
USAGE:
|
||||
sf-web-open.ps1 [-o <ORG_ALIAS_OR_USERNAME>] [-p <RELATIVE_PATH>] [-U]
|
||||
sf-web-open.ps1 -h
|
||||
|
||||
OPTIONS:
|
||||
-o Org alias or username to pass as --target-org
|
||||
-p Relative path to open inside the org (e.g., "/lightning/setup/SetupOneHome/home")
|
||||
-U URL-only: print the URL instead of opening a browser (passes --url-only)
|
||||
-h Show this help
|
||||
|
||||
EXAMPLES:
|
||||
1) Open a specific org (default home):
|
||||
sf-web-open.ps1 -o "DEMO-ORG"
|
||||
|
||||
2) Open Setup Home of a target org:
|
||||
sf-web-open.ps1 -o "NUSHUB-DR2" -p "/lightning/setup/SetupOneHome/home"
|
||||
|
||||
3) Get just the URL for scripting:
|
||||
sf-web-open.ps1 -o "NUSHUB-DR2" -U
|
||||
|
||||
4) Open the current default org (no -o provided):
|
||||
sf-web-open.ps1
|
||||
"@
|
||||
}
|
||||
|
||||
# Show help if requested
|
||||
if ($h) {
|
||||
Show-Help
|
||||
exit 0
|
||||
}
|
||||
|
||||
# If no parameters provided, show help and examples
|
||||
if ($o -eq "" -and $p -eq "" -and -not $U) {
|
||||
Show-Help
|
||||
exit 0
|
||||
}
|
||||
|
||||
# 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", "org", "open")
|
||||
|
||||
# Add target org if specified
|
||||
if ($o -ne "") {
|
||||
$cmd += "--target-org"
|
||||
$cmd += $o
|
||||
}
|
||||
|
||||
# Add path if specified
|
||||
if ($p -ne "") {
|
||||
$cmd += "--path"
|
||||
$cmd += $p
|
||||
}
|
||||
|
||||
# Add URL-only flag if specified
|
||||
if ($U) {
|
||||
$cmd += "--url-only"
|
||||
}
|
||||
|
||||
# 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
|
||||
}
|
||||
Reference in New Issue
Block a user