Public/Coding/Install-EdenTemplates.ps1

function Install-EdenTemplates {
    <#
    .SYNOPSIS
        Installs the Eden templates from a GitHub repository into the ./Eden/Templates folder.
    .DESCRIPTION
        Copies the files in either a GitHub repo or a file directory to a folder in the
        ./Eden/Templates folder. The expectation is that the root directory of the GitHub
        repo or the source folder contains folders for each template included in the group.

        Templates are organized into a two folder hierarchy under the Eden/Templates directory:
        './Eden/Templates/TemplateGroup/IndividualTemplate'. The template grouping is to help
        avoid template naming conflicts across different providers. For example you might
        install templates from both an external template development company as well as an internal
        source that contains templates your company has developed. In that case you might have
        a directory that looks like:
        ./Eden
            Templates
                ExternalCompany
                    Template1
                    Template2
                MyCompany
                    Template1
                    Template2

    .EXAMPLE
        PS> Install-EdenTemplates -GroupName MyTemplates -GitHubOrg Eden-CLI -GitHubName AzureDotNet
        or
        PS> e-ctmp -gn MyTemplates -gho Eden-CLI ghn AzureDotNet
        Downloads the https://github.com/Eden-CLI/Eden-Components-AzureDotNet.git repo to a
        './Eden/Tempaltes/MyTemplates' folder.
    .EXAMPLE
        PS> Install-EdenTemplates -GroupName MyTemplates -GroupSource ../MyTemplatesDirectory/MyTemplateGroup
        or
        PS> e-ctmp -gn MyTemplates -gs ../MyTemplatesDirectory/MyTemplateGroup
        Copies the files in
        ../MyTemplatesDirectory/MyTemplateGroup
        to
        ./Eden/Templates/MyTemplates/
    #>

    [CmdletBinding()]
    param(
        # File path to the template groups folder. This is the folder
        # that contains a sub folder for each template.
        [Alias("gs")]
        [String] $GroupSource,
        # Name of the template group to create from the source.
        [Alias("gn")]
        [String] $GroupName,
        # Name of the GitHub repo from which to copy the templates.
        [Alias("ghn")]
        [String] $GitHubName,
        # Name of the GitHub org from which to copy the templates.
        [Alias("gho")]
        [String] $GitHubOrg,
        # Causes the system to proceed and overwrite an existing template group
        # folder if one exists. Otherwise, if a folder with the template group
        # name already exists, the install command will error out.
        [Alias("f")]
        [Switch] $Force
    )

    $location = Get-Location

    try {

        $loggingPrefix = "Eden Coding"

        # If the source is a GiHub repo.
        if ($Source.EndsWith(".git")) {
            # If the name is null, retrieve the name from the leaf folder name by
            # removing the prepending 'Eden-Components-' string.
            if ([String]::IsNullOrEmpty($Name)) {
                $Name = $Source.Substring($Source.LastIndexOf('/') + 1, $Source.Length - ($Source.LastIndexOf("/") + 5))
            }
            # Create the Eden templates directory if it does not already exist.
            if (!(Test-Path "./Eden/Temlpates")) {
                New-Item -ItemType Direcotry -Name "./Eden/Templates" -Force
            }
            Set-Location "./Eden/Templates" -ErrorAction Stop

            if ((Test-Path "./$Name")) {
                if ($Force) {
                    Remove-Item "./$Name/*" -Force -Recurse
                    Remove-Item "./$Name" -Force -Recurse
                }
                else {
                    Write-EdenError "The templates have already been installed." $loggingPrefix
                    return
                }
            }
            Copy-GitRepo $Source $Name $loggingPrefix
        }
        else # the Source is a file folder.
        {
            Write-EdenInfo "Installing Eden service templates from '$Source'" $loggingPrefix

            # If the name is null, retrieve the name from the leaf folder name by
            # removing the prepending 'Eden-Components-' string.
            if ($null -eq $Name) {
                $Name = Split-Path $Source -Leaf
            }

            New-Item "./Eden/Templates" -ItemType Directory -Name $Name
            [String] $destinationDirectory = "./Eden/Templates/$Name"
            Copy-Item $Source -Destination $destinationDirectory -Force -Recurse -Verbose

            Write-EdenInfo "Finished creating a new Eden service." $loggingPrefix
        }
    }
    catch {
        Write-EdenError "Error installing Eden templates. Message: '$($_.Exception.Message)'" $loggingPrefix
    }
    finally {
        Set-Location $location
    }
}
New-Alias `
    -Name e-ctmp `
    -Value Install-EdenTemplates `
    -Force