Skip to content

Commit

Permalink
feat: updated printing
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin committed Dec 17, 2023
1 parent 4fb1148 commit 74fe667
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 11 additions & 3 deletions litestar_vite/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,14 @@ def vite_init(
if not no_install:
if find_spec("nodeenv") is not None and plugin.config.detect_nodeenv:
"""Detect nodeenv installed in the current python env before using a global version"""
nodeenv_command = str(Path(Path(sys.executable) / "nodeenv")) or "nodeenv"
nodeenv_command = (
str(Path(Path(sys.executable) / "nodeenv"))
if Path(Path(sys.executable) / "nodeenv").exists()
else "nodeenv"
)
install_dir = os.environ.get("VIRTUAL_ENV", sys.prefix)
console.rule("[yellow]Starting Nodeenv installation process[/]", align="left")
console.print("Installing Node environment to %s:", install_dir)
console.print(f"Installing Node environment into {install_dir}")
execute_command([nodeenv_command, install_dir, "--force", "--quiet"])

console.rule("[yellow]Starting package installation process[/]", align="left")
Expand Down Expand Up @@ -185,7 +189,11 @@ def vite_install(app: Litestar, verbose: bool) -> None:

if find_spec("nodeenv") is not None and plugin.config.detect_nodeenv:
"""Detect nodeenv installed in the current python env before using a global version"""
nodeenv_command = str(Path(Path(sys.executable) / "nodeenv")) or "nodeenv"
nodeenv_command = (
str(Path(Path(sys.executable) / "nodeenv"))
if Path(Path(sys.executable) / "nodeenv").exists()
else "nodeenv"
)
install_dir = os.environ.get("VIRTUAL_ENV", sys.prefix)
console.rule("[yellow]Starting Nodeenv installation process[/]", align="left")
console.print("Installing Node environment to %s:", install_dir)
Expand Down
7 changes: 3 additions & 4 deletions litestar_vite/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def to_json(value: Any) -> str:


def init_vite(
app: Litestar,
app: Litestar, # noqa: ARG001
root_path: Path,
resource_path: Path,
asset_url: str,
Expand All @@ -57,7 +57,6 @@ def init_vite(
autoescape=select_autoescape(),
)

logger = app.get_logger()
enabled_templates: set[str] = VITE_INIT_TEMPLATES
enabled_resources: set[str] = DEFAULT_RESOURCES
dependencies: dict[str, str] = DEFAULT_DEPENDENCIES
Expand All @@ -73,7 +72,7 @@ def init_vite(
for template_name, template in templates.items():
target_file_name = template_name.removesuffix(".j2")
with Path(target_file_name).open(mode="w") as file:
logger.info("Writing %s", target_file_name)
console.print(f" * Writing {target_file_name} to {Path(target_file_name).absolute()}")

file.write(
template.render(
Expand All @@ -93,7 +92,7 @@ def init_vite(

for resource_name in enabled_resources:
with Path(resource_path / resource_name).open(mode="w") as file:
console.print("Writing %s", resource_name)
console.print(f" * Writing {resource_name} to {Path(resource_path / resource_name).absolute()}")


def get_template(
Expand Down

0 comments on commit 74fe667

Please sign in to comment.