68 lines
2.0 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Скрипт сборки дистрибутива dow-wiki-frontend
# Запуск: .\build.ps1
# С шагами: .\build.ps1 -VerboseOutput
param(
[switch]$VerboseOutput
)
$ErrorActionPreference = "Stop"
$root = $PSScriptRoot
$deployDir = Join-Path $root "deploy"
$archive = Join-Path $root "dow-wiki-deploy.tar.gz"
# Файлы и папки, попадающие в дистрибутив
$artifacts = @(
".next",
"public",
"node_modules",
".env",
"next.config.mjs",
"package.json",
"package-lock.json",
"tsconfig.json",
"next-env.d.ts"
)
function Step($message) {
Write-Host "==> $message" -ForegroundColor Cyan
}
Set-Location $root
try {
# 1. Сборка Next.js
Step "Сборка Next.js (npm run build)"
npm run build
if ($LASTEXITCODE -ne 0) { throw "Сборка Next.js завершилась с ошибкой" }
# 2. Очистка папки deploy
Step "Очистка папки deploy"
if (Test-Path $deployDir) { Remove-Item $deployDir -Recurse -Force }
New-Item -ItemType Directory -Path $deployDir | Out-Null
# 3. Копирование артефактов
Step "Копирование артефактов в deploy"
Copy-Item -Path $artifacts -Destination $deployDir -Recurse -Force
# 4. Удаление старого архива
Step "Удаление старого архива"
if (Test-Path $archive) { Remove-Item $archive -Force }
# 5. Создание архива
Step "Создание архива dow-wiki-deploy.tar.gz"
tar -czf $archive -C $deployDir .
if ($LASTEXITCODE -ne 0) { throw "Ошибка при создании архива" }
# Итог
$size = "{0:N1} МБ" -f ((Get-Item $archive).Length / 1MB)
Write-Host ""
Write-Host "Сборка завершена успешно." -ForegroundColor Green
Write-Host "Дистрибутив: $archive ($size)"
}
catch {
Write-Host ""
Write-Host "ОШИБКА: $_" -ForegroundColor Red
exit 1
}