mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
155 lines
4.8 KiB
Bash
Executable File
155 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -o pipefail
|
|
|
|
# Colors and styles
|
|
readonly RESET='\033[0m'
|
|
readonly BOLD='\033[1m'
|
|
readonly DIM='\033[2m'
|
|
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'
|
|
|
|
# Essential emojis
|
|
readonly ROCKET="🚀"
|
|
readonly CHECK="✓"
|
|
readonly ERROR="❌"
|
|
|
|
# Repository mappings
|
|
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"
|
|
)
|
|
|
|
print_header() {
|
|
echo -e "\n${BOLD}${BLUE}${ROCKET} PHP-Flasher Split ${ROCKET}${RESET}\n"
|
|
echo -e "${BOLD}Date : ${RESET}${CYAN}$(date -u '+%Y-%m-%d %H:%M:%S') UTC${RESET}"
|
|
echo -e "${BOLD}User : ${RESET}${MAGENTA}$(whoami)${RESET}"
|
|
echo -e "${BOLD}Branch : ${RESET}${GREEN}$(git rev-parse --abbrev-ref HEAD)${RESET}"
|
|
echo -e "${BOLD}Directory : ${RESET}${BLUE}$(pwd)${RESET}\n"
|
|
}
|
|
|
|
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}"
|
|
local packagist_url="https://packagist.org/packages/php-flasher/${remote}"
|
|
|
|
echo -e "\nGitHub : ${UNDERLINE}${BLUE}${repo_url}${RESET}"
|
|
echo -e "Package : ${UNDERLINE}${BLUE}${packagist_url}${RESET}"
|
|
echo -e "Prefix : ${YELLOW}$prefix${RESET}"
|
|
echo -e "Branch : ${GREEN}$branch${RESET}\n"
|
|
|
|
# Split the repository
|
|
echo -e "${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 (SHA: ${YELLOW}${sha1:0:8}${RESET})"
|
|
echo -e "${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 $remote (branch: $branch)${RESET}"
|
|
return 0
|
|
}
|
|
|
|
update_repository() {
|
|
echo -e "\n${CYAN}Fetching latest changes...${RESET}"
|
|
if ! git fetch origin "$(git rev-parse --abbrev-ref HEAD)" > /dev/null 2>&1; then
|
|
echo -e "${ERROR} ${RED}Failed to fetch latest changes, continuing...${RESET}"
|
|
else
|
|
echo -e "${CHECK} ${GREEN}Repository updated successfully${RESET}"
|
|
fi
|
|
echo
|
|
}
|
|
|
|
draw_progress_bar() {
|
|
local percent=$1
|
|
local width=50
|
|
local filled=$(( (width * percent + 99) / 100 )) # Rounded up division
|
|
local empty=$(( width - filled ))
|
|
|
|
echo -n "["
|
|
printf "${GREEN}█%.0s${RESET}" $(seq 1 $filled)
|
|
printf "${DIM}─%.0s${RESET}" $(seq 1 $empty)
|
|
echo -n "] ${percent}%"
|
|
}
|
|
|
|
main() {
|
|
print_header
|
|
update_repository
|
|
|
|
local success_count=0
|
|
local failed_count=0
|
|
local total_count=${#REPOSITORIES[@]}
|
|
local start_time=$(date +%s)
|
|
|
|
for prefix in "${!REPOSITORIES[@]}"; do
|
|
local current_count=$((success_count + failed_count + 1))
|
|
local percent=$((current_count * 100 / total_count))
|
|
|
|
echo -e "\nProgress: ${BOLD}$current_count/$total_count${RESET}"
|
|
# draw_progress_bar $percent
|
|
|
|
if process_split "$prefix"; then
|
|
((success_count++))
|
|
else
|
|
((failed_count++))
|
|
fi
|
|
done
|
|
|
|
local end_time=$(date +%s)
|
|
local duration=$((end_time - start_time))
|
|
|
|
# Summary
|
|
echo -e "\n${BOLD}${CYAN}Split Summary${RESET}"
|
|
echo -e "Successful : ${GREEN}$success_count${RESET}"
|
|
[ $failed_count -gt 0 ] && echo -e "Failed : ${RED}$failed_count${RESET}"
|
|
echo -e "Duration : ${YELLOW}${duration}s${RESET}"
|
|
echo -e "Total repos : ${CYAN}$total_count${RESET}"
|
|
|
|
# Links
|
|
echo -e "\n${BOLD}${CYAN}Quick Links${RESET}"
|
|
echo -e "Packagist : ${UNDERLINE}${BLUE}https://packagist.org/packages/php-flasher/${RESET}"
|
|
echo -e "NPM : ${UNDERLINE}${BLUE}https://www.npmjs.com/org/flasher${RESET}"
|
|
echo -e "GitHub : ${UNDERLINE}${BLUE}https://github.com/php-flasher${RESET}\n"
|
|
|
|
[ $failed_count -gt 0 ] && exit 1 || exit 0
|
|
}
|
|
|
|
main
|