@kubb/core 0.0.0-canary-20231213204140

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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/dist/chunk-4A7WG6IA.js +128 -0
  4. package/dist/chunk-4A7WG6IA.js.map +1 -0
  5. package/dist/chunk-54P4AWHI.js +71 -0
  6. package/dist/chunk-54P4AWHI.js.map +1 -0
  7. package/dist/chunk-5TK7TMV6.cjs +131 -0
  8. package/dist/chunk-5TK7TMV6.cjs.map +1 -0
  9. package/dist/chunk-7S67BJXQ.js +85 -0
  10. package/dist/chunk-7S67BJXQ.js.map +1 -0
  11. package/dist/chunk-E3ANGQ5N.cjs +2290 -0
  12. package/dist/chunk-E3ANGQ5N.cjs.map +1 -0
  13. package/dist/chunk-H47IKRXJ.cjs +129 -0
  14. package/dist/chunk-H47IKRXJ.cjs.map +1 -0
  15. package/dist/chunk-HIE46T3F.js +129 -0
  16. package/dist/chunk-HIE46T3F.js.map +1 -0
  17. package/dist/chunk-K2H7BYQB.js +155 -0
  18. package/dist/chunk-K2H7BYQB.js.map +1 -0
  19. package/dist/chunk-NAWI7UXW.js +67 -0
  20. package/dist/chunk-NAWI7UXW.js.map +1 -0
  21. package/dist/chunk-PLVKILIY.cjs +162 -0
  22. package/dist/chunk-PLVKILIY.cjs.map +1 -0
  23. package/dist/chunk-W2FP7ZWW.cjs +71 -0
  24. package/dist/chunk-W2FP7ZWW.cjs.map +1 -0
  25. package/dist/chunk-WZQO3EPM.cjs +91 -0
  26. package/dist/chunk-WZQO3EPM.cjs.map +1 -0
  27. package/dist/chunk-XDHI63G7.cjs +104 -0
  28. package/dist/chunk-XDHI63G7.cjs.map +1 -0
  29. package/dist/chunk-XPOF4D5N.js +18 -0
  30. package/dist/chunk-XPOF4D5N.js.map +1 -0
  31. package/dist/fs.cjs +31 -0
  32. package/dist/fs.cjs.map +1 -0
  33. package/dist/fs.d.cts +5 -0
  34. package/dist/fs.d.ts +5 -0
  35. package/dist/fs.js +11 -0
  36. package/dist/fs.js.map +1 -0
  37. package/dist/index.cjs +3156 -0
  38. package/dist/index.cjs.map +1 -0
  39. package/dist/index.d.cts +693 -0
  40. package/dist/index.d.ts +693 -0
  41. package/dist/index.js +2160 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/logger.cjs +26 -0
  44. package/dist/logger.cjs.map +1 -0
  45. package/dist/logger.d.cts +32 -0
  46. package/dist/logger.d.ts +32 -0
  47. package/dist/logger.js +8 -0
  48. package/dist/logger.js.map +1 -0
  49. package/dist/transformers.cjs +124 -0
  50. package/dist/transformers.cjs.map +1 -0
  51. package/dist/transformers.d.cts +55 -0
  52. package/dist/transformers.d.ts +55 -0
  53. package/dist/transformers.js +95 -0
  54. package/dist/transformers.js.map +1 -0
  55. package/dist/utils.cjs +118 -0
  56. package/dist/utils.cjs.map +1 -0
  57. package/dist/utils.d.cts +94 -0
  58. package/dist/utils.d.ts +94 -0
  59. package/dist/utils.js +102 -0
  60. package/dist/utils.js.map +1 -0
  61. package/dist/write-A6VgHkYA.d.cts +10 -0
  62. package/dist/write-A6VgHkYA.d.ts +10 -0
  63. package/globals.d.ts +51 -0
  64. package/package.json +113 -0
  65. package/schema.json +86 -0
  66. package/src/BarrelManager.ts +113 -0
  67. package/src/FileManager.ts +581 -0
  68. package/src/Generator.ts +34 -0
  69. package/src/PackageManager.ts +178 -0
  70. package/src/PluginManager.ts +645 -0
  71. package/src/PromiseManager.ts +51 -0
  72. package/src/build.ts +221 -0
  73. package/src/config.ts +22 -0
  74. package/src/errors.ts +12 -0
  75. package/src/fs/clean.ts +5 -0
  76. package/src/fs/index.ts +3 -0
  77. package/src/fs/read.ts +68 -0
  78. package/src/fs/write.ts +79 -0
  79. package/src/index.ts +27 -0
  80. package/src/logger.ts +121 -0
  81. package/src/plugin.ts +80 -0
  82. package/src/transformers/casing.ts +9 -0
  83. package/src/transformers/combineCodes.ts +3 -0
  84. package/src/transformers/createJSDocBlockText.ts +9 -0
  85. package/src/transformers/escape.ts +31 -0
  86. package/src/transformers/indent.ts +3 -0
  87. package/src/transformers/index.ts +36 -0
  88. package/src/transformers/nameSorter.ts +9 -0
  89. package/src/transformers/searchAndReplace.ts +25 -0
  90. package/src/transformers/transformReservedWord.ts +97 -0
  91. package/src/transformers/trim.ts +7 -0
  92. package/src/types.ts +334 -0
  93. package/src/utils/EventEmitter.ts +24 -0
  94. package/src/utils/FunctionParams.ts +86 -0
  95. package/src/utils/TreeNode.ts +125 -0
  96. package/src/utils/URLPath.ts +133 -0
  97. package/src/utils/cache.ts +35 -0
  98. package/src/utils/executeStrategies.ts +83 -0
  99. package/src/utils/index.ts +8 -0
  100. package/src/utils/promise.ts +13 -0
  101. package/src/utils/renderTemplate.ts +31 -0
  102. package/src/utils/timeout.ts +7 -0
  103. package/src/utils/uniqueName.ts +20 -0
package/dist/utils.js ADDED
@@ -0,0 +1,102 @@
1
+ import { createRequire } from 'module';
2
+ export { URLPath, getUniqueName, setUniqueName } from './chunk-4A7WG6IA.js';
3
+ import { camelCase } from './chunk-XPOF4D5N.js';
4
+ import { init_esm_shims } from './chunk-54P4AWHI.js';
5
+ import { orderBy } from 'natural-orderby';
6
+
7
+ createRequire(import.meta.url);
8
+
9
+ // src/utils/index.ts
10
+ init_esm_shims();
11
+
12
+ // src/utils/FunctionParams.ts
13
+ init_esm_shims();
14
+ var FunctionParams = class {
15
+ constructor(type) {
16
+ this.items = [];
17
+ this.type = type;
18
+ return this;
19
+ }
20
+ add(item) {
21
+ if (!item) {
22
+ return this;
23
+ }
24
+ if (Array.isArray(item)) {
25
+ item.filter(Boolean).forEach((it) => this.items.push(it));
26
+ return this;
27
+ }
28
+ this.items.push(item);
29
+ return this;
30
+ }
31
+ toString() {
32
+ const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
33
+ return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
34
+ if (!name) {
35
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
36
+ return acc;
37
+ }
38
+ const parameterName = name.startsWith("{") ? name : camelCase(name);
39
+ if (type) {
40
+ if (required) {
41
+ acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
42
+ } else {
43
+ acc.push(`${parameterName}?: ${type}`);
44
+ }
45
+ } else {
46
+ acc.push(`${parameterName}`);
47
+ }
48
+ return acc;
49
+ }, []).join(", ");
50
+ }
51
+ };
52
+
53
+ // src/utils/promise.ts
54
+ init_esm_shims();
55
+ function isPromise(result) {
56
+ return !!result && typeof result?.then === "function";
57
+ }
58
+ function isPromiseFulfilledResult(result) {
59
+ return result.status === "fulfilled";
60
+ }
61
+ function isPromiseRejectedResult(result) {
62
+ return result.status === "rejected";
63
+ }
64
+
65
+ // src/utils/renderTemplate.ts
66
+ init_esm_shims();
67
+ function renderTemplate(template, data = void 0) {
68
+ if (!data || !Object.keys(data).length) {
69
+ return template.replace(/{{(.*?)}}/g, "");
70
+ }
71
+ const matches = template.match(/{{(.*?)}}/g);
72
+ return matches?.reduce((prev, curr) => {
73
+ const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
74
+ if (index === void 0) {
75
+ return prev;
76
+ }
77
+ const value = data[index];
78
+ if (value === void 0) {
79
+ return prev;
80
+ }
81
+ return prev.replace(curr, () => {
82
+ if (typeof value === "boolean") {
83
+ return `${value.toString()}` || "false";
84
+ }
85
+ return value || "";
86
+ }).trim();
87
+ }, template) || "";
88
+ }
89
+
90
+ // src/utils/timeout.ts
91
+ init_esm_shims();
92
+ async function timeout(ms) {
93
+ return new Promise((resolve) => {
94
+ setTimeout(() => {
95
+ resolve(true);
96
+ }, ms);
97
+ });
98
+ }
99
+
100
+ export { FunctionParams, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, timeout };
101
+ //# sourceMappingURL=out.js.map
102
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/index.ts","../src/utils/FunctionParams.ts","../src/utils/promise.ts","../src/utils/renderTemplate.ts","../src/utils/timeout.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;ACAA;AAAA,SAAS,eAAe;AAiCjB,IAAM,iBAAN,MAAqB;AAAA,EAG1B,YAAY,MAA6B;AADzC,SAAO,QAA6B,CAAC;AAEnC,SAAK,OAAO;AAEZ,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,MAA4F;AAC9F,QAAI,CAAC,MAAM;AACT,aAAO;AAAA,IACT;AAEA,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAK,OAAO,OAAO,EAAE,QAAQ,CAAC,OAAO,KAAK,MAAM,KAAK,EAAE,CAAC;AACxD,aAAO;AAAA,IACT;AACA,SAAK,MAAM,KAAK,IAAI;AAEpB,WAAO;AAAA,EACT;AAAA,EAEA,WAAmB;AACjB,UAAM,aAAa,QAAQ,KAAK,MAAM,OAAO,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,YAAY,IAAI,GAAG,CAAC,QAAQ,MAAM,CAAC;AAEvH,WAAO,WACJ,OAAO,CAAC,EAAE,UAAU,KAAK,MAAM,OAAO,EACtC,OAAO,CAAC,KAAK,EAAE,MAAM,MAAM,WAAW,MAAM,GAAG,KAAK,MAAM;AACzD,UAAI,CAAC,MAAM;AAET,YAAI,KAAK,GAAG,IAAI,GAAG,KAAK,UAAU,MAAM,KAAK,OAAO,KAAK,EAAE,EAAE;AAE7D,eAAO;AAAA,MACT;AAEA,YAAM,gBAAgB,KAAK,WAAW,GAAG,IAAI,OAAO,UAAU,IAAI;AAElE,UAAI,MAAM;AACR,YAAI,UAAU;AACZ,cAAI,KAAK,GAAG,aAAa,KAAK,IAAI,GAAG,KAAK,UAAU,MAAM,KAAK,OAAO,KAAK,EAAE,EAAE;AAAA,QACjF,OAAO;AACL,cAAI,KAAK,GAAG,aAAa,MAAM,IAAI,EAAE;AAAA,QACvC;AAAA,MACF,OAAO;AACL,YAAI,KAAK,GAAG,aAAa,EAAE;AAAA,MAC7B;AAEA,aAAO;AAAA,IACT,GAAG,CAAC,CAAa,EAChB,KAAK,IAAI;AAAA,EACd;AACF;;;ACrFA;AAEO,SAAS,UAAa,QAAkD;AAC7E,SAAO,CAAC,CAAC,UAAU,OAAQ,QAA6B,SAAS;AACnE;AAEO,SAAS,yBAAsC,QAA4E;AAChI,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,wBAA2B,QAAwG;AACjJ,SAAO,OAAO,WAAW;AAC3B;;;ACZA;AAAO,SAAS,eAAgF,UAAkB,OAA0B,QAAmB;AAC7J,MAAI,CAAC,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE,QAAQ;AACtC,WAAO,SAAS,QAAQ,cAAc,EAAE;AAAA,EAC1C;AAEA,QAAM,UAAU,SAAS,MAAM,YAAY;AAE3C,SACE,SAAS,OAAO,CAAC,MAAM,SAAS;AAC9B,UAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,OAAO,OAAO,EAAE,CAAC,GAAG,KAAK;AAC3D,QAAI,UAAU,QAAW;AACvB,aAAO;AAAA,IACT;AACA,UAAM,QAAQ,KAAK,KAAK;AAExB,QAAI,UAAU,QAAW;AACvB,aAAO;AAAA,IACT;AAEA,WAAO,KACJ,QAAQ,MAAM,MAAM;AACnB,UAAI,OAAO,UAAU,WAAW;AAC9B,eAAO,GAAG,MAAM,SAAS,CAAC,MAAM;AAAA,MAClC;AAEA,aAAQ,SAAoB;AAAA,IAC9B,CAAC,EACA,KAAK;AAAA,EACV,GAAG,QAAQ,KAAK;AAEpB;;;AC9BA;AAAA,eAAsB,QAAQ,IAA8B;AAC1D,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,MAAM;AACf,cAAQ,IAAI;AAAA,IACd,GAAG,EAAE;AAAA,EACP,CAAC;AACH","sourcesContent":["export type { FunctionParamsAST } from './FunctionParams.ts'\nexport { FunctionParams } from './FunctionParams.ts'\nexport { isPromise, isPromiseFulfilledResult, isPromiseRejectedResult } from './promise.ts'\nexport { renderTemplate } from './renderTemplate.ts'\nexport { timeout } from './timeout.ts'\nexport { getUniqueName, setUniqueName } from './uniqueName.ts'\nexport type { URLObject } from './URLPath.ts'\nexport { URLPath } from './URLPath.ts'\n","import { orderBy } from 'natural-orderby'\n\nimport { camelCase } from '../transformers/casing.ts'\n\ntype FunctionParamsASTWithoutType = {\n name?: string\n type?: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\ntype FunctionParamsASTWithType = {\n name?: never\n type: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\nexport type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType\nexport class FunctionParams {\n public type?: 'generics' | 'typed'\n public items: FunctionParamsAST[] = []\n constructor(type?: 'generics' | 'typed') {\n this.type = type\n\n return this\n }\n\n add(item: FunctionParamsAST | Array<FunctionParamsAST | undefined> | undefined): FunctionParams {\n if (!item) {\n return this\n }\n\n if (Array.isArray(item)) {\n item.filter(Boolean).forEach((it) => this.items.push(it))\n return this\n }\n this.items.push(item)\n\n return this\n }\n\n toString(): string {\n const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ['desc', 'desc'])\n\n return sortedData\n .filter(({ enabled = true }) => enabled)\n .reduce((acc, { name, type, required = true, ...rest }) => {\n if (!name) {\n // when name is not se we will use TypeScript generics\n acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)\n\n return acc\n }\n // TODO check whey we still need the camelcase here\n const parameterName = name.startsWith('{') ? name : camelCase(name)\n\n if (type) {\n if (required) {\n acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)\n } else {\n acc.push(`${parameterName}?: ${type}`)\n }\n } else {\n acc.push(`${parameterName}`)\n }\n\n return acc\n }, [] as string[])\n .join(', ')\n }\n}\n","import type { PossiblePromise } from '@kubb/types'\n\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return !!result && typeof (result as Promise<unknown>)?.then === 'function'\n}\n\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","export function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data: TData | undefined = undefined): string {\n if (!data || !Object.keys(data).length) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n const matches = template.match(/{{(.*?)}}/g)\n\n return (\n matches?.reduce((prev, curr) => {\n const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim()\n if (index === undefined) {\n return prev\n }\n const value = data[index]\n\n if (value === undefined) {\n return prev\n }\n\n return prev\n .replace(curr, () => {\n if (typeof value === 'boolean') {\n return `${value.toString()}` || 'false'\n }\n\n return (value as string) || ''\n })\n .trim()\n }, template) || ''\n )\n}\n","export async function timeout(ms: number): Promise<unknown> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n"]}
@@ -0,0 +1,10 @@
1
+ declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string;
2
+ declare function read(path: string): Promise<string>;
3
+ declare function readSync(path: string): string;
4
+
5
+ type Options = {
6
+ sanity?: boolean;
7
+ };
8
+ declare function write(data: string, path: string, options?: Options): Promise<string | undefined>;
9
+
10
+ export { readSync as a, getRelativePath as g, read as r, write as w };
@@ -0,0 +1,10 @@
1
+ declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string;
2
+ declare function read(path: string): Promise<string>;
3
+ declare function readSync(path: string): string;
4
+
5
+ type Options = {
6
+ sanity?: boolean;
7
+ };
8
+ declare function write(data: string, path: string, options?: Options): Promise<string | undefined>;
9
+
10
+ export { readSync as a, getRelativePath as g, read as r, write as w };
package/globals.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ /// <reference no-default-lib="true" />
2
+ /// <reference lib="esnext" />
3
+
4
+ /**
5
+ * `tsconfig.json`
6
+ * @example
7
+ "compilerOptions": {
8
+ ___ "types": ["@kubb/core/globals"]
9
+ }
10
+ * @example implementation
11
+ type SwaggerPlugin = Kubb.Plugins["@kubb/swagger"]
12
+ const swaggerPlugin: SwaggerPlugin={
13
+ ___ validate: true
14
+ }
15
+ */
16
+ declare namespace Kubb {
17
+ namespace Helpers {
18
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
19
+ type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never
20
+
21
+ // TS4.0+
22
+ type Push<T extends any[], V> = [...T, V]
23
+
24
+ // TS4.1+
25
+ type TuplifyUnion<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>
26
+
27
+ type ObjValueTuple<T, KS extends any[] = TuplifyUnion<keyof T>, R extends any[] = []> = KS extends [infer K, ...infer KT]
28
+ ? ObjValueTuple<T, KT, [...R, [name: K & keyof T, options: T[K & keyof T]]]>
29
+ : R
30
+
31
+ type TupleToUnion<T> = T extends Array<infer ITEMS> ? ITEMS : never
32
+ }
33
+ type Plugins = {
34
+ ['@kubb/swagger']: import('@kubb/swagger').PluginOptions
35
+ ['@kubb/swagger-client']: import('@kubb/swagger-client').PluginOptions
36
+ ['@kubb/swagger-faker']: import('@kubb/swagger-faker').PluginOptions
37
+ ['@kubb/swagger-swr']: import('@kubb/swagger-swr').PluginOptions
38
+ ['@kubb/swagger-tanstack-query']: import('@kubb/swagger-tanstack-query').PluginOptions
39
+ ['@kubb/swagger-ts']: import('@kubb/swagger-ts').PluginOptions
40
+ ['@kubb/swagger-zod']: import('@kubb/swagger-zod').PluginOptions
41
+ ['@kubb/swagger-zodios']: import('@kubb/swagger-zodios').PluginOptions
42
+ ['@kubb/swagger-msw']: import('@kubb/swagger-msw').PluginOptions
43
+ }
44
+ type OptionsPlugins = { [K in keyof Plugins]: Plugins[K]['options'] }
45
+
46
+ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options']
47
+
48
+ type PluginUnion = Helpers.TupleToUnion<Helpers.ObjValueTuple<OptionsPlugins>>
49
+
50
+ type Plugin = keyof Plugins
51
+ }
package/package.json ADDED
@@ -0,0 +1,113 @@
1
+ {
2
+ "name": "@kubb/core",
3
+ "version": "0.0.0-canary-20231213204140",
4
+ "description": "Generator core",
5
+ "keywords": [
6
+ "typescript",
7
+ "plugins",
8
+ "kubb",
9
+ "codegen"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git://github.com/kubb-project/kubb.git",
14
+ "directory": "packages/core"
15
+ },
16
+ "license": "MIT",
17
+ "author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
18
+ "sideEffects": false,
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs",
24
+ "default": "./dist/index.cjs"
25
+ },
26
+ "./utils": {
27
+ "import": "./dist/utils.js",
28
+ "require": "./dist/utils.cjs",
29
+ "default": "./dist/utils.cjs"
30
+ },
31
+ "./transformers": {
32
+ "import": "./dist/transformers.js",
33
+ "require": "./dist/transformers.cjs",
34
+ "default": "./dist/transformers.cjs"
35
+ },
36
+ "./logger": {
37
+ "import": "./dist/logger.js",
38
+ "require": "./dist/logger.cjs",
39
+ "default": "./dist/logger.cjs"
40
+ },
41
+ "./fs": {
42
+ "import": "./dist/fs.js",
43
+ "require": "./dist/fs.cjs",
44
+ "default": "./dist/fs.cjs"
45
+ },
46
+ "./package.json": "./package.json",
47
+ "./globals": {
48
+ "types": "./globals.d.ts"
49
+ },
50
+ "./*": "./*"
51
+ },
52
+ "main": "dist/index.cjs",
53
+ "module": "dist/index.js",
54
+ "types": "./dist/index.d.ts",
55
+ "files": [
56
+ "src",
57
+ "dist",
58
+ "*.d.ts",
59
+ "*.d.cts",
60
+ "schema.json",
61
+ "!/**/**.test.**",
62
+ "!/**/__tests__/**"
63
+ ],
64
+ "dependencies": {
65
+ "change-case": "^5.3.0",
66
+ "directory-tree": "^3.5.1",
67
+ "find-up": "^7.0.0",
68
+ "fs-extra": "^11.2.0",
69
+ "js-runtime": "^0.0.7",
70
+ "natural-orderby": "^3.0.2",
71
+ "p-queue": "^8.0.0",
72
+ "seedrandom": "^3.0.5",
73
+ "semver": "^7.5.4",
74
+ "@kubb/parser": "0.0.0-canary-20231213204140",
75
+ "@kubb/types": "0.0.0-canary-20231213204140"
76
+ },
77
+ "devDependencies": {
78
+ "@types/fs-extra": "^11.0.4",
79
+ "@types/lodash.isequal": "4.5.6",
80
+ "@types/react": "^18.2.45",
81
+ "@types/seedrandom": "^3.0.8",
82
+ "@types/semver": "^7.5.6",
83
+ "eslint": "^8.55.0",
84
+ "lodash.isequal": "^4.5.0",
85
+ "ora": "^7.0.1",
86
+ "tinyrainbow": "^1.1.1",
87
+ "tsup": "^8.0.1",
88
+ "typescript": "^5.3.3",
89
+ "@kubb/eslint-config": "1.1.8",
90
+ "@kubb/ts-config": "0.1.0",
91
+ "@kubb/tsup-config": "1.1.8"
92
+ },
93
+ "packageManager": "pnpm@8.3.0",
94
+ "engines": {
95
+ "node": ">=18",
96
+ "pnpm": ">=8.3.0"
97
+ },
98
+ "publishConfig": {
99
+ "access": "public",
100
+ "registry": "https://registry.npmjs.org/"
101
+ },
102
+ "scripts": {
103
+ "build": "tsup",
104
+ "clean": "npx rimraf ./dist",
105
+ "lint": "ESLINT_USE_FLAT_CONFIG=true eslint --format pretty .",
106
+ "lint-fix": "bun run lint --quiet --fix",
107
+ "release": "pnpm publish --no-git-check",
108
+ "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
109
+ "start": "tsup --watch",
110
+ "test": "vitest --passWithNoTests",
111
+ "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
112
+ }
113
+ }
package/schema.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "@kubb/define-config",
4
+ "title": "JSON schema for @kubb/core define-config",
5
+ "type": "object",
6
+ "required": [],
7
+ "properties": {
8
+ "root": {
9
+ "type": "string",
10
+ "description": "Project root directory. Can be an absolute path, or a path relative from the location of the config file itself.",
11
+ "default": "process.cwd()"
12
+ },
13
+ "input": {
14
+ "type": "object",
15
+ "description": "",
16
+ "properties": {
17
+ "path": {
18
+ "type": "string",
19
+ "description": "Path to be used as the input. Can be an absolute path, or a path relative from the defined root option."
20
+ }
21
+ }
22
+ },
23
+ "output": {
24
+ "type": "object",
25
+ "description": "",
26
+ "properties": {
27
+ "path": {
28
+ "type": "string",
29
+ "description": "Path to be used to export all generated files. Can be an absolute path, or a path relative based of the defined root option."
30
+ },
31
+ "clean": {
32
+ "type": "boolean",
33
+ "description": "Remove previous generated files and folders."
34
+ },
35
+ "write": {
36
+ "type": "boolean",
37
+ "description": "Enabled or disable the writing to the filesystem. This is being used for the playground.",
38
+ "default": "true"
39
+ }
40
+ }
41
+ },
42
+ "hooks": {
43
+ "type": "object",
44
+ "description": "Hooks that can be called when a specific action is done in Kubb. ",
45
+ "properties": {
46
+ "done": {
47
+ "oneOf": [
48
+ {
49
+ "type": "string",
50
+ "description": "Hook that will be called at the end of all executions. Useful for running Prettier or ESLint to use your own linting structure."
51
+ },
52
+ {
53
+ "type": "array",
54
+ "items": {
55
+ "type": "string"
56
+ },
57
+ "description": "Hook that will be called at the end of all executions. Useful for running Prettier or ESLint to use your own linting structure."
58
+ }
59
+ ]
60
+ }
61
+ }
62
+ },
63
+ "plugins": {
64
+ "oneOf": [
65
+ {
66
+ "type": "array",
67
+ "items": {
68
+ "type": "array",
69
+ "prefixItems": [
70
+ {
71
+ "type": "string"
72
+ }
73
+ ],
74
+ "items": {
75
+ "type": "object"
76
+ }
77
+ }
78
+ },
79
+ {
80
+ "type": "object"
81
+ }
82
+ ],
83
+ "description": "Plugins"
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,113 @@
1
+ import path from 'path'
2
+
3
+ import { trimExtName } from './transformers/trim.ts'
4
+ import { TreeNode } from './utils/TreeNode.ts'
5
+
6
+ import type { DirectoryTreeOptions } from 'directory-tree'
7
+ import type { KubbFile } from './FileManager.ts'
8
+ import type { KubbPlugin } from './index.ts'
9
+
10
+ type FileMeta = {
11
+ pluginKey?: KubbPlugin['key']
12
+ treeNode: TreeNode
13
+ }
14
+
15
+ export type BarrelManagerOptions = {
16
+ treeNode?: DirectoryTreeOptions
17
+ isTypeOnly?: boolean
18
+ /**
19
+ * Add .ts or .js
20
+ */
21
+ extName?: KubbFile.Extname
22
+ }
23
+
24
+ export class BarrelManager {
25
+ #options: BarrelManagerOptions
26
+
27
+ constructor(options: BarrelManagerOptions = {}) {
28
+ this.#options = options
29
+
30
+ return this
31
+ }
32
+
33
+ getIndexes(
34
+ pathToBuild: string,
35
+ ): Array<KubbFile.File<FileMeta>> | null {
36
+ const { treeNode = {}, isTypeOnly, extName } = this.#options
37
+ const tree = TreeNode.build(pathToBuild, treeNode)
38
+
39
+ if (!tree) {
40
+ return null
41
+ }
42
+
43
+ const fileReducer = (files: Array<KubbFile.File<FileMeta>>, treeNode: TreeNode) => {
44
+ if (!treeNode.children) {
45
+ return []
46
+ }
47
+
48
+ if (treeNode.children.length > 1) {
49
+ const indexPath: KubbFile.Path = path.resolve(treeNode.data.path, 'index.ts')
50
+
51
+ const exports: KubbFile.Export[] = treeNode.children
52
+ .filter(Boolean)
53
+ .map((file) => {
54
+ const importPath: string = file.data.type === 'directory' ? `./${file.data.name}/index` : `./${trimExtName(file.data.name)}`
55
+
56
+ if (importPath.endsWith('index') && file.data.type === 'file') {
57
+ return undefined
58
+ }
59
+
60
+ return {
61
+ path: extName ? `${importPath}${extName}` : importPath,
62
+ isTypeOnly,
63
+ } as KubbFile.Export
64
+ })
65
+ .filter(Boolean)
66
+
67
+ files.push({
68
+ path: indexPath,
69
+ baseName: 'index.ts',
70
+ source: '',
71
+ exports,
72
+ meta: {
73
+ treeNode,
74
+ },
75
+ })
76
+ } else if (treeNode.children.length === 1) {
77
+ const [treeNodeChild] = treeNode.children as [TreeNode]
78
+
79
+ const indexPath = path.resolve(treeNode.data.path, 'index.ts')
80
+ const importPath = treeNodeChild.data.type === 'directory'
81
+ ? `./${treeNodeChild.data.name}/index`
82
+ : `./${trimExtName(treeNodeChild.data.name)}`
83
+
84
+ const exports = [
85
+ {
86
+ path: extName
87
+ ? `${importPath}${extName}`
88
+ : importPath,
89
+ isTypeOnly,
90
+ },
91
+ ]
92
+
93
+ files.push({
94
+ path: indexPath,
95
+ baseName: 'index.ts',
96
+ source: '',
97
+ exports,
98
+ meta: {
99
+ treeNode,
100
+ },
101
+ })
102
+ }
103
+
104
+ treeNode.children.forEach((childItem) => {
105
+ fileReducer(files, childItem)
106
+ })
107
+
108
+ return files
109
+ }
110
+
111
+ return fileReducer([], tree).reverse()
112
+ }
113
+ }