This commit is contained in:
Steven Lee 2023-09-12 07:23:07 +00:00
parent 5e0290f8da
commit a3d1c3362f

View file

@ -13,8 +13,7 @@ from metagpt.const import PROJECT_ROOT
from metagpt.logs import logger
from metagpt.utils.common import check_cmd_exists
import os
import sys
def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height=2048) -> int:
"""suffix: png/svg/pdf
@ -28,13 +27,12 @@ def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height
# Write the Mermaid code to a temporary file
tmp = Path(f"{output_file_without_suffix}.mmd")
tmp.write_text(mermaid_code, encoding="utf-8")
if check_cmd_exists("mmdc") != 0:
logger.warning("RUN `npm install -g @mermaid-js/mermaid-cli` to install mmdc")
return -1
engine = CONFIG.mermaid_engine.lower()
if engine == "nodejs":
if check_cmd_exists("mmdc") != 0:
logger.warning("RUN `npm install -g @mermaid-js/mermaid-cli` to install mmdc")
return -1
for suffix in ["pdf", "svg", "png"]:
output_file = f"{output_file_without_suffix}.{suffix}"
# Call the `mmdc` command to convert the Mermaid code to a PNG
@ -59,12 +57,12 @@ def mermaid_to_file(mermaid_code, output_file_without_suffix, width=2048, height
else:
subprocess.run([CONFIG.mmdc, "-i", str(tmp), "-o", output_file, "-w", str(width), "-H", str(height)])
else:
if engine not in ['playwright', 'puppeteer', 'ink']:
if engine not in ['playwright', 'pyppeteer', 'ink']:
logger.warning(f"Unsupported mermaid engine: {engine}")
return -1
__dirname = os.path.dirname(os.path.abspath(__file__))
module_path = os.path.join(__dirname, f'mmdc_{engine}.py')
import sys
# 构建命令行参数
command = [
sys.executable,