diff --git a/bin/npm b/bin/npm index 6f0f8349..a2711799 100755 --- a/bin/npm +++ b/bin/npm @@ -33,36 +33,74 @@ readonly NPM_PACKAGES=( # Print functions print_header() { - echo -e "${BOLD}${BLUE}${ROCKET} PHP-Flasher NPM Release ${ROCKET}${RESET}" - echo -e "\n" - echo -e "${DIM}Generated on: $(date -u '+%Y-%m-%d %H:%M:%S') UTC${RESET}" - echo -e "${DIM}By: $(whoami)${RESET}" - echo -e "${DIM}Working Directory: $(pwd)${RESET}" + echo -e "\n${BOLD}${BLUE}╭──────────────────────────────────────────╮${RESET}" + echo -e "${BOLD}${BLUE}│ ${ROCKET} PHP-Flasher NPM Release ${ROCKET} │${RESET}" + echo -e "${BOLD}${BLUE}╰──────────────────────────────────────────╯${RESET}\n" + echo -e " ${DIM}Date : $(date -u '+%Y-%m-%d %H:%M:%S') UTC${RESET}" + echo -e " ${DIM}User : $(whoami)${RESET}" + echo -e " ${DIM}Directory: $(pwd)${RESET}" } print_section() { - echo -e "\n" - echo -e "${BOLD}${CYAN}$1 ${2:-}${RESET}" + echo -e "\n${BOLD}${CYAN}┌─ $1 ${2:-}${RESET}" } success_msg() { - echo -e "${GREEN}${CHECK} $*${RESET}" + echo -e " ${GREEN}${CHECK} $*${RESET}" } info_msg() { - echo -e "${BLUE}${LOADING} $*${RESET}" + echo -e " ${BLUE}${LOADING} $*${RESET}" } warning_msg() { - echo -e "${YELLOW}${WARN} $*${RESET}" + echo -e " ${YELLOW}${WARN} $*${RESET}" } error_msg() { - echo -e "${RED}${ERROR} $*${RESET}" + echo -e " ${RED}${ERROR} $*${RESET}" } skip_msg() { - echo -e "${YELLOW}${SKIP} $*${RESET}" + echo -e " ${YELLOW}${SKIP} $*${RESET}" +} + +print_summary() { + local version=$1 + local duration=$2 + local success_count=$3 + local skipped_count=$4 + local failed_count=$5 + local failed_packages=("${@:6}") + + print_section "Release Summary" + echo -e "\n ${DIM}Version : ${BOLD}v${version}${RESET}" + echo -e " ${DIM}Duration : ${BOLD}${duration}s${RESET}" + + if [ "$success_count" -gt 0 ]; then + echo -e "\n ${DIM}Published : ${GREEN}${success_count}${RESET} packages" + fi + + if [ "$skipped_count" -gt 0 ]; then + echo -e "\n ${DIM}Skipped : ${YELLOW}${skipped_count}${RESET} packages" + fi + + if [ "$failed_count" -gt 0 ]; then + echo -e "\n ${DIM}Failed : ${RED}${failed_count}${RESET} packages" + echo -e "\n ${DIM}Failed packages:${RESET}" + for package in "${failed_packages[@]}"; do + echo -e " ${RED}• ${package}${RESET}" + done + fi + + echo -e "" + if [ "$success_count" -eq 0 ] && [ "$skipped_count" -gt 0 ]; then + success_msg "All packages were already up to date! ${ROCKET}" + elif [ "$success_count" -gt 0 ]; then + success_msg "NPM release completed successfully! ${ROCKET}" + elif [ "$failed_count" -gt 0 ]; then + error_msg "NPM release completed with failures! ${ERROR}" + fi } # Check if version exists @@ -177,34 +215,10 @@ main() { local end_time=$(date +%s) local duration=$((end_time - start_time)) - print_section "Release Summary" - echo -e "Version: ${BOLD}v${VERSION}${RESET}" - echo -e "Duration: ${BOLD}${duration}s${RESET}" + print_summary "$VERSION" "$duration" "$success_count" "$skipped_count" "$failed_count" "${failed_packages[@]}" - if [ "$success_count" -gt 0 ]; then - echo -e "Published: ${GREEN}${success_count}${RESET} packages" - fi - - if [ "$skipped_count" -gt 0 ]; then - echo -e "Skipped: ${YELLOW}${skipped_count}${RESET} packages" - fi - - if [ "$failed_count" -gt 0 ]; then - echo -e "Failed: ${RED}${failed_count}${RESET} packages" - echo -e "\nFailed packages:" - for package in "${failed_packages[@]}"; do - echo -e "${RED} - ${package}${RESET}" - done - fi - - if [ "$success_count" -eq 0 ] && [ "$skipped_count" -gt 0 ]; then - success_msg "\nAll packages were already up to date! ${ROCKET}" - elif [ "$success_count" -gt 0 ]; then - success_msg "\nNPM release completed successfully! ${ROCKET}" - elif [ "$failed_count" -gt 0 ]; then - error_msg "\nNPM release completed with failures! ${ERROR}" - exit 1 - fi + # Exit with failure if any package failed + [ "$failed_count" -gt 0 ] && exit 1 || exit 0 } # Execute main function diff --git a/bin/status b/bin/status index c5463424..561ce185 100755 --- a/bin/status +++ b/bin/status @@ -56,23 +56,28 @@ readonly REPOSITORIES=( # Print functions print_header() { - echo -e "\n${BOLD}${BLUE}${ROCKET} PHP-Flasher Status Dashboard ${ROCKET}${RESET}" - echo -e "${DIM}Generated on: $(date '+%Y-%m-%d %H:%M:%S %Z')${RESET}" - echo -e "${DIM}By: $(git config user.name) <$(git config user.email)>${RESET}" - echo -e "${DIM}Working Directory: $(pwd)${RESET}\n" + echo -e "\n${BOLD}${BLUE}╭──────────────────────────────────────────╮${RESET}" + echo -e "${BOLD}${BLUE}│ ${ROCKET} PHP-Flasher Status ${ROCKET} │${RESET}" + echo -e "${BOLD}${BLUE}╰──────────────────────────────────────────╯${RESET}\n" + echo -e " ${DIM}Date : $(date -u '+%Y-%m-%d %H:%M:%S') UTC${RESET}" + echo -e " ${DIM}User : $(whoami)${RESET}" + echo -e " ${DIM}Directory: $(pwd)${RESET}" } print_section() { - echo -e "\n${BOLD}${CYAN}$1 ${2:-}${RESET}" - echo -e "${DIM}${CYAN}$(printf '%.s─' $(seq 1 50))${RESET}" -} - -success_msg() { - echo -e "${GREEN}${CHECK} $*${RESET}" + echo -e "\n${BOLD}${CYAN} $1 ${2:-}${RESET}" } warning_msg() { - echo -e "${YELLOW}${WARNING} $*${RESET}" + echo -e " ${YELLOW}${WARNING} $*${RESET}" +} + +success_msg() { + echo -e " ${GREEN}${CHECK} $*${RESET}" +} + +error_msg() { + echo -e " ${RED}${ERROR} $*${RESET}" } info_msg() { @@ -145,9 +150,17 @@ get_github_stars() { # Get Packagist version get_packagist_version() { local package=$1 - local response=$(curl_cmd "https://repo.packagist.org/p2/php-flasher/${package}.json") - local version=$(echo "$response" | grep -o '"latest":"[^"]*"' | cut -d'"' -f4) - echo "${version:-N/A}" + local response=$(curl -s -f "https://repo.packagist.org/p2/php-flasher/${package}.json") + if [ $? -eq 0 ] && [ ! -z "$response" ]; then + local version=$(echo "$response" | grep -o '"latest":"[^"]*"' | cut -d'"' -f4) + if [ ! -z "$version" ]; then + echo "$version" + else + echo "N/A" + fi + else + echo "N/A" + fi } # Get NPM version @@ -175,38 +188,39 @@ display_repo_info() { local repo=$1 local latest_tag=$(get_latest_tag "$repo") local stats=($(get_repo_stats "$repo" | tr '|' ' ')) - local composer_version=$(check_composer_version) local github_stars=$(get_github_stars "$repo") - local packagist_version=$(get_packagist_version "$repo") local npm_version="N/A" + local packagist_version="N/A" - # Check NPM version for main packages and those with JavaScript - if [[ "$repo" == "flasher" || "$repo" == *"-prime" || \ - "$repo" == "flasher-noty" || "$repo" == "flasher-notyf" || \ - "$repo" == "flasher-sweetalert" || "$repo" == "flasher-toastr" ]]; then + # Get NPM version for specific packages + if [[ "$repo" == "flasher" || \ + "$repo" == "flasher-noty" || \ + "$repo" == "flasher-notyf" || \ + "$repo" == "flasher-sweetalert" || \ + "$repo" == "flasher-toastr" ]]; then npm_version=$(get_npm_version "$repo") fi - echo -e "\n${BOLD}${PACKAGE} ${MAGENTA}${repo}${RESET}" - echo -e " ${BRANCH} Branch: ${stats[1]:-unknown}" - echo -e " ${TAG} Latest Tag: ${latest_tag:-none}" - echo -e " ${STAR} GitHub Stars: ${github_stars}" - echo -e " ${PACKAGIST} Packagist: v${packagist_version}" + # Get Packagist version + packagist_version=$(get_packagist_version "$repo") + + # Display repository information + echo -e "\n${BOLD}${MAGENTA} ${PACKAGE} ${repo}${RESET}" + echo -e " ${BRANCH} Branch : ${stats[1]:-unknown}" + echo -e " ${TAG} Latest Tag : ${latest_tag:-none}" + echo -e " ${STAR} Stars : ${github_stars}" + echo -e " ${PACKAGIST} Packagist : v${packagist_version}" if [ "$npm_version" != "N/A" ]; then - echo -e " ${NPM} NPM: v${npm_version}" + echo -e " ${NPM} NPM : v${npm_version}" fi - echo -e " ${GITHUB} Last Commit: ${stats[0]:-unknown} (${stats[2]:-unknown})" - echo -e " ${INFO} Last Message: ${stats[3]:-unknown}" - - if [ "$composer_version" != "N/A" ]; then - echo -e " ${INFO} Composer Version: $composer_version" - fi + echo -e " ${GITHUB} Last Commit : ${stats[0]:-unknown} (${stats[2]:-unknown})" + echo -e " ${INFO} Message : ${stats[3]:-unknown}" local commits_since_tag=$(get_commit_count_since_tag "$repo" "$latest_tag") if [ "$commits_since_tag" -gt 0 ]; then - warning_msg " $commits_since_tag commit(s) since last tag" + warning_msg "$commits_since_tag commit(s) since last tag" fi } @@ -215,30 +229,30 @@ check_git_status() { print_section "Git Status" "${GITHUB}" local current_branch=$(git rev-parse --abbrev-ref HEAD) - echo -e "${BOLD}Current Branch:${RESET} $current_branch" + echo -e " ${BRANCH} Current Branch : ${current_branch}" if [ "$current_branch" != "$MAIN_BRANCH" ]; then - warning_msg "Not on main branch ($MAIN_BRANCH)" + warning_msg " Not on main branch ($MAIN_BRANCH)" fi if [[ ! -z "$(git status --porcelain)" ]]; then - warning_msg "Working directory is not clean" - git status --short + warning_msg " Working directory is not clean" + git status --short | sed 's/^/ /' else - success_msg "Working directory is clean" + success_msg " Working directory is clean" fi local behind=$(git rev-list HEAD..origin/$current_branch --count 2>/dev/null || echo "0") local ahead=$(git rev-list origin/$current_branch..HEAD --count 2>/dev/null || echo "0") if [ "$behind" -gt 0 ]; then - warning_msg "Branch is behind by $behind commit(s)" + warning_msg " Branch is behind by $behind commit(s)" fi if [ "$ahead" -gt 0 ]; then - warning_msg "Branch is ahead by $ahead commit(s)" + warning_msg " Branch is ahead by $ahead commit(s)" fi if [ "$behind" -eq 0 ] && [ "$ahead" -eq 0 ]; then - success_msg "Branch is up to date with origin" + success_msg " Branch is up to date with origin" fi } @@ -247,13 +261,13 @@ check_dependencies() { print_section "Dependencies" "${PACKAGE}" if [ -f "composer.json" ]; then - echo -e "${BOLD}Composer Dependencies:${RESET}" - composer show | grep "php-flasher/" || echo "No PHP-Flasher dependencies found" + echo -e " ${BOLD}Composer Dependencies:${RESET}" + composer show | grep "php-flasher/" | sed 's/^/ /' || echo " No PHP-Flasher dependencies found" fi if [ -f "package.json" ]; then - echo -e "\n${BOLD}NPM Dependencies:${RESET}" - npm list | grep "@flasher/" || echo "No Flasher dependencies found" + echo -e "\n ${BOLD}NPM Dependencies:${RESET}" + npm list | grep "@flasher/" | sed 's/^/ /' || echo " No Flasher dependencies found" fi } @@ -263,10 +277,10 @@ display_modified_files() { local modified_files=$(git diff --name-only) if [ ! -z "$modified_files" ]; then - echo -e "${BOLD}Modified files:${RESET}" - echo "$modified_files" + echo -e " ${BOLD}Modified files:${RESET}" + echo "$modified_files" | sed 's/^/ /' else - success_msg "No modified files" + success_msg " No modified files" fi }