modules/devops/Write-IdeConfig.ps1

param(
    [string]$ProjectName,
    [string]$OutputPath,
    [string]$IdeConfig
)

if ($IdeConfig -ne "VSCode") { return }

. (Join-Path (Split-Path $MyInvocation.MyCommand.Path) "..\core\Utils.ps1")
$base = Join-Path $OutputPath ".vscode"

function Write-File($rel, $con) { Write-CoreFile (Join-Path $base $rel) $con }
function T($t) { $t.Replace("{P}", $ProjectName) }

# launch.json
Write-File "launch.json" (T @'
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (WebApi)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/src/{P}.WebApi/bin/Debug/net8.0/{P}.WebApi.dll",
            "args": [],
            "cwd": "${workspaceFolder}/src/{P}.WebApi",
            "stopAtEntry": false,
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        }
    ]
}
'@
)

# tasks.json
Write-File "tasks.json" (T @'
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/{P}.sln",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "docker-up",
            "type": "shell",
            "command": "docker-compose up -d --build",
            "presentation": {
                "reveal": "always",
                "panel": "new"
            }
        },
        {
            "label": "docker-down",
            "type": "shell",
            "command": "docker-compose down",
            "presentation": {
                "reveal": "always"
            }
        }
    ]
}
'@
)

# extensions.json
Write-File "extensions.json" @'
{
    "recommendations": [
        "ms-dotnettools.csharp",
        "ms-dotnettools.vscode-dotnet-runtime",
        "ms-azuretools.vscode-docker",
        "dbaeumer.vscode-eslint",
        "esbenp.prettier-vscode"
    ]
}
'@