98 lines
2.9 KiB
PowerShell
98 lines
2.9 KiB
PowerShell
|
|
|
|
#This is only temp until we make the entire transtion over to just this app...... long time but working on build process
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
$rootDir = Join-Path $scriptDir ".."
|
|
$tmpLoc = Join-Path $scriptDir "\tmp"
|
|
|
|
$envFile = Join-Path $rootDir ".env"
|
|
|
|
if (Test-Path $envFile) {
|
|
Write-Host "Loading environment variables from $envFile"
|
|
Get-Content $envFile | ForEach-Object {
|
|
if ($_ -match "^\s*([^#][^=]*)=(.*)$") {
|
|
$name = $matches[1].Trim()
|
|
$value = $matches[2].Trim()
|
|
[System.Environment]::SetEnvironmentVariable($name, $value)
|
|
}
|
|
}
|
|
} else {
|
|
Write-Host ".env file not found at $envFile"
|
|
}
|
|
|
|
if (-not $env:LSTV2) {
|
|
Write-Warning "BUILD_NAME environment variable is not set. Please make sure you have entered the correct info the env"
|
|
exit 1
|
|
}
|
|
|
|
$lstv2Loc = $env:LSTV2
|
|
$lstv2BuildsDir = Join-Path $lstv2Loc "builds"
|
|
|
|
function Build-LstV2-And-Copy {
|
|
if (Test-Path $tmpLoc) {
|
|
Write-Host "Temp folder for lst builds exist, moving to run the build function."
|
|
} else {
|
|
Write-Host "Tmp Folder dose not exist we will create it."
|
|
New-Item -Path $scriptDir -Name "tmp" -ItemType "Directory"
|
|
}
|
|
|
|
$defaultChoice = "n"
|
|
$input = Read-Host "Do we want to build lstV2? (Y/n) [$defaultChoice]"
|
|
|
|
$choice = if ([string]::IsNullOrWhiteSpace($input)) { $defaultChoice } else { $input.ToLower() }
|
|
|
|
if($choice -eq "n"){
|
|
Write-Host "Just going to copy the latest build over as we dont want to build a new one."
|
|
} else {
|
|
Write-Host "Jumping into lstV2 to build it."
|
|
Push-Location $lstv2Loc
|
|
npm run build
|
|
|
|
Write-Host "LSTV2 Finished building."
|
|
}
|
|
|
|
Write-Host "Copy the latest build to the tmpLoc"
|
|
|
|
# Get all build files and sort by creation time
|
|
$buildFiles = Get-ChildItem -Path $lstv2BuildsDir -File -Filter "*.zip" |
|
|
Sort-Object LastWriteTime -Descending
|
|
|
|
if ($buildFiles.Count -eq 0) {
|
|
Write-Error "No build files found in $lstv2BuildsDir"
|
|
Pop-Location
|
|
exit 1
|
|
}
|
|
|
|
# Get the most recent build
|
|
$latestBuild = $buildFiles[0]
|
|
$destinationPath = Join-Path $tmpLoc $latestBuild.Name
|
|
|
|
Write-Host "Copying latest build: $($latestBuild.Name)"
|
|
Write-Host "Created: $($latestBuild.LastWriteTime)"
|
|
Write-Host "Size: $([math]::Round($latestBuild.Length/1MB, 2)) MB"
|
|
|
|
# Copy the file
|
|
try {
|
|
Copy-Item -Path $latestBuild.FullName -Destination $destinationPath -Force
|
|
Write-Host "Successfully copied to: $destinationPath"
|
|
}
|
|
catch {
|
|
Write-Error "Failed to copy build file: $_"
|
|
Pop-Location
|
|
exit 1
|
|
}
|
|
|
|
Pop-Location
|
|
}
|
|
|
|
function Delete-Tmp-Folder
|
|
{
|
|
Write-Host "Removing the temp folder to keep it all clean"
|
|
if (Test-Path $tmpLoc) {
|
|
Remove-Item -Path $tmpLoc -Recurse
|
|
}else {
|
|
Write-Host "Tmp folder dose not exist, nothing to delete."
|
|
}
|
|
}
|
|
|