diff --git a/README.md b/README.md index 35d437b..59f2c0c 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,7 @@ Your Salesforce, GitHub, and Local environments should meet the following prereq [7]: http://bit.ly/install-salesforce-cli "Install the Salesforce CLI" ### Important Note for Windows Users -The commands used in this document and (more importantly) the shell scripts provided in `dev-tools` use syntax supported by the Bash shell (and its cohorts, like Zsh). - -Windows 10 users can enable the "Windows Subsystem for Linux" feature and install the Bash shell. There's a great walkthrough that shows you [How to Install and Use the Linux Bash Shell on Windows 10](https://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10) over at HowToGeek.com. +For windows users there are now PowerShell scripts available in `dev-tools-win`. ## How to Start a New Project From This Template diff --git a/data/anonymous-apex/your-anonymous-apex.apex b/data/anonymous-apex/your-anonymous-apex.apex new file mode 100644 index 0000000..e69de29 diff --git a/dev-tools-win/deploy-mdapi-source.ps1 b/dev-tools-win/deploy-mdapi-source.ps1 new file mode 100644 index 0000000..b479645 --- /dev/null +++ b/dev-tools-win/deploy-mdapi-source.ps1 @@ -0,0 +1,121 @@ +#!/bin/bash +#################################################################################################### +# +# FILENAME: deploy-mdapi-source.ps1 +# +# PURPOSE: Convert SFDX source to MDAPI format and DEPLOY to the packaging org. +# +# DESCRIPTION: TODO: Write desription +# +# INSTRUCTIONS: Execute the following command relative to your project's root directory: +# . ./dev-tools/deploy-mdapi-source.ps1 +# +# RELATED DOCS: TODO: ????? +# └─ https://???.???.com +# +# TODO: ????? +# ├─ https://www.????.com +# └─ https://www.????.com +# +#### LOAD SHARED FUNCTIONS LIBRARY ################################################################# +# +$PROJECT_ROOT = (Split-Path $PSScriptRoot -Parent) +if (Test-Path "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1") {} +else{ + Write-Output "FATAL ERROR: Could not load $PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1 File not found." + return +} +#. '/lib/shared-functions.ps1' +. "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1" +# +# +#### CONFIRM SCRIPT EXECUTION ###################################################################### +# +confirmScriptExecution "Do you want to DEPLOY the contents of sfdx-source to your packaging org?" +# +# +#### CREATE LOCAL VARIABLES ######################################################################## +# +# No local variables are used by this script. +# +# +#### REBUILD MDAPI SOURCE FILES AND FOLDERS ######################################################## +# +# 0. Reset the Step Message counter and set the TOTAL STEPS to 4. +resetStepMsgCounter 4 + +# 1. Ensure that the SFDX Package Directory specified exists. +echoStepMsg "Looking for SFDX Package Directory named `"sfdx-source/$DEFAULT_PACKAGE_DIR_NAME`"" +if ( Test-Path "$PROJECT_ROOT/sfdx-source/$DEFAULT_PACKAGE_DIR_NAME" ){ + echo "SFDX Package directory found at: $PROJECT_ROOT/sfdx-source/$DEFAULT_PACKAGE_DIR_NAME" +} else { + echoErrorMsg "No SFDX Package Directory named `"sfdx-source/$DEFAULT_PACKAGE_DIR_NAME`" found. Aborting script." + exit 1 +} + + +# 2. If there is a matching folder in the project's mdapi-source directory, delete any existing files. +echoStepMsg "Removing stale files from `"mdapi-source/$DEFAULT_PACKAGE_DIR_NAME`"" +if ( Test-Path "$PROJECT_ROOT/mdapi-source/$DEFAULT_PACKAGE_DIR_NAME" ){ + (Set-Location $PROJECT_ROOT) + if ($? -ne 0) { + rmdir .\mdapi-source\$DEFAULT_PACKAGE_DIR_NAME + if ($? -ne 0) { mkdir .\mdapi-source\$DEFAULT_PACKAGE_DIR_NAME } + } + echo "Directory $PROJECT_ROOT/mdapi-source/$DEFAULT_PACKAGE_DIR_NAME has been cleaned and is ready for updated metadata." +} else { + echo "Directory $PROJECT_ROOT/mdapi-source/$DEFAULT_PACKAGE_DIR_NAME does not exist. It will be created by the SFDX source conversion process." +} + + +# 3. Convert the SFDX source into MDAPI source. +echoStepMsg "Converting SFDX source from Package Directory `"$DEFAULT_PACKAGE_DIR_NAME`". Output folder is `"mdapi-source/$DEFAULT_PACKAGE_DIR_NAME`"" +echo ` +"Executing force:source:convert \\ + --rootdir ./sfdx-source/$DEFAULT_PACKAGE_DIR_NAME \\ + --outputdir ./mdapi-source/$DEFAULT_PACKAGE_DIR_NAME\n" +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:source:convert ` + --rootdir .\sfdx-source\$DEFAULT_PACKAGE_DIR_NAME ` + --outputdir .\mdapi-source\$DEFAULT_PACKAGE_DIR_NAME +} + +# Check if the previous command executed successfully. If not, abort this script. +if ( $? -ne 0 ) { + echoErrorMsg "SFDX source conversion to MDAPI format failed. Aborting script." + exit 1 +} + + +# 4. Attempt to deploy the MDAPI source to the packaging org. +echoStepMsg "Attempt to deploy the MDAPI source to the packaging org" +echo \ +"Executing force:mdapi:deploy \\ + --deploydir ./mdapi-source \\ + --testlevel RunLocalTests \\ + --targetusername $PACKAGING_ORG_ALIAS \\ + --wait 15\n" + +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:mdapi:deploy ` + --deploydir .\mdapi-source\$DEFAULT_PACKAGE_DIR_NAME ` + --testlevel RunLocalTests ` + --targetusername $PACKAGING_ORG_ALIAS ` + --wait 15 +} + +# Check if the previous command executed successfully. If not, abort this script. + +if ( $? -ne 'True' ){ + echoErrorMsg "Deployment to the Packaging Org failed. Terminating script." + exit 1 +} + + +# Provide a closing message telling the user where to find all the generated files. +echoScriptCompleteMsg "Deployment of MDAPI source to the Packaging Org was successful." + +exit 0 +##END## \ No newline at end of file diff --git a/dev-tools-win/install-pkg-in-sandbox.ps1 b/dev-tools-win/install-pkg-in-sandbox.ps1 new file mode 100644 index 0000000..9229cf4 --- /dev/null +++ b/dev-tools-win/install-pkg-in-sandbox.ps1 @@ -0,0 +1,87 @@ +#!/bin/bash +#################################################################################################### +# +# FILENAME: install-pkg-in-sandbox +# +# PURPOSE: Installs a 04t package into a sandbox org +# +# DESCRIPTION: TODO: Write descritption +# +# INSTRUCTIONS: Execute the following command relative to your project's root directory: +# ./dev-tools/install-pkg-in-sandbox +# +# RELATED DOCS: TODO: ????? +# └─ https://???.???.com +# +# TODO: ????? +# ├─ https://www.????.com +# └─ https://www.????.com +# +#### LOAD SHARED FUNCTIONS LIBRARY ################################################################# +# +$PROJECT_ROOT = (Split-Path $PSScriptRoot -Parent) +if (Test-Path "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1") {} +else{ + Write-Output "FATAL ERROR: Could not load $PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1 File not found." + return +} +#. '/lib/shared-functions.ps1' +. "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1" +# +# +#### CONFIRM SCRIPT EXECUTION ###################################################################### +# +confirmScriptExecution "Do you want to INSTALL a package into the specified sandbox org?" +# +# +#### CREATE LOCAL VARIABLES ######################################################################## +# +# No local variables are used by this script. +# +# +#### INSTALL PACKAGE INTO SANDBOX ################################################################## +# +#### 0. Reset the Step Message counter and set the TOTAL STEPS to 2. +resetStepMsgCounter 2 + +#### 1. Attempt to install the specified package into the target subscriber org. +echoStepMsg "Attempt to install package $PACKAGE_VERSION_ID into the org aliased as $SUBSCRIBER_SANDBOX_ALIAS" +echo \ +"Executing sfdx force:package:install \\ + --id $PACKAGE_VERSION_ID \\ + --wait 15 \\ + --publishwait 10 \\ + --targetusername $SUBSCRIBER_SANDBOX_ALIAS \\ + --loglevel error\n" +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:package:install ` + --id $PACKAGE_VERSION_ID ` + --wait 15 ` + --publishwait 10 ` + --targetusername $SUBSCRIBER_SANDBOX_ALIAS ` + --loglevel error +} + +echo $? +# Check if the previous command executed successfully. If not, abort this script. +if ( $? -ne 0 ){ + echoErrorMsg "Package installation was not successful." +} + +#### 2. List all of the packages installed in the target subscriber org. +echoStepMsg "List all packages installed in $SUBSCRIBER_SANDBOX_ALIAS" +echo "List of packages currently installed in $SUBSCRIBER_SANDBOX_ALIAS." +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:package:installed:list ` + --targetusername $SUBSCRIBER_SANDBOX_ALIAS ` + --loglevel error +} +# +# +#### ECHO CLOSING SUCCESS MESSAGE ################################################################## +# +echoScriptCompleteMsg "Package installation script complete" + +##END## \ No newline at end of file diff --git a/dev-tools-win/lib/local-config.ps1 b/dev-tools-win/lib/local-config.ps1 new file mode 100644 index 0000000..99d3260 --- /dev/null +++ b/dev-tools-win/lib/local-config.ps1 @@ -0,0 +1,86 @@ +#!/bin/bash +#<%%# +#################################################################################################### +# +# FILENAME: local-config.ps1 +# +# PURPOSE: Template for creating a personalized local-config.sh file. +# +# DESCRIPTION: All shell scripts in the dev-tools-win directory require several configuration values +# to run correctly (eg. the path to your project's root directory or the alias of +# the DevHub that you want to use. These customizations can be specific to each +# individual developer, and therefore should not be tracked by the project's VCS. +# +# This file serves as a template that Release Managers can use to establish baseline +# values for their project. When individaul developers clone the repo and initialize +# their local, personal version of the project this template is used to create a +# customized local-config.ps1 file at /dev-tools-win/lib/local-config.sh +# +# INSTRUCTIONS: Replace the values of the variables as per your local configuration +# +#################################################################################################### +#%> +## +### +#### DEFINE LOCAL CONFIGURATION VARIABLES ########################################################## +### +## +$PROJECT_ROOT = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent +# +# Alias for the Dev Hub that should be used when creating scratch orgs for this project. +# This variable will always need to be customized for individual developers. +$DEV_HUB_ALIAS='' + +# Namespace Prefix. Set to empty string ('') if this project is not building a managed package. +$NAMESPACE_PREFIX='' + +# Package Name. Specified as part of the Package Detail info in your packaging org. +# Surround this value with double-quotes if your package name contains space characters. +# Set to empty string ('') if this project is not building a managed package. +$PACKAGE_NAME='' + +# Metadata Package ID. Refers to the metadata package as a whole. Must begin with '033'. +# Set to empty string ('') if this project is not building a managed package. +$METADATA_PACKAGE_ID='033000000000000' + +# Package Version ID. Refers to a specific, installable version of a package. Must begin with '04t'. +# Set to empty string ('') if this project is not building a managed package. +$PACKAGE_VERSION_ID='04t000000000000' + +# Default Package Directory. Should match what is set in sfdx-project.json. +$DEFAULT_PACKAGE_DIR_NAME='' + +# Alias for the primary Scratch Org used by this project. +$SCRATCH_ORG_ALIAS= $NAMESPACE_PREFIX + '-SCRATCH' + +# Alias for the packaging org for this project. +$PACKAGING_ORG_ALIAS= $NAMESPACE_PREFIX + '-PACKAGE' + +# Alias for the subscriber test org used to test managed-beta package installs. +$SUBSCRIBER_ORG_ALIAS= $NAMESPACE_PREFIX + '-SUBSCRIBER' +$SUBSCRIBER_SANDBOX_ALIAS = $SUBSCRIBER_ORG_ALIAS + '-SANDBOX' + +# Git Remote URI. SSH or HTTPS URI that points to the Git remote repo used by this project. +# GitHub is used as an example here, but any Git remote (ie. BitBucket) can be used. +# Set to empty string ('') if this project is not being tracked in a remote repository. +$GIT_REMOTE_URI='' + +# Location of the primary scratch-def.json file that should be used by SFDX-Falcon scripts that +# create scratch orgs (eg. rebuild-scratch-org). +$SCRATCH_ORG_CONFIG=$PROJECT_ROOT+ '\config\project-scratch-def.json' + +# Echo the variables set by this script prior to exiting. Specify 'false' to suppress the +# display of local config that normally occurs when executing SFDX-Falcon based scripts. +$ECHO_LOCAL_CONFIG_VARS='true' +# +## +### +#### ECHO ALL VARIABLES ############################################################################ +### +## +# +if ( $ECHO_LOCAL_CONFIG_VARS -eq 'true' ) { + Write-Output "Local configuration variables set by $PROJECT_ROOT/dev-tools-win/lib/local-config.sh" + echoConfigVariables +} +##END## \ No newline at end of file diff --git a/dev-tools-win/lib/shared-functions.ps1 b/dev-tools-win/lib/shared-functions.ps1 new file mode 100644 index 0000000..3ac4a41 --- /dev/null +++ b/dev-tools-win/lib/shared-functions.ps1 @@ -0,0 +1,396 @@ +#!/bin/bash +#################################################################################################### +# +# FILENAME: shared-functions.ps1 +# +# PURPOSE: Common header file for all dev-tools-win scripts. Contains shared functions. +# +# DESCRIPTION: Contains shared functions used by all of the dev-tools-win shell scripts. +# +# INSTRUCTIONS: This script should be sourced at the top of all dev-tools-win shell scripts. +# Do not source this script manually from the command line. If you do, all of the +# shell variables set by this script (including those from local-config.ps1) will be +# set in the user's shell, and any changes to local-config.ps1 may not be picked up +# until the user manually exits their shell and opens a new one. +# +# +#################################################################################################### +# +## +### +#### PREVENT RELOAD OF THIS LIBRARY ################################################################ +### +## +# +$global:PROJECT_ROOT="" # Path to the root of this SFDX project +$global:LOCAL_CONFIG_FILE_NAME="dev-tools-win/lib/local-config.ps1"# Name of the file that contains local config variables +$global:CURRENT_STEP=1 # Used by echoStepMsg() to indicate the current step +$global:TOTAL_STEPS=0 # Used by echoStepMsg() to indicate total num of steps +$global:CURRENT_QUESTION=1 # Used by echoQuestion() to indicate the current question +$global:TOTAL_QUESTIONS=1 # Used by echoQuestion() to indicate total num of questions + +if ("$SFDX_FALCON_FRAMEWORK_SHELL_VARS_SET" -eq "true" ){ + # The SFDX_FALCON_FRAMEWORK_SHELL_VARS_SET variable is defined as part of + # this project's local configuration script (local-config.ps1). If this + # variable holds the string "true" then it means that local-config.ps1 has + # already been sourced (loaded). Since this is exactly what THIS script + # (shared-functions.ps1) is supposed to do it means that this library has + # already been loaded. + # + # We DO NOT want to load shared-functions.ps1 a second time, so we'll RETURN + # (not EXIT) gracefully so the caller can continue as if they were the + # first to load this. + return 0 +} +# +## +### +#### FUNCTION: askUserForStringValue ############################################################### +### +## +# +function askUserForStringValue ($a, $b, $c) { + # If a second argument was provided, echo its + # value before asking the user for input. + if ( "$b" -ne "" ){ + echo $b "\n" + } + + # Create a local variable to store the value of + # the variable provided by the first argument. + $LOCAL_VALUE= $a + + # Create a local variable to store the default error message. + $LOCAL_ERROR_MSG="You must provide a value at the prompt." + + # Do not allow the user to continue unless they + # provide a value when prompted. + while ( "$LOCAL_VALUE" -eq "" ){ + #eval "read -p \"$a: \" $a" + $a = Read-Host -Prompt "$a" + #eval "LOCAL_VALUE=\$$a" + $LOCAL_VALUE= $a + + if ( "$LOCAL_VALUE" -eq "" ){ + # If the caller specified a custom error message, use it. + if ( "$c" -ne "" ){ + $LOCAL_ERROR_MSG= $c + } + echoErrorMsg("$LOCAL_ERROR_MSG") + } + } +} +# +## +### +#### FUNCTION: confirmChoice ####################################################################### +### +## +# +function confirmChoice ($a, $b, $c) { + # Local variable will store the user's response. + #local USER_RESPONSE="" + $USER_RESPONSE="" + # Show the question being asked. + echo "$b" + # Prompt the user for a response and read their input. + #read -p "$3" USER_RESPONSE + $USER_RESPONSE = Read-Host -Prompt "$c" + # Save the user's response to the variable provided by the caller. + #eval "$a=\"$USER_RESPONSE\"" + $a = $USER_RESPONSE + # Add a line break + echo "" +} +# +## +### +#### FUNCTION: confirmScriptExecution ############################################################## +### +## +# +function confirmScriptExecution ($a) { + echo "$a" + #read -p "(type YES to confirm, or hit ENTER to cancel) " CONFIRM_EXECUTION + $CONFIRM_EXECUTION = Read-Host -Prompt "(type YES to confirm, or hit ENTER to cancel) " + if ( "$CONFIRM_EXECUTION" -ne "YES" ){ + echo "\nScript aborted\n" + exit 0 + } + echo "" +} +# +## +### +#### FUNCTION: echoConfigVariables () ############################################################## +### +## +# +function echoConfigVariables () { + echo "" + echo "PROJECT_ROOT --------------> " $PROJECT_ROOT + echo "NAMESPACE_PREFIX ----------> " $NAMESPACE_PREFIX + echo "PACKAGE_NAME --------------> " $PACKAGE_NAME + echo "DEFAULT_PACKAGE_DIR_NAME --> " $DEFAULT_PACKAGE_DIR_NAME + echo "DEV_HUB_ALIAS -------------> " $DEV_HUB_ALIAS + echo "SCRATCH_ORG_ALIAS ---------> " $SCRATCH_ORG_ALIAS + echo "PACKAGING_ORG_ALIAS -------> " $PACKAGING_ORG_ALIAS + echo "SUBSCRIBER_ORG_ALIAS ------> " $SUBSCRIBER_ORG_ALIAS + echo "METADATA_PACKAGE_ID -------> " $METADATA_PACKAGE_ID + echo "PACKAGE_VERSION_ID --------> " $PACKAGE_VERSION_ID + echo "SCRATCH_ORG_CONFIG --------> " $SCRATCH_ORG_CONFIG + echo "GIT_REMOTE_URI ------------> " $GIT_REMOTE_URI + echo "ECHO_LOCAL_CONFIG_VARS ----> " $ECHO_LOCAL_CONFIG_VARS + echo "" +} +# +## +### +#### FUNCTION: echoErrorMsg () ##################################################################### +### +## +# +function echoErrorMsg ($a) { + + echo "ERROR: " + + echo "" "$a" + +} +# +## +### +#### FUNCTION: echoQuestion () ##################################################################### +### +## +# +function echoQuestion ($a) { + + echo "\nQuestion $CURRENT_QUESTION of $TOTAL_QUESTIONS :" + echo " " "$a" + + $global:CURRENT_QUESTION = $CURRENT_QUESTION + 1 +} +# +## +### +#### FUNCTION: echoScriptCompleteMsg ($a) ############################################################ +### +## +# +function echoScriptCompleteMsg ($a) { + #tput sgr 0; tput setaf 7; tput bold; + echo "Script Complete: " + #tput sgr 0; + echo "" "$a" + #tput sgr 0; +} +# +## +### +#### FUNCTION: echoStepMsg ($a) ###################################################################### +### +## +# +function echoStepMsg ($a) { + #tput sgr 0; tput setaf 7; tput bold; + echo "Step $CURRENT_STEP of $TOTAL_STEPS :" + #tput sgr 0; + echo " " "$a" + #tput sgr 0; + $global:CURRENT_STEP = $global:CURRENT_STEP + 1 +} +# +## +### +#### FUNCTION: echoWarningMsg ($a) ################################################################### +### +## +# +function echoWarningMsg ($a) { + #tput sgr 0; tput setaf 7; tput bold; + echo "WARNING: " + #tput sgr 0; + echo "" "$a" + #tput sgr 0; +} +# +## +### +#### FUNCTION: findProjectRoot () ################################################################## +### +## +# +function findProjectRoot () { + # Detect the path to the directory that the running script was called from. + #local PATH_TO_RUNNING_SCRIPT="$( cd "$(dirname "$0")" ; pwd -P )" + + # Grab the last 10 characters of the detected path. This should be "/dev-tools". + #local DEV_TOOLS_SLICE=${PATH_TO_RUNNING_SCRIPT: -10} + + # Make sure the last 10 chars of the path are "/dev-tools". + # Kill the script with an error if not. + #if [[ $DEV_TOOLS_SLICE -ne "/dev-tools" ]]; then + # echoErrorMsg "Script was not executed within the /dev-tools directory." + # tput sgr 0; tput bold; + # echo "Shell scripts that utilize FALCON Developer Tools must be executed from" + # echo "inside the dev-tools directory found at the root of your SFDX project.\n" + # exit 1 + #fi + + # Calculate the Project Root path by going up one level from the path currently + # held in the PATH_TO_RUNNING_SCRIPT variable + #local PATH_TO_PROJECT_ROOT="$( cd "$PATH_TO_RUNNING_SCRIPT" ; cd .. ; pwd -P )" + + # Pass the value of the "detected path" back out to the caller by setting the + # value of the first argument provided when the function was called. + #eval "$1=\"$PATH_TO_PROJECT_ROOT\"" + return Split-Path (Split-Path $PSScriptRoot -Parent) -Parent +} +# +## +### +#### FUNCTION: initializeHelperVariables () ######################################################## +### +## +# +function initializeHelperVariables () { + $global:PROJECT_ROOT=Split-Path (Split-Path $PSScriptRoot -Parent) -Parent # Path to the root of this SFDX project + $global:LOCAL_CONFIG_FILE_NAME="dev-tools-win/lib/local-config.ps1"# Name of the file that contains local config variables + $global:CURRENT_STEP=1 # Used by echoStepMsg() to indicate the current step + $global:TOTAL_STEPS=0 # Used by echoStepMsg() to indicate total num of steps + $global:CURRENT_QUESTION=1 # Used by echoQuestion() to indicate the current question + $global:TOTAL_QUESTIONS=1 # Used by echoQuestion() to indicate total num of questions + + # Call findProjectRoot() to dynamically determine + # the path to the root of this SFDX project + #findProjectRoot PROJECT_ROOT +} +# +## +### +#### FUNCTION: resetQuestionCounter () ############################################################# +### +## +# +function resetQuestionCounter ($a) { + $global:CURRENT_QUESTION=1 + $global:TOTAL_QUESTIONS=$a +} +# +## +### +#### FUNCTION: resetStepMsgCounter () ############################################################## +### +## +# +function resetStepMsgCounter ($a) { + $global:CURRENT_STEP=1 + $global:TOTAL_STEPS=$a +} +# +## +### +#### FUNCTION: showPressAnyKeyPrompt ############################################################### +### +## +# +function showPressAnyKeyPrompt () { + #read -n 1 -sr -p "-- Press any Key to Continue --" + $CONFIRM_EXECUTION = Read-Host -Prompt "-- Press any Key to Continue --" +} +# +## +### +#### FUNCTION: suggestDefaultValue ################################################################# +### +## +# +function suggestDefaultValue ($a,$b) { + # Make sure a value was provided for the + # second argument of this function. + if ( "$b" -eq "" ){ + echoErrorMsg "You must provide two arguments to suggestDefaultValue. Terminating script." + exit 1 + } + + + # Create local variables to store the value of + # the variable provided by the first argument and the + # value of the second argument (proposed default) + #eval "local LOCAL_VALUE=\$$1" + $LOCAL_VALUE=$a + #eval "local LOCAL_DEFAULT=\"$2\"" + $LOCAL_DEFAULT=$b + + # Set a defualt prompt message in case one is not provided. + $INTERNAL_USER_PROMPT="Would you like to accept the following default value?" + + # If the caller supplied a third argument, it means they want + # a specific message to be shown before accepting the default. + # If they did now, we will use owr own "default" message. + if ( $3 -ne $null ){ + $INTERNAL_USER_PROMPT="$3" + } + + # Show prompt and display what the default var assignment would be. + echo $INTERNAL_USER_PROMPT + echo "\n"$a=$LOCAL_DEFAULT"\n" + + # Ask user to confirm or reject the proposed value. + #read -p "(type YES to accept, NO to provide a different value) " CONFIRM_EXECUTION + $CONFIRM_EXECUTION = Read-Host -Prompt "(type YES to confirm, or hit ENTER to cancel) " + if ("$CONFIRM_EXECUTION" -ne "YES" ){ + return 1 + } + + # Store the value from arg 2 into arg 1, basically + # using the "default" value for the main value. + #eval "$1=\"$2\"" + $a = $b; + + return 0 +} +# +## +### +#### BEGIN MAIN EXECUTION BLOCK #################################################################### +### +## +# +# INITIALIZE HELPER VARIABLES +initializeHelperVariables + +# CHECK IF LOCAL CONFIG SHOULD BE SUPPRESSED. +# If $SUPPRESS_LOCAL_CONFIG has been set to "true" DO NOT load the local configuration +# variables. A script that includes shared-functions.ps1 can set this variable to +# force this behavior (dev-tools/setup-core-project for example). +if ("$SUPPRESS_LOCAL_CONFIG" -eq "true" ) { + # Comment out the following line unless you're debugging setup-core-project. + # echo "Local dev-tools configuration (local-config.ps1) has been suppressed" + return 0 +} + +# CHECK IF LOCAL CONFIG FILE EXISTS +# Look for the local config variables script local-config.ps1. If the developer has not created a +# local-config.ps1 file in dev-tools/lib then EXIT from the shell script with an error message. +if (Test-Path "$PROJECT_ROOT/$LOCAL_CONFIG_FILE_NAME" ) { +} +else{ + echo "$PROJECT_ROOT/$LOCAL_CONFIG_FILE_NAME" + echoErrorMsg "Local dev-tools configuration file not found" + #tput sgr 0; tput bold; + echo "Please create a local-config.ps1 file in your dev-tools/lib directory by copying" + echo "dev-tools/templates/local-config-template.ps1 and customizing it with your local settings\n" + return +} + +# LOAD THE LOCAL CONFIG VARIABLES +# The local-config.ps1 file was found and is readable. Source (execute) it the current shell process. +# This will make all the variables defined in local-config.ps1 available to all commands that come +# after it in this shell. +. "$PROJECT_ROOT/$LOCAL_CONFIG_FILE_NAME" +# MARK THAT LOCAL CONFIG VARIABLES HAVE BEEN SET. +# Indicates that local config variables have been successfully set. +$SFDX_FALCON_FRAMEWORK_SHELL_VARS_SET="true" +##END## \ No newline at end of file diff --git a/dev-tools-win/rebuild-scratch-org.ps1 b/dev-tools-win/rebuild-scratch-org.ps1 new file mode 100644 index 0000000..10667e1 --- /dev/null +++ b/dev-tools-win/rebuild-scratch-org.ps1 @@ -0,0 +1,293 @@ +#!/bin/bash +#################################################################################################### +# +# FILENAME: rebuild-scratch-org +# +# PURPOSE: Deletes then recreates a scratch org based on the SFDX source in this project. +# +# DESCRIPTION: Executing this script will first delete the exisisting default scratch org for +# this project (if it exists), then create a new one using the source and config +# information defined in your dev-tools/lib/local-config.sh file. +# +# INSTRUCTIONS: Execute the following command from the root of your SFDX project directory. +# ./dev-tools/rebuild-scratch-org +# +#################################################################################################### +# +## +### +#### LOAD SHARED FUNCTIONS LIBRARY ################################################################# +### +## +# +# Make sure that the shared-functions.sh script exists. +$PROJECT_ROOT = (Split-Path $PSScriptRoot -Parent) +if (Test-Path "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1") {} +else{ + Write-Output "FATAL ERROR: Could not load $PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1. File not found." + return +} +#. '/lib/shared-functions.ps1' +. "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1" +# +## +### +#### CONFIRM SCRIPT EXECUTION ###################################################################### +### +## +# +confirmScriptExecution "Do you want to rebuild your scratch org?" +# +## +### +#### CREATE LOCAL VARIABLES ######################################################################## +### +## +# +# The default version of this script does not require additional local +# variables. If your customized script does require them, this is where +# you would define and initialize them. +# +## +### +#### FUNCTION: assignPermset () #################################################################### +### +## +# +function assignPermset ($a) { + # Assign permission sets to the scratch org's Admin user. + echoStepMsg "Assign the $a permission set to the scratch org's Admin user" + echo ` + "Executing force:user:permset:assign --permsetname "$a" --targetusername $SCRATCH_ORG_ALIAS --loglevel error" + (Set-Location $PROJECT_ROOT) + if($? -ne 0){ + sfdx force:user:permset:assign ` + --permsetname "$a" ` + --targetusername $SCRATCH_ORG_ALIAS ` + --loglevel error + } + if ( $? -ne 'TRUE' ){ + echoErrorMsg "Permission set `"$a`" could not be assigned to the admin user. Aborting Script." + exit 1 + } +} +# +## +### +#### FUNCTION: createScratchOrg () ################################################################# +### +## +# +function createScratchOrg() { + # Create a new scratch org using the scratch-def.json locally configured for this project. + echoStepMsg "Create a new $SCRATCH_ORG_ALIAS scratch org" + echo "Executing force:org:create -f $SCRATCH_ORG_CONFIG -a $SCRATCH_ORG_ALIAS -v $DEV_HUB_ALIAS -s -d 30" + (Set-Location $PROJECT_ROOT) + if($? -ne 0){ + sfdx force:org:create -f $SCRATCH_ORG_CONFIG -a $SCRATCH_ORG_ALIAS -v $DEV_HUB_ALIAS -s -d 30 + } + + if ( $? -ne 'TRUE' ){ + echoErrorMsg "Scratch org could not be created. Aborting Script." + exit 1 + } +} +# +## +### +#### FUNCTION: deleteScratchOrg () ################################################################# +### +## +# +function deleteScratchOrg() { + # Delete the current scratch org. + echoStepMsg "Delete the $SCRATCH_ORG_ALIAS scratch org" + echo "Executing force:org:delete -p -u $SCRATCH_ORG_ALIAS -v $DEV_HUB_ALIAS" + (Set-Location $PROJECT_ROOT) + if($? -ne 0){ + sfdx force:org:delete -p -u $SCRATCH_ORG_ALIAS -v $DEV_HUB_ALIAS + } +} +# +## +### +#### FUNCTION: importData () ####################################################################### +### +## +# +function importData ($a) { + # Setup development data + echoStepMsg "Import data from $a" + echo ` + "Executing force:data:tree:import \\ + --plan `"$a`" \\ + --targetusername $SCRATCH_ORG_ALIAS \\ + --loglevel error" + (Set-Location $PROJECT_ROOT) + if($? -ne 0){ + sfdx force:data:tree:import ` + --plan "$a" ` + --targetusername $SCRATCH_ORG_ALIAS ` + --loglevel error + } + if ( $? -ne 0 ){ + echoErrorMsg "Data import failed. Aborting Script." + exit 1 + } +} +# +## +### +#### FUNCTION: installPackage () ################################################################### +### +## +# +function installPackage ($a, $b, $c) { + # Echo the string provided by argument three. This string should provide the + # user with an easy-to-understand idea of what package is being installed. + echoStepMsg "$c" + + # Print the time (HH:MM:SS) when the installation started. + echo "Executing force:package:install -i $a -p 5 -w 10 -u $SCRATCH_ORG_ALIAS" + echo "Package installation started at " + date + $startTime=date + + # Perform the package installation. If the installation fails abort the script. + (Set-Location $DEMO_ROOT) + if ($? -ne 0) { + sfdx force:package:install -i $a -p 5 -w 10 -u $SCRATCH_ORG_ALIAS + } + + if ( $? -ne 0 ){ + echoErrorMsg "$b could not be installed. Aborting Script." + exit 1 + } + + # Print the time (HH:MM:SS) when the installation completed. + echo "Package installation completed at " + date + $endTime=date + + # Determine the total runtime (in seconds) and show the user. + $totalRuntime=$((endTime-startTime)) + echo "Total runtime for package installation was $totalRuntime seconds." +} +# +## +### +#### FUNCTION: pushMetadata () ##################################################################### +### +## +# +function pushMetadata () { + # Push metadata to the new Scratch Org. + echoStepMsg "Push metadata to the new scratch org" + echo "Executing force:source:push -u $SCRATCH_ORG_ALIAS" + (Set-Location $PROJECT_ROOT) + if ($? -ne 0) { + sfdx force:source:push -u $SCRATCH_ORG_ALIAS + } + + if ( $? -ne 'TRUE' ){ + echoErrorMsg "SFDX source could not be pushed to the scratch org. Aborting Script." + exit 1 + } +} +# +## +### +#### FUNCTION: validateScratchOrgDeletion () ####################################################### +### +## +# +function validateScratchOrgDeletion () { + # Confirm that the scratch org is no longer the default username in SFDX local config. + echoStepMsg "Validate deletion of the scratch org" + echo "Executing sfdx force:config:list to confirm deletion from project local config" + (Set-Location $PROJECT_ROOT) + if ($? -ne 0) { + sfdx force:config:list + } +} +# +## +### +#### FUNCTION: runAnonymousApex () ##################################################################### +### +## +# +function runAnonymousApex () { + # Run Anonymous code in the new Scratch Org. + echoStepMsg "Run Anonymous code in the new scratch org" + echo "Executing force:apex:execute -u $SCRATCH_ORG_ALIAS" + (Set-Location $PROJECT_ROOT) + if ($? -ne 0) { + sfdx force:apex:execute -u $SCRATCH_ORG_ALIAS --apexcodefile $PROJECT_ROOT/data/anonymous-apex/your-anonymous-apex.apex + } + + if ( $? -ne 'TRUE' ){ + echoErrorMsg "Anonymous code can't be executed. Aborting Script." + exit 1 + } +} +# +## +### +#### SCRATCH ORG SETUP (DELETE/CREATE/PUSH) ######################################################## +### +## +# +# STEP 0 +# Reset the Step Message counter to reflect the number of TOTAL STEPS +# in your rebuild process. For the baseline SFDX-Falcon template it's 4. +resetStepMsgCounter 4 + +# STEPS 1 and 2 +# Delete the current scratch org. +deleteScratchOrg + +# STEP 3 +# Create a new scratch org using the scratch-def.json locally configured for this project. +createScratchOrg + +# STEP 4 through ??? +# Install any packages (managed or unmanaged). +# Template for calling this function: +# installPackage #PACKAGE_VERSION_ID# \ +# "#PACKAGE_NAME#" \ +# "#STEP_MESSAGE#" + +# STEP 5 through ??? +# Assign any permission sets that were added by installed packages. +# Template for calling this function: +# assignPermset #PACKAGED_PERMSET_NAME# + +# STEP 6 +# Push metadata to the new Scratch Org. +pushMetadata + +# STEP 7 through ???? +# Assign any permission sets that were added by your Source Push. +# Template for calling this function: +#assignPermset #PERMSET_NAME# + +# STEP 8 through ???? +# Import data used during development. You may need to make multiple calls +# Template for calling this function: +# importData "$PROJECT_ROOT/data/#DATA_PLAN_JSON#" + + +# STEP 9 Execute Anonymous Code +#runAnonymousApex +# +## +### +#### ECHO CLOSING MESSAGE ########################################################################## +### +## +# +echoScriptCompleteMsg +"Rebuild of scratch org $SCRATCH_ORG_ALIAS completed successfully." + +exit 0 + +##END## \ No newline at end of file diff --git a/dev-tools-win/run-all-tests.ps1 b/dev-tools-win/run-all-tests.ps1 new file mode 100644 index 0000000..644bd2a --- /dev/null +++ b/dev-tools-win/run-all-tests.ps1 @@ -0,0 +1,83 @@ +#!/bin/bash +#################################################################################################### +# +# FILENAME: run_all_tests +# +# PURPOSE: ##ADD_PURPOSE_HERE## +# +# DESCRIPTION: ##ADD_DESCRIPTIION_HERE## +# +# INSTRUCTIONS: Execute the following command relative to your project's root directory: +# ./dev-tools/run_all_tests +# +# RELATED DOCS: TODO: ????? +# └─ https://???.???.com +# +# TODO: ????? +# ├─ https://www.????.com +# └─ https://www.????.com +# +#### LOAD SHARED FUNCTIONS LIBRARY ################################################################# +# +$PROJECT_ROOT = (Split-Path $PSScriptRoot -Parent) +if (Test-Path "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1") {} +else { + Write-Output "FATAL ERROR: Could not load $PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1. File not found." + return +} +#. '/lib/shared-functions.ps1' +. "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1" +# +# +#### CONFIRM SCRIPT EXECUTION ###################################################################### +# +confirmScriptExecution "Do you want to run all tests currently deployed to your scratch org?" +# +# +#### CREATE LOCAL VARIABLES ######################################################################## +# +# No local variables are used by this script. +# +# +#### RUN ALL TESTS IN THE SCRATCH ORG ############################################################## +# +# 0. Reset the Step Message counter and set the TOTAL STEPS to 1. +resetStepMsgCounter 1 + +# 1. Run all tests as human readable, with final output made to the temp directory. +echoStepMsg "Run all tets currently deployed to $SCRATCH_ORG_ALIAS" +echo ` +"Executing force:apex:test:run \\ + --targetusername $SCRATCH_ORG_ALIAS \\ + --testlevel RunLocalTests \\ + --outputdir ./temp/apex-test-results \\ + --resultformat human \\ + --synchronous \\ + --codecoverage \\ + --loglevel error)" +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:apex:test:run ` + --targetusername $SCRATCH_ORG_ALIAS ` + --testlevel RunLocalTests ` + --outputdir .\temp\apex-test-results ` + --resultformat human ` + --codecoverage ` + --wait 15 ` + --loglevel error +} + + +# TODO: Need to add a check to see if force:source:convert worked. +echo $? +# Check if the previous command executed successfully. If not, abort this script. +if ( $? -ne 'True' ) { + echoErrorMsg "The previous command did not execute as expected. Aborting script" + exit 1 +} + +#### ECHO CLOSING SUCCESS MESSAGE ################################################################## +# +echoScriptCompleteMsg "Tests complete. Test results should be available in $PROJECT_ROOT/temp/apex-test-results" + +##END## \ No newline at end of file diff --git a/dev-tools-win/setup-project-org-auth.ps1 b/dev-tools-win/setup-project-org-auth.ps1 new file mode 100644 index 0000000..dc93e73 --- /dev/null +++ b/dev-tools-win/setup-project-org-auth.ps1 @@ -0,0 +1,118 @@ +#!/bin/bash +#################################################################################################### +# +# FILENAME: setup-project-org-auth +# +# PURPOSE: ##ADD_PURPOSE_HERE## +# +# DESCRIPTION: ##ADD_DESCRIPTIION_HERE## +# +# INSTRUCTIONS: Execute the following command from the root of your SFDX project directory. +# ./dev-tools/setup-project-org-auth +# +# RELATED DOCS: TODO: ????? +# └─ https://???.???.com +# +# TODO: ????? +# ├─ https://www.????.com +# └─ https://www.????.com +# +#### LOAD SHARED FUNCTIONS LIBRARY ################################################################# +$PROJECT_ROOT = (Split-Path $PSScriptRoot -Parent) +if (Test-Path "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1") {} +else{ + Write-Output "FATAL ERROR: Could not load $PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1. File not found." + return +} +#. '/lib/shared-functions.ps1' +. "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1" +# +# +#### CONFIRM SCRIPT EXECUTION ###################################################################### +# +confirmScriptExecution 'Do you want to setup org authentication/aliases for this project?' +# +# +#### WALK THE USER THROUGH WEB AUTH FOR ALL REQUIRED PROJECT ORGS ################################# +# +# 0. Reset the Step Message counter and set the TOTAL STEPS to 3. +resetStepMsgCounter 3 + + +# 1. Setup authentication for this project's Dev Hub. +echoStepMsg 'Setup authentication for this projects Dev Hub' + +Write-Output "Do you want set/replace the auth info for the $DEV_HUB_ALIAS alias?" +$CONFIRM_EXECUTION = Read-Host -Prompt "(type YES to confirm, or hit ENTER to cancel) " +if ( "$CONFIRM_EXECUTION" -eq 'YES' ) { + Write-Output 'Web authentication in progress using default browser. Press CTRL+C to cancel.' + (Set-Location $PROJECT_ROOT) + if($? -ne 0){ + sfdx force:auth:web:login ` + --setalias $DEV_HUB_ALIAS ` + --setdefaultdevhubusername ` + --instanceurl https://login.salesforce.com ` + --loglevel error + } + # Check if the previous command executed successfully. If not, either due to user + # hitting CTRL+C or the call timing out, show the user a message. + if ( $? -ne 0 ){ + echoWarningMsg 'The web authentication request was canceled (or timed out).' + } +} + + +# 2. Setup authentication for this project's Packaging Org. +echoStepMsg 'Setup authentication for this projects Packaging Org' + +Write-Output "Do you want set/replace the auth info for the $PACKAGING_ORG_ALIAS alias?" +$CONFIRM_EXECUTION = Read-Host -Prompt "(type YES to confirm, or hit ENTER to cancel) " +if ( "$CONFIRM_EXECUTION" -eq 'YES' ){ + Write-Output 'Web authentication in progress using default browser. Press CTRL+C to cancel.' + (Set-Location $PROJECT_ROOT) + if($? -ne 0){ + sfdx force:auth:web:login ` + --setalias $PACKAGING_ORG_ALIAS ` + --instanceurl https://login.salesforce.com ` + --loglevel error + } + # Check if the previous command executed successfully. If not, either due to user + # hitting CTRL+C or the call timing out, show the user a message. + if ( $? -ne 0 ){ + echoWarningMsg 'The web authentication request was canceled (or timed out).' +} +} + + +# 3. Setup authentication for this project's Subscriber Sandbox Org. +echoStepMsg 'Setup authentication for this projects Subscriber Sandbox Org' + +Write-Output "Do you want set/replace the auth info for the $SUBSCRIBER_SANDBOX_ALIAS alias?" +$CONFIRM_EXECUTION = Read-Host -Prompt "(type YES to confirm, or hit ENTER to cancel) " +if ("$CONFIRM_EXECUTION" -eq 'YES') { + Write-Output 'Web authentication in progress using default browser. Press CTRL+C to cancel.' + (Set-Location $PROJECT_ROOT) + if($? -ne 0){ + sfdx force:auth:web:login ` + --setalias $SUBSCRIBER_SANDBOX_ALIAS ` + --instanceurl https://login.salesforce.com ` + --loglevel error + } + # Add this back if you need to have real sandbox for test --instanceurl https://test.salesforce.com ` + # Check if the previous command executed successfully. If not, either due to user + # hitting CTRL+C or the call timing out, show the user a message. + if ( $? -ne 0 ){ + echoWarningMsg 'The web authentication request was canceled (or timed out).' + } +} +# +# +#### Write-Output CLOSING MESSAGE ########################################################################## +# +echoScriptCompleteMsg('All requested authentication attempts are complete. Run validate-org-connections +to confirm that all org authentications required by this project are properly configured.') + +# Todo +#source `dirname $0`/validate-org-connections +. "$PROJECT_ROOT/dev-tools-win/validate-org-connections.ps1" +##END## \ No newline at end of file diff --git a/dev-tools-win/uninstall-pkg-from-sandbox.ps1 b/dev-tools-win/uninstall-pkg-from-sandbox.ps1 new file mode 100644 index 0000000..809ddd4 --- /dev/null +++ b/dev-tools-win/uninstall-pkg-from-sandbox.ps1 @@ -0,0 +1,85 @@ +#!/bin/bash +#################################################################################################### +# +# FILENAME: uninstall-pkg-from-sandbox.ps1 +# +# PURPOSE: Uninstalls a 04t package from a sandbox org +# +# DESCRIPTION: TODO: Write descritption +# +# INSTRUCTIONS: Execute the following command relative to your project's root directory: +# . ./dev-tools/uninstall-pkg-from-sandbox.ps1 +# +# RELATED DOCS: TODO: ????? +# └─ https://???.???.com +# +# TODO: ????? +# ├─ https://www.????.com +# └─ https://www.????.com +# +#### LOAD SHARED FUNCTIONS LIBRARY ################################################################# +# +$PROJECT_ROOT = (Split-Path $PSScriptRoot -Parent) +if (Test-Path "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1") {} +else{ + Write-Output "FATAL ERROR: Could not load $PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1 File not found." + return +} +#. '/lib/shared-functions.ps1' +. "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1" +# +# +#### CONFIRM SCRIPT EXECUTION ###################################################################### +# +confirmScriptExecution "Do you want to UNINSTALL a package from the specified sandbox org?" +# +# +#### CREATE LOCAL VARIABLES ######################################################################## +# +# No local variables are used by this script. +# +# +#### UNINSTALL PACKAGE FROM SANDBOX ################################################################## +# +#### 0. Reset the Step Message counter and set the TOTAL STEPS to 2. +resetStepMsgCounter 2 + +#### 1. Attempt to uninstall the specified package from the target subscriber sandbox org. +echoStepMsg "Attempt to uninstall package $PACKAGE_VERSION_ID from the org aliased as $SUBSCRIBER_SANDBOX_ALIAS" +echo ` +"Executing sfdx force:package:uninstall \\ + --id $PACKAGE_VERSION_ID \\ + --wait 15 \\ + --targetusername $SUBSCRIBER_SANDBOX_ALIAS \\ + --loglevel error" +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:package:uninstall ` + --id $PACKAGE_VERSION_ID ` + --wait 15 ` + --targetusername $SUBSCRIBER_SANDBOX_ALIAS ` + --loglevel error +} + +# Check if the previous command executed successfully. If not, abort this script. +if ( $? -ne 'True' ){ + echoErrorMsg "Package removal from $SUBSCRIBER_SANDBOX_ALIAS was not successful." +} + +#### 2. List all of the packages installed in the target subscriber org. +echoStepMsg "List all packages that remain in $SUBSCRIBER_SANDBOX_ALIAS" +echo "List of packages currently installed in $SUBSCRIBER_SANDBOX_ALIAS." +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:package:installed:list ` + --targetusername $SUBSCRIBER_SANDBOX_ALIAS ` + --loglevel error +} +# +# +#### ECHO CLOSING SUCCESS MESSAGE ################################################################## +# +echoScriptCompleteMsg "Package removal script complete" + + +##END## \ No newline at end of file diff --git a/dev-tools-win/validate-mdapi-source.ps1 b/dev-tools-win/validate-mdapi-source.ps1 new file mode 100644 index 0000000..4f3f9b6 --- /dev/null +++ b/dev-tools-win/validate-mdapi-source.ps1 @@ -0,0 +1,113 @@ +#!/bin/bash +#################################################################################################### +# +# FILENAME: validate-mdapi-source.ps1 +# +# PURPOSE: Convert SFDX source to MDAPI format and validate against the packaging org. +# +# DESCRIPTION: TODO: Write desription +# +# INSTRUCTIONS: Execute the following command relative to your project's root directory: +# . ./dev-tools/validate-mdapi-source.ps1 +# +# RELATED DOCS: TODO: ????? +# └─ https://???.???.com +# +# TODO: ????? +# ├─ https://www.????.com +# └─ https://www.????.com +# +#### LOAD SHARED FUNCTIONS LIBRARY ################################################################# +# +$PROJECT_ROOT = (Split-Path $PSScriptRoot -Parent) +if (Test-Path "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1") {} +else{ + Write-Output "FATAL ERROR: Could not load $PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1. File not found." + return +} +#. '/lib/shared-functions.ps1' +. "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1" +# +# +#### CONFIRM SCRIPT EXECUTION ###################################################################### +# +confirmScriptExecution "Do you want to rebuild/overwrite the existing files and folders in your mdapi-source directory?" +# +# +#### CREATE LOCAL VARIABLES ######################################################################## +# +# No local variables are used by this script. +# +# +#### REBUILD MDAPI SOURCE FILES AND FOLDERS ######################################################## +# +# 0. Reset the Step Message counter and set the TOTAL STEPS to 4. +resetStepMsgCounter 4 + +# 1. Ensure that the SFDX Package Directory specified by $DEFAULT_PACKAGE_DIR_NAME exists. +echoStepMsg "Looking for SFDX Package Directory named `"sfdx-source/$DEFAULT_PACKAGE_DIR_NAME`"" +if ( Test-Path "$PROJECT_ROOT/sfdx-source/$DEFAULT_PACKAGE_DIR_NAME" ){ + echo "SFDX Package directory found at: $PROJECT_ROOT/sfdx-source/$DEFAULT_PACKAGE_DIR_NAME" +} else { + echoErrorMsg "No SFDX Package Directory named `"sfdx-source/$DEFAULT_PACKAGE_DIR_NAME`" found. Aborting script." + exit 1 +} + +# 2. If there is a matching folder in the project's mdapi-source directory, delete any existing files. +echoStepMsg "Removing stale files from `"mdapi-source/$DEFAULT_PACKAGE_DIR_NAME`"" +if ( Test-Path "$PROJECT_ROOT/mdapi-source/$DEFAULT_PACKAGE_DIR_NAME" ){ + (Set-Location $PROJECT_ROOT) + if ($? -ne 0) { + rmdir .\mdapi-source\$DEFAULT_PACKAGE_DIR_NAME + if ($? -ne 0) { mkdir .\mdapi-source\$DEFAULT_PACKAGE_DIR_NAME } + } + echo "Directory $PROJECT_ROOT/mdapi-source/$DEFAULT_PACKAGE_DIR_NAME has been cleaned and is ready for updated metadata." +} else { + echo "Directory $PROJECT_ROOT/mdapi-source/$DEFAULT_PACKAGE_DIR_NAME does not exist. It will be created by the SFDX source conversion process." +} + +# 3. Convert the SFDX source into MDAPI source. +echoStepMsg "Converting SFDX source from Package Directory `"$DEFAULT_PACKAGE_DIR_NAME`". Output folder is `"mdapi-source/$DEFAULT_PACKAGE_DIR_NAME`"" +echo ` +"Executing force:source:convert \\ + --rootdir ./sfdx-source/$DEFAULT_PACKAGE_DIR_NAME \\ + --outputdir ./mdapi-source/$DEFAULT_PACKAGE_DIR_NAME\n" +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:source:convert ` + --rootdir .\sfdx-source\$DEFAULT_PACKAGE_DIR_NAME ` + --outputdir .\mdapi-source\$DEFAULT_PACKAGE_DIR_NAME +} + + +# TODO: Need to add a check to see if force:source:convert worked. +# If it didn't, then we need to exit this script now without doing the +# check-only deploy to the packaging org. + + +# 4. Attempt a check-only deploy of the MDAPI package against the packaging org. +echoStepMsg "Attempt a check-only deploy of the MDAPI package against the packaging org" +echo ` +"Executing force:mdapi:deploy \\ + --checkonly \\ + --deploydir ./mdapi-source/$DEFAULT_PACKAGE_DIR_NAME \\ + --testlevel NoTestRun \\ + --targetusername $PACKAGING_ORG_ALIAS \\ + --wait 15\n" +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:mdapi:deploy ` + --checkonly ` + --deploydir .\mdapi-source\$DEFAULT_PACKAGE_DIR_NAME ` + --testlevel RunLocalTests ` + --targetusername $PACKAGING_ORG_ALIAS ` + --wait 15 +} + +# TODO: Need to add a check here to see if the mdapi:deploy was successful or not. + +# Provide a closing message telling the user where to find all the generated files. +echoScriptCompleteMsg "Conversion from SFDX source to MDAPI source was successful." + +exit 0 +##END## \ No newline at end of file diff --git a/dev-tools-win/validate-org-connections.ps1 b/dev-tools-win/validate-org-connections.ps1 new file mode 100644 index 0000000..303a8a2 --- /dev/null +++ b/dev-tools-win/validate-org-connections.ps1 @@ -0,0 +1,120 @@ +#!/bin/bash +#################################################################################################### +# +# FILENAME: validate-org-connections.ps1 +# +# PURPOSE: ##ADD_PURPOSE_HERE## +# +# DESCRIPTION: ##ADD_DESCRIPTIION_HERE## +# +# INSTRUCTIONS: Execute the following command relative to your project's root directory: +# . ./dev-tools/validate-org-connections.ps1 +# +# RELATED DOCS: TODO: ????? +# └─ https://???.???.com +# +# TODO: ????? +# ├─ https://www.????.com +# └─ https://www.????.com +# +#### LOAD SHARED FUNCTIONS LIBRARY ################################################################# +# +$PROJECT_ROOT = (Split-Path $PSScriptRoot -Parent) +if (Test-Path "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1") {} +else{ + Write-Output "FATAL ERROR: Could not load $PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1. File not found." + return +} +#. '/lib/shared-functions.ps1' +. "$PROJECT_ROOT/dev-tools-win/lib/shared-functions.ps1" +# +# +#### CONFIRM SCRIPT EXECUTION ###################################################################### +# +confirmScriptExecution "Do you want to validate the org connections required by this project?" +# +# +#### CREATE LOCAL VARIABLES ######################################################################## +# +# No local variables are used by this script. +# +# +#### WALK THE USER THROUGH WEB AUTH FOR ALL REQUIRED PROJECT ORGS ################################# +# +# 0. Reset the Step Message counter and set the TOTAL STEPS to 3. +resetStepMsgCounter 3 + + +# 1. Validate the expected alias and connection to the Dev Hub by showing limits from that org. +echoStepMsg "Validate connection and available limits of the org with the $DEV_HUB_ALIAS alias" +(Set-Location $PROJECT_ROOT) +if($? -ne 0){ + sfdx force:org:display ` + --targetusername $DEV_HUB_ALIAS ` + --loglevel error +} + +# If the previous command completed successfully, it means that there is an +# alias configured for this org. Validate the connection by displaying the org limits. +if ( $? -eq 0 ) { + echo "=== Org Limits" + (Set-Location $PROJECT_ROOT) + if($? -ne 0) { + sfdx force:limits:api:display ` + --targetusername $DEV_HUB_ALIAS ` + --loglevel error + } +} + + +# 2. Validate the expected alias and connection to the Packaging Org by showing limits from that org. +echoStepMsg "Validate connection and available limits of the org with the $PACKAGING_ORG_ALIAS alias" +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:org:display ` + --targetusername $PACKAGING_ORG_ALIAS ` + --loglevel error +} + +# If the previous command completed successfully, it means that there is an +# alias configured for this org. Validate the connection by displaying the org limits. +if ( $? -eq 0 ) { + echo "=== Org Limits" + (Set-Location $PROJECT_ROOT) + if ($? -ne 0) { + sfdx force:limits:api:display ` + --targetusername $PACKAGING_ORG_ALIAS ` + --loglevel error + } +} + + +# 3. Validate the expected alias and connection to the Subscriber Sandbox Org by showing limits from that org. +echoStepMsg "Validate connection and available limits of the org with the $SUBSCRIBER_SANDBOX_ALIAS alias" +(Set-Location $PROJECT_ROOT) +if ($? -ne 0) { + sfdx force:org:display ` + --targetusername $SUBSCRIBER_SANDBOX_ALIAS ` + --loglevel error +} + +# If the previous command completed successfully, it means that there is an +# alias configured for this org. Validate the connection by displaying the org limits. +if ( $? -eq 0 ) { + echo "=== Org Limits" + (Set-Location $PROJECT_ROOT) + if ($? -ne 0) { + sfdx force:limits:api:display ` + --targetusername $SUBSCRIBER_SANDBOX_ALIAS ` + --loglevel error + } +} +# +# +#### ECHO CLOSING MESSAGE ########################################################################## +# +echoScriptCompleteMsg \ +"Validation of org connections complete. If your are missing +any aliases you can run setup-project-org-auth to re-authenticate." + +##END## \ No newline at end of file