Node/Node.psm1

function New-NodeTsProject {
    [CmdletBinding()]
    param (
    )

    $PSNativeCommandUseErrorActionPreference = $true
    $ErrorActionPreference = "Stop"
    Set-StrictMode -Version Latest

    $PSDefaultParameterValues['*:Encoding'] = 'utf8'
    $OutputEncoding = [System.Text.Encoding]::UTF8

    pnpm init
    $packages = @(
        "typescript"
        "@types/node"
        "tsx"
        "vitest"
        "@vitest/ui"
        "@typescript-eslint/parser"
        "@typescript-eslint/eslint-plugin"
        "eslint",
        "husky"
    )
    $packageList = $packages -join ' '
    Invoke-Expression "pnpm i -D $packageList"

    npx tsc --init

    Copy-Item (Join-Path $PSScriptRoot "template-files/eslintrc.sample.json") "./.eslintrc"
    Copy-Item (Join-Path $PSScriptRoot "template-files/editorconfig") "./.editorconfig"

    $packageJson = Get-Content "package.json" -Raw | ConvertFrom-Json
    $packageJson.scripts.psobject.properties.remove('test')
    $packageJson.scripts | Add-Member -MemberType NoteProperty -Name 'start' -Value 'tsx ./index.ts'
    $packageJson.scripts | Add-Member -MemberType NoteProperty -Name 'test' -Value 'vitest'
    $packageJson.scripts | Add-Member -MemberType NoteProperty -Name 'test:ui' -Value 'vitest --ui'
    $packageJson.scripts | Add-Member -MemberType NoteProperty -Name 'lint' -Value 'eslint .'
    $packageJson.scripts | Add-Member -MemberType NoteProperty -Name 'lint:fix' -Value 'eslint . --fix'
    $packageJson | ConvertTo-Json | Out-File "package.json"

    Invoke-WebRequest "https://www.toptal.com/developers/gitignore/api/node,webstorm+all,visualstudiocode" | Select-Object -ExpandProperty "Content" | Out-File ".gitignore"
    "* text=auto" > ".gitattrbutes"
    "console.log('Hello world');" > "index.ts"

    git init

    npx husky init

    git add .
    git commit -m "Initial commit" --no-verify
    git branch -m main
}

Export-ModuleMember -Function New-NodeTsProject