Write-Host "Getting last updated module file..."

$modulesSrcPath = Join-Path $PSScriptRoot "../src/"
$moduleFiles = Get-ChildItem -Path $modulesSrcPath -Recurse -Depth 2 -Filter "*.elx" -ErrorAction Stop
if (-not $moduleFiles) {
    Write-Error "No .elx files found in '$modulesSrcPath'."
    exit 1
}
Write-Host "Found module files:" -ForegroundColor Cyan
$moduleFiles | ForEach-Object { Write-Host " - $($_.FullName)" -ForegroundColor Cyan }
Write-Host "Extracting ELX internals for each module..."

Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "extract-elx-module.psm1") -Force

$moduleFiles | ForEach-Object {
    Save-ElxInternals -ModulePath $_.FullName
}

Write-Host "ELX internals extracted successfully!" -ForegroundColor Green
