Skip to content

Commit

Permalink
Fix file paths in init and show warning if Makefile and gitignore exi…
Browse files Browse the repository at this point in the history
…st in dest (#256)

* fix file path for sphinx requirement

* check files in destination to avoid overwriting existing files

* show warning and ask user confirmation before copying files

* chnage to save existing makefile as backup

* Commit suggestion

Co-authored-by: Ruth Fuchss <[email protected]>

---------

Co-authored-by: Ruth Fuchss <[email protected]>
  • Loading branch information
tang-mm and ru-fu authored Aug 1, 2024
1 parent 25c5444 commit 04f6080
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "Updating working directory in workflow files..."
sed -i "s|working-directory:\s*'\.'|working-directory: '$install_directory'|g" "$temp_directory/sp-files/.github/workflows"/*
echo "Updating .readthedocs.yaml configuration..."
sed -i "s|configuration:\s*sp-docs/conf\.py|configuration: $install_directory/conf.py|g" "$temp_directory/sp-files/.readthedocs.yaml"
sed -i "s|requirements:\s*sp-docs/\.sphinx/requirements\.txt|requirements: $install_directory/.sphinx/requirements.txt|g" "$temp_directory/.readthedocs.yaml"
sed -i "s|requirements:\s*sp-docs/\.sphinx/requirements\.txt|requirements: $install_directory/.sphinx/requirements.txt|g" "$temp_directory/sp-files/.readthedocs.yaml"
echo "Updating conf.py configuration..."
if [ "$install_directory" == "." ]; then
sed -i "s|'github_folder':\s*'/sp-docs/'|'github_folder': '/'|g" "$temp_directory/sp-files/conf.py"
Expand All @@ -32,7 +32,39 @@ if [ ! -d "$install_directory" ]; then
mkdir -p "$install_directory"
fi

# Copy the contents of the starter pack repository to the installation directory
# Check if .gitignore exists in the destination directory
# If exists, append the contents of the source .gitignore to the destination .gitignore
if [ -f "$install_directory/.gitignore" ]; then
echo "ACTION REQUIRED: .gitignore already exists in the destination directory."
read -p "Do you want to append the list of ignored files for Sphinx docs to the existing .gitginore? Enter 'n' to skip. (y/n): " confirm
if [ "$confirm" = "y" ]; then
echo "Appending contents to the existing .gitignore..."
cat "$temp_directory/sp-files/.gitignore" >> "$install_directory/.gitignore"
else
echo "Operation skipped by the user. Add the .gitignore rules for the Sphinx docs to your .gitignore file manually."
rm "$temp_directory/sp-files/.gitignore"
fi

# Check if Makefile exists in the destination directory
if [ -f "$install_directory/Makefile" ]; then
echo "ACTION REQUIRED: Makefile already exists in the destination directory. Check the contents before running the targets!"
read -p "Do you want to add the Sphinx docs targets into the Makefile? The existing file will be saved a backup file. Enter 'n' to skip. (y/n): " confirm
if [ "$confirm" = "y" ]; then
# Create a copy of the existing Makefile as backup
existing_makefile="$install_directory/Makefile"
backup_makefile="$install_directory/Makefile.backup.$(date +%Y%m%d%H%M%S)"
echo "Creating a backup: $backup_makefile"
cp "$existing_makefile" "$backup_makefile"

echo "Appending Sphinx docs targets to the existing Makefile..."
echo "" >> "$existing_makefile" # Add a new line before appending the contents
cat "$temp_directory/sp-files/Makefile" >> "$existing_makefile"
else
echo "Operation skipped by the user. Add the Makefile targets for Sphinx docs manually."
rm "$temp_directory/sp-files/Makefile"
fi

# Copy the rest of the starter pack repository to the installation directory
echo "Copying contents to the installation directory..."
cp -R "$temp_directory"/sp-files/* "$temp_directory"/sp-files/.??* "$install_directory"

Expand Down

0 comments on commit 04f6080

Please sign in to comment.