[CmdletBinding()]
param($Repository = "$Env:ProgramData\UniversalAutomation\Repository")
function Import-Folder {
param($Path)
Write-Verbose "Importing $Path"
$Excluded = @(".universal", ".git", "dashboards", "pages", "modules")
foreach ($Exclusion in $Excluded) {
Write-Verbose "Testing $Path against $Exclusion"
if (Test-Folder -Path $Path -Exclusion $Exclusion) {
Write-Verbose "Excluding $Path"
return
}
}
Get-ChildItem -Path $Path | ForEach-Object {
if ($_.PSIsContainer) {
Write-Verbose "Importing Folder $($_.FullName)"
Import-Folder -Path $_.FullName
}
else {
Write-Verbose "Importing Script $($_.FullName)"
Import-Script -Path $_.FullName
}
}
}
function Test-Folder {
param($Path, $Exclusion)
$ExclusionPath = Join-Path $Repository $Exclusion
$Path -eq $ExclusionPath
}
function Import-Script {
param($Path)
$RelativePath = $Path.Replace($Repository, "").TrimStart("\")
$Line = "New-PSUScript -Name '$($Path | Split-Path -Leaf)' -Path '$RelativePath'"
$Universal = "$Repository\.universal"
if (-not (Test-Path $Universal)) {
Write-Verbose "Creating $Universal"
New-Item -ItemType Directory -Path $Universal
}
Write-Verbose "Writing $Line to $Universal\scripts.ps1"
$Line | Out-File "$Universal\scripts.ps1" -Append
}
Import-Folder -Path $Repository