|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -# Runs "appendEnvironmentVariable.sh" for every script file in the current directory and its sub directories. |
| 3 | +# Runs "appendEnvironmentVariable.sh" for every script file in the scripts directory and its sub directories. |
| 4 | +# Note: This script can be run from any directory (e.g. the repository root). It changes to the scripts directory internally. |
4 | 5 |
|
5 | 6 | # Requires appendEnvironmentVariable.sh |
6 | 7 |
|
7 | 8 | # Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands) |
8 | 9 | set -o errexit -o pipefail |
9 | 10 |
|
10 | | -## Get this "scripts" directory if not already set |
| 11 | +## Get this "scripts/documentation" directory if not already set |
11 | 12 | # Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution. |
12 | 13 | # CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes. |
13 | 14 | # This way non-standard tools like readlink aren't needed. |
14 | 15 | DOCUMENTATION_SCRIPTS_DIR=${DOCUMENTATION_SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} # Repository directory containing the documentation generation scripts |
15 | 16 | echo "generateEnvironmentVariablesReference: DOCUMENTATION_SCRIPTS_DIR=${DOCUMENTATION_SCRIPTS_DIR}" |
16 | 17 |
|
| 18 | +# Change to the scripts directory so that the output file is written there and all relative paths work correctly |
| 19 | +cd "${DOCUMENTATION_SCRIPTS_DIR}/.." |
| 20 | + |
17 | 21 | echo "generateEnvironmentVariableReference: Generating ENVIRONMENT_VARIABLES.md..." |
18 | 22 |
|
19 | 23 | # Clear existing markdown document |
20 | 24 | source "${DOCUMENTATION_SCRIPTS_DIR}/appendEnvironmentVariables.sh" "clear" || exit 1 |
21 | 25 |
|
22 | | -# Loop through all script files in the current directory |
23 | | -find . -type f -name "*.sh" | sort | while read -r scriptFile; do |
| 26 | +# Collect search roots: always the current scripts directory, plus ../domains if it exists |
| 27 | +search_roots="." |
| 28 | +if [ -d "../domains" ]; then |
| 29 | + search_roots=". ../domains" |
| 30 | +fi |
| 31 | + |
| 32 | +# Loop through all script files in the current directory and domain directories |
| 33 | +# shellcheck disable=SC2086 |
| 34 | +find ${search_roots} -type f -name "*.sh" | sort | while read -r scriptFile; do |
24 | 35 | echo "generateEnvironmentVariablesReference: Searching for environment variables in ${scriptFile}" |
25 | 36 | source "${DOCUMENTATION_SCRIPTS_DIR}/appendEnvironmentVariables.sh" "${scriptFile}" || exit 1 |
26 | 37 | done |
|
0 commit comments