# Builds a standalone Encounter Builder executable a deployable package.
# The options below change what the script does and are generally only useful for development or debugging.
# Use the option --spec to just build a fresh spec file for PyInstaller to use.
param([string]$buildkind)

if ($buildkind -and $buildkind -eq "--help") {
	Write-Output "Builds standalone Encounter Builder program as a deployable package."
	Write-Output "Usage: build.ps1 [--spec]"
	Write-Output ""
	Write-Output "    --spec: Create fresh spec file, don't build anything."
} elseif ($buildkind -and $buildkind -eq "--spec") {
	# This creates a "fresh" spec file, you'll need to add the extras back in manually.
	Write-Output "Creating Encounter Builder PyInstaller spec file..."
	$makespecpath = & "py" -3 -c "import os, sys; print(os.path.join(sys.exec_prefix, 'Scripts', 'pyi-makespec.exe'), end='')" | Out-String
	$makespecpath = $makespecpath.Trim()
	& "$makespecpath" --noupx --onedir --name EncounterBuilder --exclude-module tkinter --icon EncounterBuilderIcon.ico --windowed encounter_builder.py 2> PyInstaller.log
} else {
	# If no "special" options were given, then go the normal path of building the standalone executable.
	Write-Output "Building Encounter Builder standalone executable..."
	$pyinstallerpath = & "py" -3 -c "import os, sys; print(os.path.join(sys.exec_prefix, 'Scripts', 'pyinstaller.exe'), end='')" | Out-String
	$pyinstallerpath = $pyinstallerpath.Trim()
	& "$pyinstallerpath" --clean --noconfirm EncounterBuilder.spec 2> PyInstaller.log
}
