-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfdx.conf
129 lines (114 loc) · 5.21 KB
/
sfdx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
###----------------------------------------------------###
### CONFIG FILE FOR SFDX RELATED ALIASES AND FUNCTIONS ###
###----------------------------------------------------###
### ALIASES ###
alias orgs='sfdx force:org:list --all' #show list of all authenticated orgs
### FUNCTIONS ###
# open org
# oo [alias] or [username]
# function to open a prior authenticated org in default browser
function oo {
sfdx force:org:open -u $1;
}
# authenticate org
# ao [alias] [myDomain]
# function to authenticated an org with a my domain
function ao {
read -p 'Enter alias for the org you would like to authenticate: ' alias;
read -p 'Enter myDomain (only middle part) of the org: ' myDomain;
sfdx force:auth:web:login -a $alias --instanceurl https://$myDomain.my.salesforce.com;
}
# logout org
# lo [alias]
# function to remove (logout) a priot authenticated org
function lo {
read -p 'Enter alias for the org you would like remove: ' alias;
sfdx force:auth:logout -u $alias;
}
# jump to sfdx project default folder
# sfd [project folder name]
# in your sfdx project folder, type "sfd", "space", then the "project folder name" (tab completion works)
# the function will bring you three levels deep to the default folder where all the good stuff is stored
# the function will list the content of the default folder – "l" is an alias for "ls" with my preferences
function sfd {
cd $1;
cd force-app/;
cd main/;
cd default/;
l;
}
# COMPARE METADATA
# to use psdiff & pfdiff as setup below, you have to
# authenticate the production org with alias "prod" and the UAT environment with alias "uat"
# local projects have to be created with identical names, then run the following scripts (in the appropriate project main folder)
# sfdx force:source:retrieve -u prod -m "Profile, PermissionSet"
# sfdx force:source:retrieve -u uat -m "Profile, PermissionSet"
# psdiff – permission set differences
# get permission set "diff" between PROD / UAT
function psdiff {
read -p 'enter permission set name (underscores instead spaces): ' permissionSet;
colordiff ~/sfdx_projects/prod/force-app/main/default/permissionsets/$permissionSet.permissionset-meta.xml ~/sfdx_projects/uat/force-app/main/default/permissionsets/$permissionSet.permissionset-meta.xml | less -R;
}
export -f psdiff
# pfdiff – profile differences
# get profile "diff" between PROD / UAT
function pfdiff {
read -p 'enter profile name "with spaces": ' profile;
colordiff ~/sfdx_projects/prod/force-app/main/default/profiles/"$profile".profile-meta.xml ~/sfdx_projects/uat/force-app/main/default/profiles/"$profile".profile-meta.xml | less -R;
}
export -f pfdiff
# corgs – compare orgs
# Retrieve custom fields metadata from two orgs (full/prod || dev/full || dev/dev) and compare differences
# Orgs must already been authorised with sfdx. !! Function will create files in working directory !!
# Prerequisites: jq needs to be installed, colordiff needs to be installed
# colordiff is optional. Change to "diff" if you don't want to install it
function corgs {
# ask for login user for org1 and org2
read -p 'Enter UserName of org1: ' userNameOrg1;
read -p 'Enter UserName of org2: ' userNameOrg2;
# org1: retrieve custom fields, parse api names, sort, create text file
sfdx force:mdapi:listmetadata -m CustomField -u "$userNameOrg1" -f customFieldsOrg1.txt;
customFieldApiNamesOrg1=$(cat customFieldsOrg1.txt|jq '.[].fullName');
echo $customFieldApiNamesOrg1 | tr ' ' '\n' | sort | sed 's/\"//g' > $userNameOrg1.txt;
rm customFieldsOrg1.txt;
# org2: retrieve custom fields, parse api names, sort, create text file
sfdx force:mdapi:listmetadata -m CustomField -u "$userNameOrg2" -f customFieldsOrg2.txt;
customFieldApiNamesOrg2=$(cat customFieldsOrg2.txt|jq '.[].fullName');
echo $customFieldApiNamesOrg2 | tr ' ' '\n' | sort | sed 's/\"//g' > $userNameOrg2.txt;
rm customFieldsOrg2.txt;
# compare org1 & org2 files, display colored differences in terminal,
# create added/removed fields report and open it
diff -u $userNameOrg1.txt $userNameOrg2.txt > comp.txt;
echo "REMOVED FIELDS:" > plus_minus_report.txt;
grep ^- comp.txt >> plus_minus_report.txt;
echo "ADDED FIELDS:" >> plus_minus_report.txt;
grep ^+ comp.txt >> plus_minus_report.txt;
colordiff -u $userNameOrg1.txt $userNameOrg2.txt;
}
export -f corgs
# medi - metadata diff
# function to get differences of all units of a specified metadata type
# 1) go to your sfdx projects main folder
# 2) use the command "medi [org alias]"
# 3) choose which type of metedata to
# 4) open the created orgAlias_matadataType_DIFF.csv to check results
# EXAMPLE how to create .csv file:
# printf "Test1\tTest2\tTest3\n" > test.csv; printf "1\t2\t3\n" >> test.csv; printf "1\t2\t3\n" >> test.csv
function medi {
read -p 'enter alias of the org you would like to check: ' ORG;
read -p 'enter metadata option (1 permissionsets, 2 profiles): ' OPT;
if [ $OPT == 1 ]
then
META='permissionsets';
elif [ $OPT == 2 ]
then
META='profiles';
fi
if [ -d "$ORG/force-app/main/default/$META/" ]; then
cd $ORG/force-app/main/default/$META/
else
echo "$ORG/force-app/main/default/$META/ does not exist.";
echo "make sure to retrieve metadata befor you run medi.";
return;
fi
}