StrasbourgTransport.psm1
|
<# .SYNOPSIS Imports classes and functions, defines module-scope variables #> param ( [String] $CtsApiKey ) # Dot-source PowerShell scripts $Classes = Get-ChildItem -Path ($PSScriptRoot | Join-Path -ChildPath 'Classes') -Include '*.ps1' -Recurse $Functions = Get-ChildItem -Path ($PSScriptRoot | Join-Path -ChildPath 'Functions') -Include '*.ps1' -Recurse @($Classes) + @($Functions) | ForEach-Object { . $_.FullName } # Export custom types $ExportableTypes = @( [Stop], [Departure] ) $TypeAcceleratorsClass = [PSCustomObject].Assembly.GetType('System.Management.Automation.TypeAccelerators') $ExportableTypes = $ExportableTypes | ForEach-Object { if ($_.FullName -notin $TypeAcceleratorsClass::Get.Keys) { $TypeAcceleratorsClass::Add($_.FullName, $_) $_ } else { Write-Warning -Message "StrasbourgTransport: Type accelerator already exists for type '$($_.FullName)'" } } $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { $null = $ExportableTypes | ForEach-Object { $TypeAcceleratorsClass::Remove($_.FullName) } }.GetNewClosure() # CTS API token $CtsApiKeyPath = $PSScriptRoot | Join-Path -ChildPath '.cts-api.key' if ($CtsApiKey) { Set-Content -Path $CtsApiKeyPath -Value $CtsApiKey -Force } else { $CtsApiKey = Get-Content -Path $CtsApiKeyPath -ErrorAction SilentlyContinue | Select-Object -First 1 } if (-not $CtsApiKey) { Write-Warning -Message 'Missing CTS API token!' Write-Warning -Message "Set your token in '$CtsApiKeyPath' or import the module with: -ArgumentList <your-token>" } Set-Variable -Name CtsApiToken -Value $CtsApiKey -Option Constant -Visibility Private -Scope Local # Pre-load stop cache Update-CtsStopCache -ErrorAction SilentlyContinue |