-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdev.ps1
More file actions
1 lines (1 loc) · 11.4 KB
/
dev.ps1
File metadata and controls
1 lines (1 loc) · 11.4 KB
1
# Aspekt Development Scripts\n# PowerShell scripts for local development, testing, and package management\n\nparam(\n [Parameter(Position=0)]\n [ValidateSet('build', 'test', 'pack', 'clean', 'format', 'restore', 'publish-local', 'help')]\n [string]$Command = 'help',\n \n [Parameter()]\n [ValidateSet('Debug', 'Release')]\n [string]$Configuration = 'Release',\n \n [Parameter()]\n [string]$OutputPath = './nupkgs',\n \n [Parameter()]\n [switch]$Verbose\n)\n\n# Colors for output\n$ErrorColor = 'Red'\n$SuccessColor = 'Green'\n$InfoColor = 'Cyan'\n$WarningColor = 'Yellow'\n\nfunction Write-Info($Message) {\n Write-Host \"[INFO] $Message\" -ForegroundColor $InfoColor\n}\n\nfunction Write-Success($Message) {\n Write-Host \"[SUCCESS] $Message\" -ForegroundColor $SuccessColor\n}\n\nfunction Write-Error($Message) {\n Write-Host \"[ERROR] $Message\" -ForegroundColor $ErrorColor\n}\n\nfunction Write-Warning($Message) {\n Write-Host \"[WARNING] $Message\" -ForegroundColor $WarningColor\n}\n\nfunction Test-DotNetVersion {\n try {\n $version = dotnet --version\n Write-Info \"Using .NET SDK version: $version\"\n \n # Check if version is 6.0 or later\n $versionNumber = [Version]::Parse($version.Split('-')[0])\n if ($versionNumber -lt [Version]::Parse(\"6.0.0\")) {\n Write-Error \"Aspekt requires .NET SDK 6.0 or later. Current version: $version\"\n return $false\n }\n return $true\n }\n catch {\n Write-Error \"Could not determine .NET SDK version. Is .NET SDK installed?\"\n return $false\n }\n}\n\nfunction Invoke-Restore {\n Write-Info \"Restoring NuGet packages...\"\n \n $restoreArgs = @('restore', 'Aspekt.sln')\n if ($Verbose) { $restoreArgs += '--verbosity', 'detailed' }\n \n & dotnet @restoreArgs\n \n if ($LASTEXITCODE -eq 0) {\n Write-Success \"Package restore completed successfully\"\n return $true\n } else {\n Write-Error \"Package restore failed with exit code $LASTEXITCODE\"\n return $false\n }\n}\n\nfunction Invoke-Build {\n Write-Info \"Building solution in $Configuration configuration...\"\n \n $buildArgs = @('build', 'Aspekt.sln', '--configuration', $Configuration, '--no-restore')\n if ($Verbose) { $buildArgs += '--verbosity', 'detailed' }\n \n & dotnet @buildArgs\n \n if ($LASTEXITCODE -eq 0) {\n Write-Success \"Build completed successfully\"\n return $true\n } else {\n Write-Error \"Build failed with exit code $LASTEXITCODE\"\n return $false\n }\n}\n\nfunction Invoke-Test {\n Write-Info \"Running tests...\"\n \n $testProjects = @(\n 'Aspekt.Test/Aspekt.Test.csproj',\n 'Aspekt.Bootstrap.Test/Aspekt.Bootstrap.Test.csproj',\n 'Aspekt.Foundation.Test/Aspekt.Foundation.Test.csproj',\n 'Aspekt.Logging.Test/Aspekt.Logging.Test.csproj'\n )\n \n $allPassed = $true\n \n foreach ($project in $testProjects) {\n if (Test-Path $project) {\n Write-Info \"Testing $project...\"\n \n $testArgs = @('test', $project, '--configuration', $Configuration, '--no-build')\n if ($Verbose) { $testArgs += '--verbosity', 'detailed' }\n $testArgs += '--logger', 'trx', '--results-directory', 'TestResults'\n \n & dotnet @testArgs\n \n if ($LASTEXITCODE -eq 0) {\n Write-Success \"Tests passed for $project\"\n } else {\n Write-Error \"Tests failed for $project (exit code: $LASTEXITCODE)\"\n $allPassed = $false\n }\n } else {\n Write-Warning \"Test project not found: $project\"\n }\n }\n \n if ($allPassed) {\n Write-Success \"All tests passed successfully\"\n return $true\n } else {\n Write-Error \"One or more test projects failed\"\n return $false\n }\n}\n\nfunction Invoke-Pack {\n Write-Info \"Creating NuGet packages...\"\n \n # Ensure output directory exists\n if (!(Test-Path $OutputPath)) {\n New-Item -ItemType Directory -Path $OutputPath -Force | Out-Null\n Write-Info \"Created output directory: $OutputPath\"\n }\n \n $packProjects = @(\n 'Aspekt/Aspekt.csproj',\n 'Aspekt.Contracts/Aspekt.Contracts.csproj',\n 'Aspekt.Logging/Aspekt.Logging.csproj'\n )\n \n $allPacked = $true\n \n foreach ($project in $packProjects) {\n if (Test-Path $project) {\n Write-Info \"Packing $project...\"\n \n $packArgs = @('pack', $project, '--configuration', $Configuration, '--no-build', '--output', $OutputPath)\n if ($Verbose) { $packArgs += '--verbosity', 'detailed' }\n \n & dotnet @packArgs\n \n if ($LASTEXITCODE -eq 0) {\n Write-Success \"Successfully packed $project\"\n } else {\n Write-Error \"Failed to pack $project (exit code: $LASTEXITCODE)\"\n $allPacked = $false\n }\n } else {\n Write-Warning \"Project not found: $project\"\n }\n }\n \n if ($allPacked) {\n Write-Success \"All packages created successfully in $OutputPath\"\n \n # List created packages\n $packages = Get-ChildItem -Path $OutputPath -Filter \"*.nupkg\" | Sort-Object Name\n if ($packages) {\n Write-Info \"Created packages:\"\n foreach ($package in $packages) {\n Write-Host \" - $($package.Name)\" -ForegroundColor $SuccessColor\n }\n }\n return $true\n } else {\n Write-Error \"One or more packages failed to create\"\n return $false\n }\n}\n\nfunction Invoke-Clean {\n Write-Info \"Cleaning solution...\"\n \n # Clean dotnet artifacts\n & dotnet clean Aspekt.sln --configuration $Configuration\n \n # Remove common build artifacts\n $cleanPaths = @(\n 'bin', 'obj', 'TestResults', 'nupkgs', 'packages'\n )\n \n foreach ($path in $cleanPaths) {\n if (Test-Path $path) {\n Write-Info \"Removing $path...\"\n Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue\n }\n }\n \n # Find and remove nested bin/obj folders\n Get-ChildItem -Path . -Recurse -Directory -Name 'bin', 'obj' | ForEach-Object {\n $fullPath = Join-Path (Get-Location) $_\n if (Test-Path $fullPath) {\n Write-Info \"Removing nested folder: $fullPath\"\n Remove-Item -Path $fullPath -Recurse -Force -ErrorAction SilentlyContinue\n }\n }\n \n Write-Success \"Clean completed\"\n return $true\n}\n\nfunction Invoke-Format {\n Write-Info \"Formatting code...\"\n \n $formatArgs = @('format', 'Aspekt.sln')\n if ($Verbose) { $formatArgs += '--verbosity', 'detailed' }\n \n & dotnet @formatArgs\n \n if ($LASTEXITCODE -eq 0) {\n Write-Success \"Code formatting completed\"\n return $true\n } else {\n Write-Error \"Code formatting failed with exit code $LASTEXITCODE\"\n return $false\n }\n}\n\nfunction Invoke-PublishLocal {\n Write-Info \"Publishing packages to local NuGet cache...\"\n \n $packages = Get-ChildItem -Path $OutputPath -Filter \"*.nupkg\" -ErrorAction SilentlyContinue\n \n if (!$packages) {\n Write-Warning \"No packages found in $OutputPath. Run 'pack' command first.\"\n return $false\n }\n \n $allPublished = $true\n \n foreach ($package in $packages) {\n Write-Info \"Installing $($package.Name) to local cache...\"\n \n # Add to local NuGet cache\n $source = \"https://api.nuget.org/v3/index.json\"\n & dotnet nuget push $package.FullName --source $env:USERPROFILE\\.nuget\\packages --skip-duplicate\n \n if ($LASTEXITCODE -eq 0) {\n Write-Success \"Successfully installed $($package.Name) to local cache\"\n } else {\n Write-Error \"Failed to install $($package.Name) (exit code: $LASTEXITCODE)\"\n $allPublished = $false\n }\n }\n \n if ($allPublished) {\n Write-Success \"All packages published to local cache\"\n Write-Info \"You can now reference these packages in other projects\"\n }\n \n return $allPublished\n}\n\nfunction Show-Help {\n Write-Host @\"\n🚀 Aspekt Development Script\n============================\n\nUsage: .\\dev.ps1 [command] [-Configuration <Debug|Release>] [-OutputPath <path>] [-Verbose]\n\nCommands:\n help Show this help message\n restore Restore NuGet packages\n build Build the solution\n test Run all tests\n pack Create NuGet packages\n clean Clean build artifacts\n format Format code using dotnet format\n publish-local Install packages to local NuGet cache\n\nParameters:\n -Configuration Build configuration (Debug|Release, default: Release)\n -OutputPath Output path for packages (default: ./nupkgs)\n -Verbose Enable verbose output\n\nExamples:\n .\\dev.ps1 build\n .\\dev.ps1 test -Configuration Debug\n .\\dev.ps1 pack -OutputPath \"C:\\packages\"\n .\\dev.ps1 clean\n\nWorkflow:\n 1. .\\dev.ps1 restore\n 2. .\\dev.ps1 build\n 3. .\\dev.ps1 test\n 4. .\\dev.ps1 pack\n\n\"@ -ForegroundColor $InfoColor\n}\n\n# Main execution\nfunction Main {\n Write-Info \"Aspekt Development Script - Command: $Command\"\n \n if ($Command -ne 'help' -and $Command -ne 'clean') {\n if (!(Test-DotNetVersion)) {\n exit 1\n }\n }\n \n switch ($Command.ToLower()) {\n 'restore' {\n $success = Invoke-Restore\n exit $(if ($success) { 0 } else { 1 })\n }\n 'build' {\n $restoreSuccess = Invoke-Restore\n if ($restoreSuccess) {\n $buildSuccess = Invoke-Build\n exit $(if ($buildSuccess) { 0 } else { 1 })\n } else {\n exit 1\n }\n }\n 'test' {\n $restoreSuccess = Invoke-Restore\n $buildSuccess = if ($restoreSuccess) { Invoke-Build } else { $false }\n if ($buildSuccess) {\n $testSuccess = Invoke-Test\n exit $(if ($testSuccess) { 0 } else { 1 })\n } else {\n exit 1\n }\n }\n 'pack' {\n $restoreSuccess = Invoke-Restore\n $buildSuccess = if ($restoreSuccess) { Invoke-Build } else { $false }\n if ($buildSuccess) {\n $packSuccess = Invoke-Pack\n exit $(if ($packSuccess) { 0 } else { 1 })\n } else {\n exit 1\n }\n }\n 'clean' {\n $cleanSuccess = Invoke-Clean\n exit $(if ($cleanSuccess) { 0 } else { 1 })\n }\n 'format' {\n $formatSuccess = Invoke-Format\n exit $(if ($formatSuccess) { 0 } else { 1 })\n }\n 'publish-local' {\n $publishSuccess = Invoke-PublishLocal\n exit $(if ($publishSuccess) { 0 } else { 1 })\n }\n 'help' {\n Show-Help\n exit 0\n }\n default {\n Write-Error \"Unknown command: $Command\"\n Show-Help\n exit 1\n }\n }\n}\n\n# Execute main function\nMain