<#
.SYNOPSIS
	Builds all Git repositories in a folder
.DESCRIPTION
	This script builds all Git repositories in a given folder.
.PARAMETER ParentDir
	Specifies the path to the folder containing the Git repositories
.EXAMPLE
	PS> ./build-repos C:\MyRepos
.NOTES
	Author: Markus Fleschutz ยท License: CC0
.LINK
	https://github.com/fleschutz/PowerShell
#>

param([string]$ParentDir = "$PWD")

try {
	$StopWatch = [system.diagnostics.stopwatch]::startNew()

	if (-not(test-path "$ParentDir" -pathType container)) { throw "Can't access directory: $ParentDir" }

	$Folders = (get-childItem "$ParentDir" -attributes Directory)
	$FolderCount = $Folders.Count
	$ParentDirName = (get-item "$ParentDir").Name
	"Found $FolderCount subfolders in ๐Ÿ“‚$ParentDirName..."

	[int]$Step = 1
	foreach ($Folder in $Folders) {
		& "$PSScriptRoot/build-repo.ps1" "$Folder"
		$Step++
	}

	[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
	"โœ”๏ธ built $FolderCount Git repositories at ๐Ÿ“‚$ParentDirName in $Elapsed sec"
	exit 0 # success
} catch {
	"โš ๏ธ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}