From 0fe463338abc9604a90bbf8b390a8bea3c888f23 Mon Sep 17 00:00:00 2001 From: Pier-Paolo Mammi Date: Tue, 26 May 2026 13:36:48 +0200 Subject: [PATCH] add more scripts to automatically update: - last updated elx file - all elx files --- extract-elx-internals-all.bat | 10 +++ extract-elx-internals-last-updated.bat | 10 +++ scripts/extract-elx-internals-all.ps1 | 19 +++++ .../extract-elx-internals-last-updated.ps1 | 16 +++++ scripts/extract-elx-internals.ps1 | 71 ++----------------- scripts/extract-elx-module.psm1 | 35 +++++++++ 6 files changed, 97 insertions(+), 64 deletions(-) create mode 100644 extract-elx-internals-all.bat create mode 100644 extract-elx-internals-last-updated.bat create mode 100644 scripts/extract-elx-internals-all.ps1 create mode 100644 scripts/extract-elx-internals-last-updated.ps1 create mode 100644 scripts/extract-elx-module.psm1 diff --git a/extract-elx-internals-all.bat b/extract-elx-internals-all.bat new file mode 100644 index 0000000..efb5242 --- /dev/null +++ b/extract-elx-internals-all.bat @@ -0,0 +1,10 @@ +@echo off +SETLOCAL EnableDelayedExpansion +echo %cmdcmdline% | findstr /i /c:"%~nx0" >NUL && set iscommandline=1 +echo %PSModulePath% | findstr /i /c:"%USERPROFILE%" >NUL && set ispowershell=1 +cd /D "%~dp0" + +@powershell -NoProfile -ExecutionPolicy Bypass -Command .\scripts\extract-elx-internals-all.ps1 + +IF DEFINED iscommandline IF NOT DEFINED ispowershell pause +ENDLOCAL diff --git a/extract-elx-internals-last-updated.bat b/extract-elx-internals-last-updated.bat new file mode 100644 index 0000000..e953cd8 --- /dev/null +++ b/extract-elx-internals-last-updated.bat @@ -0,0 +1,10 @@ +@echo off +SETLOCAL EnableDelayedExpansion +echo %cmdcmdline% | findstr /i /c:"%~nx0" >NUL && set iscommandline=1 +echo %PSModulePath% | findstr /i /c:"%USERPROFILE%" >NUL && set ispowershell=1 +cd /D "%~dp0" + +@powershell -NoProfile -ExecutionPolicy Bypass -Command .\scripts\extract-elx-internals-last-updated.ps1 + +IF DEFINED iscommandline IF NOT DEFINED ispowershell pause +ENDLOCAL diff --git a/scripts/extract-elx-internals-all.ps1 b/scripts/extract-elx-internals-all.ps1 new file mode 100644 index 0000000..abc8eeb --- /dev/null +++ b/scripts/extract-elx-internals-all.ps1 @@ -0,0 +1,19 @@ +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 diff --git a/scripts/extract-elx-internals-last-updated.ps1 b/scripts/extract-elx-internals-last-updated.ps1 new file mode 100644 index 0000000..2ab2d72 --- /dev/null +++ b/scripts/extract-elx-internals-last-updated.ps1 @@ -0,0 +1,16 @@ +Write-Host "Getting last updated module file..." + +$modulesSrcPath = Join-Path $PSScriptRoot "../src/" +$moduleFile = Get-ChildItem -Path $modulesSrcPath -Recurse -Filter "*.elx" -ErrorAction Stop | Sort-Object LastWriteTime -Descending | Select-Object -First 1 +if (-not $moduleFile) { + Write-Error "No .elx file found in '$modulesSrcPath'." + exit 1 +} +Write-Host "Latest updated module file found: '$($moduleFile.FullName)'" -ForegroundColor Cyan +Write-Host "Extracting ELX internals for module tag '$($moduleFile.FullName)'..." + +Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "extract-elx-module.psm1") -Force + +Save-ElxInternals -ModulePath $moduleFile.FullName + +Write-Host "ELX internals extracted successfully!" -ForegroundColor Green diff --git a/scripts/extract-elx-internals.ps1 b/scripts/extract-elx-internals.ps1 index f5347f7..1573514 100644 --- a/scripts/extract-elx-internals.ps1 +++ b/scripts/extract-elx-internals.ps1 @@ -1,77 +1,20 @@ -# If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { -# #"No Administrative rights, it will display a popup window asking user for Admin rights" -# $arguments = "-NoProfile -ExecutionPolicy Bypass -Command & '" + $myinvocation.mycommand.definition + "'" -# Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments #-WindowStyle Hidden -# break -# } - -# # Set execution policy remotesigned machine wide -# try { -# Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -InformationAction SilentlyContinue -# } -# catch { -# # Suppress -# } - -# # Load Environment Setup Module -# $envSetupModulePath = $(Join-Path $PSScriptRoot "EnvironmentSetup.psm1") -# if (-not (Test-Path $envSetupModulePath)) { -# Write-Warning "Environment Setup Module file '$($envSetupModulePath)' not found!" -# Write-Host -# exit 1 -# } -# Import-Module -Force $envSetupModulePath - [CmdletBinding()] param( [Parameter(Mandatory=$false)][string]$ModuleTag ) -Write-Host "Extracting ELX internals for module tag $ModuleTag..." -ForegroundColor Cyan -Write-Host "Switching to ELX Tools directory..." -ForegroundColor DarkGray - -$extractElxToolsScriptPath = Join-Path $PSScriptRoot "../tools/extract-elx/" -Push-Location -StackName ElxTools $extractElxToolsScriptPath - -Write-Host "Identifying module file..." -ForegroundColor DarkGray - +Write-Host "Checking module file existence..." $modulesSrcPath = Join-Path $PSScriptRoot "../src/$($ModuleTag)" -$moduleFile = Get-childitem -Path $modulesSrcPath -Filter "*.elx" -ErrorAction Stop | Select-Object -First 1 +$moduleFile = Get-ChildItem -Path $modulesSrcPath -Filter "*.elx" -ErrorAction Stop | Select-Object -First 1 if (-not $moduleFile) { Write-Error "No .elx file found in '$modulesSrcPath'." exit 1 } +Write-Host "Module file found: '$($moduleFile.FullName)'" -ForegroundColor Cyan +Write-Host "Extracting ELX internals for module tag '$($moduleFile.FullName)'..." -Write-Host "Module file found: $moduleFile" -ForegroundColor Gray -Write-Host "Installing Node.js dependencies for the ELX Tools..." -ForegroundColor DarkGray +Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "extract-elx-module.psm1") -Force -# Install Node.js dependencies for the ELX Tools -& npm install -if ($LASTEXITCODE -ne 0) { - Write-Error "npm install failed with exit code $LASTEXITCODE." - exit 1 -} +Save-ElxInternals -ModulePath $moduleFile.FullName -Write-Host "Node.js dependencies installed successfully!" -ForegroundColor DarkGray -Write-Host "Executing ELX extraction..." -ForegroundColor DarkGray - -& node "extract-elx.js" $moduleFile.FullName --clean -if ($LASTEXITCODE -ne 0) { - Write-Error "ELX extraction failed with exit code $LASTEXITCODE." - exit 1 -} - -Write-Host "ELX extraction completed successfully!" -ForegroundColor DarkGray - -Pop-Location -StackName ElxTools - -Write-Host "ELX internals extracted successfully!" -ForegroundColor Cyan - -# do { -# Write-Host "To complete the intallations you need to restart your computer" -ForegroundColor Cyan -# Write-Host "do you want to restart? [Y/n]" -ForegroundColor Cyan -# $key = ([console]::ReadKey()).Key.ToString().ToUpper() -# if ($key -eq 'Y') { -# Restart-Computer -# } -# } while ($key -ne 'N' -and $key -ne 'Y') +Write-Host "ELX internals extracted successfully!" -ForegroundColor Green diff --git a/scripts/extract-elx-module.psm1 b/scripts/extract-elx-module.psm1 new file mode 100644 index 0000000..ef5733e --- /dev/null +++ b/scripts/extract-elx-module.psm1 @@ -0,0 +1,35 @@ +function Save-ElxInternals { + param( + [ValidateScript({ Test-Path $_ -PathType Leaf })][Parameter(Mandatory)]$ModulePath + ) + + Write-Host "Switching to ELX Tools directory..." + + $extractElxToolsScriptPath = Join-Path $PSScriptRoot "../tools/extract-elx/" + Push-Location -StackName ElxTools $extractElxToolsScriptPath + + Write-Host "Installing Node.js dependencies for the ELX Tools..." + + # Install Node.js dependencies for the ELX Tools + & npm install + if ($LASTEXITCODE -ne 0) { + Write-Error "npm install failed with exit code $LASTEXITCODE." + exit 1 + } + + Write-Host "Node.js dependencies installed successfully!" -ForegroundColor Cyan + Write-Host "Executing ELX extraction..." + + & node "extract-elx.js" $ModulePath --clean + if ($LASTEXITCODE -ne 0) { + Write-Error "ELX extraction failed with exit code $LASTEXITCODE." + exit 1 + } + + Write-Host "ELX extraction completed successfully!" -ForegroundColor Green + Write-Host "Switching back to original directory..." + + Pop-Location -StackName ElxTools +} + +Export-ModuleMember -Function Save-ElxInternals