docs-prep.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/bash
  2. # Colors for output
  3. RED='\033[0;31m'
  4. GREEN='\033[0;32m'
  5. YELLOW='\033[0;33m'
  6. BLUE='\033[0;34m'
  7. NC='\033[0m' # No Color
  8. # Default branch suffix
  9. BRANCH_SUFFIX="release"
  10. # Check if a custom version parameter was provided
  11. if [ $# -eq 1 ]; then
  12. BRANCH_SUFFIX="$1"
  13. fi
  14. # Branch name to create
  15. NEW_BRANCH="gh-pages-${BRANCH_SUFFIX}"
  16. # Function to print colored messages
  17. print_success() {
  18. echo -e "${GREEN}✓ $1${NC}"
  19. }
  20. print_error() {
  21. echo -e "${RED}✗ $1${NC}"
  22. exit 1
  23. }
  24. print_info() {
  25. echo -e "${BLUE}ℹ $1${NC}"
  26. }
  27. print_warning() {
  28. echo -e "${YELLOW}⚠ $1${NC}"
  29. }
  30. # Function to execute command with error handling
  31. execute() {
  32. print_info "Running: $1"
  33. eval $1
  34. if [ $? -ne 0 ]; then
  35. print_error "Failed to execute: $1"
  36. else
  37. print_success "Successfully executed: $1"
  38. fi
  39. }
  40. # Check if /tmp/_site directory exists from a previous run
  41. if [ -d "/tmp/_site" ]; then
  42. print_warning "Found existing /tmp/_site directory. Removing it…"
  43. rm -rf /tmp/_site
  44. fi
  45. # Main process
  46. print_info "Starting documentation deployment process…"
  47. # Step 1: Build documentation
  48. print_info "Building documentation with npm run docs…"
  49. npm run docs
  50. if [ $? -ne 0 ]; then
  51. print_error "Documentation build failed!"
  52. fi
  53. print_success "Documentation built successfully"
  54. # Step 2: Move _site to /tmp/
  55. print_info "Moving _site to temporary location…"
  56. execute "mv _site /tmp/"
  57. # Step 3: Switch to gh-pages branch
  58. print_info "Checking out gh-pages branch…"
  59. git checkout gh-pages
  60. if [ $? -ne 0 ]; then
  61. print_error "Failed to checkout gh-pages branch. Make sure it exists."
  62. fi
  63. print_success "Switched to gh-pages branch"
  64. # Step 4: Create a new branch for the update
  65. print_info "Creating new branch ${NEW_BRANCH}…"
  66. execute "git checkout -b ${NEW_BRANCH}"
  67. # Step 5: Move root files
  68. print_info "Moving root files from temporary location…"
  69. ROOT_FILES=("404.html" "CNAME" "apple-touch-icon.png" "favicon.ico" "index.html" "robots.txt" "sitemap-0.xml" "sitemap-index.xml" "sw.js")
  70. for file in "${ROOT_FILES[@]}"; do
  71. if [ -f "/tmp/_site/$file" ]; then
  72. execute "mv /tmp/_site/$file ."
  73. else
  74. print_warning "File /tmp/_site/$file not found. Skipping."
  75. fi
  76. done
  77. # Step 6: Move directories with cleanup
  78. print_info "Moving directories from temporary location…"
  79. DIRS=("about" "components" "docsref" "examples" "getting-started" "migration")
  80. for dir in "${DIRS[@]}"; do
  81. if [ -d "/tmp/_site/$dir" ]; then
  82. if [ -d "$dir" ]; then
  83. execute "rm -rf $dir"
  84. fi
  85. execute "mv /tmp/_site/$dir ."
  86. else
  87. print_warning "Directory /tmp/_site/$dir not found. Skipping."
  88. fi
  89. done
  90. # Step 7: Handle special doc directories
  91. print_info "Handling special documentation directories…"
  92. SPECIAL_DOCS=("docs/getting-started" "docs/versions")
  93. for dir in "${SPECIAL_DOCS[@]}"; do
  94. if [ -d "/tmp/_site/$dir" ]; then
  95. if [ -d "$dir" ]; then
  96. execute "rm -rf $dir"
  97. fi
  98. # Make sure parent directory exists
  99. parent_dir=$(dirname "$dir")
  100. mkdir -p "$parent_dir"
  101. execute "mv /tmp/_site/$dir $parent_dir/"
  102. else
  103. print_warning "Directory /tmp/_site/$dir not found. Skipping."
  104. fi
  105. done
  106. # Step 8: Move docs index.html
  107. if [ -f "/tmp/_site/docs/index.html" ]; then
  108. execute "mv /tmp/_site/docs/index.html docs/index.html"
  109. else
  110. print_warning "File /tmp/_site/docs/index.html not found. Skipping."
  111. fi
  112. # Step 9: Handle docs/5.3
  113. if [ -d "/tmp/_site/docs/5.3" ]; then
  114. if [ -d "docs/5.3" ]; then
  115. execute "rm -rf docs/5.3"
  116. fi
  117. execute "mv /tmp/_site/docs/5.3 docs/"
  118. else
  119. print_warning "Directory /tmp/_site/docs/5.3 not found. Skipping."
  120. fi
  121. # Clean up remaining files in /tmp/_site if any
  122. if [ -d "/tmp/_site" ]; then
  123. remaining_files=$(find /tmp/_site -type f | wc -l)
  124. remaining_dirs=$(find /tmp/_site -type d | wc -l)
  125. if [ $remaining_files -gt 0 ] || [ $remaining_dirs -gt 1 ]; then
  126. print_warning "There are still some files or directories in /tmp/_site that weren't moved."
  127. print_warning "You may want to inspect /tmp/_site to see if anything important was missed."
  128. else
  129. print_info "Cleaning up temporary directory…"
  130. rm -rf /tmp/_site
  131. print_success "Temporary directory cleaned up"
  132. fi
  133. fi
  134. # Step 10: Remove empty site directory if it exists
  135. if [ -d "site" ]; then
  136. print_info "Removing empty site directory…"
  137. execute "rm -rf site"
  138. fi
  139. print_success "Docs prep complete!"
  140. print_info "Review changes before committing and pushing."
  141. print_info "Next steps:"
  142. print_info " 1. Run a local server to review changes"
  143. print_info " 2. Check browser and web inspector for any errors"
  144. print_info " 3. git add ."
  145. print_info " 4. git commit -m \"Update documentation\""
  146. print_info " 5. git push origin ${NEW_BRANCH}"