@kubb/core 5.0.0-alpha.6 → 5.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PluginManager-vZodFEMe.d.ts → PluginDriver-Dma9KhLK.d.ts} +7 -7
- package/dist/hooks.cjs +53 -11
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +15 -4
- package/dist/hooks.js +51 -10
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +79 -106
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -39
- package/dist/index.js +79 -105
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Kubb.ts +1 -1
- package/src/{PluginManager.ts → PluginDriver.ts} +18 -22
- package/src/build.ts +21 -21
- package/src/hooks/index.ts +1 -1
- package/src/hooks/useKubb.ts +90 -7
- package/src/hooks/usePluginDriver.ts +11 -0
- package/src/index.ts +1 -2
- package/src/types.ts +4 -4
- package/src/utils/TreeNode.ts +1 -1
- package/src/utils/getBarrelFiles.ts +71 -9
- package/src/BarrelManager.ts +0 -74
- package/src/PromiseManager.ts +0 -40
- package/src/hooks/usePluginManager.ts +0 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
|
-
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
4
3
|
import { OperationNode, Printer, PrinterFactoryOptions, RootNode, SchemaNode } from "@kubb/ast/types";
|
|
4
|
+
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
5
5
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
6
6
|
|
|
7
7
|
//#region ../../internals/utils/dist/index.d.ts
|
|
@@ -783,7 +783,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
783
783
|
options: TOptions['resolvedOptions'];
|
|
784
784
|
install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
785
785
|
/**
|
|
786
|
-
* Define a context that can be used by other plugins, see `
|
|
786
|
+
* Define a context that can be used by other plugins, see `PluginDriver' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
|
|
787
787
|
*/
|
|
788
788
|
inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
789
789
|
};
|
|
@@ -836,7 +836,7 @@ type ResolveNameParams = {
|
|
|
836
836
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
837
837
|
fabric: Fabric;
|
|
838
838
|
config: Config;
|
|
839
|
-
|
|
839
|
+
driver: PluginDriver;
|
|
840
840
|
/**
|
|
841
841
|
* Only add when the file does not exist yet
|
|
842
842
|
*/
|
|
@@ -931,7 +931,7 @@ type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
|
|
|
931
931
|
};
|
|
932
932
|
type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>;
|
|
933
933
|
//#endregion
|
|
934
|
-
//#region src/
|
|
934
|
+
//#region src/PluginDriver.d.ts
|
|
935
935
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
936
936
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
937
937
|
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
@@ -955,7 +955,7 @@ type GetFileOptions<TOptions = object> = {
|
|
|
955
955
|
options?: TOptions;
|
|
956
956
|
};
|
|
957
957
|
declare function getMode(fileOrFolder: string | undefined | null): KubbFile.Mode;
|
|
958
|
-
declare class
|
|
958
|
+
declare class PluginDriver {
|
|
959
959
|
#private;
|
|
960
960
|
readonly config: Config;
|
|
961
961
|
readonly options: Options;
|
|
@@ -1052,5 +1052,5 @@ declare class PluginManager {
|
|
|
1052
1052
|
getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[];
|
|
1053
1053
|
}
|
|
1054
1054
|
//#endregion
|
|
1055
|
-
export { UserConfig as A, defineStorage as B, PluginParameter as C, ResolveNameParams as D, PrinterFactoryOptions as E, Generator as F, URLPath as G, linters as H, ReactGeneratorV2 as I, defineGenerator as L, UserPlugin as M, UserPluginWithLifeCycle as N, ResolvePathParams as O, CoreGeneratorV2 as P, KubbEvents as R, PluginLifecycleHooks as S, Printer as T, logLevel as U, formatters as V, AsyncEventEmitter as W, Output as _, AdapterFactoryOptions as a, PluginFactoryOptions as b, Config as c, Group as d, InputData as f, LoggerOptions as g, LoggerContext as h, Adapter as i, UserLogger as j, UnknownUserPlugin as k, DevtoolsOptions as l, Logger as m,
|
|
1056
|
-
//# sourceMappingURL=
|
|
1055
|
+
export { UserConfig as A, defineStorage as B, PluginParameter as C, ResolveNameParams as D, PrinterFactoryOptions as E, Generator as F, URLPath as G, linters as H, ReactGeneratorV2 as I, defineGenerator as L, UserPlugin as M, UserPluginWithLifeCycle as N, ResolvePathParams as O, CoreGeneratorV2 as P, KubbEvents as R, PluginLifecycleHooks as S, Printer as T, logLevel as U, formatters as V, AsyncEventEmitter as W, Output as _, AdapterFactoryOptions as a, PluginFactoryOptions as b, Config as c, Group as d, InputData as f, LoggerOptions as g, LoggerContext as h, Adapter as i, UserLogger as j, UnknownUserPlugin as k, DevtoolsOptions as l, Logger as m, PluginDriver as n, AdapterSource as o, InputPath as p, getMode as r, BarrelType as s, GetFileOptions as t, GetPluginFactoryOptions as u, Plugin as v, PluginWithLifeCycle as w, PluginLifecycle as x, PluginContext as y, DefineStorage as z };
|
|
1056
|
+
//# sourceMappingURL=PluginDriver-Dma9KhLK.d.ts.map
|
package/dist/hooks.cjs
CHANGED
|
@@ -1,27 +1,69 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./chunk-ByKO4r7w.cjs");
|
|
2
|
+
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_chunk.__toESM(node_path);
|
|
3
5
|
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
4
6
|
//#region src/hooks/useKubb.ts
|
|
7
|
+
/**
|
|
8
|
+
* Generates the default "Generated by Kubb" banner from node metadata.
|
|
9
|
+
*/
|
|
10
|
+
function buildDefaultBanner({ title, description, version, config }) {
|
|
11
|
+
try {
|
|
12
|
+
let source = "";
|
|
13
|
+
if (Array.isArray(config.input)) {
|
|
14
|
+
const first = config.input[0];
|
|
15
|
+
if (first && "path" in first) source = node_path.default.basename(first.path);
|
|
16
|
+
} else if ("path" in config.input) source = node_path.default.basename(config.input.path);
|
|
17
|
+
else if ("data" in config.input) source = "text content";
|
|
18
|
+
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
|
|
19
|
+
if (config.output.defaultBanner === "simple") {
|
|
20
|
+
banner += "*/\n";
|
|
21
|
+
return banner;
|
|
22
|
+
}
|
|
23
|
+
if (source) banner += `* Source: ${source}\n`;
|
|
24
|
+
if (title) banner += `* Title: ${title}\n`;
|
|
25
|
+
if (description) {
|
|
26
|
+
const formattedDescription = description.replace(/\n/gm, "\n* ");
|
|
27
|
+
banner += `* Description: ${formattedDescription}\n`;
|
|
28
|
+
}
|
|
29
|
+
if (version) banner += `* OpenAPI spec version: ${version}\n`;
|
|
30
|
+
banner += "*/\n";
|
|
31
|
+
return banner;
|
|
32
|
+
} catch (_error) {
|
|
33
|
+
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
5
36
|
function useKubb() {
|
|
6
37
|
const { meta } = (0, _kubb_react_fabric.useFabric)();
|
|
38
|
+
const config = meta.driver.config;
|
|
7
39
|
const defaultPluginName = meta.plugin.name;
|
|
40
|
+
const output = meta.plugin.options?.output;
|
|
8
41
|
return {
|
|
9
42
|
plugin: meta.plugin,
|
|
10
43
|
mode: meta.mode,
|
|
11
|
-
config
|
|
12
|
-
getPluginByName: (pluginName = defaultPluginName) => meta.
|
|
13
|
-
getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.
|
|
44
|
+
config,
|
|
45
|
+
getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),
|
|
46
|
+
getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, {
|
|
14
47
|
pluginName,
|
|
15
48
|
...rest
|
|
16
49
|
}),
|
|
17
|
-
resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.
|
|
50
|
+
resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, {
|
|
18
51
|
pluginName,
|
|
19
52
|
...rest
|
|
20
53
|
}),
|
|
21
|
-
resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.
|
|
54
|
+
resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, {
|
|
22
55
|
pluginName,
|
|
23
56
|
...rest
|
|
24
|
-
})
|
|
57
|
+
}),
|
|
58
|
+
resolveBanner: (node) => {
|
|
59
|
+
if (typeof output?.banner === "function") return output.banner(node);
|
|
60
|
+
if (typeof output?.banner === "string") return output.banner;
|
|
61
|
+
return buildDefaultBanner({ config });
|
|
62
|
+
},
|
|
63
|
+
resolveFooter: (node) => {
|
|
64
|
+
if (typeof output?.footer === "function") return output.footer(node);
|
|
65
|
+
if (typeof output?.footer === "string") return output.footer;
|
|
66
|
+
}
|
|
25
67
|
};
|
|
26
68
|
}
|
|
27
69
|
//#endregion
|
|
@@ -43,18 +85,18 @@ function usePlugin() {
|
|
|
43
85
|
return meta.plugin;
|
|
44
86
|
}
|
|
45
87
|
//#endregion
|
|
46
|
-
//#region src/hooks/
|
|
88
|
+
//#region src/hooks/usePluginDriver.ts
|
|
47
89
|
/**
|
|
48
90
|
* @deprecated use `useKubb` instead
|
|
49
91
|
*/
|
|
50
|
-
function
|
|
92
|
+
function usePluginDriver() {
|
|
51
93
|
const { meta } = (0, _kubb_react_fabric.useFabric)();
|
|
52
|
-
return meta.
|
|
94
|
+
return meta.driver;
|
|
53
95
|
}
|
|
54
96
|
//#endregion
|
|
55
97
|
exports.useKubb = useKubb;
|
|
56
98
|
exports.useMode = useMode;
|
|
57
99
|
exports.usePlugin = usePlugin;
|
|
58
|
-
exports.
|
|
100
|
+
exports.usePluginDriver = usePluginDriver;
|
|
59
101
|
|
|
60
102
|
//# sourceMappingURL=hooks.cjs.map
|
package/dist/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":[],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/
|
|
1
|
+
{"version":3,"file":"hooks.cjs","names":["path"],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginDriver.ts"],"sourcesContent":["import path from 'node:path'\nimport type { RootNode } from '@kubb/ast/types'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\nimport type { GetFileOptions, PluginDriver } from '../PluginDriver.ts'\nimport type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'\n\ntype ResolvePathOptions = {\n pluginName?: string\n group?: {\n tag?: string\n path?: string\n }\n type?: ResolveNameParams['type']\n}\n\ntype UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n config: Config\n /**\n * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.\n */\n getPluginByName: (pluginName?: string) => Plugin | undefined\n /**\n * Resolves a file reference, defaulting `pluginName` to the current plugin.\n */\n getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>\n /**\n * Resolves a name, defaulting `pluginName` to the current plugin.\n */\n resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string\n /**\n * Resolves a path, defaulting `pluginName` to the current plugin.\n */\n resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path\n /**\n * Resolves the banner for the given node using the plugin's `output.banner` option.\n * Returns a string when `output.banner` is a string or a function, `undefined` otherwise.\n */\n resolveBanner: (node: RootNode) => string | undefined\n /**\n * Resolves the footer for the given node using the plugin's `output.footer` option.\n * Returns a string when `output.footer` is a string or a function, `undefined` otherwise.\n */\n resolveFooter: (node: RootNode) => string | undefined\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from node metadata.\n */\nfunction buildDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {\n const { meta } = useFabric<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n driver: PluginDriver\n }>()\n\n const config = meta.driver.config\n const defaultPluginName = meta.plugin.name\n\n const output = (\n meta.plugin.options as { output?: { banner?: string | ((node: RootNode) => string); footer?: string | ((node: RootNode) => string) } } | undefined\n )?.output\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config,\n getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),\n getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, { pluginName, ...rest }),\n resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, { pluginName, ...rest }),\n resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, { pluginName, ...rest }),\n resolveBanner: (node: RootNode) => {\n if (typeof output?.banner === 'function') {\n return output.banner(node)\n }\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n return buildDefaultBanner({ config })\n },\n resolveFooter: (node: RootNode) => {\n if (typeof output?.footer === 'function') {\n return output.footer(node)\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n },\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useFabric<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useKubb instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginDriver(): PluginDriver {\n const { meta } = useFabric<{ driver: PluginDriver }>()\n\n return meta.driver\n}\n"],"mappings":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WAAW,KAAK,OAAO,YAAY,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EAChI,gBAAgB,SAAmB;AACjC,OAAI,OAAO,QAAQ,WAAW,WAC5B,QAAO,OAAO,OAAO,KAAK;AAE5B,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;AAEhB,UAAO,mBAAmB,EAAE,QAAQ,CAAC;;EAEvC,gBAAgB,SAAmB;AACjC,OAAI,OAAO,QAAQ,WAAW,WAC5B,QAAO,OAAO,OAAO,KAAK;AAE5B,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;;EAInB;;;;;;;AClIH,SAAgB,UAAyB;CACvC,MAAM,EAAE,UAAA,GAAA,mBAAA,YAA6C;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,UAAA,GAAA,mBAAA,YAAkD;AAE1D,QAAO,KAAK;;;;;;;ACHd,SAAgB,kBAAgC;CAC9C,MAAM,EAAE,UAAA,GAAA,mBAAA,YAA8C;AAEtD,QAAO,KAAK"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { D as ResolveNameParams, O as ResolvePathParams, b as PluginFactoryOptions, c as Config, n as
|
|
2
|
+
import { D as ResolveNameParams, O as ResolvePathParams, b as PluginFactoryOptions, c as Config, n as PluginDriver, t as GetFileOptions, v as Plugin } from "./PluginDriver-Dma9KhLK.js";
|
|
3
|
+
import { RootNode } from "@kubb/ast/types";
|
|
3
4
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
5
|
|
|
5
6
|
//#region src/hooks/useKubb.d.ts
|
|
@@ -39,6 +40,16 @@ type UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
39
40
|
resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & {
|
|
40
41
|
pluginName?: string;
|
|
41
42
|
}) => KubbFile.Path;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves the banner for the given node using the plugin's `output.banner` option.
|
|
45
|
+
* Returns a string when `output.banner` is a string or a function, `undefined` otherwise.
|
|
46
|
+
*/
|
|
47
|
+
resolveBanner: (node: RootNode) => string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Resolves the footer for the given node using the plugin's `output.footer` option.
|
|
50
|
+
* Returns a string when `output.footer` is a string or a function, `undefined` otherwise.
|
|
51
|
+
*/
|
|
52
|
+
resolveFooter: (node: RootNode) => string | undefined;
|
|
42
53
|
};
|
|
43
54
|
declare function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions>;
|
|
44
55
|
//#endregion
|
|
@@ -54,11 +65,11 @@ declare function useMode(): KubbFile.Mode;
|
|
|
54
65
|
*/
|
|
55
66
|
declare function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions>;
|
|
56
67
|
//#endregion
|
|
57
|
-
//#region src/hooks/
|
|
68
|
+
//#region src/hooks/usePluginDriver.d.ts
|
|
58
69
|
/**
|
|
59
70
|
* @deprecated use `useKubb` instead
|
|
60
71
|
*/
|
|
61
|
-
declare function
|
|
72
|
+
declare function usePluginDriver(): PluginDriver;
|
|
62
73
|
//#endregion
|
|
63
|
-
export { useKubb, useMode, usePlugin,
|
|
74
|
+
export { useKubb, useMode, usePlugin, usePluginDriver };
|
|
64
75
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.js
CHANGED
|
@@ -1,26 +1,67 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
+
import path from "node:path";
|
|
2
3
|
import { useFabric } from "@kubb/react-fabric";
|
|
3
4
|
//#region src/hooks/useKubb.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generates the default "Generated by Kubb" banner from node metadata.
|
|
7
|
+
*/
|
|
8
|
+
function buildDefaultBanner({ title, description, version, config }) {
|
|
9
|
+
try {
|
|
10
|
+
let source = "";
|
|
11
|
+
if (Array.isArray(config.input)) {
|
|
12
|
+
const first = config.input[0];
|
|
13
|
+
if (first && "path" in first) source = path.basename(first.path);
|
|
14
|
+
} else if ("path" in config.input) source = path.basename(config.input.path);
|
|
15
|
+
else if ("data" in config.input) source = "text content";
|
|
16
|
+
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
|
|
17
|
+
if (config.output.defaultBanner === "simple") {
|
|
18
|
+
banner += "*/\n";
|
|
19
|
+
return banner;
|
|
20
|
+
}
|
|
21
|
+
if (source) banner += `* Source: ${source}\n`;
|
|
22
|
+
if (title) banner += `* Title: ${title}\n`;
|
|
23
|
+
if (description) {
|
|
24
|
+
const formattedDescription = description.replace(/\n/gm, "\n* ");
|
|
25
|
+
banner += `* Description: ${formattedDescription}\n`;
|
|
26
|
+
}
|
|
27
|
+
if (version) banner += `* OpenAPI spec version: ${version}\n`;
|
|
28
|
+
banner += "*/\n";
|
|
29
|
+
return banner;
|
|
30
|
+
} catch (_error) {
|
|
31
|
+
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
4
34
|
function useKubb() {
|
|
5
35
|
const { meta } = useFabric();
|
|
36
|
+
const config = meta.driver.config;
|
|
6
37
|
const defaultPluginName = meta.plugin.name;
|
|
38
|
+
const output = meta.plugin.options?.output;
|
|
7
39
|
return {
|
|
8
40
|
plugin: meta.plugin,
|
|
9
41
|
mode: meta.mode,
|
|
10
|
-
config
|
|
11
|
-
getPluginByName: (pluginName = defaultPluginName) => meta.
|
|
12
|
-
getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.
|
|
42
|
+
config,
|
|
43
|
+
getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),
|
|
44
|
+
getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, {
|
|
13
45
|
pluginName,
|
|
14
46
|
...rest
|
|
15
47
|
}),
|
|
16
|
-
resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.
|
|
48
|
+
resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, {
|
|
17
49
|
pluginName,
|
|
18
50
|
...rest
|
|
19
51
|
}),
|
|
20
|
-
resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.
|
|
52
|
+
resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, {
|
|
21
53
|
pluginName,
|
|
22
54
|
...rest
|
|
23
|
-
})
|
|
55
|
+
}),
|
|
56
|
+
resolveBanner: (node) => {
|
|
57
|
+
if (typeof output?.banner === "function") return output.banner(node);
|
|
58
|
+
if (typeof output?.banner === "string") return output.banner;
|
|
59
|
+
return buildDefaultBanner({ config });
|
|
60
|
+
},
|
|
61
|
+
resolveFooter: (node) => {
|
|
62
|
+
if (typeof output?.footer === "function") return output.footer(node);
|
|
63
|
+
if (typeof output?.footer === "string") return output.footer;
|
|
64
|
+
}
|
|
24
65
|
};
|
|
25
66
|
}
|
|
26
67
|
//#endregion
|
|
@@ -42,15 +83,15 @@ function usePlugin() {
|
|
|
42
83
|
return meta.plugin;
|
|
43
84
|
}
|
|
44
85
|
//#endregion
|
|
45
|
-
//#region src/hooks/
|
|
86
|
+
//#region src/hooks/usePluginDriver.ts
|
|
46
87
|
/**
|
|
47
88
|
* @deprecated use `useKubb` instead
|
|
48
89
|
*/
|
|
49
|
-
function
|
|
90
|
+
function usePluginDriver() {
|
|
50
91
|
const { meta } = useFabric();
|
|
51
|
-
return meta.
|
|
92
|
+
return meta.driver;
|
|
52
93
|
}
|
|
53
94
|
//#endregion
|
|
54
|
-
export { useKubb, useMode, usePlugin,
|
|
95
|
+
export { useKubb, useMode, usePlugin, usePluginDriver };
|
|
55
96
|
|
|
56
97
|
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/
|
|
1
|
+
{"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginDriver.ts"],"sourcesContent":["import path from 'node:path'\nimport type { RootNode } from '@kubb/ast/types'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\nimport type { GetFileOptions, PluginDriver } from '../PluginDriver.ts'\nimport type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'\n\ntype ResolvePathOptions = {\n pluginName?: string\n group?: {\n tag?: string\n path?: string\n }\n type?: ResolveNameParams['type']\n}\n\ntype UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n config: Config\n /**\n * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.\n */\n getPluginByName: (pluginName?: string) => Plugin | undefined\n /**\n * Resolves a file reference, defaulting `pluginName` to the current plugin.\n */\n getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>\n /**\n * Resolves a name, defaulting `pluginName` to the current plugin.\n */\n resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string\n /**\n * Resolves a path, defaulting `pluginName` to the current plugin.\n */\n resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path\n /**\n * Resolves the banner for the given node using the plugin's `output.banner` option.\n * Returns a string when `output.banner` is a string or a function, `undefined` otherwise.\n */\n resolveBanner: (node: RootNode) => string | undefined\n /**\n * Resolves the footer for the given node using the plugin's `output.footer` option.\n * Returns a string when `output.footer` is a string or a function, `undefined` otherwise.\n */\n resolveFooter: (node: RootNode) => string | undefined\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from node metadata.\n */\nfunction buildDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {\n const { meta } = useFabric<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n driver: PluginDriver\n }>()\n\n const config = meta.driver.config\n const defaultPluginName = meta.plugin.name\n\n const output = (\n meta.plugin.options as { output?: { banner?: string | ((node: RootNode) => string); footer?: string | ((node: RootNode) => string) } } | undefined\n )?.output\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config,\n getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),\n getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, { pluginName, ...rest }),\n resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, { pluginName, ...rest }),\n resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, { pluginName, ...rest }),\n resolveBanner: (node: RootNode) => {\n if (typeof output?.banner === 'function') {\n return output.banner(node)\n }\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n return buildDefaultBanner({ config })\n },\n resolveFooter: (node: RootNode) => {\n if (typeof output?.footer === 'function') {\n return output.footer(node)\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n },\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useFabric<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useKubb instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginDriver(): PluginDriver {\n const { meta } = useFabric<{ driver: PluginDriver }>()\n\n return meta.driver\n}\n"],"mappings":";;;;;;;AAmDA,SAAS,mBAAmB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACvJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,MAAM,QAAQ,OAAO,MAAM,EAAE;GAC/B,MAAM,QAAQ,OAAO,MAAM;AAC3B,OAAI,SAAS,UAAU,MACrB,UAAS,KAAK,SAAS,MAAM,KAAK;aAE3B,UAAU,OAAO,MAC1B,UAAS,KAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAA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