From 56dad83d4f7fbc4ef94378776b219b12b39dd921 Mon Sep 17 00:00:00 2001 From: samricotta <37125168+samricotta@users.noreply.github.com> Date: Mon, 25 Sep 2023 21:10:12 +0300 Subject: [PATCH] refactor: alternative script copying over the whole of the docs directory (#50) --- sync_script.sh | 73 +++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 58 deletions(-) diff --git a/sync_script.sh b/sync_script.sh index 9f9f9cb52..1923d88c1 100755 --- a/sync_script.sh +++ b/sync_script.sh @@ -36,7 +36,7 @@ for version in "${VERSIONS[@]}"; do fi # Change to the 'cosmos-sdk' directory - cd cosmos-sdk + cd $WORK_DIR/cosmos-sdk # Fetch the branch from the remote repository and switch to it git fetch origin "$branch" @@ -50,63 +50,20 @@ for version in "${VERSIONS[@]}"; do echo "Branch $branch exists, continuing..." fi - # Find all Markdown files in the 'docs' directory - if [ "$version" == "main" ]; then # update for 0.51 - # main has a different strucutre then versions - remote_md_files=$(find "docs" -name "*.md") - else - cd docs - remote_md_files=$(find "docs" -name "*.md") - fi - - # Change back to the original working directory - cd "$WORK_DIR" - - if [ "$version" == "main" ]; then - local_md_files=$(find "docs" -name "*.md") # For 'main', the version directory is empty - else - # Find all Markdown files in the local versioned_docs directory - local_md_files=$(find "versioned_docs/$version_directory" -name "*.md") - fi + # Run the pre.sh script + cd docs && sh ./pre.sh - if [ "$local_md_files" ]; then - echo "There are Markdown files in the directory." - # Iterate over each local Markdown file - for local_file in $local_md_files; do - # Construct the relative path of the local file - if [ "$version" != "main" ]; then - local_relative_path="${local_file#versioned_docs/$version_directory/}" - else - local_relative_path="${local_file#docs/}" - fi - # Iterate over each remote Markdown file - for remote_file in $remote_md_files; do - # Construct the relative path of the remote file - remote_relative_path="${remote_file#docs/}" - - - # Compare the relative paths to find matching files - if [ "$local_relative_path" = "$remote_relative_path" ]; then - # Check for differences between the local and remote files - if diff "$local_file" "./cosmos-sdk/docs/$remote_file" &>/dev/null; then - echo "No differences found for $local_file and $remote_file" - else - # Replace the local file with the remote file if differences are found - echo "Differences found for $local_file and $remote_file. Replacing $local_file with remote file..." - if [ "$version" == "main" ]; then - cp "./cosmos-sdk/$remote_file" "$local_file" - else - cp "./cosmos-sdk/docs/$remote_file" "$local_file" - fi - fi - fi - done - done - else - # The file does not exist, so copy the remote file - cp "./cosmos-sdk/docs/$remote_file" "$local_file" - echo "File $local_file created and replaced with ./cosmos-sdk/docs/$remote_file" - fi + for folder in "build" "user" "learn"; do + if [ "$version" == "main" ]; then + cp -r "$WORK_DIR/cosmos-sdk/docs/$folder" "$WORK_DIR/docs/" + else + cp -r "$WORK_DIR/cosmos-sdk/docs/docs/$folder" "$WORK_DIR/versioned_docs/$version_directory/" + fi + done done -rm -rf ./cosmos-sdk +# Leave the 'cosmos-sdk' directory after processing +cd "$WORK_DIR" + +# Remove the 'cosmos-sdk' directory if needed + rm -rf ./cosmos-sdk