Skip to content

Commit

Permalink
Update build.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
emadadel4 committed Feb 18, 2025
1 parent aefd015 commit ecdef90
Showing 1 changed file with 44 additions and 66 deletions.
110 changes: 44 additions & 66 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ catch {
Write-Host $psitem.Exception.Message
}


# Initializeialize synchronized hashtable
$itt = [Hashtable]::Synchronized(@{})
$itt.database = @{}
Expand All @@ -36,20 +35,46 @@ $global:DateContent = ""

# write content to output script
function WriteToScript {
param (
[string]$Content
)
$streamWriter = $null

param ([string]$Content)

try {
$streamWriter = [System.IO.StreamWriter]::new($OutputScript, $true)
$streamWriter.WriteLine($Content)
}
finally {
if ($null -ne $streamWriter) {
$streamWriter.Dispose()

if($Realsee)
{

$Content = $Content -replace '(#\s*debug start[\s\S]*?#\s*debug end)', ''
$Content = $Content -replace '<#[\s\S]*?#>', ''
$Content = $Content -replace '<!.*', ''
$Content = ($Content -split "`r?`n" | ForEach-Object {
($_ -replace '^\s*#.*$', '').Trim()
}) -join "`n"

$Content = ($Content -split "`r?`n" | Where-Object { $_ -notmatch '^\s*$' }) -join "`n"

# Remove the last empty line if it exists
$Content = $Content -replace '(\r?\n)+$', ''
}

$streamWriter = $null

try {
$streamWriter = [System.IO.StreamWriter]::new($OutputScript, $true)
if($Content) {
$streamWriter.WriteLine($Content)
}
}
finally {
if ($null -ne $streamWriter) {
$streamWriter.Dispose()
}
}
}
catch {
Write-Error "An error occurred: $_"
}
}

# Replace placeholder function
function ReplaceTextInFile {
param (
Expand Down Expand Up @@ -371,7 +396,6 @@ function GenerateThemesSwitch {

return $switchStatement
}

function GenerateLanguageSwitch {

# Define the path to the Themes directory
Expand All @@ -395,7 +419,6 @@ function GenerateLanguageSwitch {

return $switchStatement
}

function GenerateLocalesKeys {
param (
[string]$localesPath = "locales"
Expand Down Expand Up @@ -549,35 +572,6 @@ function Convert-Locales {
}
}

# comparison itt.ps1 remove all comments and space
function RemoveAllComments {

try {
Write-Host "[+] Removing all debug comments and unnecessary content..." -ForegroundColor Yellow
$FilePath = $OutputScript
$Content = Get-Content -Path $FilePath -Raw
$Content = $Content -replace '(#\s*debug start[\s\S]*?#\s*debug end)', ''
$Content = $Content -replace '<#[\s\S]*?#>', ''
$Content = $Content -replace '<!.*', ''
$Content = ($Content -split "`r?`n" | ForEach-Object {
($_ -replace '^\s*#.*$', '').Trim()
}) -join "`n"
$Content = ($Content -split "`r?`n" | Where-Object { $_ -notmatch '^\s*$' }) -join "`n"
$streamWriter = $null
try {
$streamWriter = [System.IO.StreamWriter]::new($FilePath, $false)
$streamWriter.Write($Content)
}
finally {
if ($null -ne $streamWriter) {
$streamWriter.Dispose()
}
}
}
catch {
Write-Error "An error occurred: $_"
}
}
# Write script header
function WriteHeader {
WriteToScript -Content @"
Expand Down Expand Up @@ -781,34 +775,18 @@ try {
Write-Host "[+] Build Successful." -ForegroundColor Yellow

Update-Readme


function Run {

param ($Version)

try {

$script = "& '$ProjectDir\$OutputScript'"
$pwsh = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
$wt = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $pwsh }
Start-Process $wt -ArgumentList "$pwsh -NoProfile -Command $script -$Version"
}
catch {
Write-Error "An error occurred: $_"
}

}
try {

if ($Realsee) {
RemoveAllComments
Run -Version "Realsee"
Write-Host "[+] Starting Realsee mode..." -ForegroundColor Yellow
$script = "& '$ProjectDir\$OutputScript'"
$pwsh = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" }
$wt = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $pwsh }
Start-Process $wt -ArgumentList "$pwsh -NoProfile -Command $script -Debug"
}
if ($Debug) {
Run -Version "debug"
Write-Host "[+] Starting Debug mode..." -ForegroundColor Yellow
catch {
Write-Error "An error occurred: $_"
}

}
catch {
Write-Error "An error occurred: $_"
Expand Down

0 comments on commit ecdef90

Please sign in to comment.