All files / src markdown-file.ts

100% Statements 49/49
100% Branches 8/8
100% Functions 7/7
100% Lines 49/49

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 501x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 10x 10x 1x 1x 10x 10x 1x 1x 10x 10x 1x 1x 10x 1x 1x 10x  
import { writeFileSync } from 'fs';
import { join } from 'path';
import {
  MarkdownDocument,
  MarkdownDocumentOptions,
} from './markdown-document.js';
 
export type MarkdownFileOptions = MarkdownDocumentOptions & {
  fileName: string;
 
  /**
   * The directory the markdown file will be written to
   *
   * @default project root directory
   */
  outDir?: string;
};
 
export class MarkdownFile extends MarkdownDocument {
  private _outDir: string;
 
  private _fileName: string;
 
  constructor(options: MarkdownFileOptions) {
    super(options);
 
    this._fileName = options.fileName;
    this._outDir = options.outDir ?? process.cwd();
  }
 
  public get fileName() {
    return this._fileName;
  }
 
  public get outDir() {
    return this._outDir;
  }
 
  public get fullFilePath() {
    return join(this._outDir, this._fileName);
  }
 
  public toFile() {
    writeFileSync(join(this._outDir, this._fileName), this.toString());
  }
}
 
export const markdownFile = (options: MarkdownFileOptions) =>
  new MarkdownFile(options);