litestar-vite 0.1.1__py3-none-any.whl → 0.15.0rc2__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.
Files changed (154) hide show
  1. litestar_vite/__init__.py +54 -4
  2. litestar_vite/__metadata__.py +12 -7
  3. litestar_vite/_codegen/__init__.py +26 -0
  4. litestar_vite/_codegen/inertia.py +407 -0
  5. litestar_vite/_codegen/openapi.py +233 -0
  6. litestar_vite/_codegen/routes.py +653 -0
  7. litestar_vite/_codegen/ts.py +235 -0
  8. litestar_vite/_handler/__init__.py +8 -0
  9. litestar_vite/_handler/app.py +524 -0
  10. litestar_vite/_handler/routing.py +130 -0
  11. litestar_vite/cli.py +1147 -10
  12. litestar_vite/codegen.py +39 -0
  13. litestar_vite/commands.py +79 -0
  14. litestar_vite/config.py +1594 -70
  15. litestar_vite/deploy.py +355 -0
  16. litestar_vite/doctor.py +1179 -0
  17. litestar_vite/exceptions.py +78 -0
  18. litestar_vite/executor.py +316 -0
  19. litestar_vite/handler.py +9 -0
  20. litestar_vite/html_transform.py +426 -0
  21. litestar_vite/inertia/__init__.py +53 -0
  22. litestar_vite/inertia/_utils.py +114 -0
  23. litestar_vite/inertia/exception_handler.py +172 -0
  24. litestar_vite/inertia/helpers.py +1043 -0
  25. litestar_vite/inertia/middleware.py +54 -0
  26. litestar_vite/inertia/plugin.py +133 -0
  27. litestar_vite/inertia/request.py +286 -0
  28. litestar_vite/inertia/response.py +706 -0
  29. litestar_vite/inertia/types.py +316 -0
  30. litestar_vite/loader.py +462 -121
  31. litestar_vite/plugin.py +2160 -21
  32. litestar_vite/py.typed +0 -0
  33. litestar_vite/scaffolding/__init__.py +20 -0
  34. litestar_vite/scaffolding/generator.py +270 -0
  35. litestar_vite/scaffolding/templates.py +437 -0
  36. litestar_vite/templates/__init__.py +0 -0
  37. litestar_vite/templates/addons/tailwindcss/tailwind.css.j2 +1 -0
  38. litestar_vite/templates/angular/index.html.j2 +12 -0
  39. litestar_vite/templates/angular/openapi-ts.config.ts.j2 +18 -0
  40. litestar_vite/templates/angular/package.json.j2 +35 -0
  41. litestar_vite/templates/angular/src/app/app.component.css.j2 +3 -0
  42. litestar_vite/templates/angular/src/app/app.component.html.j2 +1 -0
  43. litestar_vite/templates/angular/src/app/app.component.ts.j2 +9 -0
  44. litestar_vite/templates/angular/src/app/app.config.ts.j2 +5 -0
  45. litestar_vite/templates/angular/src/main.ts.j2 +9 -0
  46. litestar_vite/templates/angular/src/styles.css.j2 +9 -0
  47. litestar_vite/templates/angular/tsconfig.app.json.j2 +34 -0
  48. litestar_vite/templates/angular/tsconfig.json.j2 +20 -0
  49. litestar_vite/templates/angular/vite.config.ts.j2 +21 -0
  50. litestar_vite/templates/angular-cli/.postcssrc.json.j2 +5 -0
  51. litestar_vite/templates/angular-cli/angular.json.j2 +36 -0
  52. litestar_vite/templates/angular-cli/openapi-ts.config.ts.j2 +18 -0
  53. litestar_vite/templates/angular-cli/package.json.j2 +27 -0
  54. litestar_vite/templates/angular-cli/proxy.conf.json.j2 +18 -0
  55. litestar_vite/templates/angular-cli/src/app/app.component.css.j2 +3 -0
  56. litestar_vite/templates/angular-cli/src/app/app.component.html.j2 +1 -0
  57. litestar_vite/templates/angular-cli/src/app/app.component.ts.j2 +9 -0
  58. litestar_vite/templates/angular-cli/src/app/app.config.ts.j2 +5 -0
  59. litestar_vite/templates/angular-cli/src/index.html.j2 +13 -0
  60. litestar_vite/templates/angular-cli/src/main.ts.j2 +6 -0
  61. litestar_vite/templates/angular-cli/src/styles.css.j2 +10 -0
  62. litestar_vite/templates/angular-cli/tailwind.config.js.j2 +4 -0
  63. litestar_vite/templates/angular-cli/tsconfig.app.json.j2 +16 -0
  64. litestar_vite/templates/angular-cli/tsconfig.json.j2 +26 -0
  65. litestar_vite/templates/angular-cli/tsconfig.spec.json.j2 +9 -0
  66. litestar_vite/templates/astro/astro.config.mjs.j2 +28 -0
  67. litestar_vite/templates/astro/openapi-ts.config.ts.j2 +15 -0
  68. litestar_vite/templates/astro/src/layouts/Layout.astro.j2 +63 -0
  69. litestar_vite/templates/astro/src/pages/index.astro.j2 +36 -0
  70. litestar_vite/templates/astro/src/styles/global.css.j2 +1 -0
  71. litestar_vite/templates/base/.gitignore.j2 +42 -0
  72. litestar_vite/templates/base/openapi-ts.config.ts.j2 +15 -0
  73. litestar_vite/templates/base/package.json.j2 +38 -0
  74. litestar_vite/templates/base/resources/vite-env.d.ts.j2 +1 -0
  75. litestar_vite/templates/base/tsconfig.json.j2 +37 -0
  76. litestar_vite/templates/htmx/src/main.js.j2 +8 -0
  77. litestar_vite/templates/htmx/templates/base.html.j2.j2 +56 -0
  78. litestar_vite/templates/htmx/templates/index.html.j2.j2 +13 -0
  79. litestar_vite/templates/htmx/vite.config.ts.j2 +40 -0
  80. litestar_vite/templates/nuxt/app.vue.j2 +29 -0
  81. litestar_vite/templates/nuxt/composables/useApi.ts.j2 +33 -0
  82. litestar_vite/templates/nuxt/nuxt.config.ts.j2 +31 -0
  83. litestar_vite/templates/nuxt/openapi-ts.config.ts.j2 +15 -0
  84. litestar_vite/templates/nuxt/pages/index.vue.j2 +54 -0
  85. litestar_vite/templates/react/index.html.j2 +13 -0
  86. litestar_vite/templates/react/src/App.css.j2 +56 -0
  87. litestar_vite/templates/react/src/App.tsx.j2 +19 -0
  88. litestar_vite/templates/react/src/main.tsx.j2 +10 -0
  89. litestar_vite/templates/react/vite.config.ts.j2 +39 -0
  90. litestar_vite/templates/react-inertia/index.html.j2 +14 -0
  91. litestar_vite/templates/react-inertia/package.json.j2 +46 -0
  92. litestar_vite/templates/react-inertia/resources/App.css.j2 +68 -0
  93. litestar_vite/templates/react-inertia/resources/main.tsx.j2 +17 -0
  94. litestar_vite/templates/react-inertia/resources/pages/Home.tsx.j2 +18 -0
  95. litestar_vite/templates/react-inertia/resources/ssr.tsx.j2 +19 -0
  96. litestar_vite/templates/react-inertia/vite.config.ts.j2 +59 -0
  97. litestar_vite/templates/react-router/index.html.j2 +12 -0
  98. litestar_vite/templates/react-router/src/App.css.j2 +17 -0
  99. litestar_vite/templates/react-router/src/App.tsx.j2 +7 -0
  100. litestar_vite/templates/react-router/src/main.tsx.j2 +10 -0
  101. litestar_vite/templates/react-router/vite.config.ts.j2 +39 -0
  102. litestar_vite/templates/react-tanstack/index.html.j2 +12 -0
  103. litestar_vite/templates/react-tanstack/openapi-ts.config.ts.j2 +18 -0
  104. litestar_vite/templates/react-tanstack/src/App.css.j2 +17 -0
  105. litestar_vite/templates/react-tanstack/src/main.tsx.j2 +21 -0
  106. litestar_vite/templates/react-tanstack/src/routeTree.gen.ts.j2 +7 -0
  107. litestar_vite/templates/react-tanstack/src/routes/__root.tsx.j2 +9 -0
  108. litestar_vite/templates/react-tanstack/src/routes/books.tsx.j2 +9 -0
  109. litestar_vite/templates/react-tanstack/src/routes/index.tsx.j2 +9 -0
  110. litestar_vite/templates/react-tanstack/vite.config.ts.j2 +39 -0
  111. litestar_vite/templates/svelte/index.html.j2 +13 -0
  112. litestar_vite/templates/svelte/src/App.svelte.j2 +30 -0
  113. litestar_vite/templates/svelte/src/app.css.j2 +45 -0
  114. litestar_vite/templates/svelte/src/main.ts.j2 +8 -0
  115. litestar_vite/templates/svelte/src/vite-env.d.ts.j2 +2 -0
  116. litestar_vite/templates/svelte/svelte.config.js.j2 +5 -0
  117. litestar_vite/templates/svelte/vite.config.ts.j2 +39 -0
  118. litestar_vite/templates/svelte-inertia/index.html.j2 +14 -0
  119. litestar_vite/templates/svelte-inertia/resources/app.css.j2 +21 -0
  120. litestar_vite/templates/svelte-inertia/resources/main.ts.j2 +11 -0
  121. litestar_vite/templates/svelte-inertia/resources/pages/Home.svelte.j2 +43 -0
  122. litestar_vite/templates/svelte-inertia/resources/vite-env.d.ts.j2 +2 -0
  123. litestar_vite/templates/svelte-inertia/svelte.config.js.j2 +5 -0
  124. litestar_vite/templates/svelte-inertia/vite.config.ts.j2 +37 -0
  125. litestar_vite/templates/sveltekit/openapi-ts.config.ts.j2 +15 -0
  126. litestar_vite/templates/sveltekit/src/app.css.j2 +40 -0
  127. litestar_vite/templates/sveltekit/src/app.html.j2 +12 -0
  128. litestar_vite/templates/sveltekit/src/hooks.server.ts.j2 +55 -0
  129. litestar_vite/templates/sveltekit/src/routes/+layout.svelte.j2 +12 -0
  130. litestar_vite/templates/sveltekit/src/routes/+page.svelte.j2 +34 -0
  131. litestar_vite/templates/sveltekit/svelte.config.js.j2 +12 -0
  132. litestar_vite/templates/sveltekit/tsconfig.json.j2 +14 -0
  133. litestar_vite/templates/sveltekit/vite.config.ts.j2 +31 -0
  134. litestar_vite/templates/vue/env.d.ts.j2 +7 -0
  135. litestar_vite/templates/vue/index.html.j2 +13 -0
  136. litestar_vite/templates/vue/src/App.vue.j2 +28 -0
  137. litestar_vite/templates/vue/src/main.ts.j2 +5 -0
  138. litestar_vite/templates/vue/src/style.css.j2 +45 -0
  139. litestar_vite/templates/vue/vite.config.ts.j2 +39 -0
  140. litestar_vite/templates/vue-inertia/env.d.ts.j2 +7 -0
  141. litestar_vite/templates/vue-inertia/index.html.j2 +14 -0
  142. litestar_vite/templates/vue-inertia/package.json.j2 +49 -0
  143. litestar_vite/templates/vue-inertia/resources/main.ts.j2 +18 -0
  144. litestar_vite/templates/vue-inertia/resources/pages/Home.vue.j2 +22 -0
  145. litestar_vite/templates/vue-inertia/resources/ssr.ts.j2 +21 -0
  146. litestar_vite/templates/vue-inertia/resources/style.css.j2 +21 -0
  147. litestar_vite/templates/vue-inertia/vite.config.ts.j2 +59 -0
  148. litestar_vite-0.15.0rc2.dist-info/METADATA +230 -0
  149. litestar_vite-0.15.0rc2.dist-info/RECORD +151 -0
  150. {litestar_vite-0.1.1.dist-info → litestar_vite-0.15.0rc2.dist-info}/WHEEL +1 -1
  151. litestar_vite/template_engine.py +0 -103
  152. litestar_vite-0.1.1.dist-info/METADATA +0 -68
  153. litestar_vite-0.1.1.dist-info/RECORD +0 -11
  154. {litestar_vite-0.1.1.dist-info → litestar_vite-0.15.0rc2.dist-info}/licenses/LICENSE +0 -0
litestar_vite/py.typed ADDED
File without changes
@@ -0,0 +1,20 @@
1
+ """Project scaffolding module for litestar-vite.
2
+
3
+ This module provides the `litestar assets init` command with framework-specific
4
+ template generation. It supports multiple frontend frameworks and build tools.
5
+
6
+ Supported frameworks:
7
+ - React (with TypeScript)
8
+ - Vue 3 (with TypeScript)
9
+ - Vue + Inertia.js
10
+ - Svelte 5 (with runes)
11
+ - SvelteKit
12
+ - Nuxt 3
13
+ - Astro
14
+ - HTMX + Alpine.js
15
+ """
16
+
17
+ from litestar_vite.scaffolding.generator import TemplateContext, generate_project
18
+ from litestar_vite.scaffolding.templates import FrameworkTemplate, get_available_templates
19
+
20
+ __all__ = ["FrameworkTemplate", "TemplateContext", "generate_project", "get_available_templates"]
@@ -0,0 +1,270 @@
1
+ """Project scaffolding generator.
2
+
3
+ This module handles the generation of project files from templates.
4
+ """
5
+
6
+ from collections.abc import Callable
7
+ from dataclasses import dataclass, field
8
+ from pathlib import Path
9
+ from typing import TYPE_CHECKING, Any
10
+
11
+ if TYPE_CHECKING:
12
+ from litestar_vite.scaffolding.templates import FrameworkTemplate
13
+
14
+
15
+ def _dict_factory() -> dict[str, Any]:
16
+ return {}
17
+
18
+
19
+ _DictStrAnyFactory: Callable[[], dict[str, Any]] = _dict_factory
20
+
21
+
22
+ @dataclass
23
+ class TemplateContext:
24
+ """Context variables for template rendering.
25
+
26
+ Attributes:
27
+ project_name: Name of the project
28
+ framework: The selected framework template
29
+ use_typescript: Whether to use TypeScript
30
+ use_tailwind: Whether to add TailwindCSS
31
+ vite_port: Vite dev server port
32
+ litestar_port: Litestar server port
33
+ asset_url: Base URL for assets
34
+ resource_dir: Source directory for frontend files
35
+ bundle_dir: Output directory for built files
36
+ enable_ssr: Whether SSR is enabled
37
+ enable_inertia: Whether Inertia.js is used
38
+ enable_types: Whether type generation is enabled
39
+ generate_zod: Whether to generate Zod schemas
40
+ generate_client: Whether to generate API client
41
+ """
42
+
43
+ project_name: str
44
+ framework: "FrameworkTemplate"
45
+ use_typescript: bool = True
46
+ use_tailwind: bool = False
47
+ vite_port: int = 5173
48
+ litestar_port: int = 8000
49
+ asset_url: str = "/static/"
50
+ resource_dir: str = "resources"
51
+ bundle_dir: str = "public"
52
+ static_dir: str = "public"
53
+ base_dir: str = "."
54
+ enable_ssr: bool = False
55
+ enable_inertia: bool = False
56
+ enable_types: bool = True
57
+ generate_zod: bool = False
58
+ generate_client: bool = False
59
+ extra: dict[str, Any] = field(default_factory=_DictStrAnyFactory)
60
+
61
+ def to_dict(self) -> dict[str, Any]:
62
+ """Convert context to dictionary for Jinja2 rendering.
63
+
64
+ Returns:
65
+ Dictionary of template variables.
66
+ """
67
+ return {
68
+ "project_name": self.project_name,
69
+ "framework": self.framework.type.value,
70
+ "framework_name": self.framework.name,
71
+ "use_typescript": self.use_typescript,
72
+ "use_tailwind": self.use_tailwind,
73
+ "vite_port": self.vite_port,
74
+ "litestar_port": self.litestar_port,
75
+ "asset_url": self.asset_url,
76
+ "resource_dir": self.resource_dir,
77
+ "bundle_dir": self.bundle_dir,
78
+ "static_dir": self.static_dir,
79
+ "base_dir": self.base_dir,
80
+ "enable_ssr": self.enable_ssr,
81
+ "enable_inertia": self.enable_inertia,
82
+ "enable_types": self.enable_types,
83
+ "generate_zod": self.generate_zod,
84
+ "generate_client": self.generate_client,
85
+ "dependencies": self.framework.dependencies,
86
+ "dev_dependencies": self.framework.dev_dependencies,
87
+ "vite_plugin": self.framework.vite_plugin,
88
+ "uses_vite": self.framework.uses_vite,
89
+ **self.extra,
90
+ }
91
+
92
+
93
+ def get_template_dir() -> Path:
94
+ """Get the directory containing framework templates.
95
+
96
+ Returns:
97
+ Path to the templates directory.
98
+ """
99
+ return Path(__file__).parent.parent / "templates"
100
+
101
+
102
+ def render_template(template_path: Path, context: dict[str, Any]) -> str:
103
+ """Render a Jinja2 template with the given context.
104
+
105
+ Templates are rendered with autoescaping disabled because the output is code
106
+ and configuration files, not HTML.
107
+
108
+ Args:
109
+ template_path: Path to the template file.
110
+ context: Dictionary of template variables.
111
+
112
+ Returns:
113
+ Rendered template content.
114
+ """
115
+ from jinja2 import Environment, FileSystemLoader
116
+
117
+ template_dir = template_path.parent
118
+ env = Environment(
119
+ loader=FileSystemLoader(str(template_dir)),
120
+ keep_trailing_newline=True,
121
+ autoescape=False, # noqa: S701
122
+ )
123
+ template = env.get_template(template_path.name)
124
+ return template.render(**context)
125
+
126
+
127
+ def _process_templates(
128
+ template_dir: Path,
129
+ output_dir: Path,
130
+ context_dict: dict[str, Any],
131
+ resource_dir: str,
132
+ *,
133
+ overwrite: bool,
134
+ skip_paths: "set[Path] | None" = None,
135
+ ) -> list[Path]:
136
+ """Process templates from a directory and generate output files.
137
+
138
+ This function rewrites template paths so frameworks can customize the output
139
+ directory layout:
140
+
141
+ - ``resources/`` templates are rewritten to the configured ``resource_dir``.
142
+ - ``public/`` templates can be relocated via ``static_dir`` in the context.
143
+
144
+ SSR entrypoints under ``resources/`` are only generated when SSR is enabled.
145
+
146
+ Args:
147
+ template_dir: Directory containing template files.
148
+ output_dir: Directory to write generated files.
149
+ context_dict: Template context dictionary.
150
+ resource_dir: Resource directory name for path rewriting.
151
+ overwrite: Whether to overwrite existing files.
152
+ skip_paths: Set of relative paths to skip.
153
+
154
+ Returns:
155
+ List of generated file paths.
156
+ """
157
+ from litestar.cli._utils import console # pyright: ignore[reportPrivateImportUsage]
158
+
159
+ generated_files: list[Path] = []
160
+ skip_paths = skip_paths or set()
161
+ enable_ssr = bool(context_dict.get("enable_ssr"))
162
+
163
+ for template_file in template_dir.glob("**/*.j2"):
164
+ relative_path = template_file.relative_to(template_dir)
165
+
166
+ if relative_path in skip_paths:
167
+ continue
168
+
169
+ if (
170
+ not enable_ssr
171
+ and relative_path.parts
172
+ and relative_path.parts[0] == "resources"
173
+ and relative_path.name.startswith("ssr.")
174
+ ):
175
+ continue
176
+
177
+ if relative_path.parts and relative_path.parts[0] == "resources":
178
+ relative_path = Path(resource_dir, *relative_path.parts[1:])
179
+
180
+ if relative_path.parts and relative_path.parts[0] == "public":
181
+ relative_path = Path(context_dict.get("static_dir", "public"), *relative_path.parts[1:])
182
+
183
+ output_path = output_dir / str(relative_path).replace(".j2", "")
184
+
185
+ if output_path.exists() and not overwrite:
186
+ console.print(f"[yellow]Skipping {output_path} (exists)[/]")
187
+ continue
188
+
189
+ _render_and_write(template_file, output_path, context_dict)
190
+ generated_files.append(output_path)
191
+
192
+ return generated_files
193
+
194
+
195
+ def generate_project(output_dir: Path, context: TemplateContext, *, overwrite: bool = False) -> list[Path]:
196
+ """Generate project files from templates.
197
+
198
+ Args:
199
+ output_dir: Directory to generate files in.
200
+ context: Template context with configuration.
201
+ overwrite: Whether to overwrite existing files.
202
+
203
+ Returns:
204
+ List of generated file paths.
205
+ """
206
+ from litestar.cli._utils import console # pyright: ignore[reportPrivateImportUsage]
207
+
208
+ template_dir = get_template_dir()
209
+ framework_dir = template_dir / context.framework.type.value
210
+ base_dir = template_dir / "base"
211
+ context_dict = context.to_dict()
212
+ generated_files: list[Path] = []
213
+
214
+ framework_overrides: set[Path] = set()
215
+ if framework_dir.exists():
216
+ framework_overrides = {
217
+ template_file.relative_to(framework_dir) for template_file in framework_dir.glob("**/*.j2")
218
+ }
219
+
220
+ actual_output_dir = output_dir / context.base_dir if context.base_dir not in {"", "."} else output_dir
221
+ actual_output_dir.mkdir(parents=True, exist_ok=True)
222
+
223
+ if context.framework.uses_vite and base_dir.exists():
224
+ generated_files.extend(
225
+ _process_templates(
226
+ base_dir,
227
+ actual_output_dir,
228
+ context_dict,
229
+ context.resource_dir,
230
+ overwrite=overwrite,
231
+ skip_paths=framework_overrides,
232
+ )
233
+ )
234
+
235
+ if framework_dir.exists():
236
+ generated_files.extend(
237
+ _process_templates(
238
+ framework_dir, actual_output_dir, context_dict, context.resource_dir, overwrite=overwrite
239
+ )
240
+ )
241
+ else:
242
+ console.print(f"[dim]No framework templates for {context.framework.type.value}, using base templates[/]")
243
+
244
+ if context.use_tailwind:
245
+ tailwind_dir = template_dir / "addons" / "tailwindcss"
246
+ if tailwind_dir.exists():
247
+ generated_files.extend(
248
+ _process_templates(
249
+ tailwind_dir, actual_output_dir, context_dict, context.resource_dir, overwrite=overwrite
250
+ )
251
+ )
252
+
253
+ return generated_files
254
+
255
+
256
+ def _render_and_write(template_path: Path, output_path: Path, context: dict[str, Any]) -> None:
257
+ """Render a template and write to output file.
258
+
259
+ Args:
260
+ template_path: Path to the template file.
261
+ output_path: Path to write the rendered content.
262
+ context: Template context dictionary.
263
+ """
264
+ from litestar.cli._utils import console # pyright: ignore[reportPrivateImportUsage]
265
+
266
+ output_path.parent.mkdir(parents=True, exist_ok=True)
267
+
268
+ content = render_template(template_path, context)
269
+ output_path.write_text(content, encoding="utf-8")
270
+ console.print(f"[green]Created {output_path}[/]")