build: add precompiled CLI distribution

This commit is contained in:
2026-08-29 19:00:14 +08:00
parent d074681928
commit 4d1dc76e31
77 changed files with 3461 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import 'dotenv/config';
import { mkdir } from 'node:fs/promises';
import path from 'node:path';
import { loadProjectConfig } from "./lib/config.js";
import { resolveDeck } from "./lib/content.js";
import { runSlidev } from "./lib/run-slidev.js";
import { resolveTheme } from "./lib/theme.js";
const args = process.argv.slice(2);
const slug = args.find(argument => !argument.startsWith('-'));
const formatIndex = args.indexOf('--format');
const format = formatIndex >= 0 ? args[formatIndex + 1] : 'pdf';
const allowed = new Set(['pdf', 'png', 'pptx', 'md']);
if (!allowed.has(format))
throw new Error(`不支持导出格式:${format}`);
const config = await loadProjectConfig();
const deck = await resolveDeck(slug, process.cwd(), config.slidesDir);
const exportDir = path.join(process.cwd(), config.exportDir);
await mkdir(exportDir, { recursive: true });
const output = path.join(exportDir, `${deck.slug}.${format}`);
const slidevArgs = [
'export',
deck.entry,
'--theme',
resolveTheme(config.theme),
'--format',
format,
'--output',
output,
];
// Slidev's one-piece exporter may capture off-screen lazy images before they
// are painted. Per-slide export renders each canvas as the active slide and is
// reliable for Markdown images across PNG, PDF, and screenshot-based PPTX.
if (format !== 'md')
slidevArgs.push('--per-slide');
await runSlidev(slidevArgs);
console.log(`导出完成:${path.relative(process.cwd(), output)}`);
//# sourceMappingURL=export.js.map