Compare commits

...

2 Commits

Author SHA1 Message Date
69e5f4e320 added Windows batch script for build /dist for distribution of project to server 2026-02-14 14:14:19 +01:00
b0b5d0972a update AGENTS.md 2026-02-14 13:27:04 +01:00
4 changed files with 181 additions and 1 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
/backend/config/Config.cust.php /backend/config/Config.cust.php
/frontend/node_modules /frontend/node_modules
/frontend/dist /frontend/dist
/dist

View File

@ -39,16 +39,35 @@ It describes what the project is, what is already implemented, and what still ne
- state management: `frontend/src/stores/ui.ts` - state management: `frontend/src/stores/ui.ts`
- mounted globally in `frontend/src/App.vue` - mounted globally in `frontend/src/App.vue`
- card-level loading/error states are wired in `TodayView`, `MealsView`, `MealDetailView`, `IngredientsView` - card-level loading/error states are wired in `TodayView`, `MealsView`, `MealDetailView`, `IngredientsView`
- expired-session handling is global:
- token error detector in `frontend/src/utils/error.ts` emits `auth:session-expired`
- listener in `frontend/src/main.ts` clears session, shows info toast, and redirects to auth route
- Frontend i18n is wired and used across new UI: - Frontend i18n is wired and used across new UI:
- setup in `frontend/src/i18n/index.ts` - setup in `frontend/src/i18n/index.ts`
- locale files in `frontend/src/locales/{sk,cs,en,es,de}.json` - locale files in `frontend/src/locales/{sk,cs,en,es,de}.json`
- language switcher updates locale dynamically. - language switcher updates locale dynamically.
- app UI keys include (`nav`, `pageTitles`, `mealTypes`, `common`, `nutrition`, `today`, `meals`, `ingredients`, `stats`, `settings`, `ux`) - app UI keys include (`nav`, `pageTitles`, `mealTypes`, `common`, `nutrition`, `today`, `meals`, `ingredients`, `stats`, `settings`, `ux`)
- `nutrition.short.fiber` exists in all locales and is used in macro badges
- `ux.toast.sessionExpired` exists in all locales for auto-logout flow
- Frontend theme system is implemented: - Frontend theme system is implemented:
- centralized theme store: `frontend/src/stores/theme.ts` - centralized theme store: `frontend/src/stores/theme.ts`
- shared toggle component: `frontend/src/components/common/ThemeToggle.vue` - shared toggle component: `frontend/src/components/common/ThemeToggle.vue`
- toggle available in auth, app topbar, and settings - toggle available in auth, app topbar, and settings
- design tokens in `frontend/src/assets/css/style.css` (`:root` variables). - design tokens in `frontend/src/assets/css/style.css` (`:root` variables).
- Frontend macro-badge visual system is implemented:
- shared component: `frontend/src/components/common/MacroBadge.vue`
- shared colors/tokens/styles in `frontend/src/assets/css/style.css`
- used in `IngredientsView`, `MealsView`, `DayTotalsCard`, and `DayMealCard`
- `Today` day totals card layout: kcal block on the left, macros on the right in one row
- macro colors:
- protein `#3B82F6`
- carbs `#F59E0B`
- fat `#EF4444`
- fiber `#10B981`
- style uses subtle tinted background + full-color text, pill shape (no saturated full backgrounds)
- Frontend typography is local (no remote font CDN):
- `frontend/src/assets/css/style.css` uses local `@font-face` for `DM Sans` and `Space Grotesk`
- font files are stored in `frontend/src/assets/fonts/*.woff2`
- App logo is served from `frontend/public/Nutrio.png` (copied from `doc/Nutrio.png`). - App logo is served from `frontend/public/Nutrio.png` (copied from `doc/Nutrio.png`).
- Font Awesome is installed and registered globally in `frontend/src/main.ts`. - Font Awesome is installed and registered globally in `frontend/src/main.ts`.
- Pinia is installed and configured in `frontend/src/main.ts` via `frontend/src/stores/index.ts`. - Pinia is installed and configured in `frontend/src/main.ts` via `frontend/src/stores/index.ts`.
@ -58,7 +77,7 @@ It describes what the project is, what is already implemented, and what still ne
- `frontend/src/utils/{nutrition,api,date,error}.ts` - `frontend/src/utils/{nutrition,api,date,error}.ts`
- Ingredients form UX detail: - Ingredients form UX detail:
- create/edit form in `IngredientsView` is hidden by default - create/edit form in `IngredientsView` is hidden by default
- shows only after `Nová surovina` or `Upraviť` - shows only after `Nova surovina` or `Upravit`
- hides again after successful save (form remount resets fields) - hides again after successful save (form remount resets fields)
- `frontend/src/BackendAPI.ts` is generated via `backend/scripts/buildTypeScript.php` and should not be edited manually. - `frontend/src/BackendAPI.ts` is generated via `backend/scripts/buildTypeScript.php` and should not be edited manually.
- `backend/data.json` contains sample meal data (not currently wired into DB/API flow). - `backend/data.json` contains sample meal data (not currently wired into DB/API flow).
@ -168,6 +187,8 @@ All actions are invoked through `backend/public/API.php` with `?action=<method_n
- raw API response is wrapped as `{ status, data }` - raw API response is wrapped as `{ status, data }`
- generated `BackendAPI.ts` currently resolves `response.data` in `callPromise` for non-`__HELP__` actions - generated `BackendAPI.ts` currently resolves `response.data` in `callPromise` for non-`__HELP__` actions
- frontend stores use `frontend/src/utils/api.ts` (`unwrapApiData`) to normalize both envelope and unwrapped runtime shapes - frontend stores use `frontend/src/utils/api.ts` (`unwrapApiData`) to normalize both envelope and unwrapped runtime shapes
- Auto-logout on expired token currently depends on the shared error mapper:
- if a view/store handles API errors without `toErrorMessage(...)`, global `auth:session-expired` event is not emitted there
- `frontend/src/BackendAPI.ts` is generated output; regenerate when backend API changes, do not patch manually. - `frontend/src/BackendAPI.ts` is generated output; regenerate when backend API changes, do not patch manually.
- In vue-i18n locale strings, `@` must be escaped as `{'@'}` to avoid "Invalid linked format" errors. - In vue-i18n locale strings, `@` must be escaped as `{'@'}` to avoid "Invalid linked format" errors.
@ -206,3 +227,4 @@ Frontend:
- When changing schema, always bump DB version in `Maintenance.php` with forward-only migration steps. - When changing schema, always bump DB version in `Maintenance.php` with forward-only migration steps.
- Keep API action names stable unless frontend is updated at the same time. - Keep API action names stable unless frontend is updated at the same time.
- In source files, use tab characters for indentation (do not add space-based indentation). - In source files, use tab characters for indentation (do not add space-based indentation).

94
build.bat Normal file
View File

@ -0,0 +1,94 @@
@echo off
setlocal EnableExtensions
set "ROOT=%~dp0"
if "%ROOT:~-1%"=="\" set "ROOT=%ROOT:~0,-1%"
set "DIST_DIR=%ROOT%\dist"
set "DIST_PUBLIC=%DIST_DIR%\public"
set "DIST_APP=%DIST_PUBLIC%"
set "FRONTEND_DIR=%ROOT%\frontend"
set "BACKEND_DIR=%ROOT%\backend"
echo [1/6] Cleaning dist...
if exist "%DIST_DIR%" (
rmdir /S /Q "%DIST_DIR%"
if exist "%DIST_DIR%" (
echo ERROR: Failed to remove "%DIST_DIR%".
exit /b 1
)
)
mkdir "%DIST_DIR%" >nul 2>&1 || (
echo ERROR: Failed to create "%DIST_DIR%".
exit /b 1
)
echo [2/6] Building frontend...
pushd "%FRONTEND_DIR%" >nul 2>&1 || (
echo ERROR: Frontend directory not found: "%FRONTEND_DIR%".
exit /b 1
)
echo - npm install
call npm install
if errorlevel 1 (
popd >nul
echo ERROR: npm install failed.
exit /b 1
)
echo - npm run build
call npm run build
if errorlevel 1 (
popd >nul
echo ERROR: npm run build failed.
exit /b 1
)
if not exist "%FRONTEND_DIR%\dist" (
popd >nul
echo ERROR: Frontend build output not found at "%FRONTEND_DIR%\dist".
exit /b 1
)
popd >nul
echo [3/6] Copy backend root to dist/...
call :RunRobocopy "%BACKEND_DIR%" "%DIST_DIR%" /E /R:2 /W:1 /NFL /NDL /NJH /NJS /NP ^
/XD "%BACKEND_DIR%\.git" "%BACKEND_DIR%\.vscode" "%BACKEND_DIR%\tests" "%BACKEND_DIR%\node_modules" "%BACKEND_DIR%\frontend" "%BACKEND_DIR%\dist" ^
/XF ".env" ".env.*"
if errorlevel 1 exit /b 1
echo [4/6] Copy frontend/dist to dist/public...
call :RunRobocopy "%FRONTEND_DIR%\dist" "%DIST_APP%" /E /R:2 /W:1 /NFL /NDL /NJH /NJS /NP
if errorlevel 1 exit /b 1
echo [5/6] Applying .env.production (if present)...
set "ENV_NOTE=No backend/.env.production found"
if exist "%BACKEND_DIR%\.env.production" (
copy /Y "%BACKEND_DIR%\.env.production" "%DIST_DIR%\.env" >nul
if errorlevel 1 (
echo ERROR: Failed to copy backend/.env.production to dist/.env.
exit /b 1
)
set "ENV_NOTE=Copied backend/.env.production to dist/.env"
)
echo [6/6] Summary
echo - Frontend build: OK
echo - Backend root copied to: "%DIST_DIR%" (excluding excluded dirs)
echo - Frontend assets copied to: "%DIST_APP%"
echo - Env: %ENV_NOTE%
echo - DocumentRoot should be: "%DIST_PUBLIC%"
echo - Frontend app is served from: "%DIST_APP%"
echo DONE "%DIST_DIR%"
exit /b 0
:RunRobocopy
robocopy %*
if errorlevel 8 (
echo ERROR: robocopy failed with exit code %ERRORLEVEL%.
exit /b 1
)
exit /b 0

View File

@ -100,3 +100,66 @@ Layout:
Výsledok: Výsledok:
Čistý, konzistentný, moderný vzhľad bez prehnaných farieb. Čistý, konzistentný, moderný vzhľad bez prehnaných farieb.
----- 2026-02-14 13:35:31 -----------------------------------------------------
V koreňovom adresári projektu vytvor Windows batch skript build.bat.
Štruktúra projektu:
- frontend/ (Vue 3 + Vite) -> build do frontend/dist
- backend/ (PHP) -> web root je backend/public a PHP súbory v public používajú relatívne cesty typu ../src/Init.php
=> Musíme zachovať štruktúru, aby v dist platilo: dist/public/.. = dist/
Cieľ:
- v koreňi vytvoriť root/dist tak, aby som na serveri nastavil DocumentRoot na dist/public
- relatívne cesty v PHP z dist/public na dist/src musia fungovať (napr. dist/public/index.php -> ../src/Init.php)
- frontend (Vite) nasadiť ako statické súbory do dist/public/app (aby nekolidoval s backend/public/index.php)
Výsledná štruktúra dist:
- dist/public/ (WEB ROOT) = kópia backend/public
- dist/src/ = kópia backend/src
- dist/vendor/ = kópia backend/vendor (ak existuje)
- dist/config/ = kópia backend/config (ak existuje)
- dist/… = ostatné potrebné backend súbory/adresáre z backend/ (mimo public)
- dist/public/app/ = Vite build (obsah frontend/dist)
Požiadavky na build.bat:
1) Vyčistenie:
- ak existuje root/dist, zmaž ho celý
- vytvor root/dist
2) Frontend build (nepoužívaj npm ci):
- cd frontend
- spusti "npm install"
- spusti "npm run build"
- ak build zlyhá, ukonči skript s exit code 1
- vráť sa do root
3) Kopírovanie backend do dist:
- skopíruj backend/public -> dist/public
- skopíruj všetko potrebné z backend/ do dist/ TAK, aby platili relatívne cesty z dist/public na dist/src atď.
Konkrétne:
- kopíruj backend/src -> dist/src (ak existuje)
- kopíruj backend/vendor -> dist/vendor (ak existuje)
- kopíruj ďalšie bežné backend adresáre (napr. config, templates, storage…) do dist/ na rovnakú úroveň ako public
- NEkopíruj backend/public druhýkrát mimo dist/public
- NEkopíruj: .git, .vscode, tests, node_modules, frontend, dist
4) Skopírovanie Vite buildu do dist/public:
- vytvor dist/public
- skopíruj obsah frontend/dist -> dist/public
5) .env:
- ak existuje backend/.env.production, skopíruj ho do dist/.env
- inak nič
6) Robustnosť:
- použi robocopy na kopírovanie (rýchle a s exclude)
- kontroluj ERRORLEVEL po každom kritickom kroku a pri chybe ukonči skript s exit code 1
- používaj echo logy (kroky + DONE)
7) Výstup:
- na konci vypíš, že DocumentRoot má byť nastavený na dist/public a frontend je v dist/public
Dodaj kompletný obsah súboru build.bat.