slidev-workspace 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +50 -4
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { dirname, join, resolve } from "node:path";
4
4
  import { existsSync, mkdirSync, readdirSync } from "node:fs";
5
- import { cp } from "node:fs/promises";
5
+ import { cp, rm } from "node:fs/promises";
6
6
  import { execSync } from "node:child_process";
7
7
  import { build, createServer } from "vite";
8
8
  import vue from "@vitejs/plugin-vue";
@@ -365,6 +365,46 @@ async function buildAllSlides() {
365
365
  }
366
366
  }
367
367
  }
368
+ async function exportOgImages() {
369
+ const workspaceCwd = process.env.SLIDEV_WORKSPACE_CWD || process.cwd();
370
+ const config = loadConfig(workspaceCwd);
371
+ const slidesDirs = resolveSlidesDirs(config, workspaceCwd);
372
+ console.log("🖼️ Exporting OG images for all slides...");
373
+ try {
374
+ execSync("pnpm -r export --format png --range 1", {
375
+ cwd: workspaceCwd,
376
+ stdio: "inherit"
377
+ });
378
+ console.log("📦 Copying exported images to og-image.png...");
379
+ for (const slidesDir of slidesDirs) {
380
+ if (!existsSync(slidesDir)) {
381
+ console.warn(`⚠️ Slides directory not found: ${slidesDir}`);
382
+ continue;
383
+ }
384
+ const slides = readdirSync(slidesDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
385
+ for (const slideName of slides) {
386
+ const slideDir = join(slidesDir, slideName);
387
+ const packageJsonPath = join(slideDir, "package.json");
388
+ if (!existsSync(packageJsonPath)) continue;
389
+ const exportedFile = join(slideDir, "slides-export", "1.png");
390
+ const targetFile = join(slideDir, "og-image.png");
391
+ const exportDir = join(slideDir, "slides-export");
392
+ if (existsSync(exportedFile)) {
393
+ await cp(exportedFile, targetFile);
394
+ console.log(`✅ Generated OG image for: ${slideName}`);
395
+ await rm(exportDir, {
396
+ recursive: true,
397
+ force: true
398
+ });
399
+ } else console.warn(`⚠️ Export file not found for ${slideName}: ${exportedFile}`);
400
+ }
401
+ }
402
+ console.log("✅ All OG images exported successfully!");
403
+ } catch (error) {
404
+ console.error("❌ Failed to export OG images:", error);
405
+ process.exit(1);
406
+ }
407
+ }
368
408
  async function copyToGhPages() {
369
409
  const workspaceCwd = process.env.SLIDEV_WORKSPACE_CWD || process.cwd();
370
410
  const config = loadConfig(workspaceCwd);
@@ -424,13 +464,15 @@ Usage:
424
464
  slidev-workspace <command> [options]
425
465
 
426
466
  Commands:
427
- dev Start the development server
428
- build Build the project for production
429
- help Show this help message
467
+ dev Start the development server
468
+ build Build the project for production
469
+ export-og Export OG images for all slides
470
+ help Show this help message
430
471
 
431
472
  Examples:
432
473
  slidev-workspace dev # Start development server
433
474
  slidev-workspace build # Build all slides and preview app
475
+ slidev-workspace export-og # Export OG images for all slides
434
476
 
435
477
  Configuration:
436
478
  Use slidev-workspace.yml to set baseUrl for all builds
@@ -449,6 +491,10 @@ async function main() {
449
491
  process.env.SLIDEV_WORKSPACE_CWD = process.cwd();
450
492
  await runViteBuild();
451
493
  break;
494
+ case "export-og":
495
+ process.env.SLIDEV_WORKSPACE_CWD = process.cwd();
496
+ await exportOgImages();
497
+ break;
452
498
  case "help":
453
499
  case "--help":
454
500
  case "-h":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slidev-workspace",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "A workspace tool for managing multiple Slidev presentations with API-based content management",
5
5
  "type": "module",
6
6
  "license": "MIT",