@kubb/core 3.0.0-alpha.3 → 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/README.md +13 -4
- package/dist/{FileManager-BW--rO8q.d.ts → FileManager-Dnafk2I5.d.ts} +146 -92
- package/dist/{FileManager-Bw-FNS3q.d.cts → FileManager-U5yCmg00.d.cts} +146 -92
- package/dist/chunk-2EU7DMPM.js +96 -0
- package/dist/chunk-2EU7DMPM.js.map +1 -0
- package/dist/{chunk-34BPAXR2.cjs → chunk-2UQARE2O.cjs} +54 -37
- package/dist/chunk-2UQARE2O.cjs.map +1 -0
- package/dist/chunk-4X5FFJPJ.js +8 -13
- package/dist/chunk-4X5FFJPJ.js.map +1 -1
- package/dist/{chunk-3OXCZ5DJ.js → chunk-E6CN2CZC.js} +63 -54
- package/dist/chunk-E6CN2CZC.js.map +1 -0
- package/dist/{chunk-25NKJ3DV.js → chunk-HBQM723K.js} +13 -27
- package/dist/chunk-HBQM723K.js.map +1 -0
- package/dist/{chunk-LM2YQC3T.cjs → chunk-LLKRRIBF.cjs} +81 -51
- package/dist/chunk-LLKRRIBF.cjs.map +1 -0
- package/dist/chunk-MD2LDZ3Z.js +889 -0
- package/dist/chunk-MD2LDZ3Z.js.map +1 -0
- package/dist/chunk-OX2X7B4Z.cjs +101 -0
- package/dist/chunk-OX2X7B4Z.cjs.map +1 -0
- package/dist/{chunk-67C6RBGQ.cjs → chunk-RIW2LFFQ.cjs} +28 -29
- package/dist/chunk-RIW2LFFQ.cjs.map +1 -0
- package/dist/chunk-SX5FHSVT.cjs +1532 -0
- package/dist/chunk-SX5FHSVT.cjs.map +1 -0
- package/dist/chunk-VBGWLAET.cjs +42 -0
- package/dist/chunk-VBGWLAET.cjs.map +1 -0
- package/dist/index.cjs +553 -619
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -22
- package/dist/index.d.ts +7 -22
- package/dist/index.js +444 -525
- package/dist/index.js.map +1 -1
- package/dist/{logger-DChjnJMn.d.cts → logger-DvbHXjIO.d.cts} +29 -19
- package/dist/{logger-DChjnJMn.d.ts → logger-DvbHXjIO.d.ts} +29 -19
- package/dist/logger.cjs +25 -15
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -2
- package/dist/logger.d.ts +1 -2
- package/dist/logger.js +3 -15
- package/dist/logger.js.map +1 -1
- package/dist/mocks.cjs +42 -31
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +7 -9
- package/dist/mocks.d.ts +7 -9
- package/dist/mocks.js +35 -33
- package/dist/mocks.js.map +1 -1
- package/dist/{prompt-6FWP747F.cjs → prompt-2PN2F25D.cjs} +89 -89
- package/dist/prompt-2PN2F25D.cjs.map +1 -0
- package/dist/{prompt-HK3MWREM.js → prompt-WQQUN22Z.js} +9 -15
- package/dist/prompt-WQQUN22Z.js.map +1 -0
- package/dist/transformers.cjs +216 -49
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.d.cts +2 -4
- package/dist/transformers.d.ts +2 -4
- package/dist/transformers.js +149 -35
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +65 -26
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +29 -3
- package/dist/utils.d.ts +29 -3
- package/dist/utils.js +3 -26
- package/dist/utils.js.map +1 -1
- package/package.json +11 -14
- package/src/BarrelManager.ts +95 -109
- package/src/{Generator.ts → BaseGenerator.ts} +1 -1
- package/src/FileManager.ts +199 -304
- package/src/PackageManager.ts +1 -1
- package/src/PluginManager.ts +152 -93
- package/src/PromiseManager.ts +1 -1
- package/src/__snapshots__/barrel.json +73 -0
- package/src/__snapshots__/grouped.json +120 -0
- package/src/__snapshots__/ordered.json +68 -0
- package/src/build.ts +86 -131
- package/src/config.ts +2 -4
- package/src/errors.ts +0 -11
- package/src/index.ts +2 -3
- package/src/logger.ts +76 -34
- package/src/plugin.ts +2 -5
- package/src/transformers/escape.ts +0 -10
- package/src/transformers/index.ts +2 -3
- package/src/transformers/stringify.ts +1 -1
- package/src/transformers/trim.ts +0 -4
- package/src/types.ts +77 -22
- package/src/utils/TreeNode.ts +132 -50
- package/src/utils/executeStrategies.ts +3 -3
- package/src/utils/index.ts +2 -1
- package/src/utils/parser.ts +156 -0
- package/dist/chunk-25NKJ3DV.js.map +0 -1
- package/dist/chunk-34BPAXR2.cjs.map +0 -1
- package/dist/chunk-3OXCZ5DJ.js.map +0 -1
- package/dist/chunk-5JZNFPUP.js +0 -309
- package/dist/chunk-5JZNFPUP.js.map +0 -1
- package/dist/chunk-67C6RBGQ.cjs.map +0 -1
- package/dist/chunk-ADC5UNZ5.cjs +0 -1227
- package/dist/chunk-ADC5UNZ5.cjs.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-JKZG2IJR.js +0 -283
- package/dist/chunk-JKZG2IJR.js.map +0 -1
- package/dist/chunk-LM2YQC3T.cjs.map +0 -1
- package/dist/chunk-PZT4CTBV.cjs +0 -299
- package/dist/chunk-PZT4CTBV.cjs.map +0 -1
- package/dist/chunk-SA2GZKXS.js +0 -596
- package/dist/chunk-SA2GZKXS.js.map +0 -1
- package/dist/chunk-XCPFG6DO.cjs +0 -66
- package/dist/chunk-XCPFG6DO.cjs.map +0 -1
- package/dist/chunk-YTSNYMHW.cjs +0 -320
- package/dist/chunk-YTSNYMHW.cjs.map +0 -1
- package/dist/prompt-6FWP747F.cjs.map +0 -1
- package/dist/prompt-HK3MWREM.js.map +0 -1
- package/schema.json +0 -86
- package/src/utils/cache.ts +0 -35
- package/src/utils/getParser.ts +0 -17
package/dist/utils.cjs
CHANGED
|
@@ -1,27 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkSX5FHSVT_cjs = require('./chunk-SX5FHSVT.cjs');
|
|
4
|
+
require('./chunk-RIW2LFFQ.cjs');
|
|
5
|
+
require('./chunk-VBGWLAET.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "FunctionParams", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return chunkSX5FHSVT_cjs.FunctionParams; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "URLPath", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunkSX5FHSVT_cjs.URLPath; }
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "createFile", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return chunkSX5FHSVT_cjs.createFile; }
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "createFileExport", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return chunkSX5FHSVT_cjs.createFileExport; }
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "createFileImport", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return chunkSX5FHSVT_cjs.createFileImport; }
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, "createFileParser", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return chunkSX5FHSVT_cjs.createFileParser; }
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "getFileParser", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () { return chunkSX5FHSVT_cjs.getFileParser; }
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "getUniqueName", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () { return chunkSX5FHSVT_cjs.getUniqueName; }
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, "isPromise", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () { return chunkSX5FHSVT_cjs.isPromise; }
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "isPromiseFulfilledResult", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () { return chunkSX5FHSVT_cjs.isPromiseFulfilledResult; }
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "isPromiseRejectedResult", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () { return chunkSX5FHSVT_cjs.isPromiseRejectedResult; }
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(exports, "renderTemplate", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function () { return chunkSX5FHSVT_cjs.renderTemplate; }
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "setUniqueName", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () { return chunkSX5FHSVT_cjs.setUniqueName; }
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "timeout", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () { return chunkSX5FHSVT_cjs.timeout; }
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=utils.cjs.map
|
|
27
66
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"utils.cjs"}
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { PossiblePromise } from '@kubb/types';
|
|
2
|
-
import * as
|
|
2
|
+
import * as KubbFile from '@kubb/fs/types';
|
|
3
|
+
import { L as Logger } from './logger-DvbHXjIO.cjs';
|
|
4
|
+
import 'consola';
|
|
3
5
|
|
|
4
6
|
type FunctionParamsASTWithoutType = {
|
|
5
7
|
name?: string;
|
|
@@ -101,6 +103,30 @@ declare class URLPath {
|
|
|
101
103
|
toURLPath(): string;
|
|
102
104
|
}
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Helper to create a file with name and id set
|
|
108
|
+
*/
|
|
109
|
+
declare function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta>;
|
|
110
|
+
/**
|
|
111
|
+
* Helper to create a fileImport with extname set
|
|
112
|
+
*/
|
|
113
|
+
declare function createFileImport(imp: KubbFile.Import): KubbFile.ResolvedImport;
|
|
114
|
+
/**
|
|
115
|
+
* Helper to create a fileExport with extname set
|
|
116
|
+
*/
|
|
117
|
+
declare function createFileExport(exp: KubbFile.Export): KubbFile.ResolvedExport;
|
|
118
|
+
type ParserModule<TMeta extends object = object> = {
|
|
119
|
+
format: (source: string) => Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
* Convert a file to string
|
|
122
|
+
*/
|
|
123
|
+
print: (file: KubbFile.ResolvedFile<TMeta>, options: PrintOptions) => Promise<string>;
|
|
124
|
+
};
|
|
125
|
+
declare function createFileParser<TMeta extends object = object>(parser: ParserModule<TMeta>): ParserModule<TMeta>;
|
|
126
|
+
type PrintOptions = {
|
|
127
|
+
extname?: KubbFile.Extname;
|
|
128
|
+
logger?: Logger;
|
|
129
|
+
};
|
|
130
|
+
declare function getFileParser<TMeta extends object = object>(extname: KubbFile.Extname | undefined): Promise<ParserModule<TMeta>>;
|
|
105
131
|
|
|
106
|
-
export { FunctionParams, type FunctionParamsAST, type URLObject, URLPath,
|
|
132
|
+
export { FunctionParams, type FunctionParamsAST, type ParserModule, type URLObject, URLPath, createFile, createFileExport, createFileImport, createFileParser, getFileParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { PossiblePromise } from '@kubb/types';
|
|
2
|
-
import * as
|
|
2
|
+
import * as KubbFile from '@kubb/fs/types';
|
|
3
|
+
import { L as Logger } from './logger-DvbHXjIO.js';
|
|
4
|
+
import 'consola';
|
|
3
5
|
|
|
4
6
|
type FunctionParamsASTWithoutType = {
|
|
5
7
|
name?: string;
|
|
@@ -101,6 +103,30 @@ declare class URLPath {
|
|
|
101
103
|
toURLPath(): string;
|
|
102
104
|
}
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Helper to create a file with name and id set
|
|
108
|
+
*/
|
|
109
|
+
declare function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta>;
|
|
110
|
+
/**
|
|
111
|
+
* Helper to create a fileImport with extname set
|
|
112
|
+
*/
|
|
113
|
+
declare function createFileImport(imp: KubbFile.Import): KubbFile.ResolvedImport;
|
|
114
|
+
/**
|
|
115
|
+
* Helper to create a fileExport with extname set
|
|
116
|
+
*/
|
|
117
|
+
declare function createFileExport(exp: KubbFile.Export): KubbFile.ResolvedExport;
|
|
118
|
+
type ParserModule<TMeta extends object = object> = {
|
|
119
|
+
format: (source: string) => Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
* Convert a file to string
|
|
122
|
+
*/
|
|
123
|
+
print: (file: KubbFile.ResolvedFile<TMeta>, options: PrintOptions) => Promise<string>;
|
|
124
|
+
};
|
|
125
|
+
declare function createFileParser<TMeta extends object = object>(parser: ParserModule<TMeta>): ParserModule<TMeta>;
|
|
126
|
+
type PrintOptions = {
|
|
127
|
+
extname?: KubbFile.Extname;
|
|
128
|
+
logger?: Logger;
|
|
129
|
+
};
|
|
130
|
+
declare function getFileParser<TMeta extends object = object>(extname: KubbFile.Extname | undefined): Promise<ParserModule<TMeta>>;
|
|
105
131
|
|
|
106
|
-
export { FunctionParams, type FunctionParamsAST, type URLObject, URLPath,
|
|
132
|
+
export { FunctionParams, type FunctionParamsAST, type ParserModule, type URLObject, URLPath, createFile, createFileExport, createFileImport, createFileParser, getFileParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
|
package/dist/utils.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
getParser,
|
|
5
|
-
getUniqueName,
|
|
6
|
-
isPromise,
|
|
7
|
-
isPromiseFulfilledResult,
|
|
8
|
-
isPromiseRejectedResult,
|
|
9
|
-
renderTemplate,
|
|
10
|
-
setUniqueName,
|
|
11
|
-
timeout
|
|
12
|
-
} from "./chunk-5JZNFPUP.js";
|
|
13
|
-
import "./chunk-4X5FFJPJ.js";
|
|
14
|
-
import "./chunk-HMLY7DHA.js";
|
|
15
|
-
export {
|
|
16
|
-
FunctionParams,
|
|
17
|
-
URLPath,
|
|
18
|
-
getParser,
|
|
19
|
-
getUniqueName,
|
|
20
|
-
isPromise,
|
|
21
|
-
isPromiseFulfilledResult,
|
|
22
|
-
isPromiseRejectedResult,
|
|
23
|
-
renderTemplate,
|
|
24
|
-
setUniqueName,
|
|
25
|
-
timeout
|
|
26
|
-
};
|
|
1
|
+
export { FunctionParams, URLPath, createFile, createFileExport, createFileImport, createFileParser, getFileParser, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout } from './chunk-MD2LDZ3Z.js';
|
|
2
|
+
import './chunk-4X5FFJPJ.js';
|
|
3
|
+
//# sourceMappingURL=utils.js.map
|
|
27
4
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"utils.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.31",
|
|
4
4
|
"description": "Generator core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -76,31 +76,28 @@
|
|
|
76
76
|
],
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"change-case": "^5.4.4",
|
|
79
|
-
"directory-tree": "^3.5.2",
|
|
80
79
|
"find-up": "^7.0.0",
|
|
81
80
|
"natural-orderby": "^3.0.2",
|
|
81
|
+
"object-hash": "^3.0.0",
|
|
82
82
|
"p-queue": "^8.0.1",
|
|
83
|
-
"remeda": "^2.
|
|
83
|
+
"remeda": "^2.14.0",
|
|
84
84
|
"seedrandom": "^3.0.5",
|
|
85
85
|
"semver": "^7.6.3",
|
|
86
|
-
"
|
|
87
|
-
"@kubb/
|
|
88
|
-
"@kubb/
|
|
89
|
-
"@kubb/types": "3.0.0-alpha.3"
|
|
86
|
+
"@kubb/fs": "3.0.0-alpha.31",
|
|
87
|
+
"@kubb/parser-ts": "3.0.0-alpha.31",
|
|
88
|
+
"@kubb/types": "3.0.0-alpha.31"
|
|
90
89
|
},
|
|
91
90
|
"devDependencies": {
|
|
92
|
-
"@types/
|
|
91
|
+
"@types/object-hash": "^3.0.6",
|
|
93
92
|
"@types/seedrandom": "^3.0.8",
|
|
94
93
|
"@types/semver": "^7.5.8",
|
|
95
94
|
"consola": "^3.2.3",
|
|
96
|
-
"ora": "^8.0.1",
|
|
97
95
|
"prettier": "^3.3.3",
|
|
98
96
|
"tinyrainbow": "^1.2.0",
|
|
99
|
-
"tsup": "^8.
|
|
100
|
-
"typescript": "^5.
|
|
101
|
-
"@kubb/config-
|
|
102
|
-
"@kubb/config-
|
|
103
|
-
"@kubb/config-tsup": "3.0.0-alpha.3"
|
|
97
|
+
"tsup": "^8.3.0",
|
|
98
|
+
"typescript": "^5.6.2",
|
|
99
|
+
"@kubb/config-ts": "3.0.0-alpha.31",
|
|
100
|
+
"@kubb/config-tsup": "3.0.0-alpha.31"
|
|
104
101
|
},
|
|
105
102
|
"engines": {
|
|
106
103
|
"node": ">=20"
|
package/src/BarrelManager.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
-
import path from 'node:path'
|
|
4
|
-
|
|
5
|
-
import { trimExtName } from './transformers/trim.ts'
|
|
6
3
|
import { TreeNode } from './utils/TreeNode.ts'
|
|
7
4
|
|
|
5
|
+
import { getRelativePath } from '@kubb/fs'
|
|
8
6
|
import type * as KubbFile from '@kubb/fs/types'
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Add .ts or .js
|
|
16
|
-
*/
|
|
17
|
-
extName?: KubbFile.Extname
|
|
7
|
+
import type { FileMetaBase } from './FileManager.ts'
|
|
8
|
+
import type { Logger } from './logger.ts'
|
|
9
|
+
|
|
10
|
+
type BarrelManagerOptions = {
|
|
11
|
+
logger?: Logger
|
|
18
12
|
}
|
|
19
13
|
|
|
20
14
|
export class BarrelManager {
|
|
@@ -26,116 +20,108 @@ export class BarrelManager {
|
|
|
26
20
|
return this
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
if (!exportedNames) {
|
|
33
|
-
return [item]
|
|
34
|
-
}
|
|
23
|
+
getFiles({ files: generatedFiles, root, meta }: { files: KubbFile.File[]; root?: string; meta?: FileMetaBase | undefined }): Array<KubbFile.File> {
|
|
24
|
+
const { logger } = this.#options
|
|
35
25
|
|
|
36
|
-
|
|
37
|
-
(prev, curr) => {
|
|
38
|
-
if (!prev[0]?.name || !prev[1]?.name) {
|
|
39
|
-
return prev
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (curr.isTypeOnly) {
|
|
43
|
-
prev[1] = { ...prev[1], name: [...prev[1].name, curr.name] }
|
|
44
|
-
} else {
|
|
45
|
-
prev[0] = { ...prev[0], name: [...prev[0].name, curr.name] }
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return prev
|
|
49
|
-
},
|
|
50
|
-
[
|
|
51
|
-
{
|
|
52
|
-
...item,
|
|
53
|
-
name: [],
|
|
54
|
-
isTypeOnly: false,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
...item,
|
|
58
|
-
name: [],
|
|
59
|
-
isTypeOnly: true,
|
|
60
|
-
},
|
|
61
|
-
] as KubbFile.Export[],
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getNamedExports(root: string, exports: KubbFile.Export[]): KubbFile.Export[] {
|
|
66
|
-
return exports?.flatMap((item) => {
|
|
67
|
-
return this.getNamedExport(root, item)
|
|
68
|
-
})
|
|
69
|
-
}
|
|
26
|
+
const cachedFiles = new Map<KubbFile.Path, KubbFile.File>()
|
|
70
27
|
|
|
71
|
-
|
|
72
|
-
const { treeNode = {}, isTypeOnly, extName } = this.#options
|
|
73
|
-
const tree = TreeNode.build(root, treeNode)
|
|
28
|
+
logger?.emit('debug', { date: new Date(), logs: [`Start barrel generation for pluginKey ${meta?.pluginKey?.join('.')} and root '${root}'`] })
|
|
74
29
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
30
|
+
TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
|
|
31
|
+
if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
78
34
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
35
|
+
const barrelFile: KubbFile.File = {
|
|
36
|
+
path: join(treeNode.parent?.data.path, 'index.ts') as KubbFile.Path,
|
|
37
|
+
baseName: 'index.ts',
|
|
38
|
+
exports: [],
|
|
39
|
+
sources: [],
|
|
82
40
|
}
|
|
41
|
+
const previousBarrelFile = cachedFiles.get(barrelFile.path)
|
|
42
|
+
const leaves = treeNode.leaves
|
|
83
43
|
|
|
84
|
-
|
|
85
|
-
|
|
44
|
+
leaves.forEach((item) => {
|
|
45
|
+
if (!item.data.name) {
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
86
48
|
|
|
87
|
-
const
|
|
88
|
-
.filter(Boolean)
|
|
89
|
-
.map((file) => {
|
|
90
|
-
const importPath: string = file.data.type === 'split' ? `./${file.data.name}/index` : `./${trimExtName(file.data.name)}`
|
|
49
|
+
const sources = item.data.file?.sources || []
|
|
91
50
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
51
|
+
if (!sources.some((source) => source.isIndexable)) {
|
|
52
|
+
logger?.emit(
|
|
53
|
+
'warning',
|
|
54
|
+
`No isIndexable source found(source should have a name and isIndexable):\nFile: ${JSON.stringify(item.data.file, undefined, 2)}`,
|
|
55
|
+
)
|
|
56
|
+
}
|
|
95
57
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
58
|
+
sources.forEach((source) => {
|
|
59
|
+
if (!item.data.file?.path || !source.isIndexable || !source.name) {
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some((item) => item.name === source.name)
|
|
63
|
+
|
|
64
|
+
if (alreadyContainInPreviousBarrelFile) {
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!barrelFile.exports) {
|
|
69
|
+
barrelFile.exports = []
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// true when we have a subdirectory that also contains barrel files
|
|
73
|
+
const isSubExport = !!treeNode.parent?.data.path?.split?.('/')?.length
|
|
74
|
+
|
|
75
|
+
if (isSubExport) {
|
|
76
|
+
barrelFile.exports.push({
|
|
77
|
+
name: [source.name],
|
|
78
|
+
path: getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
79
|
+
isTypeOnly: source.isTypeOnly,
|
|
80
|
+
})
|
|
81
|
+
} else {
|
|
82
|
+
barrelFile.exports.push({
|
|
83
|
+
name: [source.name],
|
|
84
|
+
path: `./${item.data.file.baseName}`,
|
|
85
|
+
isTypeOnly: source.isTypeOnly,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
barrelFile.sources.push({
|
|
90
|
+
name: source.name,
|
|
91
|
+
isTypeOnly: source.isTypeOnly,
|
|
92
|
+
//TODO use parser to generate import
|
|
93
|
+
value: '',
|
|
94
|
+
isExportable: false,
|
|
95
|
+
isIndexable: false,
|
|
100
96
|
})
|
|
101
|
-
.filter(Boolean)
|
|
102
|
-
|
|
103
|
-
files.push({
|
|
104
|
-
path: indexPath,
|
|
105
|
-
baseName: 'index.ts',
|
|
106
|
-
source: '',
|
|
107
|
-
exports,
|
|
108
|
-
exportable: true,
|
|
109
97
|
})
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
path: extName ? `${importPath}${extName}` : importPath,
|
|
119
|
-
isTypeOnly,
|
|
120
|
-
},
|
|
121
|
-
]
|
|
122
|
-
|
|
123
|
-
files.push({
|
|
124
|
-
path: indexPath,
|
|
125
|
-
baseName: 'index.ts',
|
|
126
|
-
source: '',
|
|
127
|
-
exports,
|
|
128
|
-
exportable: true,
|
|
129
|
-
})
|
|
130
|
-
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
logger?.emit('debug', {
|
|
101
|
+
date: new Date(),
|
|
102
|
+
logs: [
|
|
103
|
+
`Generating barrelFile '${getRelativePath(root, barrelFile.path)}' for '${getRelativePath(root, treeNode.data?.path)}' with ${barrelFile.sources.length} indexable exports: '${barrelFile.sources?.map((source) => source.name).join(', ')}'`,
|
|
104
|
+
],
|
|
105
|
+
})
|
|
131
106
|
|
|
132
|
-
|
|
133
|
-
|
|
107
|
+
logger?.emit('debug', {
|
|
108
|
+
date: new Date(),
|
|
109
|
+
logs: [
|
|
110
|
+
`Generated barrelFile '${getRelativePath(root, barrelFile.path)}' for '${getRelativePath(root, treeNode.data?.path)}' with exports: '${cachedFiles
|
|
111
|
+
.get(barrelFile.path)
|
|
112
|
+
?.sources?.map((source) => source.name)
|
|
113
|
+
.join(', ')}'`,
|
|
114
|
+
],
|
|
134
115
|
})
|
|
135
116
|
|
|
136
|
-
|
|
137
|
-
|
|
117
|
+
if (previousBarrelFile) {
|
|
118
|
+
previousBarrelFile.sources.push(...barrelFile.sources)
|
|
119
|
+
previousBarrelFile.exports?.push(...(barrelFile.exports || []))
|
|
120
|
+
} else {
|
|
121
|
+
cachedFiles.set(barrelFile.path, barrelFile)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
138
124
|
|
|
139
|
-
return
|
|
125
|
+
return [...cachedFiles.values()]
|
|
140
126
|
}
|
|
141
127
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
3
3
|
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
4
4
|
*/
|
|
5
|
-
export abstract class
|
|
5
|
+
export abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
|
|
6
6
|
#options: TOptions = {} as TOptions
|
|
7
7
|
#context: TContext = {} as TContext
|
|
8
8
|
|