Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion mkdocs_likec4/generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import shutil
import subprocess
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -55,7 +56,13 @@ def generate(
project_path,
)

cmd = ["npx", "likec4", "codegen", "webcomponent"]
npx = shutil.which("npx")
if not npx:
log.error(
"mkdocs-likec4: 'npx' or 'likec4' command not found. "
"Ensure Node.js and likec4 are installed."
)
cmd = [npx, "likec4", "codegen", "webcomponent"]
if not use_dot:
cmd.append("--no-use-dot")
if project_name is not None:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class TestGenerate:
"""Tests for the generate method."""

@patch("mkdocs_likec4.generator.subprocess.run")
def test_generate_default_project(self, mock_run, tmp_path):
@patch("mkdocs_likec4.generator.shutil.which")
def test_generate_default_project(self, mock_which, mock_run, tmp_path):
"""Test generating web component for default project."""
site_dir = tmp_path / "site"
site_dir.mkdir()
Expand All @@ -46,10 +47,11 @@ def test_generate_default_project(self, mock_run, tmp_path):
site_dir=site_dir,
)

mock_which.assert_called_once_with("npx")
mock_run.assert_called_once()
call_args = mock_run.call_args[0][0]
call_kwargs = mock_run.call_args[1]
assert call_args[0] == "npx"
assert call_args[0] == mock_which.return_value
assert call_args[1] == "likec4"
assert call_args[2] == "codegen"
assert call_args[3] == "webcomponent"
Expand Down
3 changes: 2 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for the LikeC4 plugin module."""

import json
from pathlib import Path
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -75,7 +76,7 @@ def test_discover_nested_project(self, plugin, docs_dir):
plugin._discover_projects(docs_dir)

assert "nested" in plugin.project_map
assert plugin.project_map["nested"] == "sub/nested"
assert plugin.project_map["nested"] == str(Path("sub/nested"))

def test_discover_no_projects_uses_default(self, plugin, docs_dir):
"""Test that no projects defaults to root project."""
Expand Down
Loading