-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateCypherReference.sh
More file actions
executable file
·53 lines (39 loc) · 2.25 KB
/
generateCypherReference.sh
File metadata and controls
executable file
·53 lines (39 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
# Generates "CYPHER.md" containing a reference to all Cypher files in all directories and subdirectories.
# Note: This script is intended to be run from the repository root.
# This script was generated by Chat-GPT after some messages back and forth and then tuned manually.
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
set -o errexit -o pipefail
SCRIPT_NAME="generateCypherReference"
# Markdown file name (written to repository root)
markdown_file="./CYPHER.md"
echo "${SCRIPT_NAME}: Generating ${markdown_file}..."
{
echo "# Cypher Reference"
echo ""
echo "This document serves as a reference for all Cypher files in the repository and its subdirectories."
echo "It provides a table listing each Cypher file and its corresponding description found in the first comment line."
echo "This file was generated with the script [${SCRIPT_NAME}.sh](./scripts/documentation/${SCRIPT_NAME}.sh)."
echo ""
echo "Script | Directory | Description"
echo "-------|-----------|------------"
} > ${markdown_file}
# Loop through all Cypher files in the current directory and all subdirectories, excluding "temp" and ".github" directories
find . -type d -name "temp" -prune -o -type f -name "*.cypher" -print | sort | while read -r cypher_file; do
# Read the contents of the Cypher file
cypher_file_contents=$(cat "$cypher_file")
# Extract the beginning comment lines and remove "//" and newline characters
description=$(echo "$cypher_file_contents" | awk '/^\/\//{sub(/^\/\//, ""); printf "%s ", $0; next} !/^\/\//{exit}')
# Trim leading and trailing whitespace
description=$(echo "$description" | awk '{$1=$1;print}')
# Extract the script file name without the path
filename=$(basename "$cypher_file")
# Extract the script file path without the name
pathname=$(dirname "$cypher_file")
last_path_segment=$(basename "$pathname")
# Create a link to the script file in the table
link="[${filename}](${cypher_file})"
# Add the script file and its description to the Markdown table
echo "| ${link} | ${last_path_segment%%.} | ${description//|/\\|} |" >> ${markdown_file}
done
echo "${SCRIPT_NAME}: Successfully generated ${markdown_file}."