@redpanda-data/docs-extensions-and-macros 4.5.0 → 4.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.adoc +0 -163
  2. package/bin/doc-tools.js +492 -283
  3. package/cli-utils/antora-utils.js +127 -0
  4. package/cli-utils/generate-cluster-docs.sh +41 -29
  5. package/cli-utils/self-managed-docs-branch.js +2 -1
  6. package/cli-utils/start-cluster.sh +70 -30
  7. package/extensions/generate-rp-connect-info.js +14 -9
  8. package/package.json +6 -5
  9. package/tools/redpanda-connect/generate-rpcn-connector-docs.js +233 -0
  10. package/tools/redpanda-connect/helpers/advancedConfig.js +17 -0
  11. package/tools/redpanda-connect/helpers/buildConfigYaml.js +53 -0
  12. package/tools/redpanda-connect/helpers/commonConfig.js +31 -0
  13. package/tools/redpanda-connect/helpers/eq.js +10 -0
  14. package/tools/redpanda-connect/helpers/index.js +19 -0
  15. package/tools/redpanda-connect/helpers/isObject.js +1 -0
  16. package/tools/redpanda-connect/helpers/join.js +6 -0
  17. package/tools/redpanda-connect/helpers/ne.js +10 -0
  18. package/tools/redpanda-connect/helpers/or.js +4 -0
  19. package/tools/redpanda-connect/helpers/renderConnectExamples.js +37 -0
  20. package/tools/redpanda-connect/helpers/renderConnectFields.js +148 -0
  21. package/tools/redpanda-connect/helpers/renderLeafField.js +64 -0
  22. package/tools/redpanda-connect/helpers/renderObjectField.js +41 -0
  23. package/tools/redpanda-connect/helpers/renderYamlList.js +24 -0
  24. package/tools/redpanda-connect/helpers/toYaml.js +11 -0
  25. package/tools/redpanda-connect/helpers/uppercase.js +9 -0
  26. package/tools/redpanda-connect/parse-csv-connectors.js +63 -0
  27. package/tools/redpanda-connect/report-delta.js +152 -0
  28. package/tools/redpanda-connect/templates/connector.hbs +20 -0
  29. package/tools/redpanda-connect/templates/examples-partials.hbs +7 -0
  30. package/tools/redpanda-connect/templates/fields-partials.hbs +13 -0
  31. package/tools/redpanda-connect/templates/intro.hbs +33 -0
  32. package/macros/data-template.js +0 -591
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const yaml = require('js-yaml');
6
+
7
+ /**
8
+ * Attempts to locate and parse `antora.yml` in the current working directory.
9
+ *
10
+ * @returns {Object|undefined} The parsed YAML as a JavaScript object, or undefined if not found or on error.
11
+ */
12
+ function loadAntoraConfig() {
13
+ const antoraPath = path.join(process.cwd(), 'antora.yml');
14
+ if (!fs.existsSync(antoraPath)) {
15
+ // No antora.yml in project root
16
+ return undefined;
17
+ }
18
+
19
+ try {
20
+ const fileContents = fs.readFileSync(antoraPath, 'utf8');
21
+ const config = yaml.load(fileContents);
22
+ if (typeof config !== 'object' || config === null) {
23
+ console.error('Warning: antora.yml parsed to a non‐object value.');
24
+ return undefined;
25
+ }
26
+ return config;
27
+ } catch (err) {
28
+ console.error(`Error reading/parsing antora.yml: ${err.message}`);
29
+ return undefined;
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Safely retrieves a nested value from the Antora configuration, given a "dot path".
35
+ *
36
+ * Example usage:
37
+ * const latestVersion = getAntoraValue('asciidoc.attributes.latest-connect-version');
38
+ *
39
+ * @param {string} keyPath
40
+ * A dot-separated path into the Antora object (e.g. "asciidoc.attributes.foo").
41
+ * @returns {*}
42
+ * The value at that path, or undefined if the file is missing or the key does not exist.
43
+ */
44
+ function getAntoraValue(keyPath) {
45
+ const config = loadAntoraConfig();
46
+ if (!config) {
47
+ return undefined;
48
+ }
49
+
50
+ // Split on dots, but ignore empty segments
51
+ const segments = keyPath.split('.').filter(Boolean);
52
+ let cursor = config;
53
+
54
+ for (const seg of segments) {
55
+ if (cursor && typeof cursor === 'object' && seg in cursor) {
56
+ cursor = cursor[seg];
57
+ } else {
58
+ return undefined;
59
+ }
60
+ }
61
+ return cursor;
62
+ }
63
+
64
+ /**
65
+ * Safely sets a nested value in the Antora configuration, given a "dot path".
66
+ * If the file or path does not exist, it will create intermediate objects as needed.
67
+ * After setting the value, writes the updated YAML back to `antora.yml`.
68
+ *
69
+ * @param {string} keyPath
70
+ * A dot-separated path to set (e.g. "asciidoc.attributes.latest-connect-version").
71
+ * @param {*} newValue
72
+ * The new value to assign at that path.
73
+ * @returns {boolean}
74
+ * True if it succeeded, false otherwise.
75
+ */
76
+ function setAntoraValue(keyPath, newValue) {
77
+ const antoraPath = path.join(process.cwd(), 'antora.yml');
78
+ if (!fs.existsSync(antoraPath)) {
79
+ console.error('Cannot update antora.yml: file not found in project root.');
80
+ return false;
81
+ }
82
+
83
+ let config;
84
+ try {
85
+ const fileContents = fs.readFileSync(antoraPath, 'utf8');
86
+ config = yaml.load(fileContents) || {};
87
+ if (typeof config !== 'object' || config === null) {
88
+ config = {};
89
+ }
90
+ } catch (err) {
91
+ console.error(`Error reading/parsing antora.yml: ${err.message}`);
92
+ return false;
93
+ }
94
+
95
+ // Traverse/construct nested objects
96
+ const segments = keyPath.split('.').filter(Boolean);
97
+ let cursor = config;
98
+ for (let i = 0; i < segments.length; i++) {
99
+ const seg = segments[i];
100
+ if (i === segments.length - 1) {
101
+ // Last segment: assign
102
+ cursor[seg] = newValue;
103
+ } else {
104
+ // Intermediate: ensure object
105
+ if (!(seg in cursor) || typeof cursor[seg] !== 'object' || cursor[seg] === null) {
106
+ cursor[seg] = {};
107
+ }
108
+ cursor = cursor[seg];
109
+ }
110
+ }
111
+
112
+ // Serialize back to YAML and write
113
+ try {
114
+ const newYaml = yaml.dump(config, { lineWidth: 120 });
115
+ fs.writeFileSync(antoraPath, newYaml, 'utf8');
116
+ return true;
117
+ } catch (err) {
118
+ console.error(`Error writing antora.yml: ${err.message}`);
119
+ return false;
120
+ }
121
+ }
122
+
123
+ module.exports = {
124
+ loadAntoraConfig,
125
+ getAntoraValue,
126
+ setAntoraValue,
127
+ };
@@ -1,23 +1,34 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
+ IFS=$'\n\t'
3
4
 
4
- # Check if Docker is installed and running
5
+ ###############################################################################
6
+ # Pre-flight: Ensure Docker is available and running
7
+ ###############################################################################
5
8
  if ! command -v docker &> /dev/null; then
6
9
  echo "❌ Docker is not installed or not in PATH. Please install Docker to continue."
7
10
  exit 1
8
11
  fi
9
12
 
10
- # Check if Docker daemon is running
11
13
  if ! docker info &> /dev/null; then
12
14
  echo "❌ Docker daemon is not running. Please start Docker to continue."
13
15
  exit 1
14
16
  fi
15
17
 
16
- # Remember where we started so we can always come back
17
- ORIGINAL_PWD="$(pwd)"
18
+ ###############################################################################
19
+ # Load overrides from an optional .env file in the current directory
20
+ ###############################################################################
21
+ if [[ -f .env ]]; then
22
+ # shellcheck disable=SC2046
23
+ export $(grep -Ev '^#' .env | xargs)
24
+ fi
18
25
 
19
- # All "cli-utils…" calls should be relative to this script’s dir
26
+ ###############################################################################
27
+ # Environment setup
28
+ ###############################################################################
29
+ ORIGINAL_PWD="$(pwd)"
20
30
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
31
+ PROJECT_NAME="${PROJECT_NAME:-redpanda_quickstart}"
21
32
 
22
33
  MODE="${1:-metrics}"
23
34
  TAG="${2:-latest}"
@@ -25,16 +36,15 @@ DOCKER_REPO="${3:-redpanda}"
25
36
  CONSOLE_TAG="${4:-latest}"
26
37
  CONSOLE_REPO="${5:-console}"
27
38
 
28
- # if it's an RC tag, switch Docker repo
39
+ # Adjust Docker repo for release candidates
29
40
  shopt -s nocasematch
30
41
  if [[ "$TAG" =~ rc[0-9]+ ]]; then
31
42
  DOCKER_REPO="redpanda-unstable"
32
43
  fi
33
44
  shopt -u nocasematch
34
45
 
35
- if [[ "$TAG" == "latest" ]]; then
36
- MAJOR_MINOR="latest"
37
- else
46
+ MAJOR_MINOR="latest"
47
+ if [[ "$TAG" != "latest" ]]; then
38
48
  MAJOR_MINOR="$(echo "$TAG" | sed -E 's/^v?([0-9]+\.[0-9]+).*$/\1/')"
39
49
  fi
40
50
 
@@ -43,41 +53,43 @@ export REDPANDA_DOCKER_REPO="$DOCKER_REPO"
43
53
  export REDPANDA_CONSOLE_VERSION="$CONSOLE_TAG"
44
54
  export REDPANDA_CONSOLE_DOCKER_REPO="$CONSOLE_REPO"
45
55
 
46
- # Start up the cluster
47
- "$SCRIPT_DIR"/start-cluster.sh "$TAG"
56
+ ###############################################################################
57
+ # Start Redpanda cluster
58
+ ###############################################################################
59
+ "$SCRIPT_DIR/start-cluster.sh" "$TAG"
48
60
 
49
- # Wait for it to settle
61
+ # Wait for the cluster to settle
50
62
  if [[ "$MODE" == "metrics" ]]; then
51
- echo "Waiting 300 seconds for metrics to be available…"
63
+ echo "Waiting 300 seconds for metrics to be available…"
52
64
  sleep 300
53
65
  else
54
- echo "Waiting 30 seconds for cluster to be ready…"
66
+ echo "Waiting 30 seconds for cluster to be ready…"
55
67
  sleep 30
56
68
  fi
57
69
 
58
- # Go back to where we were
59
- cd "$ORIGINAL_PWD"
60
-
61
- # Ensure Python venv (always create under cli-utils/venv)
62
- "$SCRIPT_DIR"/python-venv.sh \
63
- "$SCRIPT_DIR"/venv \
64
- "$SCRIPT_DIR"/../tools/metrics/requirements.txt
70
+ ###############################################################################
71
+ # Python virtual environment setup
72
+ ###############################################################################
73
+ "$SCRIPT_DIR/python-venv.sh" \
74
+ "$SCRIPT_DIR/venv" \
75
+ "$SCRIPT_DIR/../tools/metrics/requirements.txt"
65
76
 
77
+ ###############################################################################
78
+ # Run documentation generator
79
+ ###############################################################################
66
80
  if [[ "$MODE" == "metrics" ]]; then
67
- "$SCRIPT_DIR"/venv/bin/python \
68
- "$SCRIPT_DIR"/../tools/metrics/metrics.py \
69
- "$TAG"
81
+ "$SCRIPT_DIR/venv/bin/python" \
82
+ "$SCRIPT_DIR/../tools/metrics/metrics.py" "$TAG"
70
83
  else
71
- "$SCRIPT_DIR"/venv/bin/python \
72
- "$SCRIPT_DIR"/../tools/gen-rpk-ascii.py \
73
- "$TAG"
84
+ "$SCRIPT_DIR/venv/bin/python" \
85
+ "$SCRIPT_DIR/../tools/gen-rpk-ascii.py" "$TAG"
74
86
  fi
75
87
 
76
88
  echo "✅ $MODE docs generated successfully!"
77
89
 
78
90
  # Tear down the cluster
79
91
  cd "$SCRIPT_DIR"/../docker-compose
80
- docker compose down --volumes
92
+ docker compose -p "$PROJECT_NAME" down --volumes
81
93
 
82
94
  # Return to the original directory
83
- cd "$ORIGINAL_PWD"
95
+ cd "$ORIGINAL_PWD" || exit 1
@@ -56,7 +56,7 @@ async function determineDocsBranch(operatorTag) {
56
56
  if (!filtered) {
57
57
  throw new Error(`Could not parse major.minor from ${TAG}`)
58
58
  }
59
-
59
+ // We started versioning the operator in line with Redpanda core versions. But when v2.4.x was the latest version, the docs were still on 25.1 and v25.1.x of the operator was still in beta. So we need to handle this special case.
60
60
  let branch
61
61
  if (filtered === 'v2.4') {
62
62
  if (ANTORA === '25.1') {
@@ -64,6 +64,7 @@ async function determineDocsBranch(operatorTag) {
64
64
  } else {
65
65
  branch = 'v/24.3'
66
66
  }
67
+ // For all other versions use the v<major>.<minor> branch unless it is the current version, in which case we use 'main'.
67
68
  } else if (filtered === `v${ANTORA}`) {
68
69
  branch = 'main'
69
70
  } else {
@@ -1,63 +1,103 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
+ IFS=$'\n\t'
3
4
 
4
- # Usage: start-cluster.sh <tag>
5
- TAG="${1:-latest}"
5
+ ###############################################################################
6
+ # Set START_CLUSTER_LOG=/path/to/logfile to capture output
7
+ ###############################################################################
8
+ if [[ -n "${START_CLUSTER_LOG:-}" ]]; then
9
+ exec > >(tee -a "$START_CLUSTER_LOG") 2>&1
10
+ fi
6
11
 
7
- # Where this script lives (cli-utils)
8
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+ ###############################################################################
13
+ # Prevent concurrent runs with a simple lockfile
14
+ ###############################################################################
15
+ LOCKFILE="/tmp/start-cluster.lock"
16
+ if [[ -e "$LOCKFILE" ]]; then
17
+ echo "❗ Another start-cluster.sh is already running. Remove $LOCKFILE if stale." >&2
18
+ exit 1
19
+ fi
20
+ trap 'rm -f "$LOCKFILE"' EXIT
21
+ touch "$LOCKFILE"
9
22
 
10
- # One level up is the package root, where we expect docker‑compose/
11
- PACKAGE_ROOT="$(cd "$SCRIPT_DIR"/.. && pwd)"
12
- QUICKSTART_DIR="$PACKAGE_ROOT/docker-compose"
23
+ ###############################################################################
24
+ # Input parameters and defaults
25
+ ###############################################################################
26
+ TAG="${1:-${CLUSTER_TAG:-latest}}"
27
+ PROJECT_NAME="${PROJECT_NAME:-redpanda_quickstart}"
13
28
 
14
- # Remember where the user called us from
29
+ ###############################################################################
30
+ # Directory discovery
31
+ ###############################################################################
32
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
33
+ PACKAGE_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
34
+ QUICKSTART_DIR="$PACKAGE_ROOT/docker-compose"
15
35
  CALLER_PWD="$(pwd)"
16
36
 
17
- # Default quickstart version
37
+ ###############################################################################
38
+ # Determine major.minor for quickstart override
39
+ ###############################################################################
18
40
  MAJOR_MINOR="latest"
19
41
  if [[ "$TAG" != "latest" ]]; then
20
42
  MAJOR_MINOR="$(echo "$TAG" | sed -E 's/^v?([0-9]+\.[0-9]+).*$/\1/')"
21
43
  fi
22
44
 
23
- # Conditionally override quickstart dir for >= 25.1
24
45
  if [[ "$MAJOR_MINOR" =~ ^([0-9]+)\.([0-9]+)$ ]]; then
25
46
  major="${BASH_REMATCH[1]}"
26
47
  minor="${BASH_REMATCH[2]}"
27
-
28
48
  if (( major > 25 )) || (( major == 25 && minor >= 1 )); then
29
49
  QUICKSTART_DIR="$PACKAGE_ROOT/docker-compose/25.1"
30
50
  fi
31
51
  fi
32
52
 
33
- # Fetch quickstart into package root if needed
53
+ ###############################################################################
54
+ # Fetch quickstart bundle if missing
55
+ ###############################################################################
34
56
  if [[ ! -d "$QUICKSTART_DIR" ]]; then
35
57
  echo "📥 Fetching Redpanda quickstart for ${MAJOR_MINOR}…"
58
+ url="https://docs.redpanda.com"
36
59
  if [[ "$TAG" == "latest" ]]; then
37
- curl -sSLf --retry 3 https://docs.redpanda.com/redpanda-quickstart.tar.gz \
38
- | tar -C "$PACKAGE_ROOT" -xzf -
60
+ url="$url/redpanda-quickstart.tar.gz"
39
61
  else
40
- curl -sSLf --retry 3 "https://docs.redpanda.com/${MAJOR_MINOR}-redpanda-quickstart.tar.gz" \
41
- | tar -C "$PACKAGE_ROOT" -xzf -
42
- fi
43
-
44
- if [[ ! -d "$QUICKSTART_DIR" ]]; then
45
- echo "❌ Expected '$QUICKSTART_DIR' but none was found after extraction."
46
- exit 1
62
+ url="$url/${MAJOR_MINOR}-redpanda-quickstart.tar.gz"
47
63
  fi
64
+ curl -sSLf --retry 3 "$url" | tar -C "$PACKAGE_ROOT" -xzf -
65
+ [[ -d "$QUICKSTART_DIR" ]] || { echo "❌ Expected '$QUICKSTART_DIR' but none was found."; exit 1; }
48
66
  fi
49
67
 
50
- # Switch into the quickstart dir and (re)start the cluster
51
- cd "$QUICKSTART_DIR"
68
+ ###############################################################################
69
+ # Move into compose directory and clean up existing cluster
70
+ ###############################################################################
71
+ cd "$QUICKSTART_DIR" || { echo "❌ Cannot cd to '$QUICKSTART_DIR'"; exit 1; }
52
72
 
53
- if docker compose ps | grep -q Up; then
54
- echo "🛑 Stopping existing cluster…"
55
- docker compose down --volumes
73
+ if docker compose -p "$PROJECT_NAME" ps -q | grep -q .; then
74
+ echo "🛑 Cleaning up existing cluster…"
75
+ docker compose -p "$PROJECT_NAME" down --volumes
76
+ else
77
+ echo "No running containers to remove for project \"$PROJECT_NAME\"."
56
78
  fi
57
79
 
58
- echo "▶️ Starting Redpanda cluster…"
59
- docker compose up -d
80
+ ###############################################################################
81
+ # Remove globally conflicting containers (dynamic list + legacy minio)
82
+ ###############################################################################
83
+ services=$(docker compose -p "$PROJECT_NAME" config --services 2>/dev/null || true)
84
+ services+=" minio" # ensure legacy /minio container is handled
85
+
86
+ for svc in $services; do
87
+ if docker ps -a --format '{{.Names}}' | grep -wq "$svc"; then
88
+ echo "🧹 Removing existing container: $svc"
89
+ docker rm -f "$svc"
90
+ fi
91
+ done
92
+
93
+ ###############################################################################
94
+ # Start cluster
95
+ ###############################################################################
96
+ echo "▶️ Starting Redpanda cluster (version: ${TAG})…"
97
+ docker compose -p "$PROJECT_NAME" up -d
60
98
 
61
- # Return to original directory
62
- cd "$CALLER_PWD"
99
+ ###############################################################################
100
+ # Return to caller and report success
101
+ ###############################################################################
102
+ cd "$CALLER_PWD" || exit 1
63
103
  echo "✅ Cluster is up (version: ${TAG})"
@@ -82,14 +82,14 @@ module.exports.register = function ({ config }) {
82
82
  }
83
83
 
84
84
  /**
85
- * Translates the parsed CSV data into our expected format.
86
- * If "enterprise" is found in the `support` column, it is replaced with "certified" in the output.
85
+ * Transforms and enriches parsed CSV connector data with normalized fields and documentation URLs.
87
86
  *
88
- * @param {object} parsedData - The CSV data parsed into an object.
89
- * @param {array} pages - The list of pages to map the URLs (used for enrichment with URLs).
90
- * @param {object} logger - The logger used for error handling.
87
+ * Each row is trimmed, mapped to expected output fields, and enriched with documentation URLs for Redpanda Connect and Cloud components if available. The `support` field is normalized, and licensing information is derived. Logs a warning if documentation URLs are missing for non-deprecated, non-SQL driver connectors that indicate cloud support.
91
88
  *
92
- * @returns {array} - The translated and enriched data.
89
+ * @param {object} parsedData - Parsed CSV data containing connector rows.
90
+ * @param {array} pages - Array of page objects used to resolve documentation URLs.
91
+ * @param {object} logger - Logger instance for warning about missing documentation.
92
+ * @returns {array} Array of enriched connector objects with normalized fields and URLs.
93
93
  */
94
94
  function translateCsvData(parsedData, pages, logger) {
95
95
  return parsedData.data.map(row => {
@@ -139,12 +139,17 @@ module.exports.register = function ({ config }) {
139
139
  }
140
140
  }
141
141
 
142
- // Log a warning if neither URL was found (only warn for missing cloud if it should support cloud)
143
- // Ignore sql_driver connectors because they are not real connectors and only used as a utility for grouping sql driver types.
144
- if (!connector.includes('sql_driver') && !redpandaConnectUrl && (!redpandaCloudUrl && is_cloud_supported === 'y')) {
142
+ // Log a warning if neither URL was found and the component is not deprecated
143
+ if (
144
+ deprecated !== 'y' &&
145
+ !connector.includes('sql_driver') &&
146
+ !redpandaConnectUrl &&
147
+ (!redpandaCloudUrl && is_cloud_supported === 'y')
148
+ ) {
145
149
  logger.warn(`Docs missing for: ${connector} of type: ${type}`);
146
150
  }
147
151
 
152
+
148
153
  // Return the translated and enriched row
149
154
  return {
150
155
  connector,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "4.5.0",
3
+ "version": "4.6.1",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",
@@ -20,7 +20,8 @@
20
20
  "get-redpanda-version": "doc-tools get-redpanda-version",
21
21
  "get-console-version": "doc-tools get-console-version",
22
22
  "build": "antora --to-dir docs --fetch local-antora-playbook.yml",
23
- "serve": "wds --node-resolve --open preview/test/ --watch --root-dir docs"
23
+ "serve": "wds --node-resolve --open preview/test/ --watch --root-dir docs",
24
+ "test": "jest"
24
25
  },
25
26
  "contributors": [
26
27
  {
@@ -56,8 +57,7 @@
56
57
  "./macros/glossary": "./macros/glossary.js",
57
58
  "./macros/rp-connect-components": "./macros/rp-connect-components.js",
58
59
  "./macros/config-ref": "./macros/config-ref.js",
59
- "./macros/helm-ref": "./macros/helm-ref.js",
60
- "./macros/data-template": "./macros/data-template.js"
60
+ "./macros/helm-ref": "./macros/helm-ref.js"
61
61
  },
62
62
  "files": [
63
63
  "extensions",
@@ -101,6 +101,7 @@
101
101
  "devDependencies": {
102
102
  "@antora/cli": "3.1.4",
103
103
  "@antora/site-generator": "3.1.4",
104
- "@web/dev-server": "^0.2.5"
104
+ "@web/dev-server": "^0.2.5",
105
+ "jest": "^29.7.0"
105
106
  }
106
107
  }