Skip to content

Commit 667a5dd

Browse files
committed
add documentation inside the shell scripts
1 parent 0b80b7a commit 667a5dd

13 files changed

Lines changed: 508 additions & 0 deletions

scripts/build-all.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
#!/usr/bin/env bash
2+
#
3+
# build-all.sh
4+
#
5+
# Purpose:
6+
# Orchestrates the build process for all components: solace-broker-api,
7+
# solace-publisher-ui, and solace-subscriber.
8+
#
9+
# Usage:
10+
# ./build-all.sh
11+
#
12+
# Required tools/dependencies:
13+
# - bash
14+
# - Tools required by individual build scripts (e.g., mvn, npm).
15+
#
16+
# Expected output:
17+
# Logs from individual build scripts and a final confirmation message.
18+
#
19+
# Exit behavior:
20+
# Exits with code 0 on success.
21+
# Exits with a non-zero code if any individual build fails.
222

323
set -euo pipefail
424

25+
# Directory where this script is located.
526
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
627

28+
# Trigger builds for all components.
729
"${SCRIPT_DIR}/build-broker-api.sh"
830
"${SCRIPT_DIR}/build-publisher-ui.sh"
931
"${SCRIPT_DIR}/build-subscriber.sh"

scripts/build-broker-api.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
#!/usr/bin/env bash
2+
#
3+
# build-broker-api.sh
4+
#
5+
# Purpose:
6+
# Builds the solace-broker-api Java component using Maven.
7+
#
8+
# Usage:
9+
# ./build-broker-api.sh
10+
#
11+
# Required tools/dependencies:
12+
# - bash
13+
# - java
14+
# - mvn
15+
#
16+
# Expected output:
17+
# Maven build logs and a final package in the target directory.
18+
#
19+
# Exit behavior:
20+
# Exits with code 0 on success.
21+
# Exits with a non-zero code if the Maven build fails.
222

323
set -euo pipefail
424

25+
# Source common utility functions.
526
source "$(cd "$(dirname "$0")" && pwd)/common.sh"
627

28+
# Ensure required commands are available.
729
require_command java
830
require_command mvn
931

32+
# Navigate to the component directory.
1033
enter_module "solace-broker-api"
1134

1235
echo "building solace-broker-api"
36+
# Execute maven build.
1337
exec mvn clean package

scripts/build-publisher-ui.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,47 @@
11
#!/usr/bin/env bash
2+
#
3+
# build-publisher-ui.sh
4+
#
5+
# Purpose:
6+
# Builds the solace-publisher-ui component using npm.
7+
# Installs dependencies if node_modules is missing.
8+
#
9+
# Usage:
10+
# ./build-publisher-ui.sh
11+
#
12+
# Required tools/dependencies:
13+
# - bash
14+
# - node
15+
# - npm
16+
#
17+
# Expected output:
18+
# npm install logs (if needed), npm build logs, and a production build in the dist folder.
19+
#
20+
# Exit behavior:
21+
# Exits with code 0 on success.
22+
# Exits with a non-zero code if dependencies installation or build fails.
223

324
set -euo pipefail
425

26+
# Source common utility functions.
527
source "$(cd "$(dirname "$0")" && pwd)/common.sh"
628

29+
# Ensure required commands are available.
730
require_command node
831
require_command npm
932

33+
# Use environment variable for module directory or default to solace-publisher-ui.
1034
PUBLISHER_UI_DIR="${PUBLISHER_UI_DIR:-solace-publisher-ui}"
1135

36+
# Navigate to the component directory.
1237
enter_module "${PUBLISHER_UI_DIR}"
1338

39+
# Check for dependencies and install them if they are missing.
1440
if [[ ! -d node_modules ]]; then
1541
echo "node_modules is missing in ${PUBLISHER_UI_DIR}; running 'npm install' first"
1642
npm install
1743
fi
1844

1945
echo "building solace-publisher-ui"
46+
# Execute npm build.
2047
exec npm run build

scripts/build-subscriber.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
#!/usr/bin/env bash
2+
#
3+
# build-subscriber.sh
4+
#
5+
# Purpose:
6+
# Builds the solace-subscriber Java component using Maven.
7+
#
8+
# Usage:
9+
# ./build-subscriber.sh
10+
#
11+
# Required tools/dependencies:
12+
# - bash
13+
# - java
14+
# - mvn
15+
#
16+
# Expected output:
17+
# Maven build logs and a final package in the target directory.
18+
#
19+
# Exit behavior:
20+
# Exits with code 0 on success.
21+
# Exits with a non-zero code if the Maven build fails.
222

323
set -euo pipefail
424

25+
# Source common utility functions.
526
source "$(cd "$(dirname "$0")" && pwd)/common.sh"
627

28+
# Ensure required commands are available.
729
require_command java
830
require_command mvn
931

32+
# Navigate to the component directory.
1033
enter_module "solace-subscriber"
1134

1235
echo "building solace-subscriber"
36+
# Execute maven build.
1337
exec mvn clean package

scripts/common.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
#!/usr/bin/env bash
2+
#
3+
# common.sh
4+
#
5+
# Purpose:
6+
# Provides shared utility functions for all scripts in the repository.
7+
#
8+
# Usage:
9+
# source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
10+
#
11+
# Required tools/dependencies:
12+
# - bash
13+
#
14+
# Expected output:
15+
# None (defines functions for other scripts).
16+
#
17+
# Exit behavior:
18+
# The utility functions may exit the script with code 1 if requirements are not met.
219

320
set -euo pipefail
421

22+
# The root directory of the repository, calculated relative to this script's location.
523
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
624

25+
# Function: require_command
26+
# Purpose: Checks if a command exists in the PATH.
27+
# Inputs:
28+
# $1 - The name of the command to check.
29+
# Outputs:
30+
# Prints an error message to stderr if the command is missing.
31+
# Exit behavior:
32+
# Exits with code 1 if the command is not found.
733
require_command() {
834
local command_name="$1"
935
if ! command -v "${command_name}" >/dev/null 2>&1; then
@@ -12,6 +38,14 @@ require_command() {
1238
fi
1339
}
1440

41+
# Function: require_env_var
42+
# Purpose: Checks if an environment variable is set and non-empty.
43+
# Inputs:
44+
# $1 - The name of the environment variable to check.
45+
# Outputs:
46+
# Prints an error message to stderr if the variable is missing.
47+
# Exit behavior:
48+
# Exits with code 1 if the variable is not set or empty.
1549
require_env_var() {
1650
local variable_name="$1"
1751
if [[ -z "${!variable_name:-}" ]]; then
@@ -20,6 +54,14 @@ require_env_var() {
2054
fi
2155
}
2256

57+
# Function: require_solace_env_vars
58+
# Purpose: Validates that all required Solace Cloud environment variables are set.
59+
# Inputs:
60+
# $1 - (Optional) Name of the caller script for logging purposes.
61+
# Outputs:
62+
# Prints error messages to stderr listing the missing variables.
63+
# Exit behavior:
64+
# Exits with code 1 if any required Solace variable is missing.
2365
require_solace_env_vars() {
2466
local caller_name="${1:-this script}"
2567
local required_vars=(
@@ -43,6 +85,14 @@ require_solace_env_vars() {
4385
done
4486
}
4587

88+
# Function: enter_module
89+
# Purpose: Changes the current working directory to a specific module.
90+
# Inputs:
91+
# $1 - The path to the module (absolute or relative to REPO_ROOT).
92+
# Outputs:
93+
# None.
94+
# Exit behavior:
95+
# Returns or exits if 'cd' fails (due to 'set -e').
4696
enter_module() {
4797
local module_path="$1"
4898
if [[ "${module_path}" = /* ]]; then

scripts/restart-all.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
11
#!/usr/bin/env bash
2+
#
3+
# restart-all.sh
4+
#
5+
# Purpose:
6+
# Restarts the entire workspace by stopping, rebuilding, and starting all components.
7+
#
8+
# Usage:
9+
# ./restart-all.sh
10+
#
11+
# Required tools/dependencies:
12+
# - bash
13+
# - Individual component build and run dependencies.
14+
#
15+
# Expected output:
16+
# Console output from stop, build, and start scripts with separators.
17+
#
18+
# Exit behavior:
19+
# Exits with code 0 on success.
20+
# Exits with a non-zero code if any sub-script fails.
221

322
set -euo pipefail
423

24+
# Directory where this script is located.
525
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
626

27+
# Function: print_separator
28+
# Purpose: Prints a formatted separator line with a label for better log readability.
29+
# Inputs:
30+
# $1 - The label to display in the separator.
31+
# Outputs:
32+
# A formatted string to stdout.
733
print_separator() {
834
local label="$1"
935
echo
1036
printf '==================== %s ====================\n' "${label}"
1137
echo
1238
}
1339

40+
# Stop all running components.
1441
print_separator "stopping workspace"
1542
"${SCRIPT_DIR}/stop-all.sh"
1643

44+
# Rebuild all components.
1745
print_separator "building workspace"
1846
"${SCRIPT_DIR}/build-all.sh"
1947

48+
# Start all components.
2049
print_separator "starting workspace"
2150
"${SCRIPT_DIR}/start-all.sh"

0 commit comments

Comments
 (0)