|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) |
| 4 | +cd $SCRIPT_PATH/.. |
| 5 | + |
| 6 | +# Check exit code function |
| 7 | +error() { |
| 8 | + echo "" |
| 9 | + if [[ $1 -eq 0 ]]; then |
| 10 | + echo "Installation completed." |
| 11 | + echo "" |
| 12 | + exit $1 |
| 13 | + else |
| 14 | + if [[ -n $2 ]]; then |
| 15 | + echo "$2" |
| 16 | + echo "" |
| 17 | + fi |
| 18 | + |
| 19 | + echo "Installation failed." |
| 20 | + echo "" |
| 21 | + exit $1 |
| 22 | + fi |
| 23 | +} |
| 24 | + |
| 25 | +cleaningPreviousScratchOrg() { |
| 26 | + sf org delete scratch --no-prompt --target-org $org_alias &> /dev/null |
| 27 | +} |
| 28 | + |
| 29 | +creatingScratchOrg () { |
| 30 | + echo "" |
| 31 | + echo "Org Alias: $org_alias" |
| 32 | + echo "" |
| 33 | + |
| 34 | + if [[ -n $npm_config_org_duration ]]; then |
| 35 | + days=$npm_config_org_duration |
| 36 | + else |
| 37 | + days=7 |
| 38 | + fi |
| 39 | + |
| 40 | + echo "Scratch org duration: $days days" |
| 41 | + sf org create scratch --set-default --definition-file config/project-scratch-def.json --duration-days "$days" --alias $org_alias || { error $? '"sf org create scratch" command failed.'; } |
| 42 | +} |
| 43 | + |
| 44 | +installDependencies() { |
| 45 | + keys="" |
| 46 | + for p in $(jq '.packageAliases | keys[]' sfdx-project.json -r); |
| 47 | + do |
| 48 | + keys+=$p":"$secret" "; |
| 49 | + done |
| 50 | + sf dependency install --installationkeys "${keys}" --targetusername "$org_alias" --targetdevhubusername "$devHubAlias" || { error $? '"sf dependency install" command failed.'; } |
| 51 | +} |
| 52 | + |
| 53 | +deployingMetadata() { |
| 54 | + if [[ $npm_config_without_deploy ]]; then |
| 55 | + echo "Skipping..." |
| 56 | + else |
| 57 | + sf project deploy start || { error $? '"sf project deploy start" command failed.'; } |
| 58 | + fi |
| 59 | +} |
| 60 | + |
| 61 | +#assignPermission() { |
| 62 | +# sf org assign permset \ |
| 63 | +# --name Messaging_Read_and_Write_Messages_and_Threads \ |
| 64 | +# --name Arbeidsgiver_Dialog_Interne \ |
| 65 | +# --name Arbeidsgiver_base \ |
| 66 | +# --name Arbeidsgiver_contract \ |
| 67 | +# || { error $? '"sf org assign permset" command failed.'; } |
| 68 | +#} |
| 69 | + |
| 70 | +#insertingTestData() { |
| 71 | +# sf data import tree --plan dummy-data/plan.json || { error $? '"sf data import tree" command failed.'; } |
| 72 | +#} |
| 73 | + |
| 74 | +#runPostInstallScripts() { |
| 75 | +# sf apex run --file ./scripts/apex/activateMock.cls || { error $? '"sf apex run" command failed for Apex class: "activateMock".'; } |
| 76 | +# sf apex run --file ./scripts/apex/createPortalUser.cls || { error $? '"sf apex run" command failed for Apex class: "createPortalUser".'; } |
| 77 | +# sf apex run --file ./scripts/apex/createTestData.cls || { error $? '"sf apex run" command failed for Apex class: "createTestData".'; } |
| 78 | +#} |
| 79 | + |
| 80 | +#publishCommunity() { |
| 81 | +# if [[ $npm_config_without_publish ]]; then |
| 82 | +# echo "Skipping..." |
| 83 | +# else |
| 84 | +# sf community publish --name "arbeidsgiver-dialog" || { error $? '"sf community publish" command failed for community: "arbeidsgiver-dialog".'; } |
| 85 | +# fi |
| 86 | +#} |
| 87 | + |
| 88 | +openOrg() { |
| 89 | + if [[ -n $npm_config_open_in ]]; then |
| 90 | + sf org open --browser "$npm_config_open_in" --path "lightning/app/standard__LightningService" || { error $? '"sf org open" command failed.'; } |
| 91 | + else |
| 92 | + sf org open --path "lightning/app/standard__LightningService" || { error $? '"sf org open" command failed.'; } |
| 93 | + fi |
| 94 | +} |
| 95 | + |
| 96 | +info() { |
| 97 | + echo "Usage: npm run mac:build [options]" |
| 98 | + echo "" |
| 99 | + echo "Options:" |
| 100 | + echo " --package-key=<key> Package key to install" |
| 101 | + echo " --org-alias=<alias> Alias for the scratch org" |
| 102 | + echo " --org-duration=<days> Duration of the scratch org" |
| 103 | + echo " --without-deploy Skip deploy" |
| 104 | + #echo " --without-publish Skip publish of community: \"{site name}\"" |
| 105 | + echo " --open-in=<option> Browser where the org opens." |
| 106 | + echo " <options: chrome|edge|firefox>" |
| 107 | + echo " --start-step=<step-nummer> Start from a specific step" |
| 108 | + echo " --step=<step-nummer> Run a specific step" |
| 109 | + #echo " <steps: clean=1|create=2|dependencies=3|deploy=4|permissions=5|test data=6|run scripts=7|publishing site=8|open=9>" |
| 110 | + echo " <steps: clean=1|create=2|dependencies=3|deploy=4|open=5>" |
| 111 | + echo " --info Show this help" |
| 112 | + echo "" |
| 113 | + exit 0 |
| 114 | +} |
| 115 | +if [[ $npm_config_info ]]; then |
| 116 | + info |
| 117 | +elif [[ -z $npm_config_package_key ]]; then |
| 118 | + echo "Package key is required." |
| 119 | + echo "" |
| 120 | + info |
| 121 | +fi |
| 122 | + |
| 123 | +sf plugins inspect @dxatscale/sfpowerscripts >/dev/null 2>&1 || { |
| 124 | + echo >&2 "\"@dxatscale/sfpowerscripts\" is required, but it's not installed." |
| 125 | + echo "Run \"sf plugins install @dxatscale/sfpowerscripts\" to install it." |
| 126 | + echo "" |
| 127 | + echo "Aborting...." |
| 128 | + echo "" |
| 129 | + exit 1 |
| 130 | +} |
| 131 | +sf plugins inspect sfdmu >/dev/null 2>&1 || { |
| 132 | + echo >&2 "\"sfdmu\" is required, but it's not installed." |
| 133 | + echo "Run \"sf plugins install sfdmu\" to install it." |
| 134 | + echo "" |
| 135 | + echo "Aborting..." |
| 136 | + echo "" |
| 137 | + exit 1 |
| 138 | +} |
| 139 | + |
| 140 | +command -v jq >/dev/null 2>&1 || { |
| 141 | + echo >&2 "\"jq\" is required, but it's not installed." |
| 142 | + echo "Run \"brew install jq\" to install it if you have Homebrew installed." |
| 143 | + echo "" |
| 144 | + echo "Aborting..." |
| 145 | + echo "" |
| 146 | + exit 1 |
| 147 | +} |
| 148 | + |
| 149 | +ORG_ALIAS="arbeidsgiver-kurs" |
| 150 | +secret=$npm_config_package_key |
| 151 | +devHubAlias=$(sf config get target-dev-hub --json | jq -r '.result[0].value') |
| 152 | + |
| 153 | +if [[ -n $npm_config_org_alias ]]; then |
| 154 | + org_alias=$npm_config_org_alias |
| 155 | +else |
| 156 | + org_alias=$ORG_ALIAS |
| 157 | +fi |
| 158 | + |
| 159 | +echo "Installing crm-arbeidsgiver-kurs scratch org ($org_alias)" |
| 160 | +echo "" |
| 161 | + |
| 162 | +operations=( |
| 163 | + cleaningPreviousScratchOrg |
| 164 | + creatingScratchOrg |
| 165 | + installDependencies |
| 166 | + deployingMetadata |
| 167 | + #assignPermission |
| 168 | + #insertingTestData |
| 169 | + #runPostInstallScripts |
| 170 | + #publishCommunity |
| 171 | + openOrg |
| 172 | +) |
| 173 | + |
| 174 | +operationNames=( |
| 175 | + "Cleaning previous scratch org" |
| 176 | + "Creating scratch org" |
| 177 | + "Installing dependencies" |
| 178 | + "Deploying/Pushing metadata" |
| 179 | + #"Assigning permissions" |
| 180 | + #"Inserting test data" |
| 181 | + #"Running post install scripts" |
| 182 | + #"Publishing {name} site" |
| 183 | + "Opening org" |
| 184 | +) |
| 185 | + |
| 186 | +if [[ -n $npm_config_step ]] && [[ -z $npm_config_start_step ]]; then |
| 187 | + if [[ "$npm_config_step" =~ ^[0-9]+$ ]] && [[ $npm_config_step -ge 1 ]]; then |
| 188 | + j=$((npm_config_step - 1)) |
| 189 | + else |
| 190 | + echo "Invalid step number: $npm_config_step" |
| 191 | + exit 1 |
| 192 | + fi |
| 193 | + |
| 194 | + echo "Running Step $npm_config_step/${#operations[@]}: ${operationNames[$j]}..." |
| 195 | + ${operations[$j]} |
| 196 | + echo "" |
| 197 | + exit 0 |
| 198 | +fi |
| 199 | + |
| 200 | +for i in ${!operations[@]}; do |
| 201 | + echo "Step $((i+1))/${#operations[@]}: ${operationNames[$i]}..." |
| 202 | + if [[ $((i+1)) -ge $npm_config_start_step ]]; then |
| 203 | + ${operations[$i]} |
| 204 | + else |
| 205 | + echo "Skipping..." |
| 206 | + fi |
| 207 | + |
| 208 | + echo "" |
| 209 | +done |
| 210 | + |
| 211 | +error $? |
| 212 | + |
0 commit comments