Templates/New-ITIDocsSiteTemplate.ps1

<#
.SYNOPSIS
    Creates DocsSite repository structure according to the IT integro project template
 
.DESCRIPTION
    This function creates folders structure, setup files and article template files for product docs site
 
.EXAMPLE
    New-ITIDocsSiteTemplate -ProductName YourProductName -ProductTradeName 'Your Product Trade Name' -Location ~/Desktop/MyProject
 
.NOTES
    The template includes two language subfolders, pl-pl and en-us. Each subfolder includes:
    - docfx.json - docfx configuration file
    - index.md - home page source file
    - .gitignore - gitignore for temp _site folder
    Product docs site directory - for storing product documentation articles
    Scripts directory - for storing build scripts and CI pipeline specification
#>

function New-ITIDocsSiteTemplate {
    [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')]
    param (
        # Product name
        [Parameter(Mandatory = $true)]
        [string] $ProductName,
        # Product trade name
        [Parameter(Mandatory = $true)]
        [string] $ProductTradeName,
        # Specifies the directory where the docs site template will be created
        [string] $Location = './',
        [Parameter()]
        #[ValidateSet('docs.integro.pl','docs-integro.pl')]
        [string] $Server = 'docs-integro.pl',
        [string] $resourceStorage
    )
    $ProductNamePattern = 'ProductName'

    if (-Not(Test-Path $Location)) {
        New-Item -Path $Location -ItemType Directory
    }

    if ($Server -eq "docs.integro.pl") {

        Copy-DirectoryContent -SourceFolder (Join-Path $PSScriptRoot 'DocsSite') -Destination $Location
        Remove-Item -Path (Join-Path $PSScriptRoot 'DocsSite/Scripts/DocsSite_docs-integro.pl_CD.yml')
        Get-ChildItem $Location -File -Recurse |
        Foreach-Object {
            Update-FileContent -FilePath $_.FullName -SearchString $ProductNamePattern -RenameToString $ProductName
            Update-FileContent -FilePath $_.FullName -SearchString 'ProductTradeName' -RenameToString $ProductTradeName
        }
        Get-ChildItem $Location -Directory -Recurse |
        Where-Object { $_.Name -match $ProductNamePattern } |
        Rename-Item -NewName { $_.Name -replace $ProductNamePattern, $ProductName }
    }
    elseif ($Server -eq "docs-integro.pl") {

        Copy-DirectoryContent -SourceFolder (Join-Path $PSScriptRoot 'DocsSite') -Destination $Location
        Remove-Item -Path (Join-Path $Location 'Scripts/DocsSite_docs.integro.pl_CD.yml')
        Get-ChildItem $Location -File -Recurse |
        Foreach-Object {
            Update-FileContent -FilePath $_.FullName -SearchString $ProductNamePattern -RenameToString $ProductName
            Update-FileContent -FilePath $_.FullName -SearchString 'ProductTradeName' -RenameToString $ProductTradeName
            Update-FileContent -FilePath $_.FullName -SearchString 'AzureStorageAccount' -RenameToString $resourceStorage
        }
        Get-ChildItem $Location -Directory -Recurse |
        Where-Object { $_.Name -match $ProductNamePattern } |
        Rename-Item -NewName { $_.Name -replace $ProductNamePattern, $ProductName }
    }
}

Export-ModuleMember -Function New-ITIDocsSiteTemplate