All files / src/pipeline/rendering copy-static-root.js

0% Statements 0/19
0% Branches 0/6
0% Functions 0/1
0% Lines 0/17

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                                                                                                     
/**
 * Copies files from `<spec_directory>/static-root/` to the docs output directory.
 *
 * Purpose: some deployment targets (GitHub Pages, Netlify, etc.) require files
 * to live at the repository/docs root — typical examples are `CNAME`,
 * `robots.txt`, and `_config.yml`. Because `docs/` is gitignored (it is
 * rebuilt on every render), these files cannot live there directly. Instead,
 * place them in `spec/static-root/`. This module bridges the gap by copying
 * every *file* in that directory to `docs/` after each render.
 *
 * Only top-level files are copied; sub-directories are intentionally ignored
 * to keep the semantics simple. The README.md that ships with the boilerplate
 * explains this and is skipped so it does not pollute the output directory.
 */
 
const fs = require('fs-extra');
const path = require('node:path');
const Logger = require('../../utils/logger');
 
const STATIC_ROOT_DIR_NAME = 'static-root';
const SKIP_FILES = ['README.md'];
 
/**
 * Copies top-level files from `<specDirectory>/static-root/` into `destination`.
 *
 * @param {string} specDirectory - Absolute or relative path to the spec source directory.
 * @param {string} destination   - Absolute or relative path to the docs output directory.
 */
function copyStaticRoot(specDirectory, destination) {
  const staticRootDir = path.join(specDirectory, STATIC_ROOT_DIR_NAME);
 
  if (!fs.existsSync(staticRootDir)) {
    return;
  }
 
  const entries = fs.readdirSync(staticRootDir, { withFileTypes: true });
 
  for (const entry of entries) {
    if (!entry.isFile()) continue;
    if (SKIP_FILES.includes(entry.name)) continue;
 
    const src = path.join(staticRootDir, entry.name);
    const dest = path.join(destination, entry.name);
 
    fs.copySync(src, dest);
    Logger.success(`Copied static-root file → ${destination}: ${entry.name}`);
  }
}
 
module.exports = { copyStaticRoot };