rebuild-docs.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env bash
  2. # Build API documentation using Node.js tooling only (Node 14.x compatible).
  3. set -euo pipefail
  4. # 1) Check that there is only one parameter
  5. # of Wekan version number:
  6. if [ $# -ne 1 ]
  7. then
  8. echo "Syntax with Wekan version number:"
  9. echo " ./rebuild-docs.sh 5.10"
  10. exit 1
  11. fi
  12. # 2) No Python dependencies; use npm/npx exclusively
  13. # 2) Go to Wekan repo directory
  14. cd ~/repos/wekan
  15. # 3) Create api docs directory, if it does not exist
  16. if [ ! -d public/api ]; then
  17. mkdir -p public/api
  18. fi
  19. # 4) Locate or generate an OpenAPI spec (YAML or JSON)
  20. SPEC_YML="./public/api/wekan.yml"
  21. SPEC_JSON="./public/openapi.json"
  22. SPEC_ALT_YML="./public/openapi.yml"
  23. if [ -s "$SPEC_YML" ]; then
  24. SPEC="$SPEC_YML"
  25. elif [ -s "$SPEC_JSON" ]; then
  26. SPEC="$SPEC_JSON"
  27. elif [ -s "$SPEC_ALT_YML" ]; then
  28. SPEC="$SPEC_ALT_YML"
  29. else
  30. echo "No existing OpenAPI spec found. Generating from models with Node..."
  31. mkdir -p ./public/api
  32. node ./openapi/generate_openapi.js --release v$1 ./models > "$SPEC_YML"
  33. SPEC="$SPEC_YML"
  34. fi
  35. chmod 644 "$SPEC" 2>/dev/null || true
  36. # Build static HTML docs (no global installs)
  37. # 1) Prefer Redocly CLI
  38. if npx --yes @redocly/cli@latest build-docs "$SPEC" -o ./public/api/wekan.html; then
  39. :
  40. else
  41. # 2) Fallback to redoc-cli
  42. if npx --yes redoc-cli@latest bundle "$SPEC" -o ./public/api/wekan.html; then
  43. :
  44. else
  45. # 3) Fallback to api2html
  46. if npx --yes api2html@0.3.0 -c ./public/logo-header.png -o ./public/api/wekan.html "$SPEC"; then
  47. :
  48. else
  49. echo "All HTML generators failed. You can preview locally with:" >&2
  50. echo " npx --yes @redocly/cli@latest preview-docs $SPEC" >&2
  51. exit 1
  52. fi
  53. fi
  54. fi
  55. # Copy docs to bundle
  56. #cp -pR ./public/api ~/repos/wekan/.build/bundle/programs/web.browser/app/