127 lines
3.2 KiB
PowerShell
127 lines
3.2 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
|
|
$Env:PATH = "$PSScriptRoot\_generator\site;$PSScriptRoot\_generator\vips;$Env:PATH"
|
|
|
|
# Check if ConsoleGuiTools are available.
|
|
$cgt = Get-Module -ListAvailable Microsoft.PowerShell.ConsoleGuiTools
|
|
if ($cgt -eq $null) {
|
|
Write-Output 'Missing ConsoleGuiTools, please make sure you have PowerShell 7 and run the following command as an administrator:'
|
|
Write-Output ' Install-Module Microsoft.PowerShell.ConsoleGuiTools'
|
|
Read-Host
|
|
Exit 1
|
|
}
|
|
|
|
function FetchGenerator {
|
|
$tempFile = New-TemporaryFile
|
|
$url = 'https://temp.ogion.cz/site-zahradka.zip'
|
|
Invoke-WebRequest -Uri $url -OutFile $tempFile
|
|
Expand-Archive $tempFile -DestinationPath '_generator' -Force
|
|
}
|
|
|
|
function EnsureGenerator {
|
|
if (!(Test-Path '_generator/site/site.exe')) {
|
|
FetchGenerator
|
|
}
|
|
}
|
|
|
|
function SiteWatch {
|
|
EnsureGenerator
|
|
site watch
|
|
}
|
|
|
|
function SiteCheck {
|
|
EnsureGenerator
|
|
site check
|
|
Read-Host
|
|
}
|
|
|
|
function SiteBuild {
|
|
EnsureGenerator
|
|
site build
|
|
Read-Host
|
|
}
|
|
|
|
function SiteRebuild {
|
|
EnsureGenerator
|
|
site rebuild
|
|
Read-Host
|
|
}
|
|
|
|
function UpdateGenerator {
|
|
FetchGenerator
|
|
Read-Host
|
|
}
|
|
|
|
function Terminate {
|
|
[Terminal.Gui.Application]::RequestStop()
|
|
}
|
|
|
|
$action = $null
|
|
|
|
function MakeUi {
|
|
Import-Module Microsoft.PowerShell.ConsoleGuiTools
|
|
$module = (Get-Module Microsoft.PowerShell.ConsoleGuiTools -List).ModuleBase
|
|
Add-Type -Path (Join-path $module Terminal.Gui.dll)
|
|
|
|
[Terminal.Gui.Application]::Init()
|
|
$window = [Terminal.Gui.Window]::new()
|
|
$window.Title = 'site: strom-roku-2023.krk-litvinov.cz'
|
|
[Terminal.Gui.Application]::Top.Add($window)
|
|
|
|
$watchButton = [Terminal.Gui.Button]::new()
|
|
$watchButton.Text = 'watch: Start test server and watch for changes'
|
|
$watchButton.add_Clicked({
|
|
$script:action = $function:SiteWatch
|
|
Terminate
|
|
})
|
|
$window.Add($watchButton)
|
|
|
|
$checkButton = [Terminal.Gui.Button]::new()
|
|
$checkButton.Text = 'check: Check links'
|
|
$checkButton.add_Clicked({
|
|
$script:action = $function:SiteCheck
|
|
Terminate
|
|
})
|
|
$checkButton.Y = [Terminal.Gui.Pos]::Bottom($watchButton)
|
|
$window.Add($checkButton)
|
|
|
|
$buildButton = [Terminal.Gui.Button]::new()
|
|
$buildButton.Text = 'build: Update output directory'
|
|
$buildButton.add_Clicked({
|
|
$script:action = $function:SiteBuild
|
|
Terminate
|
|
})
|
|
$buildButton.Y = [Terminal.Gui.Pos]::Bottom($checkButton) + 1
|
|
$window.Add($buildButton)
|
|
|
|
$rebuildButton = [Terminal.Gui.Button]::new()
|
|
$rebuildButton.Text = 'rebuild: Rebuild site from scratch'
|
|
$rebuildButton.add_Clicked({
|
|
$result = [Terminal.Gui.MessageBox]::Query('Rebuild', "Do you want to rebuild the web site output from scratch?`nIt can take a minute", @('Yes', 'No'))
|
|
if ($result -eq 0) {
|
|
$script:action = $function:SiteRebuild
|
|
Terminate
|
|
}
|
|
})
|
|
$rebuildButton.Y = [Terminal.Gui.Pos]::Bottom($buildButton)
|
|
$window.Add($rebuildButton)
|
|
|
|
$updateButton = [Terminal.Gui.Button]::new()
|
|
$updateButton.Text = 'Update the site program'
|
|
$updateButton.add_Clicked({
|
|
$script:action = $function:UpdateGenerator
|
|
Terminate
|
|
})
|
|
$updateButton.Y = [Terminal.Gui.Pos]::Bottom($rebuildButton) + 1
|
|
$window.Add($updateButton)
|
|
|
|
[Terminal.Gui.Application]::Run()
|
|
[Terminal.Gui.Application]::Shutdown()
|
|
}
|
|
|
|
MakeUi
|
|
|
|
if ($action -ne $null) {
|
|
& $action
|
|
}
|