cleanarch.psm1

# cleanarch.psm1

$ScriptRoot = $PSScriptRoot

# UTF-8 encoding (Türkçe karakter desteği)
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding            = [System.Text.Encoding]::UTF8

function cleanarch-new {
    [CmdletBinding()]
    param(
        [string]$ProjectName = "",
        [ValidateSet("Dapper","EFCore","Hybrid","")]
        [string]$OrmMode = "",
        [ValidateSet("ReactTS","ReactJS","NextJS","")]
        [string]$FrontendMode = "",
        [string[]]$Entities = @("User", "Product"),
        [ValidateSet("MSSQL","Postgres","SQLite")]
        [string]$DbProvider = "",
        [string]$OutputRootPath = "",
        [switch]$SkipFrontend,
        [switch]$SkipAiGuide,
        [switch]$SkipTests,
        [switch]$SkipCi,
        [switch]$DryRun,
        [string]$IdeConfig = "VSCode",
        [switch]$Observability,
        [switch]$NonInteractive,
        [switch]$I18n,
        [ValidateSet("GitHub","GitLab","None")]
        [string]$CiProvider = "GitHub",
        [ValidateSet("tr","en")]
        [string]$Language = "tr",
        [ValidateSet("Web","Mobile","Both","")]
        [string]$Platform = "",
        [ValidateSet("Layered","FeatureSliced")]
        [string]$Architecture = "Layered",
        [ValidateSet("Expo")]
        [string]$MobileTooling = "Expo",
        [switch]$SkipNpm,
        [string]$ConnectionString = "",
        [switch]$Version,
        [Alias("h")]
        [switch]$Help
    )

    & "$ScriptRoot\cleanarch-new.ps1" @PSBoundParameters
}

function cleanarch-version {
    [CmdletBinding()]
    param(
        [switch]$Full,
        [switch]$OnlyVersion,
        [Alias("h")]
        [switch]$Help
    )
    & "$ScriptRoot\modules\core\cleanarch-version.ps1" @PSBoundParameters
}

function cleanarch-update {
    [CmdletBinding()]
    param(
        [Alias("h")]
        [switch]$Help
    )
    if ($Help) {
        Write-Host ""
        Write-Host " cleanarch-update" -ForegroundColor Cyan
        Write-Host " ----------------" -ForegroundColor DarkCyan
        Write-Host " Modulunu PowerShell Gallery uzerinden en son surume gunceller."
        Write-Host ""
        return
    }
    Write-Host "cleanarch modülü PowerShell Gallery üzerinden güncelleniyor..." -ForegroundColor Cyan
    Update-Module -Name cleanarch -Force -ErrorAction Stop
    Write-Host "Güncelleme tamamlandı! Yeni versiyonu kontrol etmek için 'cleanarch-version' çalıştırabilirsiniz." -ForegroundColor Green
}

function cleanarch-uninstall {
    [CmdletBinding()]
    param(
        [Alias("h")]
        [switch]$Help
    )
    if ($Help) {
        Write-Host ""
        Write-Host " cleanarch-uninstall" -ForegroundColor Cyan
        Write-Host " -------------------" -ForegroundColor DarkCyan
        Write-Host " Modulunu sistemden tamamen kaldirir."
        Write-Host ""
        return
    }
    Write-Host "cleanarch modülü sistemden kaldırılıyor..." -ForegroundColor Yellow
    
    # PowerShell profilinden eski wrapper fonksiyonları varsa temizle
    if (Test-Path $PROFILE) {
        $profileContent = Get-Content $PROFILE -Raw -ErrorAction SilentlyContinue
        if ($profileContent) {
            $cleaned = $profileContent -replace "(?s)\r?\nfunction New-CleanProject \{.*?\}\r?\n", ""
            $cleaned = $cleaned -replace "(?s)\r?\nfunction Update-Generator \{.*?\}\r?\n", ""
            $cleaned = $cleaned -replace "(?s)\r?\nfunction Get-GeneratorVersion \{.*?\}\r?\n", ""
            $cleaned = $cleaned -replace "(?s)\r?\nfunction Uninstall-Generator \{.*?\}\r?\n", ""
            $cleaned = $cleaned -replace "(?s)\r?\nfunction cleanarch-new \{.*?\}\r?\n", ""
            $cleaned = $cleaned -replace "(?s)\r?\nfunction cleanarch-version \{.*?\}\r?\n", ""
            $cleaned = $cleaned -replace "(?s)\r?\nfunction cleanarch-update \{.*?\}\r?\n", ""
            $cleaned = $cleaned -replace "(?s)\r?\nfunction cleanarch-uninstall \{.*?\}\r?\n", ""
            [System.IO.File]::WriteAllText($PROFILE, $cleaned.TrimEnd() + "`n")
        }
    }
    
    # Modülü uninstall et
    Uninstall-Module -Name cleanarch -AllVersions -Force -ErrorAction SilentlyContinue
    
    # Mevcut oturumdan fonksiyonları kaldır
    Remove-Item Function:\cleanarch-new -ErrorAction SilentlyContinue
    Remove-Item Function:\cleanarch-version -ErrorAction SilentlyContinue
    Remove-Item Function:\cleanarch-update -ErrorAction SilentlyContinue
    Remove-Item Function:\cleanarch-uninstall -ErrorAction SilentlyContinue
    
    Write-Host "cleanarch modülü başarıyla kaldırıldı." -ForegroundColor Green
}

Export-ModuleMember -Function cleanarch-new, cleanarch-version, cleanarch-update, cleanarch-uninstall