function Copy-FilesContent {
    param (
        [string]$Directory,
        [string]$OutputFile,
        [switch]$ExcludeDirectories,
        [string[]]$IncludeFiles,
        [switch]$Compress
    )

    # Check if output file already exists and delete if it does
    if (Test-Path -Path $OutputFile) {
        try {
            Remove-Item -Path $OutputFile -Force
            Write-Host "Existing output file removed."
        }
        catch {
            Write-Host "Error deleting $($OutputFile): $($_.Exception.Message)"
            return
        }
    }

    # Create a new output file
    try {
        New-Item -Path $OutputFile -ItemType File -Force | Out-Null
        Write-Host "New output file created."
    }
    catch {
        Write-Host "Error creating $($OutputFile): $($_.Exception.Message)"
        return
    }

    # Files to include by default
    $defaultInclude = @("package.json", "tsconfig.json", ".eslintrc.json")
    $includedFilePaths = @()

    foreach ($fileName in $defaultInclude) {
        $filePath = Join-Path -Path $Directory -ChildPath $fileName
        if (Test-Path -Path $filePath) {
            $includedFilePaths += $filePath
        }
    }

    # Add specified include files
    if ($IncludeFiles) {
        foreach ($fileName in $IncludeFiles) {
            $filePath = Join-Path -Path $Directory -ChildPath $fileName
            if (Test-Path -Path $filePath) {
                $includedFilePaths += $filePath
            }
        }
    }

    # Function to process files
    function Process-File($file) {
        try {
            Add-Content -Path $OutputFile -Value "`n`n// $file"
            $fileContent = Get-Content -Path $file -Raw | Where-Object { $_ -notmatch 'node_modules' -and $_ -notmatch 'webpack' }
            Add-Content -Path $OutputFile -Value $fileContent
        }
        catch {
            Write-Host "Error writing to $($OutputFile): $($_.Exception.Message)"
        }
    }

    # Exclude directories and specific files
    $excludeDirs = @("node_modules", "settings.json", "next.config.js", ".next", "ssr", "vendor-chunks")
    $excludeFiles = @("package-lock.json")

    # Get all files, ensuring exclusions
    Get-ChildItem -Path $Directory -Recurse | ForEach-Object {
        $fileObject = $_
        $fileName = $fileObject.Name
        $filePath = $fileObject.FullName
        $extension = [System.IO.Path]::GetExtension($fileName)

        # Skip processing if it's a directory and ExcludeDirectories is specified
        if ($fileObject.PSIsContainer -and $ExcludeDirectories -and $excludeDirs -contains $fileName) {
            return
        }

        # Skip excluded files and directories
        if ($excludeFiles -contains $fileName -or $excludeDirs -contains $fileObject.Parent) {
            Write-Host "Skipping file: $filePath"
            return
        }

        # Include specific text-based file types
        if ($extension -in @(".tsx", ".js", ".ts", ".config.mjs", ".json", ".alo")) {
            Process-File -file $filePath
        }
    }

    # Also process included file paths
    $includedFilePaths | ForEach-Object {
        Process-File -file $_
    }

    # Compress output if requested
    if ($Compress) {
        try {
            Compress-Archive -Path $OutputFile -DestinationPath "${OutputFile}.zip" -Force
            Write-Host "Output compressed to ${OutputFile}.zip"
        }
        catch {
            Write-Host "Error compressing file: $($_.Exception.Message)"
        }
    }
}

# Example usage
Copy-FilesContent -Directory "." -OutputFile "output.txt" -ExcludeDirectories -IncludeFiles "file1.txt", "file2.txt" -Compress

enhace