Update src/core.ps1
This commit is contained in:
54
src/core.ps1
54
src/core.ps1
@@ -1,3 +1,57 @@
|
||||
# --- core.ps1: ensure functions are available without double-loading ---
|
||||
|
||||
function Ensure-SamyFunctionsLoaded {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
# Pick a "canary" function that DEFINITELY lives in samy.functions.ps1
|
||||
# Replace this with a function name you know is in samy.functions.ps1.
|
||||
$canary = 'Initialize-NuGetProvider'
|
||||
|
||||
if (Get-Command $canary -ErrorAction SilentlyContinue) {
|
||||
# Functions already loaded by bootstrap (or previously in session)
|
||||
return
|
||||
}
|
||||
|
||||
# If SamyFunctionsUrl isn't set, build it from known bases
|
||||
if ([string]::IsNullOrWhiteSpace($Script:SamyFunctionsUrl)) {
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace($Script:ChunkBase)) {
|
||||
# Bootstrap path (matches your chunk downloader)
|
||||
$Script:SamyFunctionsUrl = "$Script:ChunkBase/samy.functions.ps1?raw=1"
|
||||
}
|
||||
elseif (-not [string]::IsNullOrWhiteSpace($Script:SamyGitRepo)) {
|
||||
# Repo base (your config usually sets this)
|
||||
$Script:SamyFunctionsUrl = "$Script:SamyGitRepo/src/samy.functions.ps1?raw=1"
|
||||
}
|
||||
elseif (
|
||||
-not [string]::IsNullOrWhiteSpace($Script:SamyGitURL) -and
|
||||
-not [string]::IsNullOrWhiteSpace($Script:SamyGitBranch)
|
||||
) {
|
||||
# Last-resort rebuild
|
||||
$Script:SamyGitRepo = "$Script:SamyGitURL/$Script:SamyGitBranch"
|
||||
$Script:SamyFunctionsUrl = "$Script:SamyGitRepo/src/samy.functions.ps1?raw=1"
|
||||
}
|
||||
else {
|
||||
throw "SamyFunctionsUrl is empty and no base URL variables are set (ChunkBase/SamyGitRepo/SamyGitURL+SamyGitBranch). Cannot load samy.functions.ps1."
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "[Info] Loading functions from: $Script:SamyFunctionsUrl" -ForegroundColor Cyan
|
||||
|
||||
try {
|
||||
$functionsContent = (Invoke-WebRequest -UseBasicParsing -Uri $Script:SamyFunctionsUrl -ErrorAction Stop).Content
|
||||
. ([ScriptBlock]::Create($functionsContent))
|
||||
}
|
||||
catch {
|
||||
throw "Failed to load samy.functions.ps1 from $Script:SamyFunctionsUrl. $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if (-not (Get-Command $canary -ErrorAction SilentlyContinue)) {
|
||||
throw "Loaded samy.functions.ps1 but '$canary' still wasn't found. The file content may not be what we expect."
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-ScriptAutomationMonkey {
|
||||
|
||||
[CmdletBinding(
|
||||
|
||||
Reference in New Issue
Block a user