Files
NAFKA-crm-gui/scripts/build.ps1
2026-06-17 17:31:32 +02:00

209 lines
6.8 KiB
PowerShell

[CmdletBinding()]
Param(
[switch]$NoPackaging
)
$DEPLOYMENT_PATH = 'B:\deployments\WCE-NAFKA'
$ENV_PATH = 'B:\deployments\WCE-NAFKA\dopt_nafka_wce-crm'
$PY_PATH = Join-Path -Path $ENV_PATH -ChildPath 'python'
$SRC_PATH = (Get-Location).Path
function create_folder {
param (
[string]$base_path,
[string]$folder_name,
[switch]$recreate
)
$target_path = Join-Path -Path $base_path -ChildPath $folder_name
$target_path_exists = Test-Path -Path $target_path
if (-not $target_path_exists){
Write-Output "[PWSH] Folder >$folder_name< not existing. Create..."
New-Item -Path $target_path -ItemType Directory
}
elseif ($target_path_exists -and $recreate){
Write-Output "[PWSH] Folder >$folder_name< exists, but should be recreated..."
Remove-Item -Path $target_path -Recurse -Force
New-Item -Path $target_path -ItemType Directory
}
else {
Write-Output "Folder >$folder_name< already exists."
}
}
Write-Output "Build Pipeline for d-opt WCE/NAFKA project"
Write-Output "Delete existing artifacts..."
$pattern = "dopt_nafka_wce-crm_v*"
Get-ChildItem -Path $DEPLOYMENT_PATH -Filter $pattern | Remove-Item -Recurse -Force
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors in the deletion procedure"
Exit
}
Write-Output "Deleted outstanding artifacts successfully"
Write-Output "Create data folder..."
$pattern = "dopt_nafka_wce-crm_v*"
$data_folder = Join-Path -Path $ENV_PATH -ChildPath 'data'
if (-not (Test-Path -Path $data_folder)){
Write-Output "[PWSH] Data path not existing. Create..."
New-Item -Path $data_folder -ItemType Directory
}
else {
Write-Output "Data path already exists."
}
Write-Output "Building package..."
.\scripts\publish.ps1
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were build errors"
Exit
}
Write-Output "Built package successfully"
# documentation
Write-Output "Generate docs..."
# $doc_build_script = Join-Path -Path $SRC_PATH -ChildPath "scripts\cvt_docs.ps1" -Resolve
.\scripts\cvt_docs.ps1
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there errors while generating the doc files"
Exit
}
Write-Output "Generated doc files successfully"
Write-Output "Copying doc files..."
$docs_src_path = Join-Path -Path $SRC_PATH -ChildPath 'docs\*.pdf'
Copy-Item -Path $docs_src_path -Destination $ENV_PATH -Force
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors while copying the doc files"
Exit
}
Write-Output "Copied doc files successfully"
Write-Output "Go into env directory..."
Set-Location $ENV_PATH
Write-Output "Install package into environment..."
pycage venv add -p -i http://localhost:8001/simple/ wce-crm
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors while installing the package into the environment"
Exit
}
Write-Output "Successfully installed package"
# copy database file
Write-Output "Copying database files..."
$copy_file = Join-Path -Path $SRC_PATH -ChildPath 'data/db/wce_grunderfassung.db'
$dest_file = Join-Path -Path $ENV_PATH -ChildPath 'data'
Copy-Item -Path $copy_file -Destination $dest_file -Force
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors while copying database 'Grunderfassung'"
Exit
}
$copy_file = Join-Path -Path $SRC_PATH -ChildPath 'data/db/wce_crm.db'
Copy-Item -Path $copy_file -Destination $dest_file -Force
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors while copying database 'CRM'"
Exit
}
Write-Output "Copied database files successfully"
# copy alembic files
Write-Output "Copying alembic files..."
$copy_file = Join-Path -Path $SRC_PATH -ChildPath 'alembic'
$dest_file = Join-Path -Path $PY_PATH -ChildPath 'alembic'
create_folder -base_path $PY_PATH -folder_name 'alembic'
Copy-Item -Path $copy_file -Destination $dest_file -Force -Recurse
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors while copying the alembic folder"
Exit
}
$copy_file = Join-Path -Path $SRC_PATH -ChildPath 'alembic.ini'
Copy-Item -Path $copy_file -Destination $dest_file -Force
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors while copying the alembic INI file"
Exit
}
# copy .env file
Write-Output "Copying ENV file..."
$env_file = Join-Path -Path $SRC_PATH -ChildPath 'deployment/.env'
$env_dest_path = Join-Path -Path $PY_PATH -ChildPath '.env'
Copy-Item -Path $env_file -Destination $env_dest_path -Force
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors while copying ENV file"
Exit
}
Write-Output "Copied ENV file successfully"
# copy startup script files
Write-Output "Copying startup scripts..."
$copy_file = Join-Path -Path $SRC_PATH -ChildPath 'scripts/start.bat'
Copy-Item -Path $copy_file -Destination $ENV_PATH -Force
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors while copying startup scripts"
Exit
}
Write-Output "Copied startup scripts successfully"
# env preparation
Write-Output "Preparing environment with cleanup and pre-compilation..."
pycage clean dist-info
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors while deleting the distribution info files"
Exit
}
pycage compile -q -d -f
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors during the pre-compilation process"
Exit
}
Write-Output "Successfully prepared environment with cleanup and pre-compilation"
if ($NoPackaging) {
Write-Output "[PWSH] No packaging selected. Exit..."
Set-Location $SRC_PATH
Exit
}
Write-Output "Get version string..."
$pyproject = Get-Content $SRC_PATH\pyproject.toml -Raw
if ($pyproject -match '\[project\].*?\n[\s\w\n=""-_{}]*\[[\w-]*\]') {
$projectBlock = $matches[0]
if ($projectBlock -match 'version\s*=\s*"([^"]+)"') {
$version = $matches[1]
Write-Output "The version string is: $version"
}
else {
Write-Output "[PWSH] Exiting script because the version string was not found"
Exit
}
}
else {
Write-Output "[PWSH] Exiting script because the version string was not found"
Exit
}
Write-Output "Packaging whole standalone environment in a ZIP file"
$dest_path = Join-Path -Path $DEPLOYMENT_PATH -ChildPath "dopt_nafka_wce-crm_v$version.zip"
$compress = @{
Path = "$ENV_PATH\**"
CompressionLevel = "Optimal"
DestinationPath = $dest_path
}
Compress-Archive @compress -Force
if ($? -eq $false){
Write-Output "[PWSH] Exiting script because there were errors during the archive compression operation"
Exit
}
Write-Output "Successfully compressed archive. Saved under: >$dest_path<"
Write-Output "Go back to source directory..."
Set-Location $SRC_PATH