Files
Agent-System/docs/user-manual/scripts/build-formats.mjs
T

46 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
// 由 manual.md 生成 HTML / PDF / DOCX 三种格式到 dist/
// 依赖:pandoc(brew install pandoc)、playwright(复用 web/node_modules)
// 运行:node docs/user-manual/scripts/build-formats.mjs
import { execFileSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const MANUAL_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const DIST = path.join(MANUAL_DIR, 'dist');
const MD = path.join(MANUAL_DIR, 'manual.md');
const CSS = path.join(MANUAL_DIR, 'scripts', 'manual.css');
fs.mkdirSync(DIST, { recursive: true });
function pandoc(args) {
execFileSync('pandoc', args, { cwd: MANUAL_DIR, stdio: 'inherit' });
}
// 1) HTML(嵌入图片与样式,单文件可分发)
const htmlPath = path.join(DIST, '系统使用说明书.html');
pandoc([
'manual.md', '-f', 'gfm', '-t', 'html5', '--standalone',
'--embed-resources', `--css=${CSS}`,
'--metadata', 'title=水木东方 · 医疗器械 AI 协同工作台 — 系统使用说明书',
'--toc', '--toc-depth=2', '--shift-heading-level-by=0',
'-o', htmlPath,
]);
console.log('[ok] HTML:', htmlPath);
// 2) DOCX(pandoc 自动嵌入 images/ 下的图片)
const docxPath = path.join(DIST, '系统使用说明书.docx');
pandoc(['manual.md', '-f', 'gfm', '--resource-path=.', '-o', docxPath]);
console.log('[ok] DOCX:', docxPath);
// 3) PDF(主机缺 chromium 系统依赖,改在 playwright docker 镜像内打印)
const pdfPath = path.join(DIST, '系统使用说明书.pdf');
const REPO = '/home/weichen/projects/Agent-System';
execFileSync('docker', [
'run', '--rm', '-v', `${REPO}:${REPO}`, '-w', `${REPO}/web`,
'mcr.microsoft.com/playwright:v1.63.0-noble',
'node', path.join(MANUAL_DIR, 'scripts', 'pdf-print.mjs'), htmlPath, pdfPath,
], { stdio: 'inherit' });