Add dependency installation script

- Automatically finds and installs npm dependencies (package.json)
- Automatically finds and installs composer dependencies (composer.json)
- Excludes nested dependencies inside node_modules and vendor
- Provides colored output and installation summary
- Usage: ./install-dependencies.sh
This commit is contained in:
2025-12-09 10:26:38 +00:00
parent 86f1339793
commit 0dd4f3a020

121
install-dependencies.sh Executable file
View File

@@ -0,0 +1,121 @@
#!/bin/bash
# Install Dependencies Script
# This script installs npm and composer dependencies throughout the project
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Counters
npm_success=0
npm_failed=0
composer_success=0
composer_failed=0
echo -e "${BLUE}=====================================${NC}"
echo -e "${BLUE} Installing Project Dependencies${NC}"
echo -e "${BLUE}=====================================${NC}"
echo ""
# Check if npm is installed
if ! command -v npm &> /dev/null; then
echo -e "${RED}Error: npm is not installed${NC}"
echo "Please install Node.js and npm first"
exit 1
fi
# Check if composer is installed
if ! command -v composer &> /dev/null; then
echo -e "${YELLOW}Warning: composer is not installed${NC}"
echo "Composer dependencies will be skipped"
SKIP_COMPOSER=1
else
SKIP_COMPOSER=0
fi
echo ""
echo -e "${BLUE}Searching for package.json files...${NC}"
# Find and install npm dependencies
# Exclude node_modules and vendor directories
while IFS= read -r package_file; do
dir=$(dirname "$package_file")
# Skip if it's inside node_modules or vendor
if [[ "$dir" == *"/node_modules/"* ]] || [[ "$dir" == *"/vendor/"* ]]; then
continue
fi
echo ""
echo -e "${YELLOW}────────────────────────────────────${NC}"
echo -e "${GREEN}Found: $package_file${NC}"
echo -e "${BLUE}Installing npm dependencies in: $dir${NC}"
if (cd "$dir" && npm install); then
echo -e "${GREEN}✓ Successfully installed npm dependencies in $dir${NC}"
((npm_success++))
else
echo -e "${RED}✗ Failed to install npm dependencies in $dir${NC}"
((npm_failed++))
fi
done < <(find . -name "package.json" -type f)
echo ""
echo -e "${BLUE}Searching for composer.json files...${NC}"
# Find and install composer dependencies
if [ $SKIP_COMPOSER -eq 0 ]; then
while IFS= read -r composer_file; do
dir=$(dirname "$composer_file")
# Skip if it's inside node_modules or vendor
if [[ "$dir" == *"/node_modules/"* ]] || [[ "$dir" == *"/vendor/"* ]]; then
continue
fi
echo ""
echo -e "${YELLOW}────────────────────────────────────${NC}"
echo -e "${GREEN}Found: $composer_file${NC}"
echo -e "${BLUE}Installing composer dependencies in: $dir${NC}"
if (cd "$dir" && composer install --no-interaction); then
echo -e "${GREEN}✓ Successfully installed composer dependencies in $dir${NC}"
((composer_success++))
else
echo -e "${RED}✗ Failed to install composer dependencies in $dir${NC}"
((composer_failed++))
fi
done < <(find . -name "composer.json" -type f)
else
echo -e "${YELLOW}Skipping composer installations (composer not found)${NC}"
fi
# Summary
echo ""
echo -e "${BLUE}=====================================${NC}"
echo -e "${BLUE} Installation Summary${NC}"
echo -e "${BLUE}=====================================${NC}"
echo -e "${GREEN}NPM packages installed successfully: $npm_success${NC}"
if [ $npm_failed -gt 0 ]; then
echo -e "${RED}NPM packages failed: $npm_failed${NC}"
fi
if [ $SKIP_COMPOSER -eq 0 ]; then
echo -e "${GREEN}Composer packages installed successfully: $composer_success${NC}"
if [ $composer_failed -gt 0 ]; then
echo -e "${RED}Composer packages failed: $composer_failed${NC}"
fi
fi
echo ""
if [ $npm_failed -gt 0 ] || [ $composer_failed -gt 0 ]; then
echo -e "${YELLOW}Some installations failed. Check the output above for details.${NC}"
exit 1
else
echo -e "${GREEN}All dependencies installed successfully!${NC}"
fi