@kubb/plugin-msw 3.0.0-alpha.0
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/chunk-S4P5XPFN.cjs +105 -0
- package/dist/chunk-S4P5XPFN.cjs.map +1 -0
- package/dist/chunk-WRIEMCYI.js +105 -0
- package/dist/chunk-WRIEMCYI.js.map +1 -0
- package/dist/components.cjs +9 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +87 -0
- package/dist/components.d.ts +87 -0
- package/dist/components.js +9 -0
- package/dist/components.js.map +1 -0
- package/dist/index.cjs +149 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +96 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +149 -0
- package/dist/index.js.map +1 -0
- package/package.json +109 -0
- package/src/OperationGenerator.tsx +66 -0
- package/src/components/Mock.tsx +113 -0
- package/src/components/Operations.tsx +96 -0
- package/src/components/__snapshots__/Mock/Pets.ts +7 -0
- package/src/components/__snapshots__/Mock/showPetsById.ts +7 -0
- package/src/components/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/plugin.ts +123 -0
- package/src/types.ts +95 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkS4P5XPFNcjs = require('./chunk-S4P5XPFN.cjs');
|
|
5
|
+
|
|
6
|
+
// src/plugin.ts
|
|
7
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
8
|
+
var _core = require('@kubb/core');
|
|
9
|
+
var _transformers = require('@kubb/core/transformers');
|
|
10
|
+
var _utils = require('@kubb/core/utils');
|
|
11
|
+
var _pluginoas = require('@kubb/plugin-oas');
|
|
12
|
+
var _utils3 = require('@kubb/plugin-oas/utils');
|
|
13
|
+
var _pluginfaker = require('@kubb/plugin-faker');
|
|
14
|
+
var _plugints = require('@kubb/plugin-ts');
|
|
15
|
+
|
|
16
|
+
// src/OperationGenerator.tsx
|
|
17
|
+
|
|
18
|
+
var _components = require('@kubb/plugin-oas/components');
|
|
19
|
+
var _react = require('@kubb/react');
|
|
20
|
+
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
21
|
+
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
22
|
+
async all(operations, operationsByMethod) {
|
|
23
|
+
const { oas, pluginManager, plugin, mode } = this.context;
|
|
24
|
+
const root = _react.createRoot.call(void 0, {
|
|
25
|
+
logger: pluginManager.logger
|
|
26
|
+
});
|
|
27
|
+
const templates = {
|
|
28
|
+
operations: _chunkS4P5XPFNcjs.Operations.templates,
|
|
29
|
+
mock: _chunkS4P5XPFNcjs.Mock.templates,
|
|
30
|
+
...this.options.templates
|
|
31
|
+
};
|
|
32
|
+
root.render(
|
|
33
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations, generator: this, children: _optionalChain([templates, 'optionalAccess', _ => _.operations]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkS4P5XPFNcjs.Operations.File, { templates: templates.operations }) }) })
|
|
34
|
+
);
|
|
35
|
+
return root.files;
|
|
36
|
+
}
|
|
37
|
+
async operation(operation, options) {
|
|
38
|
+
const { oas, pluginManager, plugin, mode } = this.context;
|
|
39
|
+
const root = _react.createRoot.call(void 0, {
|
|
40
|
+
logger: pluginManager.logger
|
|
41
|
+
});
|
|
42
|
+
const templates = {
|
|
43
|
+
handlers: _chunkS4P5XPFNcjs.Operations.templates,
|
|
44
|
+
mock: _chunkS4P5XPFNcjs.Mock.templates,
|
|
45
|
+
...options.templates
|
|
46
|
+
};
|
|
47
|
+
if (!_optionalChain([templates, 'optionalAccess', _2 => _2.mock])) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
root.render(
|
|
51
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkS4P5XPFNcjs.Mock.File, { templates: templates.mock }) }) }) })
|
|
52
|
+
);
|
|
53
|
+
return root.files;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/plugin.ts
|
|
58
|
+
var pluginMswName = "plugin-msw";
|
|
59
|
+
var pluginMsw = _core.createPlugin.call(void 0, (options) => {
|
|
60
|
+
const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers = {}, templates } = options;
|
|
61
|
+
const template = _optionalChain([group, 'optionalAccess', _3 => _3.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
|
62
|
+
return {
|
|
63
|
+
name: pluginMswName,
|
|
64
|
+
options: {
|
|
65
|
+
extName: output.extName,
|
|
66
|
+
templates: {
|
|
67
|
+
operations: _chunkS4P5XPFNcjs.Operations.templates,
|
|
68
|
+
mock: _chunkS4P5XPFNcjs.Mock.templates,
|
|
69
|
+
...templates
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
pre: [_pluginoas.pluginOasName, _plugints.pluginTsName, _pluginfaker.pluginFakerName],
|
|
73
|
+
resolvePath(baseName, pathMode, options2) {
|
|
74
|
+
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
75
|
+
const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
|
|
76
|
+
if (mode === "single") {
|
|
77
|
+
return _path2.default.resolve(root, output.path);
|
|
78
|
+
}
|
|
79
|
+
if (_optionalChain([options2, 'optionalAccess', _4 => _4.tag]) && _optionalChain([group, 'optionalAccess', _5 => _5.type]) === "tag") {
|
|
80
|
+
const tag = _transformers.camelCase.call(void 0, options2.tag);
|
|
81
|
+
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
|
82
|
+
}
|
|
83
|
+
return _path2.default.resolve(root, output.path, baseName);
|
|
84
|
+
},
|
|
85
|
+
resolveName(name, type) {
|
|
86
|
+
const resolvedName = _transformers.camelCase.call(void 0, name, {
|
|
87
|
+
suffix: type ? "handler" : void 0,
|
|
88
|
+
isFile: type === "file"
|
|
89
|
+
});
|
|
90
|
+
if (type) {
|
|
91
|
+
return _optionalChain([transformers, 'optionalAccess', _6 => _6.name, 'optionalCall', _7 => _7(resolvedName, type)]) || resolvedName;
|
|
92
|
+
}
|
|
93
|
+
return resolvedName;
|
|
94
|
+
},
|
|
95
|
+
async writeFile(path2, source) {
|
|
96
|
+
if (!path2.endsWith(".ts") || !source) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
return this.fileManager.write(path2, source, { sanity: false });
|
|
100
|
+
},
|
|
101
|
+
async buildStart() {
|
|
102
|
+
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
|
103
|
+
const oas = await swaggerPlugin.api.getOas();
|
|
104
|
+
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
105
|
+
const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
|
|
106
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
107
|
+
oas,
|
|
108
|
+
pluginManager: this.pluginManager,
|
|
109
|
+
plugin: this.plugin,
|
|
110
|
+
contentType: swaggerPlugin.api.contentType,
|
|
111
|
+
exclude,
|
|
112
|
+
include,
|
|
113
|
+
override,
|
|
114
|
+
mode
|
|
115
|
+
});
|
|
116
|
+
const files = await operationGenerator.build();
|
|
117
|
+
await this.addFile(...files);
|
|
118
|
+
},
|
|
119
|
+
async buildEnd() {
|
|
120
|
+
if (this.config.output.write === false) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
124
|
+
if (_optionalChain([group, 'optionalAccess', _8 => _8.type]) === "tag") {
|
|
125
|
+
const rootFiles = await _utils3.getGroupedByTagFiles.call(void 0, {
|
|
126
|
+
logger: this.logger,
|
|
127
|
+
files: this.fileManager.files,
|
|
128
|
+
plugin: this.plugin,
|
|
129
|
+
template,
|
|
130
|
+
exportAs: group.exportAs || "{{tag}}Handlers",
|
|
131
|
+
root,
|
|
132
|
+
output
|
|
133
|
+
});
|
|
134
|
+
await this.addFile(...rootFiles);
|
|
135
|
+
}
|
|
136
|
+
await this.fileManager.addIndexes({
|
|
137
|
+
root,
|
|
138
|
+
output,
|
|
139
|
+
meta: { pluginKey: this.plugin.key },
|
|
140
|
+
logger: this.logger
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
exports.pluginMsw = pluginMsw; exports.pluginMswName = pluginMswName;
|
|
149
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-msw/dist/index.cjs","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":[],"mappings":"AAAA;AACE;AACA;AACF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6BAAO,SAAA,EAAS,KAAA,CAAM,OAAA,EAAS,CAAA,EAAA;AAEzC,EAAA;AACC,IAAA;AACG,IAAA;AACS,MAAA;AACL,MAAA;AACc,QAAA;AACZ,QAAA;AACR,QAAA;AACL,MAAA;AACF,IAAA;AACmC,IAAA;AACM,IAAA;AACK,MAAA;AACC,MAAA;AAEtB,MAAA;AAKgB,QAAA;AACvC,MAAA;AAE2C,MAAA;AACR,QAAA;AAEQ,QAAA;AAC3C,MAAA;AAEuC,MAAA;AACzC,IAAA;AACwB,IAAA;AACe,MAAA;AACR,QAAA;AACV,QAAA;AAClB,MAAA;AACS,MAAA;AACkC,QAAA;AAC5C,MAAA;AAEO,MAAA;AACT,IAAA;AAC8B,IAAA;AACU,MAAA;AACpC,QAAA;AACF,MAAA;AAE4C,MAAA;AAC9C,IAAA;AACmB,IAAA;AACqD,MAAA;AAE3B,MAAA;AACC,MAAA;AACN,MAAA;AAEP,MAAA;AAC7B,QAAA;AACoB,QAAA;AACP,QAAA;AACkB,QAAA;AAC/B,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACD,MAAA;AAE4C,MAAA;AAClB,MAAA;AAC7B,IAAA;AACiB,IAAA;AACyB,MAAA;AACtC,QAAA;AACF,MAAA;AAE4C,MAAA;AAEjB,MAAA;AACD,QAAA;AACT,UAAA;AACW,UAAA;AACX,UAAA;AACb,UAAA;AAC4B,UAAA;AAC5B,UAAA;AACA,UAAA;AACD,QAAA;AAE8B,QAAA;AACjC,MAAA;AAEkC,MAAA;AAChC,QAAA;AACA,QAAA;AACmC,QAAA;AACtB,QAAA;AACd,MAAA;AACH,IAAA;AACF,EAAA;AACD;ADsBkD;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-msw/dist/index.cjs","sourcesContent":[null,"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 { pluginOasName } from '@kubb/plugin-oas'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mock, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 = {}, templates } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n options: {\n extName: output.extName,\n templates: {\n operations: Operations.templates,\n mock: Mock.templates,\n ...templates,\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 writeFile(path, source) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.api.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.api.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n if (group?.type === 'tag') {\n const rootFiles = await getGroupedByTagFiles({\n logger: this.logger,\n files: this.fileManager.files,\n plugin: this.plugin,\n template,\n exportAs: group.exportAs || '{{tag}}Handlers',\n root,\n output,\n })\n\n await this.addFile(...rootFiles)\n }\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n logger: this.logger,\n })\n },\n }\n})\n","import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Mock } from './components/Mock.tsx'\nimport { Operations } from './components/Operations.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginMsw } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginMsw['resolvedOptions'], PluginMsw> {\n async all(operations: Operation[], operationsByMethod: OperationsByMethod): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n operations: Operations.templates,\n mock: Mock.templates,\n ...this.options.templates,\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={plugin} mode={mode}>\n <Oas oas={oas} operations={operations} generator={this}>\n {templates?.operations && <Operations.File templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginMsw['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n handlers: Operations.templates,\n mock: Mock.templates,\n ...options.templates,\n }\n\n if (!templates?.mock) {\n return []\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n <Mock.File templates={templates.mock} />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
3
|
+
import * as KubbFile from '@kubb/fs/types';
|
|
4
|
+
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
5
|
+
import { Operations, Mock } from './components.cjs';
|
|
6
|
+
import '@kubb/core/utils';
|
|
7
|
+
import '@kubb/oas';
|
|
8
|
+
import 'react';
|
|
9
|
+
import '@kubb/react';
|
|
10
|
+
|
|
11
|
+
type Templates = {
|
|
12
|
+
operations?: typeof Operations.templates | false;
|
|
13
|
+
mock?: typeof Mock.templates | false;
|
|
14
|
+
};
|
|
15
|
+
type Options = {
|
|
16
|
+
output?: {
|
|
17
|
+
/**
|
|
18
|
+
* Relative path to save the MSW mocks.
|
|
19
|
+
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
20
|
+
* @default 'mocks'
|
|
21
|
+
*/
|
|
22
|
+
path: string;
|
|
23
|
+
/**
|
|
24
|
+
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
25
|
+
*/
|
|
26
|
+
exportAs?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
29
|
+
*/
|
|
30
|
+
extName?: KubbFile.Extname;
|
|
31
|
+
/**
|
|
32
|
+
* Define what needs to exported, here you can also disable the export of barrel files
|
|
33
|
+
* @default `'barrel'`
|
|
34
|
+
*/
|
|
35
|
+
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Group the MSW mocks based on the provided name.
|
|
39
|
+
*/
|
|
40
|
+
group?: {
|
|
41
|
+
/**
|
|
42
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
43
|
+
*/
|
|
44
|
+
type: 'tag';
|
|
45
|
+
/**
|
|
46
|
+
* Relative path to save the grouped MSW mocks.
|
|
47
|
+
*
|
|
48
|
+
* `{{tag}}` will be replaced by the current tagName.
|
|
49
|
+
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
50
|
+
* @default `${output}/{{tag}}Controller`
|
|
51
|
+
*/
|
|
52
|
+
output?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Name to be used for the `export * as {{exportAs}} from './`
|
|
55
|
+
* @default `"{{tag}}Handlers"`
|
|
56
|
+
*/
|
|
57
|
+
exportAs?: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
61
|
+
*/
|
|
62
|
+
exclude?: Array<Exclude>;
|
|
63
|
+
/**
|
|
64
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
65
|
+
*/
|
|
66
|
+
include?: Array<Include>;
|
|
67
|
+
/**
|
|
68
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
69
|
+
*/
|
|
70
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
71
|
+
transformers?: {
|
|
72
|
+
/**
|
|
73
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
74
|
+
*/
|
|
75
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Make it possible to override one of the templates
|
|
79
|
+
*/
|
|
80
|
+
templates?: Partial<Templates>;
|
|
81
|
+
};
|
|
82
|
+
type ResolvedOptions = {
|
|
83
|
+
extName: KubbFile.Extname | undefined;
|
|
84
|
+
templates: NonNullable<Templates>;
|
|
85
|
+
};
|
|
86
|
+
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
87
|
+
declare module '@kubb/core' {
|
|
88
|
+
interface _Register {
|
|
89
|
+
['@kubb/plugin-msw']: PluginMsw;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare const pluginMswName = "plugin-msw";
|
|
94
|
+
declare const pluginMsw: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginMsw>;
|
|
95
|
+
|
|
96
|
+
export { type PluginMsw, pluginMsw, pluginMswName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
3
|
+
import * as KubbFile from '@kubb/fs/types';
|
|
4
|
+
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
5
|
+
import { Operations, Mock } from './components.js';
|
|
6
|
+
import '@kubb/core/utils';
|
|
7
|
+
import '@kubb/oas';
|
|
8
|
+
import 'react';
|
|
9
|
+
import '@kubb/react';
|
|
10
|
+
|
|
11
|
+
type Templates = {
|
|
12
|
+
operations?: typeof Operations.templates | false;
|
|
13
|
+
mock?: typeof Mock.templates | false;
|
|
14
|
+
};
|
|
15
|
+
type Options = {
|
|
16
|
+
output?: {
|
|
17
|
+
/**
|
|
18
|
+
* Relative path to save the MSW mocks.
|
|
19
|
+
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
20
|
+
* @default 'mocks'
|
|
21
|
+
*/
|
|
22
|
+
path: string;
|
|
23
|
+
/**
|
|
24
|
+
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
25
|
+
*/
|
|
26
|
+
exportAs?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
29
|
+
*/
|
|
30
|
+
extName?: KubbFile.Extname;
|
|
31
|
+
/**
|
|
32
|
+
* Define what needs to exported, here you can also disable the export of barrel files
|
|
33
|
+
* @default `'barrel'`
|
|
34
|
+
*/
|
|
35
|
+
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Group the MSW mocks based on the provided name.
|
|
39
|
+
*/
|
|
40
|
+
group?: {
|
|
41
|
+
/**
|
|
42
|
+
* Tag will group based on the operation tag inside the Swagger file
|
|
43
|
+
*/
|
|
44
|
+
type: 'tag';
|
|
45
|
+
/**
|
|
46
|
+
* Relative path to save the grouped MSW mocks.
|
|
47
|
+
*
|
|
48
|
+
* `{{tag}}` will be replaced by the current tagName.
|
|
49
|
+
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
50
|
+
* @default `${output}/{{tag}}Controller`
|
|
51
|
+
*/
|
|
52
|
+
output?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Name to be used for the `export * as {{exportAs}} from './`
|
|
55
|
+
* @default `"{{tag}}Handlers"`
|
|
56
|
+
*/
|
|
57
|
+
exportAs?: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
61
|
+
*/
|
|
62
|
+
exclude?: Array<Exclude>;
|
|
63
|
+
/**
|
|
64
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
65
|
+
*/
|
|
66
|
+
include?: Array<Include>;
|
|
67
|
+
/**
|
|
68
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
69
|
+
*/
|
|
70
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
71
|
+
transformers?: {
|
|
72
|
+
/**
|
|
73
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
74
|
+
*/
|
|
75
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Make it possible to override one of the templates
|
|
79
|
+
*/
|
|
80
|
+
templates?: Partial<Templates>;
|
|
81
|
+
};
|
|
82
|
+
type ResolvedOptions = {
|
|
83
|
+
extName: KubbFile.Extname | undefined;
|
|
84
|
+
templates: NonNullable<Templates>;
|
|
85
|
+
};
|
|
86
|
+
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
87
|
+
declare module '@kubb/core' {
|
|
88
|
+
interface _Register {
|
|
89
|
+
['@kubb/plugin-msw']: PluginMsw;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare const pluginMswName = "plugin-msw";
|
|
94
|
+
declare const pluginMsw: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginMsw>;
|
|
95
|
+
|
|
96
|
+
export { type PluginMsw, pluginMsw, pluginMswName };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Mock,
|
|
3
|
+
Operations
|
|
4
|
+
} from "./chunk-WRIEMCYI.js";
|
|
5
|
+
|
|
6
|
+
// src/plugin.ts
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
9
|
+
import { camelCase } from "@kubb/core/transformers";
|
|
10
|
+
import { renderTemplate } from "@kubb/core/utils";
|
|
11
|
+
import { pluginOasName } from "@kubb/plugin-oas";
|
|
12
|
+
import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
|
|
13
|
+
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
14
|
+
import { pluginTsName } from "@kubb/plugin-ts";
|
|
15
|
+
|
|
16
|
+
// src/OperationGenerator.tsx
|
|
17
|
+
import { OperationGenerator as Generator } from "@kubb/plugin-oas";
|
|
18
|
+
import { Oas } from "@kubb/plugin-oas/components";
|
|
19
|
+
import { App, createRoot } from "@kubb/react";
|
|
20
|
+
import { jsx } from "@kubb/react/jsx-runtime";
|
|
21
|
+
var OperationGenerator = class extends Generator {
|
|
22
|
+
async all(operations, operationsByMethod) {
|
|
23
|
+
const { oas, pluginManager, plugin, mode } = this.context;
|
|
24
|
+
const root = createRoot({
|
|
25
|
+
logger: pluginManager.logger
|
|
26
|
+
});
|
|
27
|
+
const templates = {
|
|
28
|
+
operations: Operations.templates,
|
|
29
|
+
mock: Mock.templates,
|
|
30
|
+
...this.options.templates
|
|
31
|
+
};
|
|
32
|
+
root.render(
|
|
33
|
+
/* @__PURE__ */ jsx(App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations, generator: this, children: templates?.operations && /* @__PURE__ */ jsx(Operations.File, { templates: templates.operations }) }) })
|
|
34
|
+
);
|
|
35
|
+
return root.files;
|
|
36
|
+
}
|
|
37
|
+
async operation(operation, options) {
|
|
38
|
+
const { oas, pluginManager, plugin, mode } = this.context;
|
|
39
|
+
const root = createRoot({
|
|
40
|
+
logger: pluginManager.logger
|
|
41
|
+
});
|
|
42
|
+
const templates = {
|
|
43
|
+
handlers: Operations.templates,
|
|
44
|
+
mock: Mock.templates,
|
|
45
|
+
...options.templates
|
|
46
|
+
};
|
|
47
|
+
if (!templates?.mock) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
root.render(
|
|
51
|
+
/* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx(Oas.Operation, { operation, children: /* @__PURE__ */ jsx(Mock.File, { templates: templates.mock }) }) }) })
|
|
52
|
+
);
|
|
53
|
+
return root.files;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/plugin.ts
|
|
58
|
+
var pluginMswName = "plugin-msw";
|
|
59
|
+
var pluginMsw = createPlugin((options) => {
|
|
60
|
+
const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers = {}, templates } = options;
|
|
61
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
62
|
+
return {
|
|
63
|
+
name: pluginMswName,
|
|
64
|
+
options: {
|
|
65
|
+
extName: output.extName,
|
|
66
|
+
templates: {
|
|
67
|
+
operations: Operations.templates,
|
|
68
|
+
mock: Mock.templates,
|
|
69
|
+
...templates
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
pre: [pluginOasName, pluginTsName, pluginFakerName],
|
|
73
|
+
resolvePath(baseName, pathMode, options2) {
|
|
74
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
75
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
76
|
+
if (mode === "single") {
|
|
77
|
+
return path.resolve(root, output.path);
|
|
78
|
+
}
|
|
79
|
+
if (options2?.tag && group?.type === "tag") {
|
|
80
|
+
const tag = camelCase(options2.tag);
|
|
81
|
+
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
82
|
+
}
|
|
83
|
+
return path.resolve(root, output.path, baseName);
|
|
84
|
+
},
|
|
85
|
+
resolveName(name, type) {
|
|
86
|
+
const resolvedName = camelCase(name, {
|
|
87
|
+
suffix: type ? "handler" : void 0,
|
|
88
|
+
isFile: type === "file"
|
|
89
|
+
});
|
|
90
|
+
if (type) {
|
|
91
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
92
|
+
}
|
|
93
|
+
return resolvedName;
|
|
94
|
+
},
|
|
95
|
+
async writeFile(path2, source) {
|
|
96
|
+
if (!path2.endsWith(".ts") || !source) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
return this.fileManager.write(path2, source, { sanity: false });
|
|
100
|
+
},
|
|
101
|
+
async buildStart() {
|
|
102
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
103
|
+
const oas = await swaggerPlugin.api.getOas();
|
|
104
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
105
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
106
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
107
|
+
oas,
|
|
108
|
+
pluginManager: this.pluginManager,
|
|
109
|
+
plugin: this.plugin,
|
|
110
|
+
contentType: swaggerPlugin.api.contentType,
|
|
111
|
+
exclude,
|
|
112
|
+
include,
|
|
113
|
+
override,
|
|
114
|
+
mode
|
|
115
|
+
});
|
|
116
|
+
const files = await operationGenerator.build();
|
|
117
|
+
await this.addFile(...files);
|
|
118
|
+
},
|
|
119
|
+
async buildEnd() {
|
|
120
|
+
if (this.config.output.write === false) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
124
|
+
if (group?.type === "tag") {
|
|
125
|
+
const rootFiles = await getGroupedByTagFiles({
|
|
126
|
+
logger: this.logger,
|
|
127
|
+
files: this.fileManager.files,
|
|
128
|
+
plugin: this.plugin,
|
|
129
|
+
template,
|
|
130
|
+
exportAs: group.exportAs || "{{tag}}Handlers",
|
|
131
|
+
root,
|
|
132
|
+
output
|
|
133
|
+
});
|
|
134
|
+
await this.addFile(...rootFiles);
|
|
135
|
+
}
|
|
136
|
+
await this.fileManager.addIndexes({
|
|
137
|
+
root,
|
|
138
|
+
output,
|
|
139
|
+
meta: { pluginKey: this.plugin.key },
|
|
140
|
+
logger: this.logger
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
export {
|
|
146
|
+
pluginMsw,
|
|
147
|
+
pluginMswName
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts","../src/OperationGenerator.tsx"],"sourcesContent":["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 { pluginOasName } from '@kubb/plugin-oas'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mock, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 = {}, templates } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n options: {\n extName: output.extName,\n templates: {\n operations: Operations.templates,\n mock: Mock.templates,\n ...templates,\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 writeFile(path, source) {\n if (!path.endsWith('.ts') || !source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.api.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.api.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n if (group?.type === 'tag') {\n const rootFiles = await getGroupedByTagFiles({\n logger: this.logger,\n files: this.fileManager.files,\n plugin: this.plugin,\n template,\n exportAs: group.exportAs || '{{tag}}Handlers',\n root,\n output,\n })\n\n await this.addFile(...rootFiles)\n }\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n logger: this.logger,\n })\n },\n }\n})\n","import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Mock } from './components/Mock.tsx'\nimport { Operations } from './components/Operations.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginMsw } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginMsw['resolvedOptions'], PluginMsw> {\n async all(operations: Operation[], operationsByMethod: OperationsByMethod): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n operations: Operations.templates,\n mock: Mock.templates,\n ...this.options.templates,\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={plugin} mode={mode}>\n <Oas oas={oas} operations={operations} generator={this}>\n {templates?.operations && <Operations.File templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginMsw['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n handlers: Operations.templates,\n mock: Mock.templates,\n ...options.templates,\n }\n\n if (!templates?.mock) {\n return []\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n <Mock.File templates={templates.mock} />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"],"mappings":";;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,aAAa,eAAe,oBAAoB;AACzD,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;;;ACR7B,SAAS,sBAAsB,iBAAiB;AAChD,SAAS,WAAW;AACpB,SAAS,KAAK,kBAAkB;AA0BI;AAjB7B,IAAM,qBAAN,cAAiC,UAAmD;AAAA,EACzF,MAAM,IAAI,YAAyB,oBAAyE;AAC1G,UAAM,EAAE,KAAK,eAAe,QAAQ,KAAK,IAAI,KAAK;AAElD,UAAM,OAAO,WAAW;AAAA,MACtB,QAAQ,cAAc;AAAA,IACxB,CAAC;AAED,UAAM,YAAY;AAAA,MAChB,YAAY,WAAW;AAAA,MACvB,MAAM,KAAK;AAAA,MACX,GAAG,KAAK,QAAQ;AAAA,IAClB;AAEA,SAAK;AAAA,MACH,oBAAC,OAAI,eAA8B,QAAgB,MACjD,8BAAC,OAAI,KAAU,YAAwB,WAAW,MAC/C,qBAAW,cAAc,oBAAC,WAAW,MAAX,EAAgB,WAAW,UAAU,YAAY,GAC9E,GACF;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,UAAU,WAAsB,SAAwE;AA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mB,MAAM;AAC7C,YAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,IAC7B;AAAA,IACA,MAAM,WAAW;AACf,UAAI,KAAK,OAAO,OAAO,UAAU,OAAO;AACtC;AAAA,MACF;AAEA,YAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AAEnE,UAAI,OAAO,SAAS,OAAO;AACzB,cAAM,YAAY,MAAM,qBAAqB;AAAA,UAC3C,QAAQ,KAAK;AAAA,UACb,OAAO,KAAK,YAAY;AAAA,UACxB,QAAQ,KAAK;AAAA,UACb;AAAA,UACA,UAAU,MAAM,YAAY;AAAA,UAC5B;AAAA,UACA;AAAA,QACF,CAAC;AAED,cAAM,KAAK,QAAQ,GAAG,SAAS;AAAA,MACjC;AAEA,YAAM,KAAK,YAAY,WAAW;AAAA,QAChC;AAAA,QACA;AAAA,QACA,MAAM,EAAE,WAAW,KAAK,OAAO,IAAI;AAAA,QACnC,QAAQ,KAAK;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":["options","path"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubb/plugin-msw",
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
|
+
"description": "Generator swagger",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"plugins",
|
|
8
|
+
"kubb",
|
|
9
|
+
"codegen",
|
|
10
|
+
"swagger",
|
|
11
|
+
"openapi"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git://github.com/kubb-labs/kubb.git",
|
|
16
|
+
"directory": "packages/plugin-msw"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
},
|
|
28
|
+
"./utils": {
|
|
29
|
+
"import": "./dist/utils.js",
|
|
30
|
+
"require": "./dist/utils.cjs",
|
|
31
|
+
"default": "./dist/utils.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./hooks": {
|
|
34
|
+
"import": "./dist/hooks.js",
|
|
35
|
+
"require": "./dist/hooks.cjs",
|
|
36
|
+
"default": "./dist/hooks.cjs"
|
|
37
|
+
},
|
|
38
|
+
"./components": {
|
|
39
|
+
"import": "./dist/components.js",
|
|
40
|
+
"require": "./dist/components.cjs",
|
|
41
|
+
"default": "./dist/components.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json",
|
|
44
|
+
"./*": "./*"
|
|
45
|
+
},
|
|
46
|
+
"main": "dist/index.cjs",
|
|
47
|
+
"module": "dist/index.js",
|
|
48
|
+
"types": "./dist/index.d.ts",
|
|
49
|
+
"typesVersions": {
|
|
50
|
+
"*": {
|
|
51
|
+
"utils": [
|
|
52
|
+
"./dist/utils.d.ts"
|
|
53
|
+
],
|
|
54
|
+
"hooks": [
|
|
55
|
+
"./dist/hooks.d.ts"
|
|
56
|
+
],
|
|
57
|
+
"components": [
|
|
58
|
+
"./dist/components.d.ts"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"files": [
|
|
63
|
+
"src",
|
|
64
|
+
"dist",
|
|
65
|
+
"!/**/**.test.**",
|
|
66
|
+
"!/**/__tests__/**"
|
|
67
|
+
],
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"@kubb/core": "3.0.0-alpha.0",
|
|
70
|
+
"@kubb/fs": "3.0.0-alpha.0",
|
|
71
|
+
"@kubb/oas": "3.0.0-alpha.0",
|
|
72
|
+
"@kubb/parser-ts": "3.0.0-alpha.0",
|
|
73
|
+
"@kubb/plugin-faker": "3.0.0-alpha.0",
|
|
74
|
+
"@kubb/plugin-oas": "3.0.0-alpha.0",
|
|
75
|
+
"@kubb/plugin-ts": "3.0.0-alpha.0",
|
|
76
|
+
"@kubb/react": "3.0.0-alpha.0"
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"@types/react": "^18.3.3",
|
|
80
|
+
"@types/react-dom": "^18.3.0",
|
|
81
|
+
"react": "^18.3.1",
|
|
82
|
+
"tsup": "^8.2.4",
|
|
83
|
+
"typescript": "^5.5.4",
|
|
84
|
+
"@kubb/config-biome": "3.0.0-alpha.0",
|
|
85
|
+
"@kubb/config-ts": "3.0.0-alpha.0",
|
|
86
|
+
"@kubb/config-tsup": "3.0.0-alpha.0"
|
|
87
|
+
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"@kubb/react": "3.0.0-alpha.0"
|
|
90
|
+
},
|
|
91
|
+
"engines": {
|
|
92
|
+
"node": ">=20"
|
|
93
|
+
},
|
|
94
|
+
"publishConfig": {
|
|
95
|
+
"access": "public",
|
|
96
|
+
"registry": "https://registry.npmjs.org/"
|
|
97
|
+
},
|
|
98
|
+
"scripts": {
|
|
99
|
+
"build": "tsup",
|
|
100
|
+
"clean": "npx rimraf ./dist",
|
|
101
|
+
"lint": "bun biome lint .",
|
|
102
|
+
"lint:fix": "bun biome lint --apply-unsafe .",
|
|
103
|
+
"release": "pnpm publish --no-git-check",
|
|
104
|
+
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
105
|
+
"start": "tsup --watch",
|
|
106
|
+
"test": "vitest --passWithNoTests",
|
|
107
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
108
|
+
}
|
|
109
|
+
}
|