add script to convert URLs to elixForms format
This commit is contained in:
@@ -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 UrlToConvert=
|
||||
IF "%~1"=="" (
|
||||
echo Absolute URL not specified.
|
||||
set /p UrlToConvert=Insert absolute URL to convert:
|
||||
IF "!UrlToConvert!"=="" (
|
||||
echo Absolute URL is required!
|
||||
exit /b 1
|
||||
) ELSE (
|
||||
echo Using absolute URL: !UrlToConvert!
|
||||
set AbsoluteUrl="!UrlToConvert!"
|
||||
)
|
||||
) ELSE (
|
||||
echo Using absolute URL: %~1
|
||||
set AbsoluteUrl=%~1
|
||||
)
|
||||
|
||||
@powershell -NoProfile -ExecutionPolicy Bypass -Command .\scripts\convert-url-to-elix.ps1 -AbsoluteUrl '%AbsoluteUrl%'
|
||||
|
||||
IF DEFINED iscommandline IF NOT DEFINED ispowershell pause
|
||||
ENDLOCAL
|
||||
@@ -0,0 +1,17 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$AbsoluteUrl
|
||||
)
|
||||
|
||||
$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
|
||||
|
||||
$convertedUrl = Convert-UrlToElixAutocompleteFormat -AbsoluteUrl $uri
|
||||
|
||||
Write-Host "Converted URL:" -ForegroundColor Cyan
|
||||
Write-Host "$convertedUrl" -ForegroundColor Cyan
|
||||
|
||||
Write-Host "URL converted successfully!" -ForegroundColor Green
|
||||
@@ -1,6 +1,6 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$false)][string]$ModuleTag
|
||||
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$ModuleTag
|
||||
)
|
||||
|
||||
Write-Host "Checking module file existence..."
|
||||
|
||||
@@ -1,14 +1,41 @@
|
||||
# Script-level parameters and cmdlet binding to support -Verbose and common parameters
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[switch]$Quiet
|
||||
)
|
||||
|
||||
function Write-LogMessage {
|
||||
param (
|
||||
[string]$message,
|
||||
[ValidateSet('Info','Warning')] [string]$Level = 'Info'
|
||||
)
|
||||
|
||||
if ($Quiet) { return }
|
||||
|
||||
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||
if ($Level -eq 'Warning') {
|
||||
Write-Host "[$timestamp] WARNING: $message"
|
||||
}
|
||||
else {
|
||||
Write-Host "[$timestamp] $message"
|
||||
}
|
||||
}
|
||||
|
||||
function Save-ElxInternals {
|
||||
param(
|
||||
[ValidateScript({ Test-Path $_ -PathType Leaf })][Parameter(Mandatory)]$ModulePath
|
||||
)
|
||||
|
||||
Write-Host "Switching to ELX Tools directory..."
|
||||
if (-not $Quiet) {
|
||||
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..."
|
||||
if (-not $Quiet) {
|
||||
Write-Host "Installing Node.js dependencies for the ELX Tools..."
|
||||
}
|
||||
|
||||
# Install Node.js dependencies for the ELX Tools
|
||||
& npm install
|
||||
@@ -17,8 +44,10 @@ function Save-ElxInternals {
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Node.js dependencies installed successfully!" -ForegroundColor Cyan
|
||||
Write-Host "Executing ELX extraction..."
|
||||
if (-not $Quiet) {
|
||||
Write-Host "Node.js dependencies installed successfully!" -ForegroundColor Cyan
|
||||
Write-Host "Executing ELX extraction..."
|
||||
}
|
||||
|
||||
& node "extract-elx.js" $ModulePath --clean
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
@@ -26,10 +55,56 @@ function Save-ElxInternals {
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "ELX extraction completed successfully!" -ForegroundColor Green
|
||||
Write-Host "Switching back to original directory..."
|
||||
if (-not $Quiet) {
|
||||
Write-Host "ELX extraction completed successfully!" -ForegroundColor Green
|
||||
Write-Host "Switching back to original directory..."
|
||||
}
|
||||
|
||||
Pop-Location -StackName ElxTools
|
||||
}
|
||||
|
||||
function Convert-UrlToElixAutocompleteFormat {
|
||||
param (
|
||||
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][uri]$AbsoluteUrl
|
||||
)
|
||||
|
||||
Write-LogMessage "Converting URL '$($AbsoluteUrl.Host)' to elixForms WS call format..."
|
||||
$domain = $AbsoluteUrl.Host -replace '-', '--' -replace '\.', '-'
|
||||
$path = $AbsoluteUrl.AbsolutePath.TrimStart('/') -replace '-', '--' -replace '/', '-'
|
||||
$url = "/eF/services/api/remote/$domain/$path/v1"
|
||||
|
||||
# Preserve query parameter order using an ordered hashtable and URL-decode values
|
||||
$queryParams = [ordered]@{}
|
||||
$rawQuery = $AbsoluteUrl.Query.TrimStart('?')
|
||||
if ($rawQuery) {
|
||||
$rawQuery.Split('&') | ForEach-Object {
|
||||
if ($_ -ne '') {
|
||||
$pair = $_ -split '=', 2
|
||||
$key = $pair[0]
|
||||
$value = if ($pair.Count -gt 1) { $pair[1] } else { '' }
|
||||
|
||||
if ($queryParams.Contains($key)) {
|
||||
# Append duplicate values with a comma, preserving existing empty-string handling
|
||||
if ($queryParams[$key] -eq '') {
|
||||
$queryParams[$key] = $value
|
||||
}
|
||||
else {
|
||||
$queryParams[$key] = "{0},{1}" -f $queryParams[$key], $value
|
||||
}
|
||||
}
|
||||
else {
|
||||
$queryParams[$key] = $value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[PSCustomObject]@{
|
||||
URL = $url
|
||||
QueryParams = $queryParams
|
||||
QueryString = ($queryParams.Keys | ForEach-Object { "$_=$($queryParams[$_])" }) -Join "&"
|
||||
} | ConvertTo-Json -Depth 2 -EscapeHandling None
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Convert-UrlToElixAutocompleteFormat
|
||||
Export-ModuleMember -Function Save-ElxInternals
|
||||
Reference in New Issue
Block a user