mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
171 lines
5.9 KiB
Bash
Executable File
171 lines
5.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Don't exit on error, we want to process all repositories
|
|
set -o pipefail
|
|
|
|
# Colors and styles
|
|
readonly RESET='\033[0m'
|
|
readonly BOLD='\033[1m'
|
|
readonly DIM='\033[2m'
|
|
readonly ITALIC='\033[3m'
|
|
readonly UNDERLINE='\033[4m'
|
|
readonly BLUE='\033[34m'
|
|
readonly GREEN='\033[32m'
|
|
readonly RED='\033[31m'
|
|
readonly YELLOW='\033[33m'
|
|
readonly CYAN='\033[36m'
|
|
readonly MAGENTA='\033[35m'
|
|
|
|
# Emojis
|
|
readonly ROCKET="🚀"
|
|
readonly SPLIT="✂️"
|
|
readonly SYNC="🔄"
|
|
readonly SUCCESS="✨"
|
|
readonly ERROR="❌"
|
|
readonly WARNING="⚠️"
|
|
readonly CHECK="✓"
|
|
readonly GITHUB="⭐"
|
|
readonly CLOCK="🕐"
|
|
readonly BRANCH="🌿"
|
|
readonly FOLDER="📂"
|
|
|
|
# Header
|
|
print_header() {
|
|
echo -e "\n${BOLD}${BLUE}╭──────────────────────────────────────────╮${RESET}"
|
|
echo -e "${BOLD}${BLUE}│ ${ROCKET} PHP-Flasher Split ${ROCKET} │${RESET}"
|
|
echo -e "${BOLD}${BLUE}╰──────────────────────────────────────────╯${RESET}\n"
|
|
echo -e "${DIM}${CLOCK} Date : ${RESET}${CYAN}$(date -u '+%Y-%m-%d %H:%M:%S') UTC${RESET}"
|
|
echo -e "${DIM}${GITHUB} User : ${RESET}${CYAN}$(whoami)${RESET}"
|
|
echo -e "${DIM}${BRANCH} Branch : ${RESET}${MAGENTA}$(git rev-parse --abbrev-ref HEAD)${RESET}"
|
|
echo -e "${DIM}${FOLDER} Directory: ${RESET}${CYAN}$(pwd)${RESET}\n"
|
|
}
|
|
|
|
# Repository mappings (same as before)
|
|
declare -A REPOSITORIES=(
|
|
# Core packages
|
|
["src/Prime"]="flasher"
|
|
["src/Laravel"]="flasher-laravel"
|
|
["src/Symfony"]="flasher-symfony"
|
|
|
|
# Toastr packages
|
|
["src/Toastr/Prime"]="flasher-toastr"
|
|
["src/Toastr/Laravel"]="flasher-toastr-laravel"
|
|
["src/Toastr/Symfony"]="flasher-toastr-symfony"
|
|
|
|
# Notyf packages
|
|
["src/Notyf/Prime"]="flasher-notyf"
|
|
["src/Notyf/Laravel"]="flasher-notyf-laravel"
|
|
["src/Notyf/Symfony"]="flasher-notyf-symfony"
|
|
|
|
# SweetAlert packages
|
|
["src/SweetAlert/Prime"]="flasher-sweetalert"
|
|
["src/SweetAlert/Laravel"]="flasher-sweetalert-laravel"
|
|
["src/SweetAlert/Symfony"]="flasher-sweetalert-symfony"
|
|
|
|
# Noty packages
|
|
["src/Noty/Prime"]="flasher-noty"
|
|
["src/Noty/Laravel"]="flasher-noty-laravel"
|
|
["src/Noty/Symfony"]="flasher-noty-symfony"
|
|
)
|
|
|
|
# Process split for a single repository
|
|
process_split() {
|
|
local prefix=$1
|
|
local remote=${REPOSITORIES[$prefix]}
|
|
local branch=$(git rev-parse --abbrev-ref HEAD)
|
|
local repo_url="https://github.com/php-flasher/${remote}"
|
|
|
|
echo -e "\n ${SPLIT} Processing ${BOLD}${CYAN}$remote${RESET}"
|
|
echo -e " ${GITHUB} Repository: ${UNDERLINE}${BLUE}${repo_url}${RESET}"
|
|
echo -e " ${SYNC} Prefix : ${YELLOW}$prefix${RESET}"
|
|
echo -e " ${BRANCH} Branch : ${MAGENTA}$branch${RESET}"
|
|
|
|
# Add remote if it doesn't exist
|
|
if ! git remote | grep -q "^$remote$"; then
|
|
if ! git remote add "$remote" "git@github.com:php-flasher/$remote.git" 2>/dev/null; then
|
|
echo -e " ${WARNING} ${YELLOW}Remote already exists${RESET}"
|
|
fi
|
|
fi
|
|
|
|
# Split the repository
|
|
echo -e "\n ${SYNC} ${CYAN}Splitting code...${RESET}"
|
|
local sha1=""
|
|
if ! sha1=$(./bin/splitsh-lite --prefix="$prefix" 2>/dev/null); then
|
|
echo -e " ${ERROR} ${RED}Split failed${RESET}"
|
|
return 1
|
|
fi
|
|
|
|
echo -e " ${CHECK} Split complete ${DIM}(SHA: ${YELLOW}${sha1:0:8}${DIM})${RESET}"
|
|
|
|
# Push the changes
|
|
echo -e " ${SYNC} ${CYAN}Pushing to remote...${RESET}"
|
|
if ! git push "$remote" "$sha1:refs/heads/$branch" -f > /dev/null 2>&1; then
|
|
echo -e " ${ERROR} ${RED}Failed to push to $remote${RESET}"
|
|
return 1
|
|
fi
|
|
|
|
echo -e " ${CHECK} ${GREEN}Pushed to ${BOLD}$remote${RESET}${GREEN} (branch: ${MAGENTA}$branch${GREEN})${RESET}"
|
|
return 0
|
|
}
|
|
|
|
# Update git repository
|
|
update_repository() {
|
|
echo -e " ${SYNC} ${CYAN}Updating repository${RESET}"
|
|
|
|
local branch=$(git rev-parse --abbrev-ref HEAD)
|
|
echo -e " ${SYNC} ${CYAN}Fetching latest changes...${RESET}"
|
|
|
|
if ! git fetch origin "$branch" > /dev/null 2>&1; then
|
|
echo -e " ${WARNING} ${YELLOW}Failed to fetch latest changes, continuing...${RESET}"
|
|
else
|
|
echo -e " ${CHECK} ${GREEN}Repository updated successfully${RESET}"
|
|
fi
|
|
echo
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
print_header
|
|
update_repository
|
|
|
|
local success_count=0
|
|
local failed_count=0
|
|
local total_count=${#REPOSITORIES[@]}
|
|
local start_time=$(date +%s)
|
|
local current=0
|
|
|
|
# Process all repositories
|
|
for prefix in "${!REPOSITORIES[@]}"; do
|
|
((current++))
|
|
echo -e " ${SYNC} ${CYAN}Progress: ${BOLD}$current${RESET}${CYAN}/${BOLD}$total_count${RESET}${CYAN} repositories${RESET}"
|
|
|
|
if process_split "$prefix"; then
|
|
((success_count++))
|
|
else
|
|
((failed_count++))
|
|
echo -e " ${WARNING} ${YELLOW}Failed to process ${REPOSITORIES[$prefix]}, continuing...${RESET}"
|
|
fi
|
|
done
|
|
|
|
local end_time=$(date +%s)
|
|
local duration=$((end_time - start_time))
|
|
|
|
# Print final summary
|
|
echo -e "\n ${SUCCESS} ${BOLD}${CYAN}Split Summary${RESET}"
|
|
echo -e " ${CHECK} Successful : ${GREEN}$success_count${RESET}"
|
|
[ $failed_count -gt 0 ] && echo -e " ${ERROR} Failed : ${RED}$failed_count${RESET}"
|
|
echo -e " ${SYNC} Duration : ${YELLOW}${duration}s${RESET}"
|
|
echo -e " ${SYNC} Total repos: ${CYAN}$total_count${RESET}"
|
|
|
|
# Add Packagist and NPM links
|
|
echo -e "\n ${GITHUB} ${BOLD}${CYAN}Quick Links${RESET}"
|
|
echo -e " ${GITHUB} Packagist : ${UNDERLINE}${BLUE}https://packagist.org/packages/php-flasher/${RESET}"
|
|
echo -e " ${GITHUB} NPM : ${UNDERLINE}${BLUE}https://www.npmjs.com/org/flasher${RESET}"
|
|
echo -e " ${GITHUB} GitHub : ${UNDERLINE}${BLUE}https://github.com/php-flasher${RESET}\n"
|
|
|
|
[ $failed_count -gt 0 ] && exit 1 || exit 0
|
|
}
|
|
|
|
# Execute main function
|
|
main
|