Skip to content

Custom checker ​

A checker is a class that extends BaseChecker and checks the stabilized state of the project. Checkers run after plugins have completed generation, cleanup, file writes, and all cascading iterations.

check ​

ts
import fs from 'node:fs';
import path from 'node:path';

import { BaseChecker, type TypeCheckerCheckArgs } from '@arfa-tools/generator';

export class CheckerReadme extends BaseChecker {
  name = 'readme';

  check({ rootDir, checkerError }: TypeCheckerCheckArgs): void {
    const readmePath = path.resolve(rootDir, 'README.md');

    if (fs.existsSync(readmePath)) return;

    checkerError({
      message: 'README.md is required',
      error: new Error(`File not found: ${readmePath}`),
    });
  }
}
ts
rootDir: string

The root directory passed to FileGenerator

ts
changedFiles: Array<{
  relativePath: string;
  absolutePath: string;
}>

Unique paths of files added or changed by the user in watch mode, or written by the generator across all iterations of the current run, excluding deleted files

ts
deletedFiles: Array<{
  relativePath: string;
  absolutePath: string;
}>

Unique paths of files deleted by the user in watch mode, or by the generator during cleanup across all iterations of the current run

ts
isFullGeneration: boolean

true for a full runFullCycle() run and false for an incremental run in watch mode

ts
checkerLog: (log: {
  message: string;
}) => void

A function for logging informational messages

ts
checkerError: (log: {
  message: string;
  error: unknown;
}) => void

A function for reporting errors

Reporting errors ​

If a checker can find multiple independent violations, call checkerError for each one instead of throwing an exception, so the full list is preserved in the logs.

Use throw for infrastructure failures, such as read errors or an inability to start an external tool. FileGenerator catches the exception and adds it to the overall result as a checker error, without blocking the next checker or the afterCheckers method.

MIT License