Public/New-DevDirectoryAndEnter.ps1

function New-DevDirectoryAndEnter {
    <#
    .SYNOPSIS
    Creates a directory, including nested paths, and changes into it.

    .DESCRIPTION
    Creates the requested directory (and any missing parent segments)
    relative to -BasePath, then sets the current location to it. The path is
    rejected if it is rooted or escapes -BasePath via a '..' segment. Under
    -WhatIf, neither the directory nor the location changes.

    .PARAMETER Path
    Relative directory path to create and enter, e.g. 'src/features/auth'.

    .PARAMETER BasePath
    Directory the path is resolved against. Defaults to the current location.

    .EXAMPLE
    mkcd src/features/auth
    #>

    [CmdletBinding(SupportsShouldProcess = $true)]
    [Alias('mkcd')]
    [OutputType([System.IO.DirectoryInfo])]
    param(
        [Parameter(Mandatory = $true, Position = 0)]
        [string]$Path,

        [Parameter()]
        [string]$BasePath = (Get-Location).Path
    )

    $resolvedPath = Resolve-DtContainedPath -BasePath $BasePath -ChildName $Path

    if (-not $PSCmdlet.ShouldProcess($resolvedPath, 'Create directory and change location')) {
        return
    }

    New-DtDirectory -Path $resolvedPath -Force -Confirm:$false | Out-Null
    Set-Location -LiteralPath $resolvedPath
    Get-Item -LiteralPath $resolvedPath
}