/
Starolat
/
DeepDive
Обзор
Документация
Войти
/
Starolat
/
DeepDive
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
deploy.bat
139 строк
6 KB
Starolat Sergei
fix: cache-busting для jszip.min.js, прогресс и обработка ошибок в deploy.bat
14 июл 2026, 08:46
14 июл 2026, 08:46
cf9387b
Код
Авторство
О чём код?
@echo off chcp 65001 >nul setlocal enabledelayedexpansion echo [deploy] Starting deployment build... :: Clean previous deploy folder if exist deploy ( echo [deploy] Cleaning old deploy folder... rmdir /s /q deploy ) :: Generate preset index before copying assets if exist scripts\generate-preset-index.js ( echo [deploy] Generating assets/presets/index.json... node scripts\generate-preset-index.js ) :: Generate CHANGELOG from git commits if exist scripts\generate-changelog.js ( echo [deploy] Updating CHANGELOG.md from git commits... node scripts\generate-changelog.js ) :: Determine cache-busting build ID for /f "tokens=*" %%a in ('git rev-parse HEAD 2^>nul') do set BUILD_ID=%%a if not defined BUILD_ID ( echo [deploy] WARNING: Could not determine git commit hash, using timestamp fallback... for /f "tokens=*" %%a in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMddHHmmss"') do set BUILD_ID=%%a ) echo [deploy] Cache-busting build ID: !BUILD_ID! :: Determine application version set APP_VERSION=unknown if exist version.json ( for /f "tokens=*" %%a in ('powershell -NoProfile -Command "(Get-Content version.json | ConvertFrom-Json).version"') do set APP_VERSION=%%a ) echo [deploy] Application version: !APP_VERSION! :: Create deploy folder mkdir deploy :: Copy root files echo [deploy] Copying root files... copy index.html deploy\ >nul copy favicon.ico deploy\ >nul if exist .nojekyll copy .nojekyll deploy\ >nul if exist version.json copy version.json deploy\ >nul :: NOTE: .env is intentionally NOT copied — it contains secrets. :: Create it on the target server separately. if exist env.js copy env.js deploy\ >nul if exist README.md copy README.md deploy\ >nul if exist CHANGELOG.md copy CHANGELOG.md deploy\ >nul if exist proxydb.py copy proxydb.py deploy\ >nul if exist requirements.txt copy requirements.txt deploy\ >nul if exist serve.py copy serve.py deploy\ >nul :: Copy required directories recursively echo [deploy] Copying assets... xcopy /s /e /i /y assets deploy\assets >nul echo [deploy] Copying css... xcopy /s /e /i /y css deploy\css >nul echo [deploy] Copying js... xcopy /s /e /i /y js deploy\js >nul echo [deploy] Copying lib... xcopy /s /e /i /y lib deploy\lib >nul echo [deploy] Copying keycloak-js... xcopy /s /e /i /y keycloak-js deploy\keycloak-js >nul :: Apply cache-busting build ID and version to files inside deploy folder only echo [deploy] Applying cache-busting build ID and version to deploy files... powershell -NoProfile -Command "(Get-Content -Raw deploy\index.html) -replace '__BUILD_ID__', '!BUILD_ID!' -replace '__APP_VERSION__', '!APP_VERSION!' | Set-Content -NoNewline deploy\index.html" set FILE_COUNT=0 for /r deploy\js %%f in (*.js) do set /a FILE_COUNT+=1 for /r deploy\lib %%f in (*.js) do set /a FILE_COUNT+=1 echo [deploy] Processing !FILE_COUNT! JS files... set FILE_IDX=0 for /r deploy\js %%f in (*.js) do ( set /a FILE_IDX+=1 powershell -NoProfile -Command "(Get-Content -Raw '%%f') -replace '__BUILD_ID__', '!BUILD_ID!' | Set-Content -NoNewline '%%f'; $pct = [math]::Floor(!FILE_IDX! * 100 / !FILE_COUNT!); $filled = [math]::Floor($pct * 30 / 100); $bar = ('#' * $filled).PadRight(30, '-'); Write-Host -NoNewline ([char]13 + '[deploy] [' + $bar + '] ' + $pct + '%% (!FILE_IDX!/!FILE_COUNT!)')" ) for /r deploy\lib %%f in (*.js) do ( set /a FILE_IDX+=1 powershell -NoProfile -Command "(Get-Content -Raw '%%f') -replace '__BUILD_ID__', '!BUILD_ID!' | Set-Content -NoNewline '%%f'; $pct = [math]::Floor(!FILE_IDX! * 100 / !FILE_COUNT!); $filled = [math]::Floor($pct * 30 / 100); $bar = ('#' * $filled).PadRight(30, '-'); Write-Host -NoNewline ([char]13 + '[deploy] [' + $bar + '] ' + $pct + '%% (!FILE_IDX!/!FILE_COUNT!)')" ) echo. :: Safety net: ensure no .env file leaks into deploy folder if exist deploy\.env ( echo [deploy] WARNING: .env leaked into deploy, removing... del /f /q deploy\.env ) :: Verify no placeholders remain in deploy folder powershell -NoProfile -Command "$remaining = Get-ChildItem -Path deploy -Recurse -File | Where-Object { $_.Extension -in @('.html','.js') } | Select-String -Pattern '__BUILD_ID__|__APP_VERSION__' -SimpleMatch; if ($remaining) { Write-Host 'ERROR: placeholders remain in deploy folder:'; $remaining | ForEach-Object { Write-Host $_.Path }; exit 1 }" if errorlevel 1 ( echo [deploy] Build failed: unresolved placeholders. goto :fail ) :: Verify CHANGELOG.md is up to date for current version if exist scripts\check-changelog.js ( echo [deploy] Verifying CHANGELOG.md... node scripts\check-changelog.js ) if errorlevel 1 ( echo [deploy] Build failed: CHANGELOG.md check failed. goto :fail ) :: Verify all dynamic JS imports in deploy folder use cache-busting echo [deploy] Verifying dynamic JS imports use cache-busting... powershell -NoProfile -Command "$jsFiles = Get-ChildItem -Path deploy\js -Recurse -Filter *.js -File; $libFiles = Get-ChildItem -Path deploy\lib -Recurse -Filter *.js -File; $allFiles = $jsFiles + $libFiles; $offenders = @(); foreach ($file in $allFiles) { $lines = Get-Content $file.FullName; for ($i = 0; $i -lt $lines.Count; $i++) { $line = $lines[$i]; if ($line -match '@type|@param|@returns|@typedef|@property|/\*\*|\*/') { continue }; if ($line -match 'import\.meta') { continue }; if ($line -match 'import\s*\(\s*[\x22''][^\x22'']*\.js[\x22'']\s*\)') { if ($line -notmatch '\?__BUILD_ID__' -and $line -notmatch '\bzlib\b|\bfs\b|\burl\b|\bpath\b|\bos\b|\bcrypto\b|\bstream\b|\bbuffer\b|\butil\b') { $offenders += '{0}:{1}: {2}' -f $file.FullName, ($i + 1), $line.Trim() } } } }; if ($offenders.Count -gt 0) { Write-Host 'ERROR: следующие динамические импорты не используют ?__BUILD_ID__:'; $offenders | ForEach-Object { Write-Host $_ }; exit 1 }" if errorlevel 1 ( echo [deploy] Build failed: dynamic JS imports without cache-busting detected. goto :fail ) echo [deploy] Build complete: deploy\ echo [deploy] Ready for deployment. echo. echo Нажмите любую клавишу чтобы закрыть окно... pause >nul exit /b 0 :fail echo. echo [deploy] Сборка завершилась с ошибкой. echo Нажмите любую клавишу чтобы закрыть окно... pause >nul exit /b 1