45b5f2fd50
ai generated docs and related tools for publishing new versions * ai generated docs and tooling * tools * add mermaid links * add task docs:ai:generate * Merged main into feature/ai-generated-docs Approved-by: Michael McGuinness
111 lines
3.6 KiB
Bash
Executable File
111 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Script to regenerate system documentation using Claude
|
|
# Usage: ./regenerate_docs.sh <path_to_prompt_file>
|
|
# This script pipes the documentation generation prompt to Claude CLI
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Check if prompt file path is provided
|
|
if [ $# -eq 0 ]; then
|
|
echo -e "${RED}Error: Please provide the path to the prompt file${NC}"
|
|
echo "Usage: $0 <path_to_prompt_file>"
|
|
echo "Example: $0 ./prompt.for.system.documentation.generation.md"
|
|
exit 1
|
|
fi
|
|
|
|
PROMPT_FILE="$1"
|
|
|
|
# Check if prompt file exists
|
|
if [ ! -f "$PROMPT_FILE" ]; then
|
|
echo -e "${RED}Error: Prompt file not found at $PROMPT_FILE${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Convert to absolute path for clarity
|
|
PROMPT_FILE="$(realpath "$PROMPT_FILE")"
|
|
|
|
# Warning prompt
|
|
echo -e "${RED}WARNING: Regeneration of the entire system docs is a time consuming and expensive operation.${NC}"
|
|
echo -e "${YELLOW}Enter 'YES' to continue. Or press Enter to abort:${NC}"
|
|
read -r confirmation
|
|
|
|
if [ "$confirmation" != "YES" ]; then
|
|
echo -e "${YELLOW}Operation aborted.${NC}"
|
|
exit 0
|
|
fi
|
|
|
|
# Get the directory where this script is located
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../" && pwd)"
|
|
TEMP_DOCS_DIR="$PROJECT_ROOT/docs_temp"
|
|
TARGET_DOCS_DIR="$PROJECT_ROOT/docs/ai.generated"
|
|
|
|
echo -e "${YELLOW}Starting documentation regeneration...${NC}"
|
|
echo -e "${GREEN}Using prompt file: $PROMPT_FILE${NC}"
|
|
|
|
# Check if claude CLI is available
|
|
if ! command -v claude &> /dev/null; then
|
|
echo -e "${RED}Error: Claude CLI not found. Please install it first.${NC}"
|
|
echo "See: https://claude.ai/code"
|
|
exit 1
|
|
fi
|
|
|
|
# Change to project root directory
|
|
cd "$PROJECT_ROOT"
|
|
echo -e "${GREEN}Working from project root: $PROJECT_ROOT${NC}"
|
|
|
|
# Remove existing temp docs directory if it exists
|
|
if [ -d "$TEMP_DOCS_DIR" ]; then
|
|
echo -e "${YELLOW}Removing existing temporary docs directory...${NC}"
|
|
rm -rf "$TEMP_DOCS_DIR"
|
|
fi
|
|
|
|
# Create temporary docs directory
|
|
mkdir -p "$TEMP_DOCS_DIR"
|
|
|
|
echo -e "${YELLOW}Piping prompt to Claude CLI...${NC}"
|
|
echo -e "${YELLOW}This may take several minutes depending on codebase size...${NC}"
|
|
|
|
# Pipe the prompt to Claude CLI
|
|
cat "$PROMPT_FILE" | claude
|
|
|
|
# Check if documentation was generated
|
|
if [ ! -d "$TEMP_DOCS_DIR" ] || [ -z "$(ls -A "$TEMP_DOCS_DIR" 2>/dev/null)" ]; then
|
|
echo -e "${RED}Error: No documentation was generated in $TEMP_DOCS_DIR${NC}"
|
|
echo -e "${YELLOW}Please check Claude's output above for any errors.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}Documentation generated successfully in $TEMP_DOCS_DIR${NC}"
|
|
|
|
# Ask user if they want to move the docs to the target location
|
|
echo -e "${YELLOW}Would you like to replace the existing docs with the newly generated ones? (y/N)${NC}"
|
|
read -r response
|
|
|
|
if [[ "$response" =~ ^[Yy]$ ]]; then
|
|
# Backup existing docs if they exist
|
|
if [ -d "$TARGET_DOCS_DIR" ]; then
|
|
BACKUP_DIR="${TARGET_DOCS_DIR}.backup.$(date +%Y%m%d_%H%M%S)"
|
|
echo -e "${YELLOW}Backing up existing docs to $BACKUP_DIR${NC}"
|
|
mv "$TARGET_DOCS_DIR" "$BACKUP_DIR"
|
|
fi
|
|
|
|
# Move new docs to target location
|
|
echo -e "${YELLOW}Moving new docs to $TARGET_DOCS_DIR${NC}"
|
|
mv "$TEMP_DOCS_DIR" "$TARGET_DOCS_DIR"
|
|
|
|
echo -e "${GREEN}Documentation update complete!${NC}"
|
|
echo -e "${GREEN}New docs are now available in: $TARGET_DOCS_DIR${NC}"
|
|
else
|
|
echo -e "${YELLOW}New documentation remains in: $TEMP_DOCS_DIR${NC}"
|
|
echo -e "${YELLOW}You can manually review and move them when ready.${NC}"
|
|
fi
|
|
|
|
echo -e "${GREEN}Documentation regeneration process completed.${NC}" |