@kubb/core
Advanced tools
Comparing version 0.31.1 to 0.31.2
@@ -174,3 +174,3 @@ import EventEmitter from 'events'; | ||
*/ | ||
validate: (this: PluginContext, plugins: KubbPlugin[]) => MaybePromise<ValidationResult>; | ||
validate: (this: PluginContext, plugins: KubbPlugin[]) => MaybePromise<true>; | ||
/** | ||
@@ -232,5 +232,2 @@ * Start of the lifecycle of a plugin. | ||
}; | ||
type ValidationResult = true | { | ||
message: string; | ||
}; | ||
type TransformResult = string | null; | ||
@@ -341,2 +338,6 @@ /** | ||
export { Argument0, CLIOptions, Cache, CacheStore, CorePluginOptions, EmittedFile, File, FileManager, FileName, KubbConfig, KubbPlugin, KubbUserConfig, LogLevel, LogType, Logger, MaybePromise, OptionalPath, Path, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, ResolveIdParams, Status, Strategy, TransformResult, TreeNode, UUID, ValidationResult, build, createPlugin, createPluginCache, build as default, defineConfig, format, getPathMode, getRelativePath, hooks, isPromise, write }; | ||
declare class ValidationPluginError extends Error { | ||
} | ||
declare const validatePlugins: (plugins: KubbPlugin[], dependedPluginNames: string | string[]) => true; | ||
export { Argument0, CLIOptions, Cache, CacheStore, CorePluginOptions, EmittedFile, File, FileManager, FileName, KubbConfig, KubbPlugin, KubbUserConfig, LogLevel, LogType, Logger, MaybePromise, OptionalPath, Path, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, ResolveIdParams, Status, Strategy, TransformResult, TreeNode, UUID, ValidationPluginError, build, createPlugin, createPluginCache, build as default, defineConfig, format, getPathMode, getRelativePath, hooks, isPromise, validatePlugins, write }; |
@@ -508,2 +508,21 @@ 'use strict'; | ||
// src/managers/pluginManager/validate.ts | ||
var ValidationPluginError = class extends Error { | ||
}; | ||
var validatePlugins = (plugins, dependedPluginNames) => { | ||
let pluginNames = []; | ||
if (typeof dependedPluginNames === "string") { | ||
pluginNames = [dependedPluginNames]; | ||
} else { | ||
pluginNames = dependedPluginNames; | ||
} | ||
pluginNames.forEach((pluginName) => { | ||
const exists = plugins.some((plugin) => plugin.name === pluginName); | ||
if (!exists) { | ||
throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`); | ||
} | ||
}); | ||
return true; | ||
}; | ||
// src/build.ts | ||
@@ -523,10 +542,5 @@ async function transformReducer(_previousCode, result, _plugin) { | ||
const { plugins, fileManager } = pluginManager; | ||
const validations = await pluginManager.hookParallel("validate", [plugins]); | ||
const validationsWithMessage = validations.filter(Boolean); | ||
if (validationsWithMessage.some((validation) => typeof validation !== "boolean")) { | ||
validationsWithMessage.forEach((validation) => { | ||
if (validation && typeof validation !== "boolean" && validation?.message) { | ||
logger?.log(validation.message, "warn"); | ||
} | ||
}); | ||
try { | ||
await pluginManager.hookParallel("validate", [plugins]); | ||
} catch (e) { | ||
return; | ||
@@ -575,2 +589,3 @@ } | ||
exports.TreeNode = TreeNode; | ||
exports.ValidationPluginError = ValidationPluginError; | ||
exports.build = build; | ||
@@ -586,4 +601,5 @@ exports.createPlugin = createPlugin; | ||
exports.isPromise = isPromise; | ||
exports.validatePlugins = validatePlugins; | ||
exports.write = write; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@kubb/core", | ||
"version": "0.31.1", | ||
"version": "0.31.2", | ||
"description": "Generator core", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
127472
1548