litestar-vite 0.1.19__py3-none-any.whl → 0.1.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of litestar-vite might be problematic. Click here for more details.
- litestar_vite/cli.py +32 -13
- litestar_vite/commands.py +11 -7
- litestar_vite/config.py +10 -4
- litestar_vite/plugin.py +13 -5
- litestar_vite/templates/vite.config.ts.j2 +4 -1
- {litestar_vite-0.1.19.dist-info → litestar_vite-0.1.21.dist-info}/METADATA +3 -3
- {litestar_vite-0.1.19.dist-info → litestar_vite-0.1.21.dist-info}/RECORD +9 -9
- {litestar_vite-0.1.19.dist-info → litestar_vite-0.1.21.dist-info}/WHEEL +1 -1
- {litestar_vite-0.1.19.dist-info → litestar_vite-0.1.21.dist-info}/licenses/LICENSE +0 -0
litestar_vite/cli.py
CHANGED
|
@@ -19,10 +19,17 @@ def vite_group() -> None:
|
|
|
19
19
|
"""Manage Vite Tasks."""
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
@vite_group.command(
|
|
22
|
+
@vite_group.command(
|
|
23
23
|
name="init",
|
|
24
24
|
help="Initialize vite for your project.",
|
|
25
25
|
)
|
|
26
|
+
@option(
|
|
27
|
+
"--root-path",
|
|
28
|
+
type=ClickPath(dir_okay=True, file_okay=False, path_type=Path),
|
|
29
|
+
help="The path for the initial the Vite application. This is the equivalent to the top-level folder in a normal Vue or React application..",
|
|
30
|
+
default=None,
|
|
31
|
+
required=False,
|
|
32
|
+
)
|
|
26
33
|
@option(
|
|
27
34
|
"--bundle-path",
|
|
28
35
|
type=ClickPath(dir_okay=True, file_okay=False, path_type=Path),
|
|
@@ -37,6 +44,13 @@ def vite_group() -> None:
|
|
|
37
44
|
default=None,
|
|
38
45
|
required=False,
|
|
39
46
|
)
|
|
47
|
+
@option(
|
|
48
|
+
"--public-path",
|
|
49
|
+
type=ClickPath(dir_okay=True, file_okay=False, path_type=Path),
|
|
50
|
+
help="The optional path to your public/static JS assets. If this were a standalone Vue or React app, this would point to your `public/` folder.",
|
|
51
|
+
default=None,
|
|
52
|
+
required=False,
|
|
53
|
+
)
|
|
40
54
|
@option("--asset-url", type=str, help="Base url to serve assets from.", default=None, required=False)
|
|
41
55
|
@option(
|
|
42
56
|
"--vite-port",
|
|
@@ -79,8 +93,10 @@ def vite_init(
|
|
|
79
93
|
vite_port: int | None,
|
|
80
94
|
enable_ssr: bool | None,
|
|
81
95
|
asset_url: str | None,
|
|
96
|
+
root_path: Path | None,
|
|
82
97
|
bundle_path: Path | None,
|
|
83
98
|
resource_path: Path | None,
|
|
99
|
+
public_path: Path | None,
|
|
84
100
|
overwrite: bool,
|
|
85
101
|
verbose: bool,
|
|
86
102
|
no_prompt: bool,
|
|
@@ -106,16 +122,18 @@ def vite_init(
|
|
|
106
122
|
ctx.obj.app.debug = True
|
|
107
123
|
env: LitestarEnv = ctx.obj
|
|
108
124
|
plugin = env.app.plugins.get(VitePlugin)
|
|
109
|
-
config = plugin._config
|
|
125
|
+
config = plugin._config
|
|
110
126
|
|
|
111
127
|
console.rule("[yellow]Initializing Vite[/]", align="left")
|
|
112
128
|
resource_path = Path(resource_path or config.resource_dir)
|
|
129
|
+
public_path = Path(public_path or config.public_dir)
|
|
113
130
|
bundle_path = Path(bundle_path or config.bundle_dir)
|
|
114
131
|
enable_ssr = enable_ssr or config.ssr_enabled
|
|
115
132
|
asset_url = asset_url or config.asset_url
|
|
116
133
|
vite_port = vite_port or config.port
|
|
117
134
|
hot_file = Path(bundle_path / config.hot_file)
|
|
118
|
-
root_path = resource_path.parent
|
|
135
|
+
root_path = Path(root_path or config.root_dir or resource_path.parent)
|
|
136
|
+
|
|
119
137
|
if any(output_path.exists() for output_path in (bundle_path, resource_path)) and not any(
|
|
120
138
|
[overwrite, no_prompt],
|
|
121
139
|
):
|
|
@@ -125,7 +143,7 @@ def vite_init(
|
|
|
125
143
|
if not confirm_overwrite:
|
|
126
144
|
console.print("Skipping Vite initialization")
|
|
127
145
|
sys.exit(2)
|
|
128
|
-
for output_path in (bundle_path, resource_path):
|
|
146
|
+
for output_path in (bundle_path, resource_path, root_path):
|
|
129
147
|
output_path.mkdir(parents=True, exist_ok=True)
|
|
130
148
|
|
|
131
149
|
enable_ssr = (
|
|
@@ -144,6 +162,7 @@ def vite_init(
|
|
|
144
162
|
vite_port=vite_port,
|
|
145
163
|
asset_url=asset_url,
|
|
146
164
|
resource_path=resource_path,
|
|
165
|
+
public_path=public_path,
|
|
147
166
|
bundle_path=bundle_path,
|
|
148
167
|
hot_file=hot_file,
|
|
149
168
|
litestar_port=env.port or 8000,
|
|
@@ -159,14 +178,14 @@ def vite_init(
|
|
|
159
178
|
install_dir = os.environ.get("VIRTUAL_ENV", sys.prefix)
|
|
160
179
|
console.rule("[yellow]Starting Nodeenv installation process[/]", align="left")
|
|
161
180
|
console.print(f"Installing Node environment into {install_dir}")
|
|
162
|
-
execute_command([nodeenv_command, install_dir, "--force", "--quiet"])
|
|
181
|
+
execute_command(command_to_run=[nodeenv_command, install_dir, "--force", "--quiet"], cwd=root_path)
|
|
163
182
|
|
|
164
183
|
console.rule("[yellow]Starting package installation process[/]", align="left")
|
|
165
184
|
|
|
166
|
-
execute_command(plugin.config.install_command)
|
|
185
|
+
execute_command(command_to_run=plugin.config.install_command, cwd=root_path)
|
|
167
186
|
|
|
168
187
|
|
|
169
|
-
@vite_group.command(
|
|
188
|
+
@vite_group.command(
|
|
170
189
|
name="install",
|
|
171
190
|
help="Install frontend packages.",
|
|
172
191
|
)
|
|
@@ -197,14 +216,14 @@ def vite_install(app: Litestar, verbose: bool) -> None:
|
|
|
197
216
|
install_dir = os.environ.get("VIRTUAL_ENV", sys.prefix)
|
|
198
217
|
console.rule("[yellow]Starting Nodeenv installation process[/]", align="left")
|
|
199
218
|
console.print("Installing Node environment to %s:", install_dir)
|
|
200
|
-
execute_command([nodeenv_command, install_dir, "--force", "--quiet"])
|
|
219
|
+
execute_command(command_to_run=[nodeenv_command, install_dir, "--force", "--quiet"], cwd=plugin.config.root_dir)
|
|
201
220
|
|
|
202
221
|
console.rule("[yellow]Starting package installation process[/]", align="left")
|
|
203
222
|
|
|
204
|
-
execute_command(plugin.config.install_command)
|
|
223
|
+
execute_command(command_to_run=plugin.config.install_command, cwd=plugin.config.root_dir)
|
|
205
224
|
|
|
206
225
|
|
|
207
|
-
@vite_group.command(
|
|
226
|
+
@vite_group.command(
|
|
208
227
|
name="build",
|
|
209
228
|
help="Building frontend assets with Vite.",
|
|
210
229
|
)
|
|
@@ -224,14 +243,14 @@ def vite_build(app: Litestar, verbose: bool) -> None:
|
|
|
224
243
|
plugin = app.plugins.get(VitePlugin)
|
|
225
244
|
if plugin.config.set_environment:
|
|
226
245
|
set_environment(config=plugin.config)
|
|
227
|
-
p = execute_command(plugin.config.build_command)
|
|
246
|
+
p = execute_command(command_to_run=plugin.config.build_command, cwd=plugin.config.root_dir)
|
|
228
247
|
if p.returncode == 0:
|
|
229
248
|
console.print("[bold green] Assets built.[/]")
|
|
230
249
|
else:
|
|
231
250
|
console.print("[bold red] There was an error building the assets.[/]")
|
|
232
251
|
|
|
233
252
|
|
|
234
|
-
@vite_group.command(
|
|
253
|
+
@vite_group.command(
|
|
235
254
|
name="serve",
|
|
236
255
|
help="Serving frontend assets with Vite.",
|
|
237
256
|
)
|
|
@@ -256,5 +275,5 @@ def vite_serve(app: Litestar, verbose: bool) -> None:
|
|
|
256
275
|
else:
|
|
257
276
|
console.rule("[yellow]Starting Vite watch and build process[/]", align="left")
|
|
258
277
|
command_to_run = plugin.config.run_command if plugin.config.hot_reload else plugin.config.build_watch_command
|
|
259
|
-
execute_command(command_to_run)
|
|
278
|
+
execute_command(command_to_run=command_to_run, cwd=plugin.config.root_dir)
|
|
260
279
|
console.print("[yellow]Vite process stopped.[/]")
|
litestar_vite/commands.py
CHANGED
|
@@ -5,9 +5,6 @@ import subprocess
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from typing import TYPE_CHECKING, Any, MutableMapping
|
|
7
7
|
|
|
8
|
-
from jinja2 import select_autoescape
|
|
9
|
-
from litestar.serialization import encode_json
|
|
10
|
-
|
|
11
8
|
if TYPE_CHECKING:
|
|
12
9
|
from jinja2 import Environment, Template
|
|
13
10
|
from litestar import Litestar
|
|
@@ -33,14 +30,17 @@ def to_json(value: Any) -> str:
|
|
|
33
30
|
Returns:
|
|
34
31
|
JSON string.
|
|
35
32
|
"""
|
|
33
|
+
from litestar.serialization import encode_json
|
|
34
|
+
|
|
36
35
|
return encode_json(value).decode("utf-8")
|
|
37
36
|
|
|
38
37
|
|
|
39
38
|
def init_vite(
|
|
40
|
-
app: Litestar,
|
|
39
|
+
app: Litestar,
|
|
41
40
|
root_path: Path,
|
|
42
41
|
resource_path: Path,
|
|
43
42
|
asset_url: str,
|
|
43
|
+
public_path: Path,
|
|
44
44
|
bundle_path: Path,
|
|
45
45
|
enable_ssr: bool,
|
|
46
46
|
vite_port: int,
|
|
@@ -48,7 +48,7 @@ def init_vite(
|
|
|
48
48
|
litestar_port: int,
|
|
49
49
|
) -> None:
|
|
50
50
|
"""Initialize a new vite project."""
|
|
51
|
-
from jinja2 import Environment, FileSystemLoader
|
|
51
|
+
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
|
52
52
|
from litestar.cli._utils import console
|
|
53
53
|
|
|
54
54
|
entry_point: list[str] = []
|
|
@@ -81,6 +81,7 @@ def init_vite(
|
|
|
81
81
|
asset_url=asset_url,
|
|
82
82
|
root_path=str(root_path.relative_to(Path.cwd().absolute())),
|
|
83
83
|
resource_path=str(resource_path.relative_to(root_path)),
|
|
84
|
+
public_path=str(public_path.relative_to(root_path)),
|
|
84
85
|
bundle_path=str(bundle_path.relative_to(root_path)),
|
|
85
86
|
hot_file=str(hot_file.relative_to(Path.cwd().absolute())),
|
|
86
87
|
vite_port=str(vite_port),
|
|
@@ -105,6 +106,9 @@ def get_template(
|
|
|
105
106
|
return environment.get_template(name=name, parent=parent, globals=globals)
|
|
106
107
|
|
|
107
108
|
|
|
108
|
-
def execute_command(command_to_run: list[str]) -> subprocess.CompletedProcess[bytes]:
|
|
109
|
+
def execute_command(command_to_run: list[str], cwd: str | Path | None = None) -> subprocess.CompletedProcess[bytes]:
|
|
109
110
|
"""Run Vite in a subprocess."""
|
|
110
|
-
|
|
111
|
+
kwargs = {}
|
|
112
|
+
if cwd is not None:
|
|
113
|
+
kwargs["cwd"] = Path(cwd)
|
|
114
|
+
return subprocess.run(command_to_run, check=False, shell=platform.system() == "Windows", **kwargs) # type: ignore[call-overload]
|
litestar_vite/config.py
CHANGED
|
@@ -43,7 +43,11 @@ class ViteConfig:
|
|
|
43
43
|
In a standalone Vue or React application, this would be equivalent to the ``./src`` directory.
|
|
44
44
|
"""
|
|
45
45
|
template_dir: Path | str | None = field(default=None)
|
|
46
|
-
"""Location of the Jinja2 template file.
|
|
46
|
+
"""Location of the Jinja2 template file."""
|
|
47
|
+
public_dir: Path | str = field(default="public")
|
|
48
|
+
"""The optional public directory Vite serves assets from.
|
|
49
|
+
|
|
50
|
+
In a standalone Vue or React application, this would be equivalent to the ``./public`` directory.
|
|
47
51
|
"""
|
|
48
52
|
manifest_name: str = "manifest.json"
|
|
49
53
|
"""Name of the manifest file."""
|
|
@@ -63,12 +67,12 @@ class ViteConfig:
|
|
|
63
67
|
root_dir: Path | str | None = None
|
|
64
68
|
"""The is the base path to your application.
|
|
65
69
|
|
|
66
|
-
In a standalone Vue or React application, this would be equivalent to the ``./src`` directory.
|
|
70
|
+
In a standalone Vue or React application, this would be equivalent to the top-level project folder containing the ``./src`` directory.
|
|
67
71
|
|
|
68
72
|
"""
|
|
69
73
|
is_react: bool = False
|
|
70
74
|
"""Enable React components."""
|
|
71
|
-
asset_url: str =field(default_factory=lambda: os.getenv("ASSET_URL", "/static/"))
|
|
75
|
+
asset_url: str = field(default_factory=lambda: os.getenv("ASSET_URL", "/static/"))
|
|
72
76
|
"""Base URL to generate for static asset references.
|
|
73
77
|
|
|
74
78
|
This URL will be prepended to anything generated from Vite.
|
|
@@ -91,7 +95,7 @@ class ViteConfig:
|
|
|
91
95
|
default_factory=lambda: os.getenv("VITE_USE_SERVER_LIFESPAN", "False") in {"True", "1", "yes", "Y", "T"},
|
|
92
96
|
)
|
|
93
97
|
"""Utilize the server lifespan hook to run Vite."""
|
|
94
|
-
dev_mode: bool =
|
|
98
|
+
dev_mode: bool = field(
|
|
95
99
|
default_factory=lambda: os.getenv("VITE_DEV_MODE", "False") in {"True", "1", "yes", "Y", "T"},
|
|
96
100
|
)
|
|
97
101
|
"""When True, Vite will run with HMR or watch build"""
|
|
@@ -112,6 +116,8 @@ class ViteConfig:
|
|
|
112
116
|
self.root_dir = Path(self.root_dir)
|
|
113
117
|
if self.template_dir is not None and isinstance(self.template_dir, str):
|
|
114
118
|
self.template_dir = Path(self.template_dir)
|
|
119
|
+
if self.public_dir is not None and isinstance(self.public_dir, str):
|
|
120
|
+
self.public_dir = Path(self.public_dir)
|
|
115
121
|
if isinstance(self.resource_dir, str):
|
|
116
122
|
self.resource_dir = Path(self.resource_dir)
|
|
117
123
|
if isinstance(self.bundle_dir, str):
|
litestar_vite/plugin.py
CHANGED
|
@@ -2,7 +2,8 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
from contextlib import contextmanager
|
|
5
|
-
from
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import TYPE_CHECKING, Iterator, cast
|
|
6
7
|
|
|
7
8
|
from litestar.plugins import CLIPlugin, InitPluginProtocol
|
|
8
9
|
from litestar.static_files import create_static_files_router
|
|
@@ -66,14 +67,19 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
|
|
|
66
67
|
)
|
|
67
68
|
|
|
68
69
|
if self._config.set_static_folders:
|
|
70
|
+
static_dirs = [Path(self._config.bundle_dir), Path(self._config.resource_dir)]
|
|
71
|
+
if Path(self._config.public_dir).exists() and self._config.public_dir != self._config.bundle_dir:
|
|
72
|
+
static_dirs.append(Path(self._config.public_dir))
|
|
69
73
|
app_config.route_handlers.append(
|
|
70
74
|
create_static_files_router(
|
|
71
|
-
directories=[
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
directories=cast( # type: ignore[arg-type]
|
|
76
|
+
"list[Path]",
|
|
77
|
+
static_dirs if self._config.dev_mode else [Path(self._config.bundle_dir)],
|
|
78
|
+
),
|
|
74
79
|
path=self._config.asset_url,
|
|
75
80
|
name="vite",
|
|
76
81
|
html_mode=False,
|
|
82
|
+
include_in_schema=False,
|
|
77
83
|
opt={"exclude_from_auth": True},
|
|
78
84
|
),
|
|
79
85
|
)
|
|
@@ -96,8 +102,10 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
|
|
|
96
102
|
if self._config.set_environment:
|
|
97
103
|
set_environment(config=self._config)
|
|
98
104
|
vite_thread = threading.Thread(
|
|
105
|
+
name="vite",
|
|
99
106
|
target=execute_command,
|
|
100
|
-
args=[
|
|
107
|
+
args=[],
|
|
108
|
+
kwargs={"command_to_run": command_to_run, "cwd": self._config.root_dir},
|
|
101
109
|
)
|
|
102
110
|
try:
|
|
103
111
|
vite_thread.start()
|
|
@@ -10,9 +10,12 @@ export default defineConfig({
|
|
|
10
10
|
base: `${ASSET_URL}`,
|
|
11
11
|
{% if root_path and root_path != '.' %} root: "{{ root_path }}",{% endif %}
|
|
12
12
|
server: {
|
|
13
|
-
host:
|
|
13
|
+
host: "0.0.0.0",
|
|
14
14
|
port: +`${VITE_PORT}`,
|
|
15
15
|
cors: true,
|
|
16
|
+
hmr: {
|
|
17
|
+
host: `${VITE_HOST}`,
|
|
18
|
+
},
|
|
16
19
|
},
|
|
17
20
|
plugins: [
|
|
18
21
|
{% if include_vue %}vue(),{% endif %}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: litestar-vite
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.21
|
|
4
4
|
Summary: Vite plugin for Litestar
|
|
5
5
|
Project-URL: Changelog, https://cofin.github.io/litestar-vite/latest/changelog
|
|
6
6
|
Project-URL: Discord, https://discord.gg/X3FJqy8d2j
|
|
@@ -30,7 +30,7 @@ Classifier: Topic :: Database :: Database Engines/Servers
|
|
|
30
30
|
Classifier: Topic :: Software Development
|
|
31
31
|
Classifier: Typing :: Typed
|
|
32
32
|
Requires-Python: >=3.8
|
|
33
|
-
Requires-Dist: litestar[
|
|
33
|
+
Requires-Dist: litestar[jinja]>=2.4.0
|
|
34
34
|
Provides-Extra: nodeenv
|
|
35
35
|
Requires-Dist: nodeenv; extra == 'nodeenv'
|
|
36
36
|
Description-Content-Type: text/markdown
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
litestar_vite/__init__.py,sha256=9X3i67Q8DJN2lQYAMa9NSPTZGzHASGn8X8yeWJqBvWg,357
|
|
2
2
|
litestar_vite/__metadata__.py,sha256=Eml1c9xezV-GSodmysksrT8jPWqE__x0ENO1wM5g6q0,319
|
|
3
|
-
litestar_vite/cli.py,sha256=
|
|
4
|
-
litestar_vite/commands.py,sha256=
|
|
5
|
-
litestar_vite/config.py,sha256=
|
|
3
|
+
litestar_vite/cli.py,sha256=6SmKu_wdduotTsx1xbmQFooQqG8SZyHwIDvZrr3KMJI,9527
|
|
4
|
+
litestar_vite/commands.py,sha256=_TrBJE12HbsdKFkjGLpu8b_WvkoDp5-VV0xvRkYjsjk,4107
|
|
5
|
+
litestar_vite/config.py,sha256=L93F0CrghlNrAHlmTPqYtZxtZoLPf5kOJebqFxAlVOE,6824
|
|
6
6
|
litestar_vite/loader.py,sha256=3BFvcsXdaTwyym6bHaGhTkNDFaAcdjQDUHRfuKHj2vM,7699
|
|
7
|
-
litestar_vite/plugin.py,sha256=
|
|
7
|
+
litestar_vite/plugin.py,sha256=nNB62gqRXv6x1nxJNxZZPd67zOaw9XvGQxP_AxDyPbk,4230
|
|
8
8
|
litestar_vite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
litestar_vite/template_engine.py,sha256=UIxphAoAKrAcpAuV_CJmZgsN9GOFfqq0azQdId6yofg,2995
|
|
10
10
|
litestar_vite/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -12,8 +12,8 @@ litestar_vite/templates/index.html.j2,sha256=GobZbXgrlFRf3sCoS-416iWfV8lBP_v3AXP
|
|
|
12
12
|
litestar_vite/templates/main.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYuzBjXrziXNw,299
|
|
14
14
|
litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
|
|
15
|
-
litestar_vite/templates/vite.config.ts.j2,sha256=
|
|
16
|
-
litestar_vite-0.1.
|
|
17
|
-
litestar_vite-0.1.
|
|
18
|
-
litestar_vite-0.1.
|
|
19
|
-
litestar_vite-0.1.
|
|
15
|
+
litestar_vite/templates/vite.config.ts.j2,sha256=FZ4OJaB8Kjby_nlx4_LCP8eCe1LRi8kW2GspCiVMfDY,1115
|
|
16
|
+
litestar_vite-0.1.21.dist-info/METADATA,sha256=iWyAfdMchcgSKoDC-MX6Oq6zJ5a3TBQ-kO-7ELzpBO8,6437
|
|
17
|
+
litestar_vite-0.1.21.dist-info/WHEEL,sha256=bq9SyP5NxIRA9EpQgMCd-9RmPHWvbH-4lTDGwxgIR64,87
|
|
18
|
+
litestar_vite-0.1.21.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
|
|
19
|
+
litestar_vite-0.1.21.dist-info/RECORD,,
|
|
File without changes
|