update build scripts

This commit is contained in:
Younes ENNAJI
2025-03-08 11:29:23 +00:00
parent 29cea6f9d3
commit 3d66271ac8
5 changed files with 402 additions and 97 deletions
+27 -62
View File
@@ -1,70 +1,35 @@
#!/usr/bin/env php #!/bin/bash
<?php
declare(strict_types=1); # Default to the current directory if no directory is provided
dir=${1:-.}
require __DIR__.'/../vendor/autoload.php'; # Optional: A list of file extensions to filter by, e.g., "txt md". Leave empty to include all files.
extensions=($2)
use Symfony\Component\Filesystem\Filesystem; # Temporary file to store results
use Symfony\Component\Finder\Finder; temp_file=$(mktemp)
$filesystem = new Filesystem(); # Function to print file details (now inline within find command)
print_file_details() {
// Define the shared resources echo "File Path: $1"
$shared = realpath(__DIR__.'/../.shared'); echo "Contents:"
cat "$1"
$resources = [ echo
$shared,
__DIR__.'/../.github/FUNDING.yml',
__DIR__.'/../README.md',
__DIR__.'/../LICENSE',
];
// Directories to search for packages
$dirs = [__DIR__.'/../src'];
// Find all composer.json files within the specified directories
$finder = new Finder();
$finder->files()
->in($dirs)
->name('composer.json')
->depth('< 3'); // Adjust depth as needed
$packages = [];
// Collect package directories
foreach ($finder as $file) {
$packages[] = dirname($file->getRealPath());
} }
foreach ($packages as $packageDir) { # Finding and processing files
foreach ($resources as $resource) { if [ ${#extensions[@]} -eq 0 ]; then
if (!is_string($resource)) { # If no extensions are specified, process all files
continue; 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) { echo "Results copied to clipboard."
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]);
}
}
}
}
-35
View File
@@ -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."
Executable
+101
View File
@@ -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 "$@"
Executable
+158
View File
@@ -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
Executable
+116
View File
@@ -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