setup-dev-environment.shā¢8.2 kB
#!/bin/bash
/**
* EuConquisto Composer MCP Server - Development Environment Setup
*
* @version 0.1.0
* @created 2025-06-08
* @updated 2025-06-08
* @author EuConquisto Development Team
*
* @description Automated setup script for development environment including
* dependency installation, environment configuration, and tool setup.
*
* @testStatus PENDING
* @coverage N/A
*
* @dependencies
* - Node.js 18+
* - npm or yarn
* - Git
*
* @supersedes N/A
* @supersededBy N/A
*/
set -e # Exit on any 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
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check Node.js version
check_node_version() {
if command_exists node; then
NODE_VERSION=$(node --version | sed 's/v//')
REQUIRED_VERSION="18.0.0"
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$NODE_VERSION" | sort -V | head -n1)" = "$REQUIRED_VERSION" ]; then
print_success "Node.js version $NODE_VERSION is compatible"
return 0
else
print_error "Node.js version $NODE_VERSION is not compatible. Required: $REQUIRED_VERSION+"
return 1
fi
else
print_error "Node.js is not installed"
return 1
fi
}
# Function to check npm version
check_npm_version() {
if command_exists npm; then
NPM_VERSION=$(npm --version)
print_success "npm version $NPM_VERSION is available"
return 0
else
print_error "npm is not installed"
return 1
fi
}
# Function to install dependencies
install_dependencies() {
print_status "Installing project dependencies..."
if [ -f "package.json" ]; then
npm install
print_success "Dependencies installed successfully"
else
print_error "package.json not found"
return 1
fi
}
# Function to setup environment file
setup_environment() {
print_status "Setting up environment configuration..."
if [ -f ".env.example" ]; then
if [ ! -f ".env" ]; then
cp .env.example .env
print_success "Environment file created from template"
print_warning "Please review and update .env file with your configuration"
else
print_warning ".env file already exists"
fi
else
print_error ".env.example not found"
return 1
fi
}
# Function to create necessary directories
create_directories() {
print_status "Creating necessary directories..."
# Create log directories if they don't exist
mkdir -p logs/development
mkdir -p logs/testing
mkdir -p logs/validation
# Create validation directories
mkdir -p validation/test-results
mkdir -p validation/quality-metrics
print_success "Directories created successfully"
}
# Function to install development tools
install_dev_tools() {
print_status "Installing development tools..."
# Install global tools if not present
if ! command_exists typescript; then
npm install -g typescript
print_success "TypeScript installed globally"
fi
if ! command_exists ts-node; then
npm install -g ts-node
print_success "ts-node installed globally"
fi
if ! command_exists eslint; then
npm install -g eslint
print_success "ESLint installed globally"
fi
}
# Function to verify installation
verify_installation() {
print_status "Verifying installation..."
# Check if TypeScript compiles
if npm run build > /dev/null 2>&1; then
print_success "TypeScript compilation successful"
else
print_warning "TypeScript compilation failed - this is expected for initial setup"
fi
# Check if linting works
if npm run lint > /dev/null 2>&1; then
print_success "Linting configuration working"
else
print_warning "Linting issues found - review and fix as needed"
fi
print_success "Installation verification completed"
}
# Function to setup Git hooks
setup_git_hooks() {
print_status "Setting up Git hooks..."
if [ -d ".git" ]; then
# Copy our pre-commit hook
if [ -f "tools/git-pre-commit-hook.sh" ]; then
cp tools/git-pre-commit-hook.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
print_success "Pre-commit hook installed with versioning validation"
else
# Create basic pre-commit hook
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
# Run linting and tests before commit
npm run lint && npm run test
EOF
chmod +x .git/hooks/pre-commit
print_success "Basic Git hooks configured"
fi
else
print_warning "Not a Git repository - skipping Git hooks setup"
fi
}
# Function to generate initial documentation
generate_docs() {
print_status "Generating initial documentation..."
# Create basic API documentation structure
mkdir -p docs/api/generated
mkdir -p docs/architecture/diagrams
mkdir -p docs/guides/examples
print_success "Documentation structure created"
}
# Function to run initial tests
run_initial_tests() {
print_status "Running initial tests..."
if npm run test > /dev/null 2>&1; then
print_success "Initial tests passed"
else
print_warning "Some tests failed - this is expected for initial setup"
fi
}
# Function to display next steps
show_next_steps() {
echo ""
echo "=========================================="
echo "š Development Environment Setup Complete!"
echo "=========================================="
echo ""
echo "Next steps:"
echo "1. Review and update .env file with your configuration"
echo "2. Start development server: npm run dev"
echo "3. Run tests: npm run test"
echo "4. Check code quality: npm run lint"
echo "5. Build project: npm run build"
echo ""
echo "Available commands:"
echo " npm run dev - Start development server"
echo " npm run build - Build for production"
echo " npm run test - Run test suite"
echo " npm run test:watch - Run tests in watch mode"
echo " npm run lint - Run linting"
echo " npm run lint:fix - Fix linting issues"
echo " npm run validate - Run full validation"
echo ""
echo "Documentation:"
echo " README.md - Project overview"
echo " ROADMAP.md - Development roadmap"
echo " docs/ - Detailed documentation"
echo ""
echo "Happy coding! š"
}
# Main execution
main() {
echo "=============================================="
echo "EuConquisto Composer MCP Server Setup"
echo "=============================================="
echo ""
# Check prerequisites
print_status "Checking prerequisites..."
if ! check_node_version; then
print_error "Node.js version check failed"
exit 1
fi
if ! check_npm_version; then
print_error "npm version check failed"
exit 1
fi
# Install dependencies
if ! install_dependencies; then
print_error "Dependency installation failed"
exit 1
fi
# Setup environment
if ! setup_environment; then
print_error "Environment setup failed"
exit 1
fi
# Create directories
create_directories
# Install development tools
install_dev_tools
# Setup Git hooks
setup_git_hooks
# Generate documentation structure
generate_docs
# Verify installation
verify_installation
# Run initial tests
run_initial_tests
# Show next steps
show_next_steps
}
# Execute main function
main "$@"