Skip to content

Instantly share code, notes, and snippets.

@masiur
Last active January 15, 2024 20:51
Show Gist options
  • Save masiur/86e9916deae1d493133f0ffabec8d078 to your computer and use it in GitHub Desktop.
Save masiur/86e9916deae1d493133f0ffabec8d078 to your computer and use it in GitHub Desktop.
wordpress plugin build bash
#!/bin/bash
# Function to handle copying and compressing
copy_and_compress() {
local source_dir="$1"
local destination_dir="$2"
local copy_list=("${@:3}")
# Delete existing files in the destination directory
rm -rf "$destination_dir"
# Ensure the destination directory exists
mkdir -p "$destination_dir"
# Copy selected folders and files
for item in "${copy_list[@]}"; do
source_path="$source_dir/$item"
destination_path="$destination_dir/$item"
if [ -e "$source_path" ]; then
cp -r "$source_path" "$destination_path"
echo "Copied: $item"
else
echo "Warning: $item does not exist in the source directory."
fi
done
echo -e "\nCopy completed."
# Run the zip command and suppress output
zip -rq "builds/$(basename "$destination_dir").zip" "$destination_dir" -x "*.DS_Store"
# Check for errors
if [ $? -ne 0 ]; then
echo "Error occurred while compressing."
exit 1
fi
# Print completion message
echo -e "\nCompressing Completed. builds/$(basename "$destination_dir").zip is ready. Check the builds directory. Thanks!\n"
}
# Get args from command line
nodeBuild=true
withPro=false
for arg in "$@"; do
case "$arg" in
"--node-build")
nodeBuild=true
;;
"--with-pro")
withPro=true
;;
esac
done
if "$nodeBuild"; then
echo -e "\nBuilding Main App\n"
npx mix --production
echo -e "\nBuild Completed"
fi
# Copy and compress Fluent CRM
copy_and_compress "." "builds/fluent-crm" "app" "assets" "boot" "config" "database" "includes" "language" "vendor" "composer.json" "fluent-crm.php" "index.php" "readme.txt"
if ! "$withPro"; then
exit 0
fi
echo -e "\nReadying Pro Addon\n"
# Copy and compress Fluent Campaign Pro
copy_and_compress "../fluentcampaign-pro" "builds/fluentcampaign-pro" "app" "languages" "fluentcampaign-pro.php" "index.php" "readme.txt" "fluentcampaign_boot.php"
@masiur
Copy link
Author

masiur commented Jan 15, 2024

Modified Version

#!/bin/bash

# Function to handle copying and compressing
copy_and_compress() {
  local source_dir="$1"
  local destination_dir="$2"
  local copy_list=("${@:3}")

  # Delete existing files in the destination directory
  rm -rf "$destination_dir"

  # Ensure the destination directory exists
  mkdir -p "$destination_dir"

  # Copy selected folders and files
  for item in "${copy_list[@]}"; do
    source_path="$source_dir/$item"
    destination_path="$destination_dir/$item"

    if [ -e "$source_path" ]; then
      cp -r "$source_path" "$destination_path"
      echo "Copied: $item"
    else
      echo "Warning: $item does not exist in the source directory."
    fi
  done

  echo -e "\nCopy completed."

  # Run the zip command and suppress output
  zip -rq "builds/$(basename "$destination_dir").zip" "$destination_dir" -x "*.DS_Store"

  # Check for errors
  if [ $? -ne 0 ]; then
    echo "Error occurred while compressing."
    exit 1
  fi

  # Print completion message
  echo -e "\nCompressing Completed. builds/$(basename "$destination_dir").zip is ready. Check the builds directory. Thanks!\n"
}

# Get args from command line
nodeBuild=true
withPro=false

for arg in "$@"; do
  case "$arg" in
    "--node-build")
      nodeBuild=true
      ;;
    "--with-pro")
      withPro=true
      ;;
  esac
done

if "$nodeBuild"; then
  echo -e "\nBuilding Main App\n"
  npx mix --production
  echo -e "\nBuild Completed"
fi

# Copy and compress Fluent CRM
copy_and_compress "." "builds/fluent-crm" "app" "assets" "boot" "config" "database" "includes" "language" "vendor" "composer.json" "fluent-crm.php" "index.php" "readme.txt"

if ! "$withPro"; then
  exit 0
fi

echo -e "\nReadying Pro Addon\n"

# Copy and compress Fluent Campaign Pro
copy_and_compress "../fluentcampaign-pro" "builds/fluentcampaign-pro" "app" "languages" "fluentcampaign-pro.php" "index.php" "readme.txt" "fluentcampaign_boot.php"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment