Scripts
- set minimum PowerShell usage version to 7.4 - replace npx env-cmd with PS Environment option - move latest downloaded file by Selenium to module folder - cleanup code
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ IF "%~1"=="" (
|
|||||||
set ModuleTag=%~1
|
set ModuleTag=%~1
|
||||||
)
|
)
|
||||||
|
|
||||||
@powershell -NoProfile -ExecutionPolicy Bypass -Command .\scripts\export-elx.ps1 -ModuleTag %ModuleTag%
|
@pwsh -NoProfile -ExecutionPolicy Bypass -Command .\scripts\export-elx.ps1 -ModuleTag %ModuleTag%
|
||||||
|
|
||||||
IF DEFINED iscommandline IF NOT DEFINED ispowershell pause
|
IF DEFINED iscommandline IF NOT DEFINED ispowershell pause
|
||||||
ENDLOCAL
|
ENDLOCAL
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Script-level parameters and cmdlet binding to support -Verbose and common parameters
|
# Script-level parameters and cmdlet binding to support -Verbose and common parameters
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
[switch]$Quiet
|
[switch]$Quiet = $false
|
||||||
)
|
)
|
||||||
|
|
||||||
function Write-LogMessage {
|
function Write-LogMessage {
|
||||||
@@ -56,6 +56,16 @@ function New-EnvFileContent {
|
|||||||
[ValidateNotNullOrEmpty()][Parameter(Mandatory)][string]$ModuleTag
|
[ValidateNotNullOrEmpty()][Parameter(Mandatory)][string]$ModuleTag
|
||||||
)
|
)
|
||||||
|
|
||||||
|
$envValues = Get-EnvironmentFromFile -ModuleTag $ModuleTag
|
||||||
|
|
||||||
|
$out = ($envValues.Keys | ForEach-Object { "$_='$($envValues[$_])'" }) -join "`n"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-EnvironmentFromFile {
|
||||||
|
param(
|
||||||
|
[ValidateNotNullOrEmpty()][Parameter(Mandatory)][string]$ModuleTag
|
||||||
|
)
|
||||||
|
|
||||||
$envFileScriptPath = Join-Path $PSScriptRoot "../"
|
$envFileScriptPath = Join-Path $PSScriptRoot "../"
|
||||||
# Load existing .env if present
|
# Load existing .env if present
|
||||||
$envPath = Join-Path $envFileScriptPath '.env'
|
$envPath = Join-Path $envFileScriptPath '.env'
|
||||||
@@ -67,7 +77,7 @@ function New-EnvFileContent {
|
|||||||
|
|
||||||
$envValues = @{}
|
$envValues = @{}
|
||||||
$envLines = Get-Content -Raw -Path $envPath -ErrorAction Stop
|
$envLines = Get-Content -Raw -Path $envPath -ErrorAction Stop
|
||||||
Write-Host $envLines
|
|
||||||
foreach ($line in $envLines -split "`n") {
|
foreach ($line in $envLines -split "`n") {
|
||||||
$l = $line.Trim()
|
$l = $line.Trim()
|
||||||
if ($l -eq '' -or $l.StartsWith('#') -or $l.StartsWith(';')) { continue }
|
if ($l -eq '' -or $l.StartsWith('#') -or $l.StartsWith(';')) { continue }
|
||||||
@@ -81,8 +91,8 @@ function New-EnvFileContent {
|
|||||||
$envValues[$name] = $ModuleTag
|
$envValues[$name] = $ModuleTag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$out = foreach ($name in $settingNames) { "$name='$($envValues[$name])'" }
|
|
||||||
$out -join "`n"
|
$envValues
|
||||||
}
|
}
|
||||||
|
|
||||||
function Export-ElxModule {
|
function Export-ElxModule {
|
||||||
@@ -98,20 +108,19 @@ function Export-ElxModule {
|
|||||||
$seleniumToolsScriptPath = Join-Path $PSScriptRoot "../tools/selenium/"
|
$seleniumToolsScriptPath = Join-Path $PSScriptRoot "../tools/selenium/"
|
||||||
Push-Location -StackName Selenium $seleniumToolsScriptPath
|
Push-Location -StackName Selenium $seleniumToolsScriptPath
|
||||||
|
|
||||||
|
try {
|
||||||
if (-not $Quiet) {
|
if (-not $Quiet) {
|
||||||
Write-Host "Executing module export for '$ModuleTag'..."
|
Write-Host "Executing module export for '$ModuleTag'..."
|
||||||
}
|
}
|
||||||
|
|
||||||
#HACK: il tool prende in ingresso un env file
|
$NpmPath = (Get-Command npm).Source
|
||||||
$tmpEnvFile = [System.IO.Path]::GetTempFileName()
|
if (-not $NpmPath) {
|
||||||
|
Write-Error "npm is not installed or not found in PATH. Please install Node.js and npm, then try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Start-Process pwsh -ArgumentList "$NpmPath run export" -Environment (Get-EnvironmentFromFile -ModuleTag $ModuleTag) -NoNewWindow -Wait -PassThru | Out-Null
|
||||||
|
|
||||||
New-EnvFileContent -ModuleTag $ModuleTag | Set-Content -LiteralPath $tmpEnvFile -Encoding UTF8
|
if ($LASTEXITCODE -and ($LASTEXITCODE -ne 0)) {
|
||||||
|
|
||||||
& npx env-cmd --file "$tmpEnvFile" -- npm run export
|
|
||||||
|
|
||||||
Remove-Item -LiteralPath $tmpEnvFile -Force -ErrorAction SilentlyContinue
|
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
|
||||||
Write-Error "Module export for '$ModuleTag' failed with exit code $LASTEXITCODE."
|
Write-Error "Module export for '$ModuleTag' failed with exit code $LASTEXITCODE."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -121,8 +130,24 @@ function Export-ElxModule {
|
|||||||
Write-Host "Switching back to original directory..."
|
Write-Host "Switching back to original directory..."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$seleniumDownloadDir = Join-Path $seleniumToolsScriptPath "downloads"
|
||||||
|
if (-not (Test-Path -Path $seleniumDownloadDir)) {
|
||||||
|
Write-Error "Selenium download directory not found at '$seleniumDownloadDir'."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$latestDownloadedFile = Get-ChildItem -Path $seleniumDownloadDir -Filter "*.elx" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
||||||
|
if (-not $latestDownloadedFile) {
|
||||||
|
Write-Error "No .elx file found in Selenium download directory '$seleniumDownloadDir'."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Move-Item -Path $latestDownloadedFile.FullName -Destination (Join-Path $ModulePath $latestDownloadedFile.Name) -Force
|
||||||
|
}
|
||||||
|
finally {
|
||||||
Pop-Location -StackName Selenium
|
Pop-Location -StackName Selenium
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Convert-UrlToElixAutocompleteFormat {
|
function Convert-UrlToElixAutocompleteFormat {
|
||||||
param (
|
param (
|
||||||
@@ -170,3 +195,4 @@ function Convert-UrlToElixAutocompleteFormat {
|
|||||||
Export-ModuleMember -Function Convert-UrlToElixAutocompleteFormat
|
Export-ModuleMember -Function Convert-UrlToElixAutocompleteFormat
|
||||||
Export-ModuleMember -Function Save-ElxInternals
|
Export-ModuleMember -Function Save-ElxInternals
|
||||||
Export-ModuleMember -Function Export-ElxModule
|
Export-ModuleMember -Function Export-ElxModule
|
||||||
|
Export-ModuleMember -Function New-EnvFileContent
|
||||||
+16
-7
@@ -3,17 +3,26 @@ param(
|
|||||||
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$ModuleTag
|
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$ModuleTag
|
||||||
)
|
)
|
||||||
|
|
||||||
Write-Host "Checking module folder existence..."
|
$psVersion = $PSVersionTable.PSVersion
|
||||||
$modulesSrcPath = Join-Path -Resolve $PSScriptRoot "../src/$ModuleTag"
|
if ($psVersion.Major -lt 7 -or ($psVersion.Major -eq 7 -and $psVersion.Minor -lt 4)) {
|
||||||
if (-not (Test-Path -Path "$modulesSrcPath")) {
|
Write-Host "This script requires PowerShell 7.4 or higher. Please install PowerShell >= 7.4 and try again." -ForegroundColor Red
|
||||||
Write-Host "Module folder not found. Creating folder for module tag '$ModuleTag'..." -ForegroundColor Yellow
|
exit 1
|
||||||
New-Item -ItemType Directory -Path "$modulesSrcPath" -Force | Out-Null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Exporting module tag '$ModuleTag' from elixForms..."
|
Write-Host "Checking module folder existence..."
|
||||||
|
$modulesSrcPath = Join-Path $PSScriptRoot "../src/$ModuleTag"
|
||||||
|
if (-not (Test-Path -Path $modulesSrcPath)) {
|
||||||
|
Write-Host "Module folder not found. Creating folder for module tag '$ModuleTag'..." -ForegroundColor Yellow
|
||||||
|
New-Item -ItemType Directory -Path $modulesSrcPath -Force | Out-Null
|
||||||
|
}
|
||||||
|
$modulesSrcPath = Join-Path -Resolve $PSScriptRoot "../src/$ModuleTag"
|
||||||
|
|
||||||
|
Write-Host "Module tag '$ModuleTag' will be exported to '$modulesSrcPath'"
|
||||||
|
|
||||||
Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "elx-tools-module.psm1") -Force
|
Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "elx-tools-module.psm1") -Force
|
||||||
|
|
||||||
Export-ElxModule -ModuleTag $ModuleTag -ModulePath "$modulesSrcPath"
|
Write-Host "Exporting module tag '$ModuleTag' from elixForms..."
|
||||||
|
|
||||||
|
Export-ElxModule -ModuleTag $ModuleTag -ModulePath $modulesSrcPath
|
||||||
|
|
||||||
Write-Host "Module tag '$ModuleTag' exported successfully!" -ForegroundColor Green
|
Write-Host "Module tag '$ModuleTag' exported successfully!" -ForegroundColor Green
|
||||||
|
|||||||
Reference in New Issue
Block a user