All files / stream-counter/scripts copy-coverage.js

0% Statements 0/45
0% Branches 0/1
0% Functions 0/1
0% Lines 0/45

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                                                                               
import { promises as fs } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
 
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
 
const sourceDir = join(__dirname, "..", "coverage");
const targetDir = join(__dirname, "..", "reports-build", "coverage");
 
async function copyCoverage() {
  try {
    // カバレッジディレクトリが存在するかチェック
    try {
      await fs.access(sourceDir);
    } catch {
      console.log(
        "⚠️  Coverage directory not found. Please run coverage tests first."
      );
      return;
    }
 
    // reports-build/coverageディレクトリを作成
    await fs.mkdir(targetDir, { recursive: true });
 
    // カバレッジディレクトリの内容を再帰的にコピー
    await copyDirectory(sourceDir, targetDir);
 
    console.log(
      "✅ Coverage reports copied successfully to reports-build/coverage/"
    );
  } catch (error) {
    console.error("❌ Error copying coverage:", error);
    process.exit(1);
  }
}
 
async function copyDirectory(source, target) {
  const entries = await fs.readdir(source, { withFileTypes: true });
 
  for (const entry of entries) {
    const sourcePath = join(source, entry.name);
    const targetPath = join(target, entry.name);
 
    if (entry.isDirectory()) {
      await fs.mkdir(targetPath, { recursive: true });
      await copyDirectory(sourcePath, targetPath);
    } else {
      await fs.copyFile(sourcePath, targetPath);
      console.log(`✅ Copied: ${entry.name}`);
    }
  }
}
 
copyCoverage();