Invoke-MkProj.ps1
|
function Invoke-MkProj { <# .SYNOPSIS Creates a project skeleton in a new or existing directory. .DESCRIPTION Scaffolds a deterministic project structure with src, tests, docs, and config folders, plus .gitignore and README.md. Existing files are not overwritten unless -Force is used. .PARAMETER Name Name of the project folder to create or update. .PARAMETER Template Project template flavor. Supported values: default, webapp, lib. .PARAMETER Force Overwrites generated files if they already exist. .EXAMPLE mkproj -Name SampleApp -Template webapp #> [CmdletBinding()] [Alias('mkproj')] param( [Parameter(Mandatory = $true, Position = 0)] [string]$Name, [ValidateSet('default', 'webapp', 'lib')] [string]$Template = 'default', [switch]$Force ) $projectRoot = Resolve-DtContainedPath -BasePath (Get-Location) -ChildName $Name if (-not (Test-Path -LiteralPath $projectRoot)) { New-DtDirectory -Path $projectRoot -Force:$Force | Out-Null } else { Write-Verbose "Project root already exists: $projectRoot" } foreach ($folder in @('src', 'tests', 'docs', 'config')) { $folderPath = Join-Path -Path $projectRoot -ChildPath $folder New-DtDirectory -Path $folderPath -Force:$Force | Out-Null } $gitignoreContent = @" # Build outputs bin/ obj/ dist/ # Environment .env .venv/ env/ node_modules/ # IDE .vscode/ .idea/ "@ $readmeDescription = switch ($Template) { 'webapp' { 'Web application scaffold generated by DevXToolkit.' } 'lib' { 'Library scaffold generated by DevXToolkit.' } default { 'Project scaffold generated by DevXToolkit.' } } $safeName = ConvertTo-DtSafeMarkdownText -Text $Name $readmeContent = @" # $safeName $readmeDescription ## Setup TODO: Add setup instructions. ## Usage TODO: Add usage examples. ## License TODO: Add license details. "@ Set-DtFileContent -Path (Join-Path $projectRoot '.gitignore') -Content $gitignoreContent -Force:$Force | Out-Null Set-DtFileContent -Path (Join-Path $projectRoot 'README.md') -Content $readmeContent -Force:$Force | Out-Null Write-Verbose "Project scaffold completed at: $projectRoot" Get-Item -LiteralPath $projectRoot } |