@kubb/core 3.0.0-alpha.0 → 3.0.0-alpha.10
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/FileManager-BbUCeEyv.d.cts +469 -0
- package/dist/FileManager-CpuFz6eH.d.ts +469 -0
- package/dist/chunk-2EU7DMPM.js +97 -0
- package/dist/chunk-2EU7DMPM.js.map +1 -0
- package/dist/chunk-5E2I6KH4.cjs +1071 -0
- package/dist/chunk-5E2I6KH4.cjs.map +1 -0
- package/dist/{chunk-XRC6KXC3.cjs → chunk-A6PCLWEY.cjs} +5 -5
- package/dist/{chunk-XRC6KXC3.cjs.map → chunk-A6PCLWEY.cjs.map} +1 -1
- package/dist/chunk-DID47EQD.cjs +102 -0
- package/dist/chunk-DID47EQD.cjs.map +1 -0
- package/dist/chunk-HBQM723K.js +1063 -0
- package/dist/chunk-HBQM723K.js.map +1 -0
- package/dist/chunk-L6YLVCKM.js +929 -0
- package/dist/chunk-L6YLVCKM.js.map +1 -0
- package/dist/{chunk-XRUOSVKX.cjs → chunk-M7NLNCSM.cjs} +71 -38
- package/dist/chunk-M7NLNCSM.cjs.map +1 -0
- package/dist/{chunk-3OXCZ5DJ.js → chunk-MU3CBCQT.js} +59 -35
- package/dist/chunk-MU3CBCQT.js.map +1 -0
- package/dist/chunk-NB4JMN75.cjs +1548 -0
- package/dist/chunk-NB4JMN75.cjs.map +1 -0
- package/dist/chunk-SEH6NUCX.cjs +42 -0
- package/dist/chunk-SEH6NUCX.cjs.map +1 -0
- package/dist/index.cjs +496 -552
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -477
- package/dist/index.d.ts +9 -477
- package/dist/index.js +438 -492
- 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 +4 -5
- 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 +2 -4
- package/dist/mocks.cjs +25 -19
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +6 -9
- package/dist/mocks.d.ts +6 -9
- package/dist/mocks.js +21 -16
- package/dist/mocks.js.map +1 -1
- package/dist/prompt-DVQN7JTN.cjs +760 -0
- package/dist/prompt-DVQN7JTN.cjs.map +1 -0
- package/dist/prompt-WQQUN22Z.js +754 -0
- package/dist/prompt-WQQUN22Z.js.map +1 -0
- package/dist/transformers.cjs +198 -42
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.d.cts +1 -3
- package/dist/transformers.d.ts +1 -3
- package/dist/transformers.js +155 -14
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +12 -4
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +31 -3
- package/dist/utils.d.ts +31 -3
- package/dist/utils.js +11 -4
- package/package.json +11 -14
- package/src/BarrelManager.ts +93 -107
- package/src/{Generator.ts → BaseGenerator.ts} +1 -1
- package/src/FileManager.ts +198 -297
- package/src/PackageManager.ts +1 -1
- package/src/PluginManager.ts +152 -101
- package/src/__snapshots__/barrel.json +91 -0
- package/src/__snapshots__/grouped.json +114 -0
- package/src/__snapshots__/ordered.json +62 -0
- package/src/build.ts +86 -171
- package/src/errors.ts +0 -11
- package/src/index.ts +1 -5
- package/src/logger.ts +76 -34
- package/src/plugin.ts +3 -3
- package/src/transformers/index.ts +2 -3
- package/src/transformers/trim.ts +0 -4
- package/src/types.ts +35 -40
- package/src/utils/TreeNode.ts +132 -50
- package/src/utils/executeStrategies.ts +1 -1
- package/src/utils/index.ts +2 -1
- package/src/utils/parser.ts +157 -0
- 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-DKW7IBJV.cjs +0 -299
- package/dist/chunk-DKW7IBJV.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-LKXUCYWU.cjs +0 -66
- package/dist/chunk-LKXUCYWU.cjs.map +0 -1
- package/dist/chunk-OPOT6TCT.cjs +0 -320
- package/dist/chunk-OPOT6TCT.cjs.map +0 -1
- package/dist/chunk-SA2GZKXS.js +0 -596
- package/dist/chunk-SA2GZKXS.js.map +0 -1
- package/dist/chunk-XRUOSVKX.cjs.map +0 -1
- package/dist/chunk-Y3LLJA4H.cjs +0 -1227
- package/dist/chunk-Y3LLJA4H.cjs.map +0 -1
- package/globals.d.ts +0 -49
- package/schema.json +0 -86
- package/src/kubb.ts +0 -11
- package/src/utils/getParser.ts +0 -17
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"path": "src/index.ts",
|
|
4
|
+
"baseName": "index.ts",
|
|
5
|
+
"exports": [
|
|
6
|
+
{
|
|
7
|
+
"name": [
|
|
8
|
+
"hello"
|
|
9
|
+
],
|
|
10
|
+
"path": "./sub/hello.ts",
|
|
11
|
+
"extName": ".ts"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": [
|
|
15
|
+
"world"
|
|
16
|
+
],
|
|
17
|
+
"path": "./sub/world.ts",
|
|
18
|
+
"extName": ".ts"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": [
|
|
22
|
+
"test"
|
|
23
|
+
],
|
|
24
|
+
"path": "./test.ts",
|
|
25
|
+
"extName": ".ts"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"sources": [
|
|
29
|
+
{
|
|
30
|
+
"name": "test",
|
|
31
|
+
"value": "",
|
|
32
|
+
"isExportable": false,
|
|
33
|
+
"isIndexable": false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "hello",
|
|
37
|
+
"value": "",
|
|
38
|
+
"isExportable": false,
|
|
39
|
+
"isIndexable": false
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "world",
|
|
43
|
+
"value": "",
|
|
44
|
+
"isExportable": false,
|
|
45
|
+
"isIndexable": false
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"id": "feabc02536bd6630458e734990f7e2a21a55c469",
|
|
49
|
+
"name": "index",
|
|
50
|
+
"extName": ".ts",
|
|
51
|
+
"imports": []
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "src/sub/index.ts",
|
|
55
|
+
"baseName": "index.ts",
|
|
56
|
+
"exports": [
|
|
57
|
+
{
|
|
58
|
+
"name": [
|
|
59
|
+
"hello"
|
|
60
|
+
],
|
|
61
|
+
"path": "./hello.ts",
|
|
62
|
+
"extName": ".ts"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": [
|
|
66
|
+
"world"
|
|
67
|
+
],
|
|
68
|
+
"path": "./world.ts",
|
|
69
|
+
"extName": ".ts"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"sources": [
|
|
73
|
+
{
|
|
74
|
+
"name": "hello",
|
|
75
|
+
"value": "",
|
|
76
|
+
"isExportable": false,
|
|
77
|
+
"isIndexable": false
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "world",
|
|
81
|
+
"value": "",
|
|
82
|
+
"isExportable": false,
|
|
83
|
+
"isIndexable": false
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"id": "c67967bd2363dd9637437671f6fe1ed146debdbf",
|
|
87
|
+
"name": "index",
|
|
88
|
+
"extName": ".ts",
|
|
89
|
+
"imports": []
|
|
90
|
+
}
|
|
91
|
+
]
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "",
|
|
3
|
+
"path": "",
|
|
4
|
+
"children": [
|
|
5
|
+
{
|
|
6
|
+
"name": "src",
|
|
7
|
+
"path": "src",
|
|
8
|
+
"children": [
|
|
9
|
+
{
|
|
10
|
+
"name": "axios",
|
|
11
|
+
"path": "src/axios",
|
|
12
|
+
"children": [
|
|
13
|
+
{
|
|
14
|
+
"name": "file2.ts",
|
|
15
|
+
"file": {
|
|
16
|
+
"path": "src/axios/file2.ts",
|
|
17
|
+
"baseName": "file2.ts",
|
|
18
|
+
"sources": [],
|
|
19
|
+
"id": "6af477de6b602aafbb2e1ce0011b1f411a7ab3a5",
|
|
20
|
+
"name": "file2",
|
|
21
|
+
"extName": ".ts",
|
|
22
|
+
"imports": [],
|
|
23
|
+
"exports": []
|
|
24
|
+
},
|
|
25
|
+
"path": "src/axios/file2.ts"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "file1.ts",
|
|
29
|
+
"file": {
|
|
30
|
+
"path": "src/axios/file1.ts",
|
|
31
|
+
"baseName": "file2.ts",
|
|
32
|
+
"sources": [],
|
|
33
|
+
"id": "a9679944d24c174b2f2fd5b1f19c9861f1d35d0e",
|
|
34
|
+
"name": "file2",
|
|
35
|
+
"extName": ".ts",
|
|
36
|
+
"imports": [],
|
|
37
|
+
"exports": []
|
|
38
|
+
},
|
|
39
|
+
"path": "src/axios/file1.ts"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "controller",
|
|
43
|
+
"path": "src/axios/controller",
|
|
44
|
+
"children": [
|
|
45
|
+
{
|
|
46
|
+
"name": "pet.ts",
|
|
47
|
+
"file": {
|
|
48
|
+
"path": "src/axios/controller/pet.ts",
|
|
49
|
+
"baseName": "pet.ts",
|
|
50
|
+
"sources": [],
|
|
51
|
+
"id": "8beaaf5e1b1a6b89a11589c2e3dc5fd7f5eb5e8c",
|
|
52
|
+
"name": "pet",
|
|
53
|
+
"extName": ".ts",
|
|
54
|
+
"imports": [],
|
|
55
|
+
"exports": []
|
|
56
|
+
},
|
|
57
|
+
"path": "src/axios/controller/pet.ts"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "index.ts",
|
|
63
|
+
"file": {
|
|
64
|
+
"path": "src/axios/index.ts",
|
|
65
|
+
"baseName": "index.ts",
|
|
66
|
+
"sources": [],
|
|
67
|
+
"id": "b077038b83c1ef4050649be406937a73c1f41ad3",
|
|
68
|
+
"name": "index",
|
|
69
|
+
"extName": ".ts",
|
|
70
|
+
"imports": [],
|
|
71
|
+
"exports": []
|
|
72
|
+
},
|
|
73
|
+
"path": "src/axios/index.ts"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": "controller",
|
|
79
|
+
"path": "src/controller",
|
|
80
|
+
"children": [
|
|
81
|
+
{
|
|
82
|
+
"name": "test.ts",
|
|
83
|
+
"file": {
|
|
84
|
+
"path": "src/controller/test.ts",
|
|
85
|
+
"baseName": "test.ts",
|
|
86
|
+
"sources": [],
|
|
87
|
+
"id": "a2d277093a81a74c56c0d094071195302d6bb484",
|
|
88
|
+
"name": "test",
|
|
89
|
+
"extName": ".ts",
|
|
90
|
+
"imports": [],
|
|
91
|
+
"exports": []
|
|
92
|
+
},
|
|
93
|
+
"path": "src/controller/test.ts"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"name": "test.ts",
|
|
99
|
+
"file": {
|
|
100
|
+
"path": "src/test.ts",
|
|
101
|
+
"baseName": "test.ts",
|
|
102
|
+
"sources": [],
|
|
103
|
+
"id": "f8e2d98f76d6e33f21aa686d674544b5c7d6fa3e",
|
|
104
|
+
"name": "test",
|
|
105
|
+
"extName": ".ts",
|
|
106
|
+
"imports": [],
|
|
107
|
+
"exports": []
|
|
108
|
+
},
|
|
109
|
+
"path": "src/test.ts"
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"path": "src/test.ts",
|
|
4
|
+
"baseName": "test.ts",
|
|
5
|
+
"sources": [],
|
|
6
|
+
"id": "f8e2d98f76d6e33f21aa686d674544b5c7d6fa3e",
|
|
7
|
+
"name": "test",
|
|
8
|
+
"extName": ".ts",
|
|
9
|
+
"imports": [],
|
|
10
|
+
"exports": []
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"path": "src/axios/file2.ts",
|
|
14
|
+
"baseName": "file2.ts",
|
|
15
|
+
"sources": [],
|
|
16
|
+
"id": "6af477de6b602aafbb2e1ce0011b1f411a7ab3a5",
|
|
17
|
+
"name": "file2",
|
|
18
|
+
"extName": ".ts",
|
|
19
|
+
"imports": [],
|
|
20
|
+
"exports": []
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "src/axios/file1.ts",
|
|
24
|
+
"baseName": "file2.ts",
|
|
25
|
+
"sources": [],
|
|
26
|
+
"id": "a9679944d24c174b2f2fd5b1f19c9861f1d35d0e",
|
|
27
|
+
"name": "file2",
|
|
28
|
+
"extName": ".ts",
|
|
29
|
+
"imports": [],
|
|
30
|
+
"exports": []
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "src/axios/index.ts",
|
|
34
|
+
"baseName": "index.ts",
|
|
35
|
+
"sources": [],
|
|
36
|
+
"id": "b077038b83c1ef4050649be406937a73c1f41ad3",
|
|
37
|
+
"name": "index",
|
|
38
|
+
"extName": ".ts",
|
|
39
|
+
"imports": [],
|
|
40
|
+
"exports": []
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"path": "src/controller/test.ts",
|
|
44
|
+
"baseName": "test.ts",
|
|
45
|
+
"sources": [],
|
|
46
|
+
"id": "a2d277093a81a74c56c0d094071195302d6bb484",
|
|
47
|
+
"name": "test",
|
|
48
|
+
"extName": ".ts",
|
|
49
|
+
"imports": [],
|
|
50
|
+
"exports": []
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"path": "src/axios/controller/pet.ts",
|
|
54
|
+
"baseName": "pet.ts",
|
|
55
|
+
"sources": [],
|
|
56
|
+
"id": "8beaaf5e1b1a6b89a11589c2e3dc5fd7f5eb5e8c",
|
|
57
|
+
"name": "pet",
|
|
58
|
+
"extName": ".ts",
|
|
59
|
+
"imports": [],
|
|
60
|
+
"exports": []
|
|
61
|
+
}
|
|
62
|
+
]
|
package/src/build.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import c from 'tinyrainbow'
|
|
2
|
-
|
|
3
1
|
import { clean, read } from '@kubb/fs'
|
|
4
|
-
import
|
|
2
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
3
|
+
import { FileManager, processFiles } from './FileManager.ts'
|
|
5
4
|
import { PluginManager } from './PluginManager.ts'
|
|
6
|
-
import { isPromise } from './PromiseManager.ts'
|
|
7
5
|
import { isInputPath } from './config.ts'
|
|
8
|
-
import {
|
|
6
|
+
import { createLogger } from './logger.ts'
|
|
9
7
|
import { URLPath } from './utils/URLPath.ts'
|
|
10
8
|
|
|
9
|
+
import { join, resolve } from 'node:path'
|
|
10
|
+
import { getRelativePath } from '@kubb/fs'
|
|
11
11
|
import type { Logger } from './logger.ts'
|
|
12
|
-
import type {
|
|
12
|
+
import type { PluginContext } from './types.ts'
|
|
13
13
|
|
|
14
14
|
type BuildOptions = {
|
|
15
15
|
config: PluginContext['config']
|
|
@@ -28,18 +28,8 @@ type BuildOutput = {
|
|
|
28
28
|
error?: Error
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
async function transformReducer(
|
|
32
|
-
this: PluginContext,
|
|
33
|
-
_previousCode: string,
|
|
34
|
-
result: TransformResult | Promise<TransformResult>,
|
|
35
|
-
_plugin: Plugin,
|
|
36
|
-
): Promise<string | null> {
|
|
37
|
-
return result
|
|
38
|
-
}
|
|
39
|
-
|
|
40
31
|
async function setup(options: BuildOptions): Promise<PluginManager> {
|
|
41
|
-
const { config, logger = createLogger(
|
|
42
|
-
let count = 0
|
|
32
|
+
const { config, logger = createLogger() } = options
|
|
43
33
|
|
|
44
34
|
try {
|
|
45
35
|
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
@@ -47,196 +37,121 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
|
|
|
47
37
|
}
|
|
48
38
|
} catch (e) {
|
|
49
39
|
if (isInputPath(config)) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
cause: e,
|
|
54
|
-
},
|
|
55
|
-
)
|
|
40
|
+
throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${config.input.path}`, {
|
|
41
|
+
cause: e,
|
|
42
|
+
})
|
|
56
43
|
}
|
|
57
44
|
}
|
|
58
45
|
|
|
59
46
|
if (config.output.clean) {
|
|
60
47
|
await clean(config.output.path)
|
|
48
|
+
await clean(join(config.root, '.kubb'))
|
|
61
49
|
}
|
|
62
50
|
|
|
63
|
-
|
|
64
|
-
const { path } = file
|
|
65
|
-
|
|
66
|
-
let source: string | null = await FileManager.getSource(file)
|
|
67
|
-
|
|
68
|
-
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
69
|
-
hookName: 'load',
|
|
70
|
-
parameters: [path],
|
|
71
|
-
})
|
|
72
|
-
if (loadedResult && isPromise(loadedResult)) {
|
|
73
|
-
source = await loadedResult
|
|
74
|
-
}
|
|
75
|
-
if (loadedResult && !isPromise(loadedResult)) {
|
|
76
|
-
source = loadedResult
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (source) {
|
|
80
|
-
source = await pluginManager.hookReduceArg0({
|
|
81
|
-
hookName: 'transform',
|
|
82
|
-
parameters: [path, source],
|
|
83
|
-
reduce: transformReducer,
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
if (config.output.write || config.output.write === undefined) {
|
|
87
|
-
if (file.meta?.pluginKey) {
|
|
88
|
-
// run only for pluginKey defined in the meta of the file
|
|
89
|
-
await pluginManager.hookForPlugin({
|
|
90
|
-
pluginKey: file.meta?.pluginKey,
|
|
91
|
-
hookName: 'writeFile',
|
|
92
|
-
parameters: [path, source],
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
await pluginManager.hookFirst({
|
|
97
|
-
hookName: 'writeFile',
|
|
98
|
-
parameters: [path, source],
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
...file,
|
|
105
|
-
source: source || '',
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const pluginManager = new PluginManager(config, { logger, task })
|
|
110
|
-
|
|
111
|
-
pluginManager.on('execute', (executer) => {
|
|
112
|
-
const { hookName, parameters, plugin } = executer
|
|
113
|
-
|
|
114
|
-
if (hookName === 'writeFile') {
|
|
115
|
-
const [code] = parameters as PluginParameter<'writeFile'>
|
|
116
|
-
|
|
117
|
-
logger.emit('debug', [`PluginKey ${c.dim(JSON.stringify(plugin.key))} \nwith source\n\n${code}`])
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
pluginManager.queue.on('add', () => {
|
|
122
|
-
if (logger.logLevel !== LogLevel.info) {
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (count === 0) {
|
|
127
|
-
logger.emit('start', '💾 Writing')
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
pluginManager.queue.on('active', () => {
|
|
132
|
-
if (logger.logLevel !== LogLevel.info) {
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (logger.spinner && pluginManager.queue.size > 0) {
|
|
137
|
-
const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`
|
|
138
|
-
|
|
139
|
-
logger.spinner.suffixText = c.dim(text)
|
|
140
|
-
}
|
|
141
|
-
++count
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
pluginManager.queue.on('completed', () => {
|
|
145
|
-
if (logger.logLevel !== LogLevel.info) {
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (logger.spinner) {
|
|
150
|
-
const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`
|
|
151
|
-
|
|
152
|
-
logger.spinner.suffixText = c.dim(text)
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
pluginManager.on('executed', (executer) => {
|
|
157
|
-
const { hookName, plugin, output, parameters } = executer
|
|
158
|
-
|
|
159
|
-
const logs = [
|
|
160
|
-
`${randomCliColour(plugin.name)} Executing ${hookName}`,
|
|
161
|
-
parameters && `${c.bgWhite('Parameters')} ${randomCliColour(plugin.name)} ${hookName}`,
|
|
162
|
-
JSON.stringify(parameters, undefined, 2),
|
|
163
|
-
output && `${c.bgWhite('Output')} ${randomCliColour(plugin.name)} ${hookName}`,
|
|
164
|
-
output,
|
|
165
|
-
].filter(Boolean)
|
|
166
|
-
|
|
167
|
-
logger.emit('debug', logs as string[])
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
return pluginManager
|
|
51
|
+
return new PluginManager(config, { logger })
|
|
171
52
|
}
|
|
172
53
|
|
|
173
54
|
export async function build(options: BuildOptions): Promise<BuildOutput> {
|
|
174
|
-
const pluginManager = await
|
|
175
|
-
|
|
176
|
-
const { fileManager, logger } = pluginManager
|
|
177
|
-
|
|
178
|
-
await pluginManager.hookParallel({
|
|
179
|
-
hookName: 'buildStart',
|
|
180
|
-
parameters: [options.config],
|
|
181
|
-
})
|
|
55
|
+
const { files, pluginManager, error } = await safeBuild(options)
|
|
182
56
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (logger.logLevel === LogLevel.info) {
|
|
186
|
-
logger.emit('end', '💾 Writing completed')
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const files = await Promise.all(
|
|
190
|
-
fileManager.files.map(async (file) => ({
|
|
191
|
-
...file,
|
|
192
|
-
source: await FileManager.getSource(file),
|
|
193
|
-
})),
|
|
194
|
-
)
|
|
57
|
+
if (error) throw error
|
|
195
58
|
|
|
196
59
|
return {
|
|
197
60
|
files,
|
|
198
61
|
pluginManager,
|
|
62
|
+
error,
|
|
199
63
|
}
|
|
200
64
|
}
|
|
201
65
|
|
|
202
66
|
export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
|
|
67
|
+
let files = []
|
|
203
68
|
const pluginManager = await setup(options)
|
|
204
69
|
|
|
205
|
-
const { fileManager, logger } = pluginManager
|
|
206
|
-
|
|
207
70
|
try {
|
|
71
|
+
pluginManager.events.on('executing', ({ plugin, message }) => {
|
|
72
|
+
pluginManager.logger.emit('debug', { date: new Date(), logs: [`Executing pluginKey ${plugin.key?.join('.')} | ${message}`] })
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
pluginManager.events.on('executed', ({ plugin, message, output }) => {
|
|
76
|
+
pluginManager.logger.emit('debug', {
|
|
77
|
+
date: new Date(),
|
|
78
|
+
logs: [`Executed pluginKey ${plugin.key?.join('.')} | ${message} | ${JSON.stringify(output, undefined, 2)}`],
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
208
82
|
await pluginManager.hookParallel({
|
|
209
83
|
hookName: 'buildStart',
|
|
210
84
|
parameters: [options.config],
|
|
85
|
+
message: 'buildStart',
|
|
211
86
|
})
|
|
212
87
|
|
|
213
|
-
|
|
88
|
+
// create root barrel file
|
|
89
|
+
const root = resolve(options.config.root)
|
|
90
|
+
const rootPath = resolve(root, options.config.output.path, 'index.ts')
|
|
91
|
+
const barrelFiles = pluginManager.fileManager.files.filter((file) => {
|
|
92
|
+
return file.sources.some((source) => source.isIndexable)
|
|
93
|
+
})
|
|
214
94
|
|
|
215
|
-
|
|
216
|
-
|
|
95
|
+
const rootFile: KubbFile.File = {
|
|
96
|
+
path: rootPath,
|
|
97
|
+
baseName: 'index.ts',
|
|
98
|
+
exports: barrelFiles
|
|
99
|
+
.flatMap((file) => {
|
|
100
|
+
return file.sources
|
|
101
|
+
?.map((source) => {
|
|
102
|
+
if (!file.path || !source.isIndexable) {
|
|
103
|
+
return undefined
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// validate of the file is coming from plugin x, needs pluginKey on every file TODO update typing
|
|
107
|
+
const plugin = pluginManager.plugins.find((item) => {
|
|
108
|
+
const meta = file.meta as any
|
|
109
|
+
return item.name === meta?.pluginKey?.[0]
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
if (plugin?.output?.exportType === false) {
|
|
113
|
+
return undefined
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (FileManager.getMode(plugin?.output?.path) === 'single') {
|
|
117
|
+
return undefined
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
name: options.config.output.exportType === 'barrel' ? undefined : [source.name],
|
|
121
|
+
path: getRelativePath(rootPath, file.path),
|
|
122
|
+
isTypeOnly: source.isTypeOnly,
|
|
123
|
+
} as KubbFile.Export
|
|
124
|
+
})
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
})
|
|
127
|
+
.filter(Boolean),
|
|
128
|
+
sources: [],
|
|
129
|
+
meta: {},
|
|
217
130
|
}
|
|
218
|
-
} catch (e) {
|
|
219
|
-
const files = await Promise.all(
|
|
220
|
-
fileManager.files.map(async (file) => ({
|
|
221
|
-
...file,
|
|
222
|
-
source: await FileManager.getSource(file),
|
|
223
|
-
})),
|
|
224
|
-
)
|
|
225
131
|
|
|
132
|
+
if (options.config.output.exportType) {
|
|
133
|
+
await pluginManager.fileManager.add(rootFile)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//TODO set extName here instead of the files, extName is private. All exports will have extName, it's up the the process to hide.override the name
|
|
137
|
+
files = await processFiles({
|
|
138
|
+
config: options.config,
|
|
139
|
+
dryRun: !options.config.output.write,
|
|
140
|
+
files: pluginManager.fileManager.files,
|
|
141
|
+
logger: pluginManager.logger,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
await pluginManager.hookParallel({ hookName: 'buildEnd', message: `Build stopped for ${options.config.name}` })
|
|
145
|
+
|
|
146
|
+
pluginManager.fileManager.clear()
|
|
147
|
+
} catch (e) {
|
|
226
148
|
return {
|
|
227
|
-
files,
|
|
149
|
+
files: [],
|
|
228
150
|
pluginManager,
|
|
229
151
|
error: e as Error,
|
|
230
152
|
}
|
|
231
153
|
}
|
|
232
154
|
|
|
233
|
-
const files = await Promise.all(
|
|
234
|
-
fileManager.files.map(async (file) => ({
|
|
235
|
-
...file,
|
|
236
|
-
source: await FileManager.getSource(file),
|
|
237
|
-
})),
|
|
238
|
-
)
|
|
239
|
-
|
|
240
155
|
return {
|
|
241
156
|
files,
|
|
242
157
|
pluginManager,
|
package/src/errors.ts
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
3
|
-
*/
|
|
4
|
-
export class Warning extends Error {
|
|
5
|
-
constructor(message?: string, options?: { cause: Error }) {
|
|
6
|
-
super(message, { cause: options?.cause })
|
|
7
|
-
|
|
8
|
-
this.name = 'Warning'
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
1
|
export class ValidationPluginError extends Error {}
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
export { build, build as default, safeBuild } from './build.ts'
|
|
2
2
|
export { defineConfig, isInputPath } from './config.ts'
|
|
3
|
-
export { Warning } from './errors.ts'
|
|
4
3
|
export { FileManager } from './FileManager.ts'
|
|
5
4
|
export type { FileMetaBase } from './FileManager.ts'
|
|
6
|
-
export {
|
|
5
|
+
export { BaseGenerator } from './BaseGenerator.ts'
|
|
7
6
|
export { PackageManager } from './PackageManager.ts'
|
|
8
7
|
export { createPlugin } from './plugin.ts'
|
|
9
8
|
export { PluginManager } from './PluginManager.ts'
|
|
10
9
|
export { PromiseManager } from './PromiseManager.ts'
|
|
11
10
|
export type * from './types.ts'
|
|
12
|
-
|
|
13
|
-
// biome-ignore lint/suspicious/noEmptyInterface: <explanation>
|
|
14
|
-
export interface _Register {}
|