@@ -30,6 +30,67 @@ export COMPOSER_MEMORY_LIMIT=-1
3030# This automatically accepts all recipes from both main and contrib repositories
3131export SYMFONY_FLEX_RECIPES_AUTO_ACCEPT=1
3232
33+ # --- Version Management ---
34+
35+ # Extract version from booster composer.json
36+ function get_booster_version() {
37+ local booster_composer=" ${BOOSTER_INTERNAL_PATH} /composer.json"
38+ if [ -f " $booster_composer " ]; then
39+ jq -r ' .version // "unknown"' " $booster_composer "
40+ else
41+ echo " unknown"
42+ fi
43+ }
44+
45+ # Get the currently installed booster version
46+ function get_installed_version() {
47+ local version_file=" .booster-version"
48+ if [ -f " $version_file " ]; then
49+ grep " ^VERSION=" " $version_file " 2> /dev/null | cut -d' =' -f2 || echo " "
50+ else
51+ echo " "
52+ fi
53+ }
54+
55+ # Create or update the version stamp file
56+ function create_version_stamp() {
57+ local version=" $1 "
58+ local version_file=" .booster-version"
59+ local timestamp=$( date ' +%Y-%m-%d %H:%M:%S' )
60+
61+ cat > " $version_file " << EOF
62+ # PHP Booster Version Stamp
63+ # This file tracks which booster version was integrated into this project
64+ # Generated by integrate_booster.sh
65+
66+ VERSION=$version
67+ INSTALLED_DATE=$timestamp
68+ INTEGRATION_METHOD=script
69+ EOF
70+
71+ log " Created version stamp: $version (installed $timestamp )"
72+ }
73+
74+ # Show version information and upgrade status
75+ function show_version_info() {
76+ local current_version=" $1 "
77+ local installed_version
78+ installed_version=$( get_installed_version)
79+
80+ if [ -n " $installed_version " ]; then
81+ echo -e " ${GREEN} [INFO]${NC} Previous booster installation detected: $installed_version "
82+ echo -e " ${GREEN} [INFO]${NC} Current booster version: $current_version "
83+
84+ if [ " $installed_version " != " $current_version " ]; then
85+ echo -e " ${YELLOW} [UPGRADE]${NC} This will upgrade your booster from $installed_version to $current_version "
86+ else
87+ echo -e " ${GREEN} [INFO]${NC} Re-integrating same version (idempotent operation)"
88+ fi
89+ else
90+ echo -e " ${GREEN} [INFO]${NC} Installing PHP Booster version: $current_version "
91+ fi
92+ }
93+
3394# --- Helper Functions ---
3495
3596function log() {
@@ -847,15 +908,78 @@ EOF
847908 success " Nginx configuration updated with XDEBUG_TRIGGER."
848909}
849910
911+ # Display help information
912+ function show_help() {
913+ echo " PHP Booster Integration Script"
914+ echo " "
915+ echo " USAGE:"
916+ echo " $0 [OPTIONS]"
917+ echo " "
918+ echo " OPTIONS:"
919+ echo " -v Enable verbose logging"
920+ echo " -c Skip cleanup (preserve temporary files for debugging)"
921+ echo " -i Show version information and exit"
922+ echo " -h Show this help message and exit"
923+ echo " "
924+ echo " DESCRIPTION:"
925+ echo " Integrates PHP Booster tooling into an existing PHP project."
926+ echo " Supports both standard PHP projects and DDEV environments."
927+ echo " "
928+ echo " EXAMPLES:"
929+ echo " $0 # Run integration with default settings"
930+ echo " $0 -v # Run with verbose output"
931+ echo " $0 -i # Show version information"
932+ echo " "
933+ echo " ENVIRONMENT VARIABLES:"
934+ echo " BOOSTER_LOCAL_DEV=1 # Use local booster directory instead of GitHub"
935+ echo " BOOSTER_LOCAL_PATH # Path to local booster (default: ../booster)"
936+ }
937+
938+ # Show version information and exit
939+ function show_version_info_and_exit() {
940+ echo " PHP Booster Integration Script"
941+ echo " "
942+
943+ # Try to get installed version first
944+ local installed_version
945+ installed_version=$( get_installed_version)
946+
947+ if [ -n " $installed_version " ]; then
948+ echo " Installed version: $installed_version "
949+ if [ -f " .booster-version" ]; then
950+ echo " Installation details:"
951+ grep -E " ^(INSTALLED_DATE|INTEGRATION_METHOD)=" " .booster-version" 2> /dev/null | sed ' s/^/ /' || true
952+ fi
953+ else
954+ echo " No booster installation detected in current directory"
955+ fi
956+
957+ echo " "
958+ # Try to get available version, but handle errors gracefully
959+ local available_version
960+ available_version=$( get_booster_version 2> /dev/null || echo " unknown" )
961+ if [ " $available_version " = " unknown" ]; then
962+ echo " Available version: unknown (booster not downloaded yet)"
963+ echo " Run without -i to integrate and see available version"
964+ else
965+ echo " Available version (will be installed): $available_version "
966+ fi
967+ echo " "
968+ echo " To integrate or upgrade, run: $0 "
969+ exit 0
970+ }
971+
850972# --- Main Execution ---
851973
852974function main() {
853975
854- while getopts " :vc " opt; do
976+ while getopts " :vchi " opt; do
855977 case $opt in
856978 v) VERBOSE=true ;;
857979 c) NO_CLEANUP=true ;;
858- \? ) error " Invalid option: -$OPTARG " ;;
980+ h) show_help; exit 0 ;;
981+ i) show_version_info_and_exit ;;
982+ \? ) error " Invalid option: -$OPTARG . Use -h for help." ;;
859983 :) error " Option -$OPTARG requires an argument." ;;
860984 esac
861985 done
@@ -877,6 +1001,11 @@ function main() {
8771001 check_dependencies
8781002 download_php_booster
8791003
1004+ # --- Version Management ---
1005+ local current_version
1006+ current_version=$( get_booster_version)
1007+ show_version_info " $current_version "
1008+
8801009 copy_files
8811010 update_package_json
8821011 update_readme
@@ -904,6 +1033,10 @@ function main() {
9041033 fi
9051034
9061035 add_code_quality_tools # Merges composer scripts & installs deps
1036+
1037+ # --- Create Version Stamp ---
1038+ create_version_stamp " $current_version "
1039+
9071040 success " Integration process completed."
9081041
9091042 if [ $IS_DDEV_PROJECT -eq 1 ]; then
0 commit comments