Shell Scripts and System Tools

Shell scripts and system-level tools for the monorepo

Shell Scripts and System Tools

🐚 Overview

These shell scripts provide system-level automation, deployment tools, and environment setup for the monorepo.

📁 Available Shell Scripts

1. Build Scripts

build-docs-angular.sh - Smart Build for docs-angular

Purpose: Reliable build script for docs-angular with cache corruption prevention.

Usage:

# Build docs-angular with smart cache handling
./tools/scripts/build-docs-angular.sh

# Or run directly
bash tools/scripts/build-docs-angular.sh

Features:

build-nx.sh - Reliable NX Build

Purpose: Reliable NX build script that handles cache issues.

Usage:

# Build default project (editor-web) in production
./tools/scripts/build-nx.sh

# Build specific project
./tools/scripts/build-nx.sh docs-angular production

# Build in development mode
./tools/scripts/build-nx.sh ux-test development

Parameters:

2. Environment Setup Scripts

pre-dev-setup.sh - Pre-Development Setup

Purpose: Sets up the development environment before starting work.

Usage:

# Run pre-development setup
./tools/scripts/pre-dev-setup.sh

# Or source it for environment variables
source tools/scripts/pre-dev-setup.sh

What it does:

install-advanced-history.sh - Advanced Shell History

Purpose: Installs advanced shell history features for better development experience.

Usage:

# Install advanced history features
./tools/scripts/install-advanced-history.sh

# Test the installation
./tools/scripts/test-advanced-history.sh

Features:

3. Migration and Conversion Scripts

migrate-theme-system.sh - Theme System Migration

Purpose: Migrates theme system to new structure.

Usage:

# Run theme system migration
./tools/scripts/migrate-theme-system.sh

# Run with backup
./tools/scripts/migrate-theme-system.sh --backup

What it does:

convert-app-to-lib.sh - App to Library Conversion

Purpose: Converts Angular applications to libraries.

Usage:

# Convert app to library
./tools/scripts/convert-app-to-lib.sh my-app

# Convert with specific options
./tools/scripts/convert-app-to-lib.sh my-app --preserve-routing

Features:

4. Database and Deployment Scripts

create-firebase-database.sh - Firebase Database Setup

Purpose: Sets up Firebase database for the project.

Usage:

# Create Firebase database
./tools/scripts/create-firebase-database.sh

# Create with specific configuration
./tools/scripts/create-firebase-database.sh --project=my-project

What it does:

deploy-firestore-rules.sh - Firestore Rules Deployment

Purpose: Deploys Firestore security rules.

Usage:

# Deploy Firestore rules
./tools/scripts/deploy-firestore-rules.sh

# Deploy to specific project
./tools/scripts/deploy-firestore-rules.sh --project=my-project

5. Utility Scripts

consolidate-types.sh - Type Consolidation

Purpose: Consolidates TypeScript types across the project.

Usage:

# Consolidate types
./tools/scripts/consolidate-types.sh

# Consolidate with specific options
./tools/scripts/consolidate-types.sh --dry-run

What it does:

🔧 System Configuration

Environment Variables

# Set in pre-dev-setup.sh or your shell profile
export NX_CACHE_DIRECTORY=/tmp/nx-cache
export NODE_ENV=development
export FIREBASE_PROJECT=your-project-id

Shell Configuration

# Add to your .zshrc or .bashrc
source tools/scripts/zsh-advanced-history.zsh
source tools/scripts/pre-dev-setup.sh

🚀 Quick Start Examples

Development Environment Setup

# 1. Run pre-development setup
./tools/scripts/pre-dev-setup.sh

# 2. Install advanced history (optional)
./tools/scripts/install-advanced-history.sh

# 3. Test the setup
./tools/scripts/test-advanced-history.sh

Building Applications

# Build docs-angular
./tools/scripts/build-docs-angular.sh

# Build specific project
./tools/scripts/build-nx.sh ux-test production

# Build with custom cache
NX_CACHE_DIRECTORY=/tmp/nx-cache ./tools/scripts/build-nx.sh

Database Setup

# Create Firebase database
./tools/scripts/create-firebase-database.sh

# Deploy Firestore rules
./tools/scripts/deploy-firestore-rules.sh

Migration Tasks

# Migrate theme system
./tools/scripts/migrate-theme-system.sh

# Convert app to library
./tools/scripts/convert-app-to-lib.sh my-app

# Consolidate types
./tools/scripts/consolidate-types.sh

🐛 Troubleshooting

Permission Issues

# Make scripts executable
chmod +x tools/scripts/*.sh

# Or run with bash explicitly
bash tools/scripts/build-docs-angular.sh

Environment Issues

# Source environment setup
source tools/scripts/pre-dev-setup.sh

# Check environment variables
env | grep NX

Build Issues

# Use alternative cache directory
NX_CACHE_DIRECTORY=/tmp/nx-cache ./tools/scripts/build-nx.sh

# Clean and rebuild
rm -rf .nx/cache
./tools/scripts/build-nx.sh

📊 Script Output Examples

Build Success

$ ./tools/scripts/build-docs-angular.sh
🚀 Starting smart build for docs-angular...
🔧 Using alternative cache directory to avoid corruption...
✅ Build completed successfully!
📁 Output: dist/apps/docs-angular

Build Failure

$ ./tools/scripts/build-nx.sh
🚀 Building editor-web with configuration production...
❌ Build failed!

Migration Success

$ ./tools/scripts/migrate-theme-system.sh
🔄 Starting theme system migration...
📁 Creating backup...
✅ Migration completed successfully!

🔧 Customization

Custom Build Configuration

# Create custom build script
cat > tools/scripts/build-custom.sh << 'EOF'
#!/bin/bash
PROJECT=${1:-my-project}
CONFIG=${2:-production}

echo "🚀 Building $PROJECT with configuration $CONFIG..."
NX_CACHE_DIRECTORY=/tmp/nx-cache nx build $PROJECT --configuration=$CONFIG

if [ $? -eq 0 ]; then
    echo "✅ Build completed successfully!"
else
    echo "❌ Build failed!"
    exit 1
fi
EOF

chmod +x tools/scripts/build-custom.sh

Custom Environment Setup

# Add to pre-dev-setup.sh
export CUSTOM_VAR="value"
export PATH="$PATH:./tools/scripts"

📝 Best Practices

  1. Always Check Permissions: Ensure scripts are executable
  2. Use Environment Variables: Set up proper environment configuration
  3. Handle Errors: Scripts should provide clear error messages
  4. Create Backups: Migration scripts should create backups
  5. Test Scripts: Verify scripts work before using in production
  6. Document Changes: Update documentation when modifying scripts

🤝 Contributing

To improve shell scripts:

  1. Add error handling and validation
  2. Improve user feedback and output
  3. Add configuration options
  4. Enhance portability across systems
  5. Add logging and debugging features

📄 License

These scripts are part of the project and follow the same license terms.