diff --git a/scripts/cad_dxf_report.py b/scripts/cad_dxf_report.py index 1eafed2..4f23287 100755 --- a/scripts/cad_dxf_report.py +++ b/scripts/cad_dxf_report.py @@ -107,11 +107,41 @@ def libredwg_wasm_module_dir() -> Path | None: return None +def node_executable() -> str | None: + """Resolve Node from env, PATH, or common platform install locations.""" + override = os.environ.get("NODE") + if override: + return override if Path(override).exists() else None + found = shutil.which("node") + if found: + return found + candidates = [] + if sys.platform == "darwin": + candidates.extend((Path("/opt/homebrew/bin/node"), Path("/usr/local/bin/node"))) + elif sys.platform == "win32": + candidates.extend( + Path(path) / "nodejs" / "node.exe" + for path in (os.environ.get("ProgramFiles"), os.environ.get("ProgramFiles(x86)")) + if path + ) + for candidate in candidates: + if candidate.exists(): + return str(candidate) + return None + + def run_wasm_libredwg(source: Path, dest: Path, work_dir: Path, vendor_dir: Path) -> dict: """Convert one DWG through the packaged libredwg WASM bridge.""" - node = shutil.which("node") + node = node_executable() module_dir = libredwg_wasm_module_dir() - if not node or module_dir is None: + if not node: + return { + "source": str(source), + "dest": str(dest), + "status": "missing_node", + "message": "Install Node.js or set NODE to its executable path.", + } + if module_dir is None: return { "source": str(source), "dest": str(dest),