Skip to content
Open
95 changes: 95 additions & 0 deletions src/checks/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { CheckConfig } from '../types.ts';

/**
* Manages a collection of registered checks.
*
* @since TBD
*/
export class CheckCollection {
private checks: Map<string, CheckConfig> = new Map();

/**
* Registers a check configuration.
*
* @since TBD
*
* @param {CheckConfig} config - The check configuration to add.
*
* @returns {void}
*/
add(config: CheckConfig): void {
this.checks.set(config.slug, config);
}

/**
* Retrieves a check configuration by its slug.
*
* @since TBD
*
* @param {string} slug - The slug of the check to retrieve.
*
* @returns {CheckConfig | undefined} The check configuration, or undefined if not found.
*/
get(slug: string): CheckConfig | undefined {
return this.checks.get(slug);
}

/**
* Checks whether a check with the given slug is registered.
*
* @since TBD
*
* @param {string} slug - The slug to check for.
*
* @returns {boolean} True if a check with the given slug is registered, false otherwise.
*/
has(slug: string): boolean {
return this.checks.has(slug);
}

/**
* Removes a check by its slug.
*
* @since TBD
*
* @param {string} slug - The slug of the check to remove.
*
* @returns {void}
*/
remove(slug: string): void {
this.checks.delete(slug);
}

/**
* Returns all registered checks as an array.
*
* @since TBD
*
* @returns {CheckConfig[]} An array of all registered check configurations.
*/
getAll(): CheckConfig[] {
return Array.from(this.checks.values());
}

/**
* Returns the number of registered checks.
*
* @since TBD
*
* @returns {number} The number of registered checks.
*/
get size(): number {
return this.checks.size;
}

/**
* Allows iterating over all registered checks.
*
* @since TBD
*
* @returns {Iterator<CheckConfig>} An iterator over all registered check configurations.
*/
[Symbol.iterator](): Iterator<CheckConfig> {
return this.checks.values();
}
}
12 changes: 12 additions & 0 deletions src/checks/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { CheckConfig, CheckResult } from '../types.ts';

export interface CheckContext {
config: CheckConfig;
workingDir: string;
isDev: boolean;
}

export interface CheckModule {
configure?: (config: CheckConfig) => void;
execute: (context: CheckContext) => Promise<CheckResult>;
}
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { createApp } from './app.ts';
import { registerCheckCommand } from './commands/check.ts';
import { registerHelpCommand } from './commands/help.ts';

const program = createApp();

registerCheckCommand(program);
registerHelpCommand(program);

program.parseAsync(process.argv).catch((err) => {
Expand Down
Loading