diff --git a/bin/copy b/bin/copy index cf2b4921..9e9961b9 100755 --- a/bin/copy +++ b/bin/copy @@ -1,70 +1,35 @@ -#!/usr/bin/env php -files() - ->in($dirs) - ->name('composer.json') - ->depth('< 3'); // Adjust depth as needed - -$packages = []; - -// Collect package directories -foreach ($finder as $file) { - $packages[] = dirname($file->getRealPath()); +# Function to print file details (now inline within find command) +print_file_details() { + echo "File Path: $1" + echo "Contents:" + cat "$1" + echo } -foreach ($packages as $packageDir) { - foreach ($resources as $resource) { - if (!is_string($resource)) { - continue; - } +# Finding and processing files +if [ ${#extensions[@]} -eq 0 ]; then + # If no extensions are specified, process all files + find "$dir" -type f -exec bash -c 'echo "File Path: $1"; echo "Contents:"; cat "$1"; echo' bash {} \; >> "$temp_file" +else + # Process only files with specified extensions + for ext in "${extensions[@]}"; do + find "$dir" -type f -name "*.$ext" -exec bash -c 'echo "File Path: $1"; echo "Contents:"; cat "$1"; echo' bash {} \; >> "$temp_file" + done +fi - $resourcePath = realpath($resource); +# Copy results to clipboard and remove the temporary file +cat "$temp_file" | pbcopy +rm "$temp_file" - if (!$resourcePath) { - continue; // Skip if the resource doesn't exist - } - - $relativePath = str_replace(realpath(__DIR__.'/../') ?: '', '', $resourcePath); - $destination = $packageDir.$relativePath; - - if (is_file($resourcePath)) { - // Ensure the destination directory exists - $filesystem->mkdir(dirname($destination)); - // Copy the file - $filesystem->copy($resourcePath, $destination, true); - } elseif (is_dir($resourcePath)) { - if ($resourcePath === $shared) { - // Copy contents of the shared directory into the package directory - $filesystem->mirror($shared, $packageDir, null, ['override' => true]); - } else { - // Copy the entire directory to the destination - $filesystem->mirror($resourcePath, $destination, null, ['override' => true]); - } - } - } -} +echo "Results copied to clipboard." diff --git a/bin/cp b/bin/cp deleted file mode 100755 index 9e9961b9..00000000 --- a/bin/cp +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# Default to the current directory if no directory is provided -dir=${1:-.} - -# Optional: A list of file extensions to filter by, e.g., "txt md". Leave empty to include all files. -extensions=($2) - -# Temporary file to store results -temp_file=$(mktemp) - -# Function to print file details (now inline within find command) -print_file_details() { - echo "File Path: $1" - echo "Contents:" - cat "$1" - echo -} - -# Finding and processing files -if [ ${#extensions[@]} -eq 0 ]; then - # If no extensions are specified, process all files - find "$dir" -type f -exec bash -c 'echo "File Path: $1"; echo "Contents:"; cat "$1"; echo' bash {} \; >> "$temp_file" -else - # Process only files with specified extensions - for ext in "${extensions[@]}"; do - find "$dir" -type f -name "*.$ext" -exec bash -c 'echo "File Path: $1"; echo "Contents:"; cat "$1"; echo' bash {} \; >> "$temp_file" - done -fi - -# Copy results to clipboard and remove the temporary file -cat "$temp_file" | pbcopy -rm "$temp_file" - -echo "Results copied to clipboard." diff --git a/bin/docs b/bin/docs new file mode 100755 index 00000000..e17d1039 --- /dev/null +++ b/bin/docs @@ -0,0 +1,101 @@ +#!/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="โŒ" +readonly WARNING="โš ๏ธ" +readonly BOOKS="๐Ÿ“š" +readonly HAMMER="๐Ÿ—๏ธ" +readonly SPARKLES="โœจ" + +print_header() { + echo -e "\n${BOLD}${BLUE}${ROCKET} PHP-Flasher Documentation Builder ${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}yoeunes${RESET}" + echo -e "${BOLD}Branch : ${RESET}${GREEN}$(git rev-parse --abbrev-ref HEAD)${RESET}" + echo -e "${BOLD}Directory : ${RESET}${BLUE}$(pwd)${RESET}\n" +} + +install_dependencies() { + echo -e "${BOLD}${BOOKS} Installing dependencies${RESET}" + + if npm install --force; then + echo -e "${CHECK} ${GREEN}Dependencies installed successfully${RESET}\n" + return 0 + else + echo -e "${WARNING} ${YELLOW}Dependency installation had issues${RESET}\n" + return 1 + fi +} + +build_documentation() { + echo -e "${BOLD}${HAMMER} Building documentation${RESET}" + + if npm run build; then + echo -e "${CHECK} ${GREEN}Documentation built successfully${RESET}\n" + return 0 + else + echo -e "${ERROR} ${RED}Documentation build failed${RESET}\n" + return 1 + fi +} + +main() { + local command=${1:-"build"} + local start_time=$(date +%s) + local success=true + + # Change directory to docs/ + if [[ ! -d "docs/" ]]; then + echo -e "${ERROR} ${RED}Documentation directory 'docs/' not found${RESET}\n" + exit 1 + fi + + cd docs/ + + print_header + echo -e "${BOLD}Command : ${RESET}${CYAN}${command}${RESET}\n" + + case $command in + "build") + install_dependencies || success=false + build_documentation || success=false + ;; + *) + echo -e "${ERROR} ${RED}Unknown command: ${command}${RESET}" + echo -e "Available commands: build" + exit 1 + ;; + esac + + local end_time=$(date +%s) + local duration=$((end_time - start_time)) + + # Summary + echo -e "${BOLD}${CYAN}Documentation ${command^} Summary${RESET}" + if [ "$success" = true ]; then + echo -e "${SPARKLES} ${GREEN}Documentation ${command} completed successfully${RESET}" + else + echo -e "${WARNING} ${YELLOW}Documentation ${command} completed with issues${RESET}" + fi + echo -e "Duration : ${YELLOW}${duration}s${RESET}\n" + + [ "$success" = true ] && exit 0 || exit 1 +} + +main "$@" diff --git a/bin/lint b/bin/lint new file mode 100755 index 00000000..7ea1dce6 --- /dev/null +++ b/bin/lint @@ -0,0 +1,158 @@ +#!/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="โŒ" +readonly WARNING="โš ๏ธ" +readonly SEARCH="๐Ÿ”" +readonly PALETTE="๐ŸŽจ" +readonly MICROSCOPE="๐Ÿ”ฌ" +readonly MEMO="๐Ÿ“" +readonly MAGNIFIER="๐Ÿ”Ž" +readonly TEST_TUBE="๐Ÿงช" +readonly SPARKLES="โœจ" + +print_header() { + echo -e "\n${BOLD}${BLUE}${ROCKET} PHP-Flasher Code Quality Check ${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}yoeunes${RESET}" + echo -e "${BOLD}Branch : ${RESET}${GREEN}$(git rev-parse --abbrev-ref HEAD)${RESET}" + echo -e "${BOLD}Directory : ${RESET}${BLUE}$(pwd)${RESET}\n" +} + +run_rector() { + echo -e "${BOLD}${SEARCH} Running Rector${RESET}" + + if php vendor/bin/rector; then + echo -e "${CHECK} ${GREEN}Rector completed successfully${RESET}\n" + return 0 + else + echo -e "${WARNING} ${YELLOW}Rector found issues${RESET}\n" + return 1 + fi +} + +run_php_cs_fixer() { + echo -e "${BOLD}${PALETTE} Running PHP-CS-Fixer${RESET}" + + if php vendor/bin/php-cs-fixer fix -v; then + echo -e "${CHECK} ${GREEN}PHP-CS-Fixer completed successfully${RESET}\n" + return 0 + else + echo -e "${WARNING} ${YELLOW}CS-Fixer found issues${RESET}\n" + return 1 + fi +} + +run_phpstan() { + echo -e "${BOLD}${MICROSCOPE} Running PHPStan${RESET}" + + if php vendor/bin/phpstan analyse --memory-limit=-1; then + echo -e "${CHECK} ${GREEN}PHPStan analysis completed successfully${RESET}\n" + return 0 + else + echo -e "${WARNING} ${YELLOW}PHPStan found issues${RESET}\n" + return 1 + fi +} + +validate_composer_files() { + echo -e "${BOLD}${MEMO} Validating Composer Files${RESET}" + local validation_success=true + + if ! composer validate --strict; then + echo -e "${WARNING} ${YELLOW}Main composer.json validation failed${RESET}" + validation_success=false + fi + + # Find and validate all composer.json files in src/ + find src/ -name "composer.json" | while read file; do + echo -e "${DIM}Validating ${file}${RESET}" + if ! composer validate --strict "$file"; then + echo -e "${WARNING} ${YELLOW}Package validation failed for ${file}${RESET}" + validation_success=false + fi + done + + if [ "$validation_success" = true ]; then + echo -e "${CHECK} ${GREEN}All composer.json files are valid${RESET}\n" + return 0 + else + echo -e "${WARNING} ${YELLOW}Some composer.json files have issues${RESET}\n" + return 1 + fi +} + +run_phplint() { + echo -e "${BOLD}${MAGNIFIER} Running PHPLint${RESET}" + + if php vendor/bin/phplint; then + echo -e "${CHECK} ${GREEN}PHPLint completed successfully${RESET}\n" + return 0 + else + echo -e "${WARNING} ${YELLOW}PHPLint found issues${RESET}\n" + return 1 + fi +} + +run_phpunit() { + echo -e "${BOLD}${TEST_TUBE} Running PHPUnit Tests${RESET}" + + if php vendor/bin/phpunit; then + echo -e "${CHECK} ${GREEN}All tests passed successfully${RESET}\n" + return 0 + else + echo -e "${WARNING} ${YELLOW}Tests failed${RESET}\n" + return 1 + fi +} + +main() { + local start_time=$(date +%s) + local issues_found=false + + print_header + + # Run all quality tools + run_rector || issues_found=true + run_php_cs_fixer || issues_found=true + run_phpstan || issues_found=true + validate_composer_files || issues_found=true + run_phplint || issues_found=true + run_phpunit || issues_found=true + + local end_time=$(date +%s) + local duration=$((end_time - start_time)) + + # Summary + echo -e "${BOLD}${CYAN}Quality Check Summary${RESET}" + if [ "$issues_found" = true ]; then + echo -e "${WARNING} ${YELLOW}Quality check completed with issues${RESET}" + else + echo -e "${SPARKLES} ${GREEN}All quality checks passed successfully${RESET}" + fi + echo -e "Duration : ${YELLOW}${duration}s${RESET}\n" + + echo -e "${SPARKLES} ${BOLD}Quality Check Complete${RESET}" + echo -e "${CHECK} All checks finished\n" + + # We don't exit with error code because the original task continues despite failures + exit 0 +} + +main diff --git a/bin/update b/bin/update new file mode 100755 index 00000000..0dbe6ad2 --- /dev/null +++ b/bin/update @@ -0,0 +1,116 @@ +#!/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="โŒ" +readonly PACKAGE="๐Ÿ“ฆ" +readonly SEARCH="๐Ÿ”" +readonly HAMMER="๐Ÿ—๏ธ" +readonly SPARKLES="โœจ" +readonly WARNING="โš ๏ธ" + +print_header() { + echo -e "\n${BOLD}${BLUE}${ROCKET} PHP-Flasher Update ${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" +} + +update_composer_dependencies() { + echo -e "${BOLD}${PACKAGE} Composer Dependencies${RESET}" + + if composer update --prefer-lowest -W; then + echo -e "${CHECK} ${GREEN}Dependencies updated successfully${RESET}\n" + return 0 + else + echo -e "${ERROR} ${RED}Failed to update Composer dependencies${RESET}\n" + return 1 + fi +} + +check_npm_updates() { + echo -e "${BOLD}${SEARCH} NPM Updates Check${RESET}" + + if npm run ncu > /dev/null 2>&1; then + echo -e "${CHECK} ${GREEN}NPM check completed successfully${RESET}\n" + else + echo -e "${WARNING} ${YELLOW}NPM check failed, continuing...${RESET}\n" + fi + + return 0 # Continue regardless of outcome +} + +update_npm_dependencies() { + echo -e "${BOLD}${PACKAGE} NPM Dependencies${RESET}" + + if npm install --force; then + echo -e "${CHECK} ${GREEN}NPM dependencies installed successfully${RESET}\n" + return 0 + else + echo -e "${WARNING} ${YELLOW}NPM install failed, continuing...${RESET}\n" + return 0 # Continue despite failure + fi +} + +build_assets() { + echo -e "${BOLD}${HAMMER} Building Assets${RESET}" + + if npm run build; then + echo -e "${CHECK} ${GREEN}Assets built successfully${RESET}\n" + return 0 + else + echo -e "${WARNING} ${YELLOW}Build failed, continuing...${RESET}\n" + return 0 # Continue despite failure + fi +} + +main() { + local start_time=$(date +%s) + local success=true + + print_header + + # Update composer dependencies + update_composer_dependencies || success=false + + # Check NPM updates + check_npm_updates + + # Update NPM dependencies + update_npm_dependencies + + # Build assets + build_assets + + local end_time=$(date +%s) + local duration=$((end_time - start_time)) + + # Summary + echo -e "${BOLD}${CYAN}Update Summary${RESET}" + if [ "$success" = true ]; then + echo -e "${SPARKLES} ${GREEN}Update completed successfully${RESET}" + else + echo -e "${WARNING} ${YELLOW}Update completed with some issues${RESET}" + fi + echo -e "Duration : ${YELLOW}${duration}s${RESET}\n" + + [ "$success" = true ] && exit 0 || exit 1 +} + +main