Skip to content

Commit 8f9a16d

Browse files
committed
feat(integration): add partial update flags for existing installations
Add --update-hooks, --update-configs, and --update-deps flags to allow targeted updates of specific components without full reinstallation. Partial update modes: - --update-hooks: Refresh only .husky directory with backup/restore - --update-configs: Update config files (commitlint, validate-branch-name, PHP configs if applicable) - --update-deps: Update npm and composer dependencies Flags can be combined and used with existing flags like -J for JS/TS projects. Includes documentation updates with usage examples.
1 parent 3cba3ad commit 8f9a16d

File tree

3 files changed

+407
-0
lines changed

3 files changed

+407
-0
lines changed

booster/integrate_booster.sh

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,17 +1496,27 @@ function show_help() {
14961496
echo " -i Show version information and exit"
14971497
echo " -h Show this help message and exit"
14981498
echo ""
1499+
echo "PARTIAL UPDATE OPTIONS (for existing installations):"
1500+
echo " --update-hooks Update only Git hooks (.husky directory)"
1501+
echo " --update-configs Update only config files (commitlint, validate-branch-name, etc.)"
1502+
echo " --update-deps Update only dependencies (composer/npm packages)"
1503+
echo ""
14991504
echo "DESCRIPTION:"
15001505
echo " Integrates PHP Booster tooling into an existing PHP project."
15011506
echo " Supports both standard PHP projects and DDEV environments."
15021507
echo " Use -J flag for JavaScript/TypeScript projects without PHP."
15031508
echo ""
1509+
echo " For existing installations, use partial update flags to refresh"
1510+
echo " specific components without a full reinstall."
1511+
echo ""
15041512
echo "EXAMPLES:"
15051513
echo " $0 # Run integration with default settings"
15061514
echo " $0 -I # Run in interactive mode (guided setup)"
15071515
echo " $0 -J # Install hooks only (for JS/TS projects)"
15081516
echo " $0 -v # Run with verbose output"
15091517
echo " $0 -i # Show version information"
1518+
echo " $0 --update-hooks # Update Git hooks only"
1519+
echo " $0 --update-configs # Update config files only"
15101520
echo ""
15111521
echo "ENVIRONMENT VARIABLES:"
15121522
echo " BOOSTER_LOCAL_DEV=1 # Use local booster directory instead of GitHub"
@@ -1549,8 +1559,141 @@ function show_version_info_and_exit() {
15491559

15501560
# --- Main Execution ---
15511561

1562+
# Partial update mode flags
1563+
UPDATE_HOOKS_ONLY=false
1564+
UPDATE_CONFIGS_ONLY=false
1565+
UPDATE_DEPS_ONLY=false
1566+
1567+
# --- Partial Update Functions ---
1568+
1569+
function update_hooks_only() {
1570+
log "Starting partial update: Git hooks only..."
1571+
1572+
download_php_booster
1573+
1574+
local husky_src="${BOOSTER_INTERNAL_PATH}/.husky"
1575+
if [ -d "$husky_src" ]; then
1576+
log "Updating .husky directory..."
1577+
1578+
# Backup existing husky if it exists
1579+
if [ -d ".husky" ]; then
1580+
rm -rf ".husky.bak"
1581+
mv ".husky" ".husky.bak"
1582+
log " Backed up existing .husky to .husky.bak"
1583+
fi
1584+
1585+
mkdir -p .husky
1586+
1587+
# Copy everything except the 'tests' directory
1588+
for item in "$husky_src"/*; do
1589+
local item_name=$(basename "$item")
1590+
if [ "$item_name" != "tests" ]; then
1591+
cp -R "$item" .husky/
1592+
fi
1593+
done
1594+
1595+
# Set execute permissions for scripts and hooks
1596+
find ".husky" -type f \( -name "*.sh" -o -name "*.bash" -o -name "*.mjs" -o -name "pre-commit" -o -name "commit-msg" -o -name "pre-push" \) -exec chmod +x {} \;
1597+
1598+
# Remove backup on success
1599+
rm -rf ".husky.bak"
1600+
1601+
success "Git hooks updated successfully."
1602+
else
1603+
error "Could not find .husky directory in booster."
1604+
fi
1605+
}
1606+
1607+
function update_configs_only() {
1608+
log "Starting partial update: Config files only..."
1609+
1610+
download_php_booster
1611+
1612+
local updated_count=0
1613+
1614+
# Config files to update (always overwrite)
1615+
local config_files=(
1616+
"commitlint.config.ts"
1617+
"validate-branch-name.config.cjs"
1618+
"renovate.json"
1619+
)
1620+
1621+
for config in "${config_files[@]}"; do
1622+
local src="${BOOSTER_INTERNAL_PATH}/${config}"
1623+
if [ -f "$src" ]; then
1624+
cp "$src" . || warn "Failed to copy $config"
1625+
log " Updated $config"
1626+
((updated_count++))
1627+
else
1628+
log " $config not found in booster, skipping."
1629+
fi
1630+
done
1631+
1632+
# Update .editorconfig
1633+
local editorconfig_src="${BOOSTER_INTERNAL_PATH}/.editorconfig"
1634+
if [ -f "$editorconfig_src" ]; then
1635+
cp "$editorconfig_src" . || warn "Failed to copy .editorconfig"
1636+
log " Updated .editorconfig"
1637+
((updated_count++))
1638+
fi
1639+
1640+
# PHP-specific configs (only if not hooks-only mode and files exist)
1641+
if [ "$HOOKS_ONLY_MODE" != true ] && [ -f "composer.json" ]; then
1642+
local php_configs=("ecs.php" "rector.php" "phpstan.neon.dist" "psalm.xml" "deptrac.yaml" "sonar-project.properties")
1643+
for config in "${php_configs[@]}"; do
1644+
local src="${BOOSTER_INTERNAL_PATH}/${config}"
1645+
if [ -f "$src" ]; then
1646+
cp "$src" . || warn "Failed to copy $config"
1647+
log " Updated $config"
1648+
((updated_count++))
1649+
fi
1650+
done
1651+
fi
1652+
1653+
success "Config files updated ($updated_count files)."
1654+
}
1655+
1656+
function update_deps_only() {
1657+
log "Starting partial update: Dependencies only..."
1658+
1659+
download_php_booster
1660+
1661+
IS_DDEV_PROJECT=$(is_ddev_project)
1662+
1663+
# Update node dependencies
1664+
log "Updating Node.js dependencies..."
1665+
install_node_dependencies
1666+
1667+
# Update PHP dependencies (only if not hooks-only mode)
1668+
if [ "$HOOKS_ONLY_MODE" != true ] && [ -f "composer.json" ]; then
1669+
log "Updating PHP dependencies..."
1670+
add_code_quality_tools
1671+
fi
1672+
1673+
success "Dependencies updated."
1674+
}
15521675

15531676
function main() {
1677+
# Parse long options first (before getopts)
1678+
local args=()
1679+
for arg in "$@"; do
1680+
case $arg in
1681+
--update-hooks)
1682+
UPDATE_HOOKS_ONLY=true
1683+
;;
1684+
--update-configs)
1685+
UPDATE_CONFIGS_ONLY=true
1686+
;;
1687+
--update-deps)
1688+
UPDATE_DEPS_ONLY=true
1689+
;;
1690+
*)
1691+
args+=("$arg")
1692+
;;
1693+
esac
1694+
done
1695+
set -- "${args[@]}"
1696+
15541697
# Process command line arguments
15551698
while getopts ":vchiINJ" opt; do
15561699
case $opt in
@@ -1567,6 +1710,42 @@ function main() {
15671710
done
15681711
shift $((OPTIND - 1))
15691712

1713+
# --- Handle Partial Update Modes ---
1714+
if [ "$UPDATE_HOOKS_ONLY" = true ] || [ "$UPDATE_CONFIGS_ONLY" = true ] || [ "$UPDATE_DEPS_ONLY" = true ]; then
1715+
log "Running in partial update mode..."
1716+
1717+
# Check for existing booster installation
1718+
if [ ! -f ".booster-version" ] && [ ! -d ".husky" ]; then
1719+
warn "No existing booster installation detected. Running partial update anyway..."
1720+
fi
1721+
1722+
check_dependencies
1723+
1724+
if [ "$UPDATE_HOOKS_ONLY" = true ]; then
1725+
update_hooks_only
1726+
fi
1727+
1728+
if [ "$UPDATE_CONFIGS_ONLY" = true ]; then
1729+
update_configs_only
1730+
fi
1731+
1732+
if [ "$UPDATE_DEPS_ONLY" = true ]; then
1733+
update_deps_only
1734+
fi
1735+
1736+
# Update version stamp with partial update info
1737+
local current_version
1738+
current_version=$(get_booster_version 2>/dev/null || echo "unknown")
1739+
if [ "$current_version" != "unknown" ]; then
1740+
create_version_stamp "$current_version" "partial-update"
1741+
fi
1742+
1743+
success "Partial update completed."
1744+
exit 0
1745+
fi
1746+
1747+
# --- Full Installation Mode ---
1748+
15701749
# Determine installation mode
15711750
if [ "$HOOKS_ONLY_MODE" = true ]; then
15721751
log "Starting php-booster integration (hooks-only mode for JS/TS projects)..."

0 commit comments

Comments
 (0)