From 20521147594f40efb3ace03ed1723da65702b941 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Sat, 25 Feb 2023 01:54:17 +1300 Subject: [PATCH] feat: add validator run event to allow plugins to perform custom validation --- src/index.ts | 2 ++ src/lib/validation/index.ts | 1 + src/lib/validation/validator-events.ts | 3 +++ src/lib/validation/validator.ts | 14 ++++++++++++++ 4 files changed, 20 insertions(+) create mode 100644 src/lib/validation/index.ts create mode 100644 src/lib/validation/validator-events.ts diff --git a/src/index.ts b/src/index.ts index a9f154079a..e91d5a77e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,6 +28,8 @@ export { } from "./lib/output"; export type { RenderTemplate, RendererHooks } from "./lib/output"; +export { Validator } from "./lib/validation"; + export { ArgumentsReader, BindOption, diff --git a/src/lib/validation/index.ts b/src/lib/validation/index.ts new file mode 100644 index 0000000000..db7351171d --- /dev/null +++ b/src/lib/validation/index.ts @@ -0,0 +1 @@ +export { Validator } from "./validator"; diff --git a/src/lib/validation/validator-events.ts b/src/lib/validation/validator-events.ts new file mode 100644 index 0000000000..6eaf8a137b --- /dev/null +++ b/src/lib/validation/validator-events.ts @@ -0,0 +1,3 @@ +export const ValidatorEvents = { + RUN: "run_validator", +} as const; diff --git a/src/lib/validation/validator.ts b/src/lib/validation/validator.ts index 840e88caef..47cd17dfdc 100644 --- a/src/lib/validation/validator.ts +++ b/src/lib/validation/validator.ts @@ -6,6 +6,7 @@ import { ValidatorComponent } from "./components"; import { validateExports } from "./exports"; import { validateDocumentation } from "./documentation"; import { validateLinks } from "./links"; +import { ValidatorEvents } from "./validator-events"; @Component({ name: "validator", @@ -16,6 +17,17 @@ export class Validator extends ChildableComponent< Application, ValidatorComponent > { + /** + * General events + */ + + /** + * Triggered when the converter begins converting a project. + * The listener will be given a {@link Context} object. + * @event + */ + static readonly EVENT_RUN = ValidatorEvents.RUN; + constructor(owner: Application) { super(owner); } @@ -44,6 +56,8 @@ export class Validator extends ChildableComponent< validateLinks(project, this.application.logger); } + this.trigger(Validator.EVENT_RUN, project); + this.application.logger.verbose( `Validation took ${Date.now() - start}ms` );