Skip to content

Commit

Permalink
fix: enhance templates and various bug fixes
Browse files Browse the repository at this point in the history
fix: cleanup templates; add default entry points
  • Loading branch information
cofin authored Dec 17, 2023
2 parents 77ec4cc + fb6bc63 commit 9116ab1
Show file tree
Hide file tree
Showing 48 changed files with 1,592 additions and 1,812 deletions.
9 changes: 2 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.7"
rev: "v0.1.8"
hooks:
- id: ruff
args: ["--fix"]
Expand All @@ -26,11 +26,6 @@ repos:
rev: v2.2.6
hooks:
- id: codespell
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
args: [--config=./pyproject.toml]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.7.1"
hooks:
Expand All @@ -52,6 +47,6 @@ repos:
"litestar[cli]",
]
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: "v0.9.0"
rev: "v0.9.1"
hooks:
- id: sphinx-lint
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL := /bin/bash
.DEFAULT_GOAL:=help
.ONESHELL:
USING_PDM = $(shell grep "tool.pdm" pyproject.toml && echo "yes")
ENV_PREFIX = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/bin/')")
ENV_PREFIX = .venv/bin/
VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')")
PDM_OPTS ?=
PDM ?= pdm $(PDM_OPTS)
Expand Down
22 changes: 3 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Create a template to serve the application in `./templates/index.html.h2`:

```html
<!DOCTYPE html>
<html class="h-full">
<html>
<head>
<meta charset="utf-8" />
<!--IE compatibility-->
Expand All @@ -63,7 +63,7 @@ Create a template to serve the application in `./templates/index.html.h2`:
/>
</head>

<body class="font-sans leading-none text-gray-700 antialiased">
<body>
<div id="app"></div>
{{ vite_hmr() }} {{ vite('resources/main.ts') }}
</body>
Expand All @@ -86,22 +86,6 @@ INFO - 2023-12-11 12:33:41,456 - root - commands - Writing package.json
INFO - 2023-12-11 12:33:41,456 - root - commands - Writing tsconfig.json
```

```shell
❯ tree
.
├── app.py
├── __init__.py
├── package.json
├── tsconfig.json
├── vite.config.ts
└── web
├── controllers.py
├── __init__.py
├── public
└── resources
└── assets
```

### Install Javascript/Typescript Packages

Install the packages required for development:
Expand Down Expand Up @@ -144,7 +128,7 @@ vite v5.0.7 building for production...

```

**Note** This is equivalent to the the `npm run dev` command when `hot_reload` is enabled. Otherwise it is equivalent to `npm run build --watch`. This command is configurable.
**Note** This is equivalent to the the `npm run dev` command when `hot_reload` is enabled. Otherwise it is equivalent to `npm run build -- --watch`. This command is configurable.

### Building for Production

Expand Down
19 changes: 0 additions & 19 deletions examples/htmx/app.py

This file was deleted.

20 changes: 0 additions & 20 deletions examples/htmx/package.json

This file was deleted.

31 changes: 0 additions & 31 deletions examples/htmx/tsconfig.json

This file was deleted.

25 changes: 0 additions & 25 deletions examples/htmx/vite.config.ts

This file was deleted.

19 changes: 0 additions & 19 deletions examples/react/app.py

This file was deleted.

File renamed without changes.
36 changes: 36 additions & 0 deletions examples/vanilla/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations

from pathlib import Path

from litestar import Controller, Litestar, get
from litestar.response import Template

from litestar_vite import ViteConfig, VitePlugin

here = Path(__file__).parent


class WebController(Controller):
"""Web Controller."""

opt = {"exclude_from_auth": True}
include_in_schema = False

@get("/")
async def index(self) -> Template:
"""Serve site root."""
return Template(template_name="index.html.j2")


vite = VitePlugin(
config=ViteConfig(
bundle_dir=Path(here / "public"),
resource_dir=Path(here / "resources"),
template_dir=Path(here / "templates"),
hot_reload=True,
port=3006,
use_server_lifespan=True,
dev_mode=True,
),
)
app = Litestar(plugins=[vite], route_handlers=[WebController])
Loading

0 comments on commit 9116ab1

Please sign in to comment.