@berlysia/vertical-writing-slide-system 0.0.25 → 0.0.26

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.
package/cli.js CHANGED
@@ -25,9 +25,12 @@ async function runDev() {
25
25
  libPath,
26
26
  // Allow serving files from the current working directory
27
27
  projectPath,
28
+ // Allow serving public assets from project directory
29
+ resolve(projectPath, "public"),
28
30
  ],
29
31
  },
30
32
  },
33
+ publicDir: resolve(projectPath, "public"), // Set public directory to project path
31
34
  });
32
35
 
33
36
  await server.listen();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@berlysia/vertical-writing-slide-system",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "vertical-slides": "./cli.js"
@@ -1,7 +1,8 @@
1
1
  import type { Plugin, ViteDevServer, ResolvedConfig } from "vite";
2
2
  import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
- import { mkdirSync, copyFileSync, readdirSync } from "node:fs";
4
+ import { mkdirSync, readdirSync } from "node:fs";
5
+ import { copyFile } from "node:fs/promises";
5
6
  import prompts from "prompts";
6
7
  import { compile } from "@mdx-js/mdx";
7
8
  import { unified } from "unified";
@@ -116,7 +117,7 @@ function loadAdjacentScripts(
116
117
  );
117
118
  }
118
119
  } catch (error) {
119
- logger.warn("Failed to parse scripts.json:", error);
120
+ logger.warn(`Failed to parse scripts.json: ${error}`);
120
121
  }
121
122
  }
122
123
 
@@ -474,36 +475,56 @@ export default async function slidesPlugin(
474
475
  async buildStart() {
475
476
  // Handle images during dev mode
476
477
  if (resolvedConfig.command === "serve") {
477
- const targetImagesDir = path.resolve(
478
- resolvedConfig.root,
479
- "public/slide-assets/images",
480
- );
478
+ // CLIモードでは適切なパスを使用
479
+ const isExternalCLI = process.cwd() !== resolvedConfig.root;
480
+ const targetImagesDir = isExternalCLI
481
+ ? path.resolve(process.cwd(), "public/slide-assets/images")
482
+ : path.resolve(resolvedConfig.root, "public/slide-assets/images");
483
+
481
484
  const sourceImagesDir = path.resolve(
482
485
  config.slidesDir,
483
486
  config.collection,
484
487
  "images",
485
488
  );
486
489
 
490
+ logger.info(`Checking for images in: ${sourceImagesDir}`);
491
+ logger.info(`Target images directory: ${targetImagesDir}`);
492
+
487
493
  // Copy images from slides directory
488
494
  if (fs.existsSync(sourceImagesDir)) {
489
495
  try {
490
496
  // Create target directory if it doesn't exist
491
497
  mkdirSync(targetImagesDir, { recursive: true });
492
498
 
493
- // Copy all files from source to target
499
+ // Copy all files from source to target using async operations
494
500
  const imageFiles = readdirSync(sourceImagesDir);
495
- for (const file of imageFiles) {
496
- const sourcePath = path.join(sourceImagesDir, file);
497
- const targetPath = path.join(targetImagesDir, file);
498
- copyFileSync(sourcePath, targetPath);
501
+ logger.info(`Found ${imageFiles.length} image files to copy`);
502
+
503
+ if (imageFiles.length > 0) {
504
+ const copyPromises = imageFiles.map(async (file) => {
505
+ const sourcePath = path.join(sourceImagesDir, file);
506
+ const targetPath = path.join(targetImagesDir, file);
507
+ await copyFile(sourcePath, targetPath);
508
+ logger.info(`Copied image: ${file}`);
509
+ return file;
510
+ });
511
+
512
+ // すべての画像コピーが完了するまで待機
513
+ const copiedFiles = await Promise.all(copyPromises);
514
+ logger.info(
515
+ `Successfully copied ${copiedFiles.length} slide images`,
516
+ );
517
+ } else {
518
+ logger.info("No image files found to copy");
499
519
  }
500
- logger.info("Copied slide images successfully");
501
520
  } catch (error) {
502
521
  if (error instanceof Error) {
503
522
  logger.error("Failed to copy slide images", error);
504
523
  }
505
524
  throw error;
506
525
  }
526
+ } else {
527
+ logger.info(`No images directory found at: ${sourceImagesDir}`);
507
528
  }
508
529
  }
509
530
  },