Created
May 21, 2019 11:53
-
-
Save sohalloran/075a5eb6b703688856f5765c805f2300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function clean-metadata { | |
clean-item $1 '/<fieldPermissions>/,/<\/fieldPermissions>/d' | |
clean-item $1 '/<userPermissions>/,/<\/userPermissions>/d' | |
clean-item $1 '/<recordTypeVisibilities>/,/<\/recordTypeVisibilities>/d' | |
clean-item $1 '/<recordTypeVisibilities>/,/<\/recordTypeVisibilities>/d' | |
clean-item $1 '/<categoryGroupVisibilities>/,/<\/categoryGroupVisibilities>/d' | |
clean-item $1 '/<applicationVisibilities>/,/<\/applicationVisibilities>/d' | |
clean-item $1 '/<tabVisibilities>/,/<\/tabVisibilities>/d' | |
clean-item $1 '/<tabSettings>/,/<\/tabSettings>/d' | |
clean-item $1 '/<userLicense>.*<\/userLicense>.*/d' | |
clean-item $1 '/<custom>.*<\/custom>.*/d' | |
clean-item $1 '/<hasActivationRequired>.*<\/hasActivationRequired>.*/d' | |
clean-item $1 '/<label>.*<\/label>.*/d' | |
clean-item $1 '/<allowCreate>false<\/allowCreate>.*/d' | |
clean-item $1 '/<allowDelete>false<\/allowDelete>.*/d' | |
clean-item $1 '/<allowEdit>false<\/allowEdit>.*/d' | |
clean-item $1 '/<allowRead>false<\/allowRead>.*/d' | |
clean-item $1 '/<modifyAllRecords>false<\/modifyAllRecords>.*/d' | |
clean-item $1 '/<viewAllRecords>false<\/viewAllRecords>.*/d' | |
clean-item $1 '/<description>.*<\/description>.*/d' | |
clean-item $1 '/<fieldPermissions>/,/<\/fieldPermissions>/d' | |
} | |
function clean-item { | |
find $1/*/*.* -type f -exec sed -i -e $2 {} + | |
find . -type f -name '*.*-e' -delete | |
} | |
function get-metadata { | |
echo "Creating Project for $1" | |
sfdx force:project:create -x -n $1 | |
cd $1 | |
echo "Getting Object List for $1" | |
objects=$(sfdx force:schema:sobject:list -c all -u $1) | |
sed -i -e 's/\s/<</g' $objects | |
x="$(echo $objects | sed 's/ /,CustomObject:/g')" | |
echo "Retrieving Metadata for $1 (this can take a few minutes...)" | |
sfdx force:source:retrieve --json -u $1 -m Profile,PermissionSet,$x | |
echo "Cleaning Metadata for $1" | |
clean-metadata "force-app/main/default" | |
cd .. | |
} | |
function start-dx { | |
read -p "Sandbox Login to get metadata. Press any key to launch auth: `echo $'\n> '`" | |
sfdx force:auth:web:login -r https://test.salesforce.com -a "sandbox" | |
get-metadata "sandbox" | |
read -p "Production Login to get metadata. Press any key to launch auth: `echo $'\n> '`" | |
sfdx force:auth:web:login -a "production" | |
get-metadata "production" | |
clean-metadata sandbox/force-app/main/default | |
clean-metadata production/force-app/main/default | |
diff-files production/force-app/main/default sandbox/force-app/main/default | |
} | |
function ft-diff { | |
rm -rf ft-baudev | |
rm -rf ft-prod | |
unzip ft-baudev.zip | |
unzip ft-prod.zip | |
clean-metadata ft-baudev/src | |
clean-metadata ft-prod/src | |
diff-files ft-prod/src/ ft-baudev/src/ | |
} | |
function diff-files { | |
echo "Comparing Metadata" | |
diff -rqC4 $1/profiles $2/profiles > profile-diff.txt | |
diff -rC4 $1/profiles $2/profiles > profile-diff-detail.txt | |
diff -rqC4 $1/permissionsets $2/permissionsets > permset-diff.txt | |
diff -rC4 $1/permissionsets $2/permissionsets > permset-diff-detail.txt | |
echo "Diff files created with extensions *-diff.txt" | |
#for file in $2/profiles/*.profile; do | |
# dfile="${file##*/}" | |
# diff -yr "$1/profiles/${file##*/}" "$file" > "${dfile}-diff.txt" | |
#done | |
} | |
function git-compare { | |
mkdir repo | |
cd repo | |
git init | |
git checkout -b sandbox | |
git checkout -b production | |
cp -r production/force-app/main/default . | |
git add . | |
git commit -m 'production init' | |
git checkout sandbox | |
cp -r sandbox/force-app/main/default . | |
git add . | |
git commit -m 'sandbox init' | |
cd .. | |
} | |
start-dx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment