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
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 | The root directory passed to |
ts | 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 | 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 |
|
ts | A function for logging informational messages |
ts | 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.