@kubb/plugin-swr 3.0.0-alpha.30 → 3.0.0-alpha.31
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/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/index.cjs +5 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/{types-D4iiS34S.d.cts → types-Cf8HYgyD.d.cts} +2 -20
- package/dist/{types-D4iiS34S.d.ts → types-Cf8HYgyD.d.ts} +2 -20
- package/package.json +12 -12
- package/src/plugin.ts +7 -8
- package/src/types.ts +2 -20
package/dist/components.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Operation } from '@kubb/oas';
|
|
2
2
|
import { OperationSchemas } from '@kubb/plugin-oas';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
|
-
import { P as PluginSwr } from './types-
|
|
4
|
+
import { P as PluginSwr } from './types-Cf8HYgyD.cjs';
|
|
5
5
|
import { FunctionParams } from '@kubb/react';
|
|
6
6
|
import '@kubb/core';
|
|
7
7
|
|
package/dist/components.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Operation } from '@kubb/oas';
|
|
2
2
|
import { OperationSchemas } from '@kubb/plugin-oas';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
|
-
import { P as PluginSwr } from './types-
|
|
4
|
+
import { P as PluginSwr } from './types-Cf8HYgyD.js';
|
|
5
5
|
import { FunctionParams } from '@kubb/react';
|
|
6
6
|
import '@kubb/core';
|
|
7
7
|
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ require('./chunk-JWGWABV5.cjs');
|
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var core = require('@kubb/core');
|
|
7
7
|
var transformers = require('@kubb/core/transformers');
|
|
8
|
-
|
|
8
|
+
require('@kubb/core/utils');
|
|
9
9
|
var pluginOas = require('@kubb/plugin-oas');
|
|
10
10
|
var pluginTs = require('@kubb/plugin-ts');
|
|
11
11
|
var pluginZod = require('@kubb/plugin-zod');
|
|
@@ -30,7 +30,6 @@ var pluginSwr = core.createPlugin((options) => {
|
|
|
30
30
|
pathParamsType = "inline",
|
|
31
31
|
generators = [chunkPTOQHHST_cjs.queryGenerator, chunkPTOQHHST_cjs.mutationGenerator].filter(Boolean)
|
|
32
32
|
} = options;
|
|
33
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}SWRController`;
|
|
34
33
|
return {
|
|
35
34
|
name: pluginSwrName,
|
|
36
35
|
options: {
|
|
@@ -60,13 +59,13 @@ var pluginSwr = core.createPlugin((options) => {
|
|
|
60
59
|
resolvePath(baseName, pathMode, options2) {
|
|
61
60
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
62
61
|
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
62
|
+
if (options2?.tag && group?.type === "tag") {
|
|
63
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
64
|
+
return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
|
|
65
|
+
}
|
|
63
66
|
if (mode === "single") {
|
|
64
67
|
return path__default.default.resolve(root, output.path);
|
|
65
68
|
}
|
|
66
|
-
if (options2?.tag && group?.type === "tag") {
|
|
67
|
-
const tag = transformers.camelCase(options2.tag);
|
|
68
|
-
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
69
|
-
}
|
|
70
69
|
return path__default.default.resolve(root, output.path, baseName);
|
|
71
70
|
},
|
|
72
71
|
resolveName(name, type) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;;AAeO,IAAM,aAAgB,GAAA,aAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,MAAS,GAAA,QAAA;AAAA,kBACTC,iBAAe,EAAC;AAAA,IAChB,KAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,cAAiB,GAAA,QAAA;AAAA,IACjB,aAAa,CAACC,gCAAA,EAAgBC,mCAAiB,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,GAC7D,GAAA,OAAA,CAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,aAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,cAAA;AAAA,MACA,MAAQ,EAAA;AAAA,QACN,UAAY,EAAA,4BAAA;AAAA,QACZ,cAAgB,EAAA,MAAA;AAAA,QAChB,GAAG,MAAA;AAAA,OACL;AAAA,MACA,KAAO,EAAA;AAAA,QACL,GAAA,EAAK,CAAC,GAAmB,KAAA,GAAA;AAAA,QACzB,UAAY,EAAA,KAAA;AAAA,QACZ,OAAA,EAAS,CAAC,KAAK,CAAA;AAAA,QACf,GAAG,KAAA;AAAA,OACL;AAAA,MACA,QAAU,EAAA;AAAA,QACR,GAAA,EAAK,CAAC,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AA;AAEvD,MAAA,MAAM,qBAAqB,IAAIK,4BAAA;AAAA,QAC7B;AAAA,UACE,GAAG,KAAK,MAAO,CAAA,OAAA;AAAA,UACf,OAAA;AAAA,SACF;AAAA,QACA;AAAA,UACE,GAAA;AAAA,UACA,eAAe,IAAK,CAAA,aAAA;AAAA,UACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,UACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,UACnC,OAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAA;AAAA,UACA,IAAA;AAAA,SACF;AAAA,OACF,CAAA;AAEA,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA,MAAA;AAAA,OACd,CAAA,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,KACnC;AAAA,GACF,CAAA;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = createPlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n pathParamsType = 'inline',\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n } = options\n\n return {\n name: pluginSwrName,\n options: {\n output,\n pathParamsType,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...client,\n },\n query: {\n key: (key: unknown[]) => key,\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutation: {\n key: (key: unknown[]) => key,\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n baseURL: undefined,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\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 (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\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 const baseURL = await swaggerPlugin.context.getBaseURL()\n\n const operationGenerator = new OperationGenerator(\n {\n ...this.plugin.options,\n baseURL,\n },\n {\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\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\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"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import './chunk-H23WKEYP.js';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
5
|
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
6
|
-
import
|
|
6
|
+
import '@kubb/core/utils';
|
|
7
7
|
import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
8
8
|
import { pluginTsName } from '@kubb/plugin-ts';
|
|
9
9
|
import { pluginZodName } from '@kubb/plugin-zod';
|
|
@@ -24,7 +24,6 @@ var pluginSwr = createPlugin((options) => {
|
|
|
24
24
|
pathParamsType = "inline",
|
|
25
25
|
generators = [queryGenerator, mutationGenerator].filter(Boolean)
|
|
26
26
|
} = options;
|
|
27
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}SWRController`;
|
|
28
27
|
return {
|
|
29
28
|
name: pluginSwrName,
|
|
30
29
|
options: {
|
|
@@ -54,13 +53,13 @@ var pluginSwr = createPlugin((options) => {
|
|
|
54
53
|
resolvePath(baseName, pathMode, options2) {
|
|
55
54
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
56
55
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
56
|
+
if (options2?.tag && group?.type === "tag") {
|
|
57
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
58
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
59
|
+
}
|
|
57
60
|
if (mode === "single") {
|
|
58
61
|
return path.resolve(root, output.path);
|
|
59
62
|
}
|
|
60
|
-
if (options2?.tag && group?.type === "tag") {
|
|
61
|
-
const tag = camelCase(options2.tag);
|
|
62
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
63
|
-
}
|
|
64
63
|
return path.resolve(root, output.path, baseName);
|
|
65
64
|
},
|
|
66
65
|
resolveName(name, type) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;;AAeO,IAAM,aAAgB,GAAA,aAAA;AAEhB,IAAA,SAAA,GAAY,YAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,MAAS,GAAA,QAAA;AAAA,IACT,eAAe,EAAC;AAAA,IAChB,KAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,cAAiB,GAAA,QAAA;AAAA,IACjB,aAAa,CAAC,cAAA,EAAgB,iBAAiB,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,GA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A;AAAA,UACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,UACnC,OAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAA;AAAA,UACA,IAAA;AAAA,SACF;AAAA,OACF,CAAA;AAEA,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA,MAAA;AAAA,OACd,CAAA,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,KACnC;AAAA,GACF,CAAA;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = createPlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n pathParamsType = 'inline',\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n } = options\n\n return {\n name: pluginSwrName,\n options: {\n output,\n pathParamsType,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...client,\n },\n query: {\n key: (key: unknown[]) => key,\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutation: {\n key: (key: unknown[]) => key,\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n baseURL: undefined,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\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 (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\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 const baseURL = await swaggerPlugin.context.getBaseURL()\n\n const operationGenerator = new OperationGenerator(\n {\n ...this.plugin.options,\n baseURL,\n },\n {\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\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
2
|
import { HttpMethod } from '@kubb/oas';
|
|
3
3
|
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
4
4
|
|
|
@@ -10,25 +10,7 @@ type Options = {
|
|
|
10
10
|
/**
|
|
11
11
|
* Group the SWR hooks based on the provided name.
|
|
12
12
|
*/
|
|
13
|
-
group?:
|
|
14
|
-
/**
|
|
15
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
16
|
-
*/
|
|
17
|
-
type: 'tag';
|
|
18
|
-
/**
|
|
19
|
-
* Relative path to save the grouped SWR hooks.
|
|
20
|
-
*
|
|
21
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
22
|
-
* @example `${output}/{{tag}}Controller` => `hooks/PetController`
|
|
23
|
-
* @default `${output}/{{tag}}Controller`
|
|
24
|
-
*/
|
|
25
|
-
output?: string;
|
|
26
|
-
/**
|
|
27
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
28
|
-
* @default `"{{tag}}SWRHooks"`
|
|
29
|
-
*/
|
|
30
|
-
exportAs?: string;
|
|
31
|
-
};
|
|
13
|
+
group?: Group;
|
|
32
14
|
/**
|
|
33
15
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
34
16
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
2
|
import { HttpMethod } from '@kubb/oas';
|
|
3
3
|
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
4
4
|
|
|
@@ -10,25 +10,7 @@ type Options = {
|
|
|
10
10
|
/**
|
|
11
11
|
* Group the SWR hooks based on the provided name.
|
|
12
12
|
*/
|
|
13
|
-
group?:
|
|
14
|
-
/**
|
|
15
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
16
|
-
*/
|
|
17
|
-
type: 'tag';
|
|
18
|
-
/**
|
|
19
|
-
* Relative path to save the grouped SWR hooks.
|
|
20
|
-
*
|
|
21
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
22
|
-
* @example `${output}/{{tag}}Controller` => `hooks/PetController`
|
|
23
|
-
* @default `${output}/{{tag}}Controller`
|
|
24
|
-
*/
|
|
25
|
-
output?: string;
|
|
26
|
-
/**
|
|
27
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
28
|
-
* @default `"{{tag}}SWRHooks"`
|
|
29
|
-
*/
|
|
30
|
-
exportAs?: string;
|
|
31
|
-
};
|
|
13
|
+
group?: Group;
|
|
32
14
|
/**
|
|
33
15
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
34
16
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-swr",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.31",
|
|
4
4
|
"description": "Generator plugin-swr",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -63,25 +63,25 @@
|
|
|
63
63
|
"!/**/__tests__/**"
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@kubb/core": "3.0.0-alpha.
|
|
67
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
68
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
69
|
-
"@kubb/plugin-client": "3.0.0-alpha.
|
|
70
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
71
|
-
"@kubb/plugin-ts": "3.0.0-alpha.
|
|
72
|
-
"@kubb/plugin-zod": "3.0.0-alpha.
|
|
73
|
-
"@kubb/react": "3.0.0-alpha.
|
|
66
|
+
"@kubb/core": "3.0.0-alpha.31",
|
|
67
|
+
"@kubb/fs": "3.0.0-alpha.31",
|
|
68
|
+
"@kubb/oas": "3.0.0-alpha.31",
|
|
69
|
+
"@kubb/plugin-client": "3.0.0-alpha.31",
|
|
70
|
+
"@kubb/plugin-oas": "3.0.0-alpha.31",
|
|
71
|
+
"@kubb/plugin-ts": "3.0.0-alpha.31",
|
|
72
|
+
"@kubb/plugin-zod": "3.0.0-alpha.31",
|
|
73
|
+
"@kubb/react": "3.0.0-alpha.31"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/react": "^18.3.10",
|
|
77
77
|
"react": "^18.3.1",
|
|
78
78
|
"tsup": "^8.3.0",
|
|
79
79
|
"typescript": "^5.6.2",
|
|
80
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
81
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
80
|
+
"@kubb/config-ts": "3.0.0-alpha.31",
|
|
81
|
+
"@kubb/config-tsup": "3.0.0-alpha.31"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
|
-
"@kubb/react": "3.0.0-alpha.
|
|
84
|
+
"@kubb/react": "3.0.0-alpha.31"
|
|
85
85
|
},
|
|
86
86
|
"engines": {
|
|
87
87
|
"node": ">=20"
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
|
|
3
|
-
import { FileManager, PluginManager, createPlugin } from '@kubb/core'
|
|
3
|
+
import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
|
|
4
4
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
5
5
|
import { renderTemplate } from '@kubb/core/utils'
|
|
6
6
|
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
@@ -30,7 +30,6 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
|
|
|
30
30
|
pathParamsType = 'inline',
|
|
31
31
|
generators = [queryGenerator, mutationGenerator].filter(Boolean),
|
|
32
32
|
} = options
|
|
33
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}SWRController`
|
|
34
33
|
|
|
35
34
|
return {
|
|
36
35
|
name: pluginSwrName,
|
|
@@ -62,6 +61,12 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
|
|
|
62
61
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
63
62
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
64
63
|
|
|
64
|
+
if (options?.tag && group?.type === 'tag') {
|
|
65
|
+
const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`
|
|
66
|
+
|
|
67
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)
|
|
68
|
+
}
|
|
69
|
+
|
|
65
70
|
if (mode === 'single') {
|
|
66
71
|
/**
|
|
67
72
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
@@ -70,12 +75,6 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
|
|
|
70
75
|
return path.resolve(root, output.path)
|
|
71
76
|
}
|
|
72
77
|
|
|
73
|
-
if (options?.tag && group?.type === 'tag') {
|
|
74
|
-
const tag = camelCase(options.tag)
|
|
75
|
-
|
|
76
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
78
|
return path.resolve(root, output.path, baseName)
|
|
80
79
|
},
|
|
81
80
|
resolveName(name, type) {
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
1
|
+
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
2
|
import type { HttpMethod } from '@kubb/oas'
|
|
3
3
|
import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
4
4
|
|
|
@@ -10,25 +10,7 @@ export type Options = {
|
|
|
10
10
|
/**
|
|
11
11
|
* Group the SWR hooks based on the provided name.
|
|
12
12
|
*/
|
|
13
|
-
group?:
|
|
14
|
-
/**
|
|
15
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
16
|
-
*/
|
|
17
|
-
type: 'tag'
|
|
18
|
-
/**
|
|
19
|
-
* Relative path to save the grouped SWR hooks.
|
|
20
|
-
*
|
|
21
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
22
|
-
* @example `${output}/{{tag}}Controller` => `hooks/PetController`
|
|
23
|
-
* @default `${output}/{{tag}}Controller`
|
|
24
|
-
*/
|
|
25
|
-
output?: string
|
|
26
|
-
/**
|
|
27
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
28
|
-
* @default `"{{tag}}SWRHooks"`
|
|
29
|
-
*/
|
|
30
|
-
exportAs?: string
|
|
31
|
-
}
|
|
13
|
+
group?: Group
|
|
32
14
|
/**
|
|
33
15
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
34
16
|
*/
|