Last active
          September 18, 2025 19:05 
        
      - 
      
- 
        Save ahmadrosid/85166af57da431f815807dcbf576ba62 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # Migration script to move project files under src/ directory | |
| # This script will move app/, components/, lib/, and styles/ directories into src/ | |
| set -e | |
| echo "π Starting migration to src/ directory structure..." | |
| # Create src directory if it doesn't exist | |
| if [ ! -d "src" ]; then | |
| echo "π Creating src/ directory..." | |
| mkdir src | |
| fi | |
| # Move directories to src/ | |
| directories_to_move=("app" "components" "lib" "styles") | |
| for dir in "${directories_to_move[@]}"; do | |
| if [ -d "$dir" ]; then | |
| echo "π¦ Moving $dir/ to src/$dir/..." | |
| # Check if destination already exists | |
| if [ -d "src/$dir" ]; then | |
| echo "β οΈ src/$dir/ already exists, merging contents..." | |
| # Move contents instead of the directory itself | |
| cp -r "$dir"/* "src/$dir/" 2>/dev/null || true | |
| rm -rf "$dir" | |
| else | |
| mv "$dir" "src/" | |
| fi | |
| else | |
| echo "β οΈ Directory $dir/ not found, skipping..." | |
| fi | |
| done | |
| echo "β Directory migration completed!" | |
| # Update configuration files | |
| echo "π§ Updating configuration files..." | |
| # Update next.config.mjs if it exists | |
| if [ -f "next.config.mjs" ]; then | |
| echo "π Updating next.config.mjs..." | |
| # Add srcDir configuration | |
| if ! grep -q "srcDir" next.config.mjs; then | |
| sed -i.bak 's/const nextConfig = {/const nextConfig = {\n srcDir: ".\/src",/' next.config.mjs | |
| echo " β Added srcDir configuration to next.config.mjs" | |
| fi | |
| fi | |
| # Update tsconfig.json | |
| if [ -f "tsconfig.json" ]; then | |
| echo "π Updating tsconfig.json paths..." | |
| # Backup original file | |
| cp tsconfig.json tsconfig.json.bak | |
| # Update paths in tsconfig.json | |
| cat tsconfig.json | jq '.compilerOptions.paths = { | |
| "@/*": ["./src/*"], | |
| "@/components/*": ["./src/components/*"], | |
| "@/lib/*": ["./src/lib/*"], | |
| "@/app/*": ["./src/app/*"], | |
| "@/styles/*": ["./src/styles/*"] | |
| }' > tsconfig.json.tmp && mv tsconfig.json.tmp tsconfig.json | |
| echo " β Updated tsconfig.json with new path mappings" | |
| fi | |
| # Update tailwind.config.js | |
| if [ -f "tailwind.config.js" ]; then | |
| echo "π Updating tailwind.config.js..." | |
| # Backup original file | |
| cp tailwind.config.js tailwind.config.js.bak | |
| # Update content paths | |
| sed -i.tmp 's|"./app/|"./src/app/|g; s|"./components/|"./src/components/|g; s|"./lib/|"./src/lib/|g' tailwind.config.js | |
| rm tailwind.config.js.tmp | |
| echo " β Updated tailwind.config.js content paths" | |
| fi | |
| # Update package.json scripts if needed | |
| if [ -f "package.json" ]; then | |
| echo "π Checking package.json..." | |
| # Most Next.js scripts should work without changes due to srcDir config | |
| echo " β package.json should work with new structure" | |
| fi | |
| echo "" | |
| echo "π Migration completed successfully!" | |
| echo "" | |
| echo "π Summary of changes:" | |
| echo " β’ Moved app/, components/, lib/, styles/ to src/" | |
| echo " β’ Updated next.config.mjs with srcDir configuration" | |
| echo " β’ Updated tsconfig.json with new path mappings" | |
| echo " β’ Updated tailwind.config.js content paths" | |
| echo "" | |
| echo "π Next steps:" | |
| echo " 1. Test your application: npm run dev" | |
| echo " 2. Update any remaining import paths if needed" | |
| echo " 3. Remove .bak files if everything works correctly" | |
| echo "" | |
| echo "π New project structure:" | |
| echo " src/" | |
| echo " βββ app/" | |
| echo " βββ components/" | |
| echo " βββ lib/" | |
| echo " βββ styles/" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment