diff --git a/export-elx.bat b/export-elx.bat new file mode 100644 index 0000000..e2a72bf --- /dev/null +++ b/export-elx.bat @@ -0,0 +1,26 @@ +@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" + +SET UserModuleTag= +IF "%~1"=="" ( + echo Module tag not specified. + set /p UserModuleTag=Insert module tag: + IF "!UserModuleTag!"=="" ( + echo Module tag is required to extract internals! + exit /b 1 + ) ELSE ( + echo Using module tag: !UserModuleTag! + set ModuleTag=!UserModuleTag! + ) +) ELSE ( + echo Using module tag: %~1 + set ModuleTag=%~1 +) + +@powershell -NoProfile -ExecutionPolicy Bypass -Command .\scripts\export-elx.ps1 -ModuleTag %ModuleTag% + +IF DEFINED iscommandline IF NOT DEFINED ispowershell pause +ENDLOCAL diff --git a/scripts/convert-url-to-elix.ps1 b/scripts/convert-url-to-elix.ps1 index 2cbc433..b566810 100644 --- a/scripts/convert-url-to-elix.ps1 +++ b/scripts/convert-url-to-elix.ps1 @@ -7,7 +7,7 @@ $uri = [System.Uri]$AbsoluteUrl Write-Host "Converting URL '$uri' to elixForms WS call format..." -Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "extract-elx-module.psm1") -Force +Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "elx-tools-module.psm1") -Force $convertedUrl = Convert-UrlToElixAutocompleteFormat -AbsoluteUrl $uri diff --git a/scripts/extract-elx-module.psm1 b/scripts/elx-tools-module.psm1 similarity index 54% rename from scripts/extract-elx-module.psm1 rename to scripts/elx-tools-module.psm1 index 92af8e5..8d2e83b 100644 --- a/scripts/extract-elx-module.psm1 +++ b/scripts/elx-tools-module.psm1 @@ -51,6 +51,79 @@ function Save-ElxInternals { Pop-Location -StackName ElxTools } +function New-EnvFileContent { + param( + [ValidateNotNullOrEmpty()][Parameter(Mandatory)][string]$ModuleTag + ) + + $envFileScriptPath = Join-Path $PSScriptRoot "../" + # Load existing .env if present + $envPath = Join-Path $envFileScriptPath '.env' + + if (-not (Test-Path $envPath)) { + Write-Error "No existing .env file found!" + exit 1 + } + + $envValues = @{} + $envLines = Get-Content -Raw -Path $envPath -ErrorAction Stop + Write-Host $envLines + foreach ($line in $envLines -split "`n") { + $l = $line.Trim() + if ($l -eq '' -or $l.StartsWith('#') -or $l.StartsWith(';')) { continue } + if ($l -match '=') { + $parts = $l -split '=', 2 + $name = $parts[0].Trim() + $value = $parts[1].Trim().Trim("'").Trim('"') + $envValues[$name] = $value + } + if ($name -eq 'ELIXFORMS_MODULE_TAG') { + $envValues[$name] = $ModuleTag + } + } + $out = foreach ($name in $settingNames) { "$name='$($envValues[$name])'" } + $out -join "`n" +} + +function Export-ElxModule { + param( + [ValidateNotNullOrEmpty()][Parameter(Mandatory)][string]$ModuleTag, + [ValidateScript({ Test-Path $_ })][Parameter(Mandatory)]$ModulePath + ) + + if (-not $Quiet) { + Write-Host "Switching to Selenium directory..." + } + + $seleniumToolsScriptPath = Join-Path $PSScriptRoot "../tools/selenium/" + Push-Location -StackName Selenium $seleniumToolsScriptPath + + if (-not $Quiet) { + Write-Host "Executing module export for '$ModuleTag'..." + } + + #HACK: il tool prende in ingresso un env file + $tmpEnvFile = [System.IO.Path]::GetTempFileName() + + New-EnvFileContent -ModuleTag $ModuleTag | Set-Content -LiteralPath $tmpEnvFile -Encoding UTF8 + + & 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." + exit 1 + } + + if (-not $Quiet) { + Write-Host "Module export for '$ModuleTag' completed successfully!" -ForegroundColor Green + Write-Host "Switching back to original directory..." + } + + Pop-Location -StackName Selenium +} + function Convert-UrlToElixAutocompleteFormat { param ( [Parameter(Mandatory)][ValidateNotNullOrEmpty()][uri]$AbsoluteUrl @@ -95,4 +168,5 @@ function Convert-UrlToElixAutocompleteFormat { } Export-ModuleMember -Function Convert-UrlToElixAutocompleteFormat -Export-ModuleMember -Function Save-ElxInternals \ No newline at end of file +Export-ModuleMember -Function Save-ElxInternals +Export-ModuleMember -Function Export-ElxModule \ No newline at end of file diff --git a/scripts/export-elx.ps1 b/scripts/export-elx.ps1 new file mode 100644 index 0000000..6654750 --- /dev/null +++ b/scripts/export-elx.ps1 @@ -0,0 +1,19 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$ModuleTag +) + +Write-Host "Checking module folder existence..." +$modulesSrcPath = Join-Path -Resolve $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 +} + +Write-Host "Exporting module tag '$ModuleTag' from elixForms..." + +Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "elx-tools-module.psm1") -Force + +Export-ElxModule -ModuleTag $ModuleTag -ModulePath "$modulesSrcPath" + +Write-Host "Module tag '$ModuleTag' exported successfully!" -ForegroundColor Green diff --git a/scripts/extract-elx-internals-all.ps1 b/scripts/extract-elx-internals-all.ps1 index abc8eeb..7c7456f 100644 --- a/scripts/extract-elx-internals-all.ps1 +++ b/scripts/extract-elx-internals-all.ps1 @@ -10,7 +10,7 @@ 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 +Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "elx-tools-module.psm1") -Force $moduleFiles | ForEach-Object { Save-ElxInternals -ModulePath $_.FullName diff --git a/scripts/extract-elx-internals-last-updated.ps1 b/scripts/extract-elx-internals-last-updated.ps1 index 2ab2d72..b2f4f5e 100644 --- a/scripts/extract-elx-internals-last-updated.ps1 +++ b/scripts/extract-elx-internals-last-updated.ps1 @@ -9,7 +9,7 @@ if (-not $moduleFile) { 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 +Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "elx-tools-module.psm1") -Force Save-ElxInternals -ModulePath $moduleFile.FullName diff --git a/scripts/extract-elx-internals.ps1 b/scripts/extract-elx-internals.ps1 index dc13cdd..c3a1dbd 100644 --- a/scripts/extract-elx-internals.ps1 +++ b/scripts/extract-elx-internals.ps1 @@ -13,7 +13,7 @@ if (-not $moduleFile) { Write-Host "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 +Import-Module $(Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) "elx-tools-module.psm1") -Force Save-ElxInternals -ModulePath $moduleFile.FullName diff --git a/scripts/setup-environment.ps1 b/scripts/setup-environment.ps1 index ea7b603..8f1aec8 100644 --- a/scripts/setup-environment.ps1 +++ b/scripts/setup-environment.ps1 @@ -63,8 +63,8 @@ function Initialize-EnvironmentSettings { Write-Host "Settings preparation complete" } -function Initialize-NodeTools { - Write-Host "Installing Node.js dependencies for the ELX Tools..." +function Initialize-ExtractElxTools { + Write-Host "Installing Node.js dependencies for the ELX Tools..." -ForegroundColor Cyan $extractElxToolsScriptPath = Join-Path $PSScriptRoot "../tools/extract-elx/" @@ -82,6 +82,44 @@ function Initialize-NodeTools { Write-Host "Node.js dependencies installed successfully!" } +function Initialize-PlaywrightTools { + Write-Host "Installing Node.js dependencies for Playwright..." -ForegroundColor Cyan + + $playwrightScriptPath = Join-Path $PSScriptRoot "../tools/playwright/" + + Push-Location -StackName Playwright $playwrightScriptPath + + # Install Node.js dependencies for Playwright + & npm install + if ($LASTEXITCODE -ne 0) { + Write-Error "npm install failed with exit code $LASTEXITCODE." + exit 1 + } + + Pop-Location -StackName Playwright + + Write-Host "Node.js dependencies installed successfully!" +} + +function Initialize-SeleniumTools { + Write-Host "Installing Node.js dependencies for Selenium..." -ForegroundColor Cyan + + $seleniumScriptPath = Join-Path $PSScriptRoot "../tools/selenium/" + + Push-Location -StackName Selenium $seleniumScriptPath + + # Install Node.js dependencies for Selenium + & npm install + if ($LASTEXITCODE -ne 0) { + Write-Error "npm install failed with exit code $LASTEXITCODE." + exit 1 + } + + Pop-Location -StackName Selenium + + Write-Host "Node.js dependencies installed successfully!" +} + # 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 + "'" @@ -113,7 +151,15 @@ Initialize-EnvironmentSettings Write-Host -Initialize-NodeTools +Initialize-ExtractElxTools + +Write-Host + +Initialize-PlaywrightTools + +Write-Host + +Initialize-SeleniumTools Write-Host Write-Host "Environment preparation complete!" -ForegroundColor Green diff --git a/tools/playwright/package-lock.json b/tools/playwright/package-lock.json index 759b1f6..44bdb2b 100644 --- a/tools/playwright/package-lock.json +++ b/tools/playwright/package-lock.json @@ -1,12 +1,12 @@ { - "name": "playwright", - "version": "1.0.0", + "name": "playwright-export-module", + "version": "0.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "playwright", - "version": "1.0.0", + "name": "playwright-export-module", + "version": "0.0.1", "license": "ISC", "dependencies": { "dotenv": "^17.4.2"