@kubb/plugin-msw 3.0.0-alpha.19 → 3.0.0-alpha.20
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/{chunk-AKZGQPQJ.js → chunk-73P6BBZZ.js} +12 -9
- package/dist/chunk-73P6BBZZ.js.map +1 -0
- package/dist/{chunk-2KJPEZPX.cjs → chunk-UZ4ZUY3N.cjs} +12 -9
- package/dist/chunk-UZ4ZUY3N.cjs.map +1 -0
- package/dist/generators.cjs +3 -3
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{types-D5Xedaf6.d.cts → types-B2IuaP_7.d.cts} +3 -1
- package/dist/{types-D5Xedaf6.d.ts → types-B2IuaP_7.d.ts} +3 -1
- package/package.json +12 -12
- package/src/generators/handlersGenerator.tsx +2 -2
- package/src/generators/mswGenerator.tsx +3 -1
- package/src/plugin.ts +5 -4
- package/src/types.ts +3 -1
- package/dist/chunk-2KJPEZPX.cjs.map +0 -1
- package/dist/chunk-AKZGQPQJ.js.map +0 -1
|
@@ -14,7 +14,9 @@ var mswGenerator = createReactGenerator({
|
|
|
14
14
|
name: "msw",
|
|
15
15
|
Operation({ operation }) {
|
|
16
16
|
const {
|
|
17
|
-
plugin: {
|
|
17
|
+
plugin: {
|
|
18
|
+
options: { output }
|
|
19
|
+
}
|
|
18
20
|
} = useApp();
|
|
19
21
|
const { getSchemaName, getName, getFile } = useOperationManager();
|
|
20
22
|
const mock = {
|
|
@@ -38,11 +40,12 @@ var pluginMsw = createPlugin((options) => {
|
|
|
38
40
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
39
41
|
return {
|
|
40
42
|
name: pluginMswName,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
options: {
|
|
44
|
+
output: {
|
|
45
|
+
exportType: "barrelNamed",
|
|
46
|
+
...output
|
|
47
|
+
}
|
|
44
48
|
},
|
|
45
|
-
options: {},
|
|
46
49
|
pre: [pluginOasName, pluginTsName, pluginFakerName],
|
|
47
50
|
resolvePath(baseName, pathMode, options2) {
|
|
48
51
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
@@ -107,10 +110,10 @@ var handlersGenerator = createReactGenerator({
|
|
|
107
110
|
const imports = operations.map((operation) => {
|
|
108
111
|
const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
|
|
109
112
|
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
110
|
-
return /* @__PURE__ */ jsx(File.Import, { extName: plugin.output?.extName, name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
113
|
+
return /* @__PURE__ */ jsx(File.Import, { extName: plugin.options.output?.extName, name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
111
114
|
});
|
|
112
115
|
const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
|
|
113
|
-
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.output?.banner, footer: plugin.output?.footer, children: [
|
|
116
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
114
117
|
imports,
|
|
115
118
|
/* @__PURE__ */ jsx(Handlers, { name: "handlers", handlers })
|
|
116
119
|
] });
|
|
@@ -118,5 +121,5 @@ var handlersGenerator = createReactGenerator({
|
|
|
118
121
|
});
|
|
119
122
|
|
|
120
123
|
export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
|
|
121
|
-
//# sourceMappingURL=chunk-
|
|
122
|
-
//# sourceMappingURL=chunk-
|
|
124
|
+
//# sourceMappingURL=chunk-73P6BBZZ.js.map
|
|
125
|
+
//# sourceMappingURL=chunk-73P6BBZZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["pluginFakerName","options","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;;;;;;;;AAQO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO,EAAA;AAAA,OACpB;AAAA,QACE,MAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,aAAA,EAAe,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA,CAAA;AAEhE,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS,CAAA;AAAA,KACzB,CAAA;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,aAAc,CAAA,SAAA,EAAW,UAAY,EAAA,EAAE,SAAW,EAAA,CAAC,eAAe,CAAA,EAAG,IAAM,EAAA,UAAA,EAAY,CAAA;AAAA,MAC7F,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,eAAe,GAAG,CAAA;AAAA,KAC3D,CAAA;AAEA,IAAA,4BACG,IAAK,EAAA,EAAA,QAAA,EAAU,KAAK,IAAK,CAAA,QAAA,EAAU,MAAM,IAAK,CAAA,IAAA,CAAK,MAAM,IAAM,EAAA,IAAA,CAAK,KAAK,IAAM,EAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,EAAQ,QAAQ,MACtH,EAAA,QAAA,EAAA;AAAA,sBAAC,GAAA,CAAA,IAAA,CAAK,QAAL,EAAY,IAAA,EAAM,CAAC,MA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A;AAED,IAAA,MAAM,QAAW,GAAA,UAAA,CAAW,GAAI,CAAA,CAAC,cAAc,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,CAAC,aAAa,CAAA,EAAG,CAAC,CAAA,CAAA;AAEnH,IACE,uBAAAC,KAACD,IAAA,EAAA,EAAK,UAAU,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,MACpI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDD,GAAAA,CAAC,QAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-73P6BBZZ.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Mock } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginMsw>()\n const { getSchemaName, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n options: {\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n },\n pre: [pluginOasName, pluginTsName, pluginFakerName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import extName={plugin.options.output?.extName} key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -20,7 +20,9 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
20
20
|
name: "msw",
|
|
21
21
|
Operation({ operation }) {
|
|
22
22
|
const {
|
|
23
|
-
plugin: {
|
|
23
|
+
plugin: {
|
|
24
|
+
options: { output }
|
|
25
|
+
}
|
|
24
26
|
} = react.useApp();
|
|
25
27
|
const { getSchemaName, getName, getFile } = hooks.useOperationManager();
|
|
26
28
|
const mock = {
|
|
@@ -44,11 +46,12 @@ var pluginMsw = core.createPlugin((options) => {
|
|
|
44
46
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
45
47
|
return {
|
|
46
48
|
name: pluginMswName,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
options: {
|
|
50
|
+
output: {
|
|
51
|
+
exportType: "barrelNamed",
|
|
52
|
+
...output
|
|
53
|
+
}
|
|
50
54
|
},
|
|
51
|
-
options: {},
|
|
52
55
|
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, pluginFaker.pluginFakerName],
|
|
53
56
|
resolvePath(baseName, pathMode, options2) {
|
|
54
57
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
@@ -113,10 +116,10 @@ var handlersGenerator = pluginOas.createReactGenerator({
|
|
|
113
116
|
const imports = operations.map((operation) => {
|
|
114
117
|
const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
|
|
115
118
|
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
116
|
-
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { extName: plugin.output?.extName, name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
119
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { extName: plugin.options.output?.extName, name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
117
120
|
});
|
|
118
121
|
const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
|
|
119
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.output?.banner, footer: plugin.output?.footer, children: [
|
|
122
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
120
123
|
imports,
|
|
121
124
|
/* @__PURE__ */ jsxRuntime.jsx(chunkGODA4G5K_cjs.Handlers, { name: "handlers", handlers })
|
|
122
125
|
] });
|
|
@@ -127,5 +130,5 @@ exports.handlersGenerator = handlersGenerator;
|
|
|
127
130
|
exports.mswGenerator = mswGenerator;
|
|
128
131
|
exports.pluginMsw = pluginMsw;
|
|
129
132
|
exports.pluginMswName = pluginMswName;
|
|
130
|
-
//# sourceMappingURL=chunk-
|
|
131
|
-
//# sourceMappingURL=chunk-
|
|
133
|
+
//# sourceMappingURL=chunk-UZ4ZUY3N.cjs.map
|
|
134
|
+
//# sourceMappingURL=chunk-UZ4ZUY3N.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginFakerName","File","jsx","Mock","URLPath","createPlugin","transformers","pluginOasName","pluginTsName","options","path","FileManager","camelCase","renderTemplate","PluginManager","OperationGenerator","jsxs","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AAQO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO,EAAA;AAAA,OACpB;AAAA,QACEC,YAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,aAAA,EAAe,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA,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;AAAA,MAAA,OAAA;AAAA,sBACDC,cAAAA,CAACe,0BAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-UZ4ZUY3N.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Mock } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginMsw>()\n const { getSchemaName, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n options: {\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n },\n pre: [pluginOasName, pluginTsName, pluginFakerName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import extName={plugin.options.output?.extName} key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkUZ4ZUY3N_cjs = require('./chunk-UZ4ZUY3N.cjs');
|
|
4
4
|
require('./chunk-GODA4G5K.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "handlersGenerator", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkUZ4ZUY3N_cjs.handlersGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "mswGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkUZ4ZUY3N_cjs.mswGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkUZ4ZUY3N_cjs = require('./chunk-UZ4ZUY3N.cjs');
|
|
4
4
|
require('./chunk-GODA4G5K.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "pluginMsw", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkUZ4ZUY3N_cjs.pluginMsw; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "pluginMswName", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkUZ4ZUY3N_cjs.pluginMswName; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=index.cjs.map
|
|
17
17
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -52,7 +52,9 @@ type Options = {
|
|
|
52
52
|
*/
|
|
53
53
|
handlers?: boolean;
|
|
54
54
|
};
|
|
55
|
-
type ResolvedOptions = {
|
|
55
|
+
type ResolvedOptions = {
|
|
56
|
+
output: Output;
|
|
57
|
+
};
|
|
56
58
|
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
57
59
|
|
|
58
60
|
export type { Options as O, PluginMsw as P };
|
|
@@ -52,7 +52,9 @@ type Options = {
|
|
|
52
52
|
*/
|
|
53
53
|
handlers?: boolean;
|
|
54
54
|
};
|
|
55
|
-
type ResolvedOptions = {
|
|
55
|
+
type ResolvedOptions = {
|
|
56
|
+
output: Output;
|
|
57
|
+
};
|
|
56
58
|
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
57
59
|
|
|
58
60
|
export type { Options as O, PluginMsw as P };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.20",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -74,24 +74,24 @@
|
|
|
74
74
|
"!/**/__tests__/**"
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@kubb/core": "3.0.0-alpha.
|
|
78
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
79
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
80
|
-
"@kubb/plugin-faker": "3.0.0-alpha.
|
|
81
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
82
|
-
"@kubb/plugin-ts": "3.0.0-alpha.
|
|
83
|
-
"@kubb/react": "3.0.0-alpha.
|
|
77
|
+
"@kubb/core": "3.0.0-alpha.20",
|
|
78
|
+
"@kubb/fs": "3.0.0-alpha.20",
|
|
79
|
+
"@kubb/oas": "3.0.0-alpha.20",
|
|
80
|
+
"@kubb/plugin-faker": "3.0.0-alpha.20",
|
|
81
|
+
"@kubb/plugin-oas": "3.0.0-alpha.20",
|
|
82
|
+
"@kubb/plugin-ts": "3.0.0-alpha.20",
|
|
83
|
+
"@kubb/react": "3.0.0-alpha.20"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@types/react": "^18.3.
|
|
86
|
+
"@types/react": "^18.3.6",
|
|
87
87
|
"react": "^18.3.1",
|
|
88
88
|
"tsup": "^8.2.4",
|
|
89
89
|
"typescript": "^5.6.2",
|
|
90
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
91
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
90
|
+
"@kubb/config-ts": "3.0.0-alpha.20",
|
|
91
|
+
"@kubb/config-tsup": "3.0.0-alpha.20"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@kubb/react": "3.0.0-alpha.
|
|
94
|
+
"@kubb/react": "3.0.0-alpha.20"
|
|
95
95
|
},
|
|
96
96
|
"engines": {
|
|
97
97
|
"node": ">=20"
|
|
@@ -17,13 +17,13 @@ export const handlersGenerator = createReactGenerator<PluginMsw>({
|
|
|
17
17
|
const operationFile = getFile(operation, { pluginKey: [pluginMswName] })
|
|
18
18
|
const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })
|
|
19
19
|
|
|
20
|
-
return <File.Import extName={plugin.output?.extName} key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />
|
|
20
|
+
return <File.Import extName={plugin.options.output?.extName} key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
|
-
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.output?.banner} footer={plugin.output?.footer}>
|
|
26
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>
|
|
27
27
|
{imports}
|
|
28
28
|
<Handlers name={'handlers'} handlers={handlers} />
|
|
29
29
|
</File>
|
|
@@ -10,7 +10,9 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
10
10
|
name: 'msw',
|
|
11
11
|
Operation({ operation }) {
|
|
12
12
|
const {
|
|
13
|
-
plugin: {
|
|
13
|
+
plugin: {
|
|
14
|
+
options: { output },
|
|
15
|
+
},
|
|
14
16
|
} = useApp<PluginMsw>()
|
|
15
17
|
const { getSchemaName, getName, getFile } = useOperationManager()
|
|
16
18
|
|
package/src/plugin.ts
CHANGED
|
@@ -21,11 +21,12 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
21
21
|
|
|
22
22
|
return {
|
|
23
23
|
name: pluginMswName,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
options: {
|
|
25
|
+
output: {
|
|
26
|
+
exportType: 'barrelNamed',
|
|
27
|
+
...output,
|
|
28
|
+
},
|
|
27
29
|
},
|
|
28
|
-
options: {},
|
|
29
30
|
pre: [pluginOasName, pluginTsName, pluginFakerName],
|
|
30
31
|
resolvePath(baseName, pathMode, options) {
|
|
31
32
|
const root = path.resolve(this.config.root, this.config.output.path)
|
package/src/types.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginFakerName","File","jsx","Mock","URLPath","createPlugin","transformers","pluginOasName","pluginTsName","options","path","FileManager","camelCase","renderTemplate","PluginManager","OperationGenerator","jsxs","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AAQO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAA,EAAQ,EAAE,MAAO,EAAA;AAAA,QACfC,YAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,aAAA,EAAe,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA,CAAA;AAEhE,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AA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.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Mock } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: { output },\n } = useApp<PluginMsw>()\n const { getSchemaName, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {},\n pre: [pluginOasName, pluginTsName, pluginFakerName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import extName={plugin.output?.extName} key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.output?.banner} footer={plugin.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["pluginFakerName","options","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;;;;;;;;AAQO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAA,EAAQ,EAAE,MAAO,EAAA;AAAA,QACf,MAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,aAAA,EAAe,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA,CAAA;AAEhE,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS,CAAA;A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-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Mock } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: { output },\n } = useApp<PluginMsw>()\n const { getSchemaName, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {},\n pre: [pluginOasName, pluginTsName, pluginFakerName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import extName={plugin.output?.extName} key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.output?.banner} footer={plugin.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|