Source code for litestar_vite.commands

"""Vite commands module.

This module provides utility functions for Vite project initialization.
The main scaffolding functionality has moved to litestar_vite.scaffolding.
"""

from typing import TYPE_CHECKING

from litestar_vite.config import JINJA_INSTALLED
from litestar_vite.exceptions import MissingDependencyError

if TYPE_CHECKING:
    from pathlib import Path

    from litestar import Litestar


[docs] def init_vite( app: "Litestar", root_path: "Path", resource_path: "Path", asset_url: "str", public_path: "Path", bundle_path: "Path", enable_ssr: "bool", vite_port: int, hot_file: "Path", litestar_port: int, framework: str = "react", ) -> None: """Initialize a new Vite project using the scaffolding system. Args: app: The Litestar application instance. root_path: Root directory for the Vite project. resource_path: Directory containing source files. asset_url: Base URL for serving assets. public_path: Directory for static files. bundle_path: Output directory for built files. enable_ssr: Enable server-side rendering. vite_port: Port for Vite dev server. hot_file: Path to hot reload manifest. litestar_port: Port for Litestar server. framework: Framework template to use (default: react). Raises: MissingDependencyError: If Jinja2 is not installed. """ if not JINJA_INSTALLED: raise MissingDependencyError(package="jinja2", install_package="jinja") from litestar_vite.scaffolding import TemplateContext, generate_project from litestar_vite.scaffolding.templates import FrameworkType, get_template # Get the framework template template = get_template(framework) if template is None: template = get_template(FrameworkType.REACT) if template is None: # pragma: no cover msg = f"Could not find template for framework: {framework}" raise ValueError(msg) # Create template context context = TemplateContext( project_name=root_path.name or "my-project", framework=template, use_typescript=template.uses_typescript, use_tailwind=False, vite_port=vite_port, litestar_port=litestar_port, asset_url=asset_url, resource_dir=str(resource_path), bundle_dir=str(bundle_path), enable_ssr=enable_ssr, enable_inertia=template.inertia_compatible and "inertia" in framework, enable_types=True, ) # Generate project files generate_project(root_path, context, overwrite=True)