Add frontend source code update warning
- Add frontend freshness check logic - Warn when rebuild needed - Remove --production from install docs
This commit is contained in:
@@ -36,7 +36,7 @@ pip install -e ".[api]"
|
|||||||
|
|
||||||
# Build front-end artifacts
|
# Build front-end artifacts
|
||||||
cd lightrag_webui
|
cd lightrag_webui
|
||||||
bun install --frozen-lockfile --production
|
bun install --frozen-lockfile
|
||||||
bun run build
|
bun run build
|
||||||
cd ..
|
cd ..
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ pip install -e ".[api]"
|
|||||||
|
|
||||||
# Build front-end artifacts
|
# Build front-end artifacts
|
||||||
cd lightrag_webui
|
cd lightrag_webui
|
||||||
bun install --frozen-lockfile --production
|
bun install --frozen-lockfile
|
||||||
bun run build
|
bun run build
|
||||||
cd ..
|
cd ..
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -146,10 +146,11 @@ class LLMConfigCache:
|
|||||||
|
|
||||||
|
|
||||||
def check_frontend_build():
|
def check_frontend_build():
|
||||||
"""Check if frontend is built before starting server"""
|
"""Check if frontend is built and optionally check if source is up-to-date"""
|
||||||
webui_dir = Path(__file__).parent / "webui"
|
webui_dir = Path(__file__).parent / "webui"
|
||||||
index_html = webui_dir / "index.html"
|
index_html = webui_dir / "index.html"
|
||||||
|
|
||||||
|
# 1. Check if build files exist (required)
|
||||||
if not index_html.exists():
|
if not index_html.exists():
|
||||||
ASCIIColors.red("\n" + "=" * 80)
|
ASCIIColors.red("\n" + "=" * 80)
|
||||||
ASCIIColors.red("ERROR: Frontend Not Built")
|
ASCIIColors.red("ERROR: Frontend Not Built")
|
||||||
@@ -169,6 +170,99 @@ def check_frontend_build():
|
|||||||
ASCIIColors.red("=" * 80 + "\n")
|
ASCIIColors.red("=" * 80 + "\n")
|
||||||
sys.exit(1) # Exit immediately
|
sys.exit(1) # Exit immediately
|
||||||
|
|
||||||
|
# 2. Check if this is a development environment (source directory exists)
|
||||||
|
try:
|
||||||
|
source_dir = Path(__file__).parent.parent.parent / "lightrag_webui"
|
||||||
|
src_dir = source_dir / "src"
|
||||||
|
|
||||||
|
# Determine if this is a development environment: source directory exists and contains src directory
|
||||||
|
if not source_dir.exists() or not src_dir.exists():
|
||||||
|
# Production environment, skip source code check
|
||||||
|
logger.debug(
|
||||||
|
"Production environment detected, skipping source freshness check"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Development environment, perform source code timestamp check
|
||||||
|
logger.debug("Development environment detected, checking source freshness")
|
||||||
|
|
||||||
|
# Source code file extensions (files to check)
|
||||||
|
source_extensions = {
|
||||||
|
".ts",
|
||||||
|
".tsx",
|
||||||
|
".js",
|
||||||
|
".jsx",
|
||||||
|
".mjs",
|
||||||
|
".cjs", # TypeScript/JavaScript
|
||||||
|
".css",
|
||||||
|
".scss",
|
||||||
|
".sass",
|
||||||
|
".less", # Style files
|
||||||
|
".json",
|
||||||
|
".jsonc", # Configuration/data files
|
||||||
|
".html",
|
||||||
|
".htm", # Template files
|
||||||
|
".md",
|
||||||
|
".mdx", # Markdown
|
||||||
|
}
|
||||||
|
|
||||||
|
# Key configuration files (in lightrag_webui root directory)
|
||||||
|
key_files = [
|
||||||
|
source_dir / "package.json",
|
||||||
|
source_dir / "bun.lock",
|
||||||
|
source_dir / "vite.config.ts",
|
||||||
|
source_dir / "tsconfig.json",
|
||||||
|
source_dir / "tailwind.config.js",
|
||||||
|
source_dir / "index.html",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Get the latest modification time of source code
|
||||||
|
latest_source_time = 0
|
||||||
|
|
||||||
|
# Check source code files in src directory
|
||||||
|
for file_path in src_dir.rglob("*"):
|
||||||
|
if file_path.is_file():
|
||||||
|
# Only check source code files, ignore temporary files and logs
|
||||||
|
if file_path.suffix.lower() in source_extensions:
|
||||||
|
mtime = file_path.stat().st_mtime
|
||||||
|
latest_source_time = max(latest_source_time, mtime)
|
||||||
|
|
||||||
|
# Check key configuration files
|
||||||
|
for key_file in key_files:
|
||||||
|
if key_file.exists():
|
||||||
|
mtime = key_file.stat().st_mtime
|
||||||
|
latest_source_time = max(latest_source_time, mtime)
|
||||||
|
|
||||||
|
# Get build time
|
||||||
|
build_time = index_html.stat().st_mtime
|
||||||
|
|
||||||
|
# Compare timestamps (5 second tolerance to avoid file system time precision issues)
|
||||||
|
if latest_source_time > build_time + 5:
|
||||||
|
ASCIIColors.yellow("\n" + "=" * 80)
|
||||||
|
ASCIIColors.yellow("WARNING: Frontend Source Code Has Been Updated")
|
||||||
|
ASCIIColors.yellow("=" * 80)
|
||||||
|
ASCIIColors.yellow(
|
||||||
|
"The frontend source code is newer than the current build."
|
||||||
|
)
|
||||||
|
ASCIIColors.yellow(
|
||||||
|
"This might happen after 'git pull' or manual code changes.\n"
|
||||||
|
)
|
||||||
|
ASCIIColors.cyan(
|
||||||
|
"Recommended: Rebuild the frontend to use the latest changes:"
|
||||||
|
)
|
||||||
|
ASCIIColors.cyan(" cd lightrag_webui")
|
||||||
|
ASCIIColors.cyan(" bun install --frozen-lockfile")
|
||||||
|
ASCIIColors.cyan(" bun run build")
|
||||||
|
ASCIIColors.cyan(" cd ..")
|
||||||
|
ASCIIColors.yellow("\nThe server will continue with the current build.")
|
||||||
|
ASCIIColors.yellow("=" * 80 + "\n")
|
||||||
|
else:
|
||||||
|
logger.info("Frontend build is up-to-date")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
# If check fails, log warning but don't affect startup
|
||||||
|
logger.warning(f"Failed to check frontend source freshness: {e}")
|
||||||
|
|
||||||
|
|
||||||
def create_app(args):
|
def create_app(args):
|
||||||
# Check frontend build first
|
# Check frontend build first
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ LightRAG WebUI is a React-based web interface for interacting with the LightRAG
|
|||||||
In the `lightrag_webui` directory, run the following command to install project dependencies:
|
In the `lightrag_webui` directory, run the following command to install project dependencies:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bun install --frozen-lockfile --production
|
bun install --frozen-lockfile
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Build the Project:**
|
3. **Build the Project:**
|
||||||
|
|||||||
Reference in New Issue
Block a user