Public/Invoke-MkConfig.ps1
|
function Invoke-MkConfig { <# .SYNOPSIS Creates a configuration JSON file in the config directory. .DESCRIPTION Generates a configuration stub based on the selected type: eco, lasso, or project. Creates config directory if missing and avoids overwriting unless -Force is used. .PARAMETER Type Configuration type to generate. Supported values: eco, lasso, project. .PARAMETER Force Overwrites the config file if it already exists. .EXAMPLE mkconfig -Type eco #> [CmdletBinding()] [Alias('mkconfig')] param( [Parameter(Mandatory = $true)] [ValidateSet('eco', 'lasso', 'project')] [string]$Type, [switch]$Force ) $configDir = Join-Path -Path (Get-Location) -ChildPath 'config' if (-not (Test-Path -LiteralPath $configDir)) { New-DtDirectory -Path $configDir -Force:$Force | Out-Null } $fileName = "$Type.config.json" $path = Join-Path -Path $configDir -ChildPath $fileName $obj = switch ($Type) { 'eco' { [ordered]@{ name = 'eco-app' version = '0.1.0' environment = 'dev' telemetry = [ordered]@{ enabled = $false endpoint = 'TODO' } } } 'lasso' { [ordered]@{ name = 'lasso-app' version = '0.1.0' pipeline = [ordered]@{ provider = 'TODO' profile = 'default' } runtime = [ordered]@{ mode = 'local' } } } 'project' { [ordered]@{ name = 'project-name' version = '0.1.0' owner = 'TODO' modules = @() } } } $content = $obj | ConvertTo-Json -Depth 8 Set-DtFileContent -Path $path -Content $content -Force:$Force | Out-Null if (Test-Path -LiteralPath $path) { [System.IO.FileInfo]::new($path) } } |