deploy-docs

  1#!/bin/bash
  2
  3# Set the environment variables
  4TARGET_DIR="../zed-docs"
  5PUSH_CHANGES=false
  6CLEAN_FOLDERS=false
  7
  8# Parse command line arguments
  9while getopts "pc" opt; do
 10  case ${opt} in
 11    p )
 12      PUSH_CHANGES=true
 13      ;;
 14    c )
 15      CLEAN_FOLDERS=true
 16      ;;
 17    \? )
 18      echo "Invalid option: $OPTARG" 1>&2
 19      exit 1
 20      ;;
 21  esac
 22done
 23
 24if "$CLEAN_FOLDERS"; then
 25  echo "Cleaning ./doc and ./debug folders..."
 26  rm -rf "$TARGET_DIR/doc"
 27  rm -rf "$TARGET_DIR/debug"
 28fi
 29
 30# Check if the target documentation directory exists
 31if [ ! -d "$TARGET_DIR" ]; then
 32    # Prompt the user for input
 33    read -p "The zed-docs directory does not exist. Make sure you are running this from the zed repo root." -n 1 -r
 34    read -p "Do you want to clone the repository (y/n)? " -n 1 -r
 35    echo  # Move to a new line
 36
 37    if [[ $REPLY =~ ^[Yy]$ ]]; then
 38        # Clone the repo if the user agrees
 39        git clone https://github.com/zed-industries/zed-docs.git "$TARGET_DIR"
 40    else
 41        # Exit if the user does not agree to clone the repo
 42        echo "Exiting without cloning the repository."
 43        exit 1
 44    fi
 45else
 46    # If the directory exists, pull the latest changes
 47    pushd "$TARGET_DIR" > /dev/null
 48    git pull
 49    popd > /dev/null
 50fi
 51
 52# Build the documentation
 53CARGO_TARGET_DIR="$TARGET_DIR" cargo doc --workspace --no-deps --open \
 54--exclude activity_indicator \
 55--exclude ai \
 56--exclude ai2 \
 57--exclude assistant \
 58--exclude audio \
 59--exclude audio2 \
 60--exclude auto_update \
 61--exclude auto_update2 \
 62--exclude breadcrumbs \
 63--exclude call \
 64--exclude call2 \
 65--exclude channel \
 66--exclude channel2 \
 67--exclude cli \
 68--exclude client \
 69--exclude client2 \
 70--exclude clock \
 71--exclude collab \
 72--exclude collab2 \
 73--exclude collab_ui \
 74--exclude collab_ui2 \
 75--exclude collections \
 76--exclude command_palette \
 77--exclude command_palette2 \
 78--exclude component_test \
 79--exclude context_menu \
 80--exclude copilot \
 81--exclude copilot2 \
 82--exclude copilot_button \
 83--exclude db \
 84--exclude db2 \
 85--exclude diagnostics \
 86--exclude diagnostics2 \
 87--exclude drag_and_drop \
 88--exclude editor \
 89--exclude feature_flags \
 90--exclude feature_flags2 \
 91--exclude feedback \
 92--exclude file_finder \
 93--exclude file_finder2 \
 94--exclude fs \
 95--exclude fs2 \
 96--exclude fsevent \
 97--exclude fuzzy \
 98--exclude fuzzy2 \
 99--exclude git \
100--exclude git3 \
101--exclude go_to_line \
102--exclude go_to_line2 \
103--exclude gpui \
104--exclude gpui_macros \
105--exclude install_cli \
106--exclude install_cli2 \
107--exclude journal \
108--exclude journal2 \
109--exclude language \
110--exclude language2 \
111--exclude language_selector \
112--exclude language_tools \
113--exclude live_kit_client \
114--exclude live_kit_client2 \
115--exclude live_kit_server \
116--exclude lsp \
117--exclude lsp2 \
118--exclude media \
119--exclude menu \
120--exclude menu2 \
121--exclude multi_buffer \
122--exclude multi_buffer2 \
123--exclude node_runtime \
124--exclude notifications \
125--exclude notifications2 \
126--exclude outline \
127--exclude picker \
128--exclude picker2 \
129--exclude plugin \
130--exclude plugin_macros \
131--exclude plugin_runtime \
132--exclude prettier \
133--exclude prettier2 \
134--exclude project \
135--exclude project2 \
136--exclude project_panel \
137--exclude project_panel2 \
138--exclude project_symbols \
139--exclude quick_action_bar \
140--exclude recent_projects \
141--exclude refineable \
142--exclude rich_text \
143--exclude rich_text2 \
144--exclude rope \
145--exclude rope2 \
146--exclude rpc \
147--exclude rpc2 \
148--exclude search \
149--exclude semantic_index \
150--exclude settings \
151--exclude settings2 \
152--exclude snippet \
153--exclude sqlez \
154--exclude sqlez_macros \
155--exclude storybook2 \
156--exclude storybook3 \
157--exclude sum_tree \
158--exclude terminal \
159--exclude terminal2 \
160--exclude terminal_view \
161--exclude terminal_view2 \
162--exclude text \
163--exclude text2 \
164--exclude theme \
165--exclude theme_importer \
166--exclude theme_selector \
167--exclude util \
168--exclude vcs_menu \
169--exclude vim \
170--exclude welcome \
171--exclude workspace2 \
172--exclude xtask \
173--exclude zed \
174--exclude zed-actions \
175--exclude zed_actions2
176
177if "$PUSH_CHANGES"; then
178    # Commit the changes and push
179    pushd "$TARGET_DIR" > /dev/null
180    # Check if there are any changes to commit
181    if git diff --quiet && git diff --staged --quiet; then
182        echo "No changes to the documentation."
183    else
184        # Staging the changes
185        git add .
186
187        # Creating a commit with the current datetime
188        DATETIME=$(date +"%Y-%m-%d %H:%M:%S")
189        git commit -m "Update docs – $DATETIME"
190
191        # Pushing the changes
192        git push
193    fi
194    popd > /dev/null
195fi