Newer
Older
hello-programmer-world / src / lib / getRawText.ts
import fs from "node:fs";
import path from "node:path";

/**
 * 指定されたパスのファイルをプレーンテキストとして読み込む
 * @param relativePath project root からの相対パス
 */
export default function readRawText(relativePath: string): string {
  console.log(`Reading file from path: ${relativePath}`);
  const fullPath = path.resolve(process.cwd(), relativePath);

  if (!fs.existsSync(fullPath)) {
    throw new Error(`File not found: ${fullPath}`);
  }

  return fs.readFileSync(fullPath, "utf8");
}