@kubb/fabric-core 0.5.4 → 0.5.5
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 +21 -23
- package/dist/{Fabric-BzIhBn8t.d.cts → Fabric-CtqeUUFU.d.ts} +24 -25
- package/dist/{Fabric-igvWKffO.d.ts → Fabric-DlBN6CDR.d.cts} +24 -25
- package/dist/{defaultParser-n9VW2iVf.cjs → defaultParser-CIF-0xIK.cjs} +3 -3
- package/dist/{defaultParser-n9VW2iVf.cjs.map → defaultParser-CIF-0xIK.cjs.map} +1 -1
- package/dist/{defaultParser-Csot2aaT.js → defaultParser-DPHcM2NR.js} +3 -3
- package/dist/{defaultParser-Csot2aaT.js.map → defaultParser-DPHcM2NR.js.map} +1 -1
- package/dist/defineParser-Bxv4mb-N.js +11 -0
- package/dist/{createParser-D_ANHZTa.js.map → defineParser-Bxv4mb-N.js.map} +1 -1
- package/dist/defineParser-DODGK4rM.cjs +17 -0
- package/dist/{createParser-C4IkyTs5.cjs.map → defineParser-DODGK4rM.cjs.map} +1 -1
- package/dist/index.cjs +75 -85
- 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 +76 -85
- package/dist/index.js.map +1 -1
- package/dist/parsers/typescript.cjs +2 -2
- package/dist/parsers/typescript.d.cts +2 -2
- package/dist/parsers/typescript.d.ts +2 -2
- package/dist/parsers/typescript.js +2 -2
- package/dist/parsers.cjs +5 -5
- package/dist/parsers.cjs.map +1 -1
- package/dist/parsers.d.cts +6 -6
- package/dist/parsers.d.ts +6 -6
- package/dist/parsers.js +5 -5
- package/dist/parsers.js.map +1 -1
- package/dist/plugins.cjs +36 -36
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +4 -4
- package/dist/plugins.d.ts +4 -4
- package/dist/plugins.js +36 -36
- package/dist/plugins.js.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/{typescriptParser-BN1vEX-I.d.ts → typescriptParser-BAlwCe3a.d.ts} +2 -2
- package/dist/{typescriptParser-Cw2wm0gX.js → typescriptParser-BLX7eX2k.js} +3 -3
- package/dist/{typescriptParser-Cw2wm0gX.js.map → typescriptParser-BLX7eX2k.js.map} +1 -1
- package/dist/{typescriptParser-BlRK18rx.d.cts → typescriptParser-CnzxSeDN.d.cts} +2 -2
- package/dist/{typescriptParser-DRdx9q2o.cjs → typescriptParser-OjFZ_DeI.cjs} +3 -3
- package/dist/{typescriptParser-DRdx9q2o.cjs.map → typescriptParser-OjFZ_DeI.cjs.map} +1 -1
- package/package.json +1 -1
- package/src/Fabric.ts +28 -24
- package/src/FileManager.ts +6 -6
- package/src/FileProcessor.ts +5 -5
- package/src/createFabric.ts +96 -2
- package/src/index.ts +0 -1
- package/src/parsers/defaultParser.ts +2 -2
- package/src/parsers/{createParser.ts → defineParser.ts} +1 -1
- package/src/parsers/index.ts +1 -2
- package/src/parsers/tsxParser.ts +2 -2
- package/src/parsers/typescriptParser.ts +2 -2
- package/src/plugins/barrelPlugin.ts +3 -3
- package/src/plugins/{createPlugin.ts → definePlugin.ts} +1 -1
- package/src/plugins/fsPlugin.ts +3 -3
- package/src/plugins/graphPlugin.ts +3 -3
- package/src/plugins/index.ts +1 -1
- package/src/plugins/loggerPlugin.ts +41 -31
- package/dist/createParser-C4IkyTs5.cjs +0 -17
- package/dist/createParser-D_ANHZTa.js +0 -11
- package/src/defineFabric.ts +0 -119
package/src/Fabric.ts
CHANGED
|
@@ -40,36 +40,40 @@ export type FabricMode = 'sequential' | 'parallel'
|
|
|
40
40
|
*/
|
|
41
41
|
export interface FabricEvents {
|
|
42
42
|
/** Called at the beginning of the app lifecycle. */
|
|
43
|
-
start: []
|
|
43
|
+
'lifecycle:start': []
|
|
44
44
|
|
|
45
45
|
/** Called at the end of the app lifecycle. */
|
|
46
|
-
end: []
|
|
46
|
+
'lifecycle:end': []
|
|
47
47
|
|
|
48
|
-
/** Called when Fabric is rendering. */
|
|
49
|
-
render: [{ fabric: Fabric }]
|
|
48
|
+
/** Called when Fabric is rendering. Provides the Fabric instance. */
|
|
49
|
+
'lifecycle:render': [{ fabric: Fabric }]
|
|
50
50
|
|
|
51
|
-
/** Called once before any files are processed. */
|
|
52
|
-
'
|
|
53
|
-
/**
|
|
54
|
-
* Called when FileManager is adding files to its cache
|
|
55
|
-
*/
|
|
56
|
-
'file:add': [{ files: KubbFile.ResolvedFile[] }]
|
|
57
|
-
'file:resolve:path': [{ file: KubbFile.File }]
|
|
58
|
-
'file:resolve:name': [{ file: KubbFile.File }]
|
|
59
|
-
'write:start': [{ files: KubbFile.ResolvedFile[] }]
|
|
60
|
-
'write:end': [{ files: KubbFile.ResolvedFile[] }]
|
|
51
|
+
/** Called once before any files are processed. Provides all files that will be processed. */
|
|
52
|
+
'files:processing:start': [{ files: KubbFile.ResolvedFile[] }]
|
|
61
53
|
|
|
62
|
-
/** Called
|
|
63
|
-
'
|
|
54
|
+
/** Called when FileManager is adding files to its cache. */
|
|
55
|
+
'files:added': [{ files: KubbFile.ResolvedFile[] }]
|
|
64
56
|
|
|
65
|
-
/** Called
|
|
66
|
-
'file:
|
|
57
|
+
/** Called when resolving a file's path. Allows modification of the file path. */
|
|
58
|
+
'file:path:resolving': [{ file: KubbFile.File }]
|
|
67
59
|
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
'
|
|
60
|
+
/** Called when resolving a file's name. Allows modification of the file name. */
|
|
61
|
+
'file:name:resolving': [{ file: KubbFile.File }]
|
|
62
|
+
|
|
63
|
+
/** Called before writing files to disk. Provides all files that will be written. */
|
|
64
|
+
'files:writing:start': [{ files: KubbFile.ResolvedFile[] }]
|
|
65
|
+
|
|
66
|
+
/** Called after writing files to disk. Provides all files that were written. */
|
|
67
|
+
'files:writing:end': [{ files: KubbFile.ResolvedFile[] }]
|
|
68
|
+
|
|
69
|
+
/** Called when processing of an individual file begins. Provides file, current index, and total count. */
|
|
70
|
+
'file:processing:start': [{ file: KubbFile.ResolvedFile; index: number; total: number }]
|
|
71
|
+
|
|
72
|
+
/** Called when processing of an individual file completes. Provides file, current index, and total count. */
|
|
73
|
+
'file:processing:end': [{ file: KubbFile.ResolvedFile; index: number; total: number }]
|
|
74
|
+
|
|
75
|
+
/** Called periodically to indicate processing progress. Useful for progress bars or logging. */
|
|
76
|
+
'files:processing:update': [
|
|
73
77
|
{
|
|
74
78
|
processed: number
|
|
75
79
|
total: number
|
|
@@ -80,7 +84,7 @@ export interface FabricEvents {
|
|
|
80
84
|
]
|
|
81
85
|
|
|
82
86
|
/** Called once all files have been processed successfully. */
|
|
83
|
-
'
|
|
87
|
+
'files:processing:end': [{ files: KubbFile.ResolvedFile[] }]
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
/**
|
package/src/FileManager.ts
CHANGED
|
@@ -34,13 +34,13 @@ export class FileManager {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
#resolvePath(file: KubbFile.File): KubbFile.File {
|
|
37
|
-
this.events.emit('file:
|
|
37
|
+
this.events.emit('file:path:resolving', { file })
|
|
38
38
|
|
|
39
39
|
return file
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
#resolveName(file: KubbFile.File): KubbFile.File {
|
|
43
|
-
this.events.emit('file:
|
|
43
|
+
this.events.emit('file:name:resolving', { file })
|
|
44
44
|
|
|
45
45
|
return file
|
|
46
46
|
}
|
|
@@ -71,7 +71,7 @@ export class FileManager {
|
|
|
71
71
|
resolvedFiles.push(resolvedFile)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
await this.events.emit('
|
|
74
|
+
await this.events.emit('files:added', { files: resolvedFiles })
|
|
75
75
|
|
|
76
76
|
return resolvedFiles
|
|
77
77
|
}
|
|
@@ -105,7 +105,7 @@ export class FileManager {
|
|
|
105
105
|
resolvedFiles.push(resolvedFile)
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
await this.events.emit('
|
|
108
|
+
await this.events.emit('files:added', { files: resolvedFiles })
|
|
109
109
|
|
|
110
110
|
return resolvedFiles
|
|
111
111
|
}
|
|
@@ -155,13 +155,13 @@ export class FileManager {
|
|
|
155
155
|
|
|
156
156
|
//TODO add test and check if write of FileManager contains the newly added file
|
|
157
157
|
async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {
|
|
158
|
-
await this.events.emit('
|
|
158
|
+
await this.events.emit('files:writing:start', { files: this.files })
|
|
159
159
|
|
|
160
160
|
const resolvedFiles = await this.processor.run(this.files, options)
|
|
161
161
|
|
|
162
162
|
this.clear()
|
|
163
163
|
|
|
164
|
-
await this.events.emit('
|
|
164
|
+
await this.events.emit('files:writing:end', { files: resolvedFiles })
|
|
165
165
|
|
|
166
166
|
return resolvedFiles
|
|
167
167
|
}
|
package/src/FileProcessor.ts
CHANGED
|
@@ -60,20 +60,20 @@ export class FileProcessor {
|
|
|
60
60
|
files: Array<KubbFile.ResolvedFile>,
|
|
61
61
|
{ parsers, mode = 'sequential', dryRun, extension }: ProcessFilesProps = {},
|
|
62
62
|
): Promise<KubbFile.ResolvedFile[]> {
|
|
63
|
-
await this.events.emit('
|
|
63
|
+
await this.events.emit('files:processing:start', { files })
|
|
64
64
|
|
|
65
65
|
const total = files.length
|
|
66
66
|
let processed = 0
|
|
67
67
|
|
|
68
68
|
const processOne = async (resolvedFile: KubbFile.ResolvedFile, index: number) => {
|
|
69
|
-
await this.events.emit('file:start', { file: resolvedFile, index, total })
|
|
69
|
+
await this.events.emit('file:processing:start', { file: resolvedFile, index, total })
|
|
70
70
|
|
|
71
71
|
const source = dryRun ? undefined : await this.parse(resolvedFile, { extension, parsers })
|
|
72
72
|
|
|
73
73
|
const currentProcessed = ++processed
|
|
74
74
|
const percentage = (currentProcessed / total) * 100
|
|
75
75
|
|
|
76
|
-
await this.events.emit('
|
|
76
|
+
await this.events.emit('files:processing:update', {
|
|
77
77
|
file: resolvedFile,
|
|
78
78
|
source,
|
|
79
79
|
processed: currentProcessed,
|
|
@@ -81,7 +81,7 @@ export class FileProcessor {
|
|
|
81
81
|
total,
|
|
82
82
|
})
|
|
83
83
|
|
|
84
|
-
await this.events.emit('file:end', { file: resolvedFile, index, total })
|
|
84
|
+
await this.events.emit('file:processing:end', { file: resolvedFile, index, total })
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
if (mode === 'sequential') {
|
|
@@ -101,7 +101,7 @@ export class FileProcessor {
|
|
|
101
101
|
await Promise.all(promises)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
await this.events.emit('
|
|
104
|
+
await this.events.emit('files:processing:end', { files })
|
|
105
105
|
|
|
106
106
|
return files
|
|
107
107
|
}
|
package/src/createFabric.ts
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isFunction } from 'remeda'
|
|
2
|
+
import type { Fabric, FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'
|
|
3
|
+
import { FileManager } from './FileManager.ts'
|
|
4
|
+
import type * as KubbFile from './KubbFile.ts'
|
|
5
|
+
import type { Parser } from './parsers/types.ts'
|
|
6
|
+
import type { Plugin } from './plugins/types.ts'
|
|
7
|
+
import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new Fabric instance
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const fabric = createFabric()
|
|
14
|
+
* fabric.use(myPlugin())
|
|
15
|
+
*/
|
|
16
|
+
export function createFabric<T extends FabricOptions>(config: FabricConfig<T> = { mode: 'sequential' } as FabricConfig<T>): Fabric<T> {
|
|
17
|
+
const events = new AsyncEventEmitter<FabricEvents>()
|
|
18
|
+
const installedPlugins = new Set<Plugin<any>>()
|
|
19
|
+
const installedParsers = new Map<KubbFile.Extname, Parser<any>>()
|
|
20
|
+
const installedParserNames = new Set<string>()
|
|
21
|
+
const fileManager = new FileManager({ events })
|
|
22
|
+
|
|
23
|
+
const context: FabricContext<T> = {
|
|
24
|
+
get files() {
|
|
25
|
+
return fileManager.files
|
|
26
|
+
},
|
|
27
|
+
async addFile(...files) {
|
|
28
|
+
await fileManager.add(...files)
|
|
29
|
+
},
|
|
30
|
+
config,
|
|
31
|
+
fileManager,
|
|
32
|
+
installedPlugins,
|
|
33
|
+
installedParsers,
|
|
34
|
+
on: events.on.bind(events),
|
|
35
|
+
off: events.off.bind(events),
|
|
36
|
+
onOnce: events.onOnce.bind(events),
|
|
37
|
+
removeAll: events.removeAll.bind(events),
|
|
38
|
+
emit: events.emit.bind(events),
|
|
39
|
+
} as FabricContext<T>
|
|
40
|
+
|
|
41
|
+
const fabric: Fabric<T> = {
|
|
42
|
+
context,
|
|
43
|
+
get files() {
|
|
44
|
+
return fileManager.files
|
|
45
|
+
},
|
|
46
|
+
async addFile(...files) {
|
|
47
|
+
await fileManager.add(...files)
|
|
48
|
+
},
|
|
49
|
+
async upsertFile(...files) {
|
|
50
|
+
await fileManager.upsert(...files)
|
|
51
|
+
},
|
|
52
|
+
async use(pluginOrParser, ...options) {
|
|
53
|
+
if (pluginOrParser.type === 'plugin') {
|
|
54
|
+
if (installedPlugins.has(pluginOrParser)) {
|
|
55
|
+
console.warn(`Plugin "${pluginOrParser.name}" already applied.`)
|
|
56
|
+
} else {
|
|
57
|
+
installedPlugins.add(pluginOrParser)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (isFunction(pluginOrParser.inject)) {
|
|
61
|
+
const injecter = pluginOrParser.inject
|
|
62
|
+
|
|
63
|
+
const injected = (injecter as any)(context, ...options)
|
|
64
|
+
Object.assign(fabric, injected)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (pluginOrParser.type === 'parser') {
|
|
69
|
+
if (installedParserNames.has(pluginOrParser.name)) {
|
|
70
|
+
console.warn(`Parser "${pluginOrParser.name}" already applied.`)
|
|
71
|
+
} else {
|
|
72
|
+
installedParserNames.add(pluginOrParser.name)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (pluginOrParser.extNames) {
|
|
76
|
+
for (const extName of pluginOrParser.extNames) {
|
|
77
|
+
const existing = installedParsers.get(extName)
|
|
78
|
+
if (existing && existing.name !== pluginOrParser.name) {
|
|
79
|
+
console.warn(`Parser "${pluginOrParser.name}" is overriding parser "${existing.name}" for extension "${extName}".`)
|
|
80
|
+
}
|
|
81
|
+
installedParsers.set(extName, pluginOrParser)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (isFunction(pluginOrParser.install)) {
|
|
87
|
+
const installer = pluginOrParser.install
|
|
88
|
+
|
|
89
|
+
await (installer as any)(context, ...options)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return fabric
|
|
93
|
+
},
|
|
94
|
+
} as Fabric<T>
|
|
95
|
+
|
|
96
|
+
return fabric
|
|
97
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { createFabric } from './createFabric.ts'
|
|
2
2
|
export { createFile } from './createFile.ts'
|
|
3
|
-
export { defineFabric } from './defineFabric.ts'
|
|
4
3
|
// we need this to override the globals of `fabric.use`
|
|
5
4
|
export type { Fabric } from './Fabric.ts'
|
|
6
5
|
export { FileManager } from './FileManager.ts'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Parser, UserParser } from './types.ts'
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function defineParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta> {
|
|
4
4
|
return {
|
|
5
5
|
type: 'parser',
|
|
6
6
|
...parser,
|
package/src/parsers/index.ts
CHANGED
package/src/parsers/tsxParser.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineParser } from './defineParser.ts'
|
|
2
2
|
import { typescriptParser } from './typescriptParser.ts'
|
|
3
3
|
|
|
4
|
-
export const tsxParser =
|
|
4
|
+
export const tsxParser = defineParser({
|
|
5
5
|
name: 'tsx',
|
|
6
6
|
extNames: ['.tsx', '.jsx'],
|
|
7
7
|
install() {},
|
|
@@ -2,7 +2,7 @@ import path from 'node:path'
|
|
|
2
2
|
import ts from 'typescript'
|
|
3
3
|
import { getRelativePath } from '../utils/getRelativePath.ts'
|
|
4
4
|
import { trimExtName } from '../utils/trimExtName.ts'
|
|
5
|
-
import {
|
|
5
|
+
import { defineParser } from './defineParser.ts'
|
|
6
6
|
|
|
7
7
|
const { factory } = ts
|
|
8
8
|
|
|
@@ -122,7 +122,7 @@ export function createExport({
|
|
|
122
122
|
)
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
export const typescriptParser =
|
|
125
|
+
export const typescriptParser = defineParser({
|
|
126
126
|
name: 'typescript',
|
|
127
127
|
extNames: ['.ts', '.js'],
|
|
128
128
|
install() {},
|
|
@@ -5,7 +5,7 @@ import { createFile } from '../createFile.ts'
|
|
|
5
5
|
import type * as KubbFile from '../KubbFile.ts'
|
|
6
6
|
import { getRelativePath } from '../utils/getRelativePath.ts'
|
|
7
7
|
import { TreeNode } from '../utils/TreeNode.ts'
|
|
8
|
-
import {
|
|
8
|
+
import { definePlugin } from './definePlugin.ts'
|
|
9
9
|
|
|
10
10
|
type Mode = 'all' | 'named' | 'propagate' | false
|
|
11
11
|
|
|
@@ -144,7 +144,7 @@ export function getBarrelFiles({ files, root, mode }: GetBarrelFilesOptions): Ar
|
|
|
144
144
|
return result
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
export const barrelPlugin =
|
|
147
|
+
export const barrelPlugin = definePlugin<Options, ExtendOptions>({
|
|
148
148
|
name: 'barrel',
|
|
149
149
|
install(ctx, options) {
|
|
150
150
|
if (!options) {
|
|
@@ -155,7 +155,7 @@ export const barrelPlugin = createPlugin<Options, ExtendOptions>({
|
|
|
155
155
|
return undefined
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
ctx.on('
|
|
158
|
+
ctx.on('files:writing:start', async ({ files }) => {
|
|
159
159
|
const root = options.root
|
|
160
160
|
const barrelFiles = getBarrelFiles({ files, root, mode: options.mode })
|
|
161
161
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Plugin, UserPlugin } from './types.ts'
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function definePlugin<Options = unknown, TAppExtension extends Record<string, any> = {}>(
|
|
4
4
|
plugin: UserPlugin<Options, TAppExtension>,
|
|
5
5
|
): Plugin<Options, TAppExtension> {
|
|
6
6
|
return {
|
package/src/plugins/fsPlugin.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolve } from 'node:path'
|
|
2
2
|
import fs from 'fs-extra'
|
|
3
3
|
import type * as KubbFile from '../KubbFile.ts'
|
|
4
|
-
import {
|
|
4
|
+
import { definePlugin } from './definePlugin.ts'
|
|
5
5
|
|
|
6
6
|
type WriteOptions = {
|
|
7
7
|
extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
|
|
@@ -85,14 +85,14 @@ declare global {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export const fsPlugin =
|
|
88
|
+
export const fsPlugin = definePlugin<Options, ExtendOptions>({
|
|
89
89
|
name: 'fs',
|
|
90
90
|
install(ctx, options = {}) {
|
|
91
91
|
if (options.clean) {
|
|
92
92
|
fs.removeSync(options.clean.path)
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
ctx.on('
|
|
95
|
+
ctx.on('files:processing:update', async ({ file, source }) => {
|
|
96
96
|
if (options.onBeforeWrite) {
|
|
97
97
|
await options.onBeforeWrite(file.path, source)
|
|
98
98
|
}
|
|
@@ -6,7 +6,7 @@ import { createFile } from '../createFile.ts'
|
|
|
6
6
|
import type * as KubbFile from '../KubbFile.ts'
|
|
7
7
|
import { open } from '../utils/open.ts'
|
|
8
8
|
import { type Graph, TreeNode } from '../utils/TreeNode.ts'
|
|
9
|
-
import {
|
|
9
|
+
import { definePlugin } from './definePlugin.ts'
|
|
10
10
|
|
|
11
11
|
type Options = {
|
|
12
12
|
root: string
|
|
@@ -84,14 +84,14 @@ async function serve(root: string) {
|
|
|
84
84
|
})
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
export const graphPlugin =
|
|
87
|
+
export const graphPlugin = definePlugin<Options>({
|
|
88
88
|
name: 'graph',
|
|
89
89
|
install(ctx, options) {
|
|
90
90
|
if (!options) {
|
|
91
91
|
throw new Error('Graph plugin requires options.root and options.mode')
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
ctx.on('
|
|
94
|
+
ctx.on('files:writing:start', async ({ files }) => {
|
|
95
95
|
const root = options.root
|
|
96
96
|
|
|
97
97
|
const graph = getGraph({ files, root })
|
package/src/plugins/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { barrelPlugin } from './barrelPlugin.ts'
|
|
2
|
-
export {
|
|
2
|
+
export { definePlugin } from './definePlugin.ts'
|
|
3
3
|
export { fsPlugin } from './fsPlugin.ts'
|
|
4
4
|
export { graphPlugin } from './graphPlugin.ts'
|
|
5
5
|
export { loggerPlugin } from './loggerPlugin.ts'
|
|
@@ -6,10 +6,9 @@ import { createConsola, type LogLevel } from 'consola'
|
|
|
6
6
|
import { WebSocket, WebSocketServer } from 'ws'
|
|
7
7
|
import type { FabricEvents } from '../Fabric.ts'
|
|
8
8
|
import type * as KubbFile from '../KubbFile.ts'
|
|
9
|
-
import {
|
|
9
|
+
import { definePlugin } from './definePlugin.ts'
|
|
10
10
|
|
|
11
11
|
type Broadcast = <T = unknown>(event: keyof FabricEvents | string, payload: T) => void
|
|
12
|
-
|
|
13
12
|
type WebSocketOptions = {
|
|
14
13
|
/**
|
|
15
14
|
* Hostname to bind the websocket server to.
|
|
@@ -43,7 +42,10 @@ type Options = {
|
|
|
43
42
|
websocket?: boolean | WebSocketOptions
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
function normalizeAddress(address: AddressInfo): {
|
|
45
|
+
function normalizeAddress(address: AddressInfo): {
|
|
46
|
+
host: string
|
|
47
|
+
port: number
|
|
48
|
+
} {
|
|
47
49
|
const host = address.address === '::' ? '127.0.0.1' : address.address
|
|
48
50
|
|
|
49
51
|
return { host, port: address.port }
|
|
@@ -76,7 +78,7 @@ const createProgressBar = () =>
|
|
|
76
78
|
Presets.shades_grey,
|
|
77
79
|
)
|
|
78
80
|
|
|
79
|
-
export const loggerPlugin =
|
|
81
|
+
export const loggerPlugin = definePlugin<Options>({
|
|
80
82
|
name: 'logger',
|
|
81
83
|
install(ctx, options = {}) {
|
|
82
84
|
const { level, websocket = true, progress = true } = options
|
|
@@ -140,40 +142,43 @@ export const loggerPlugin = createPlugin<Options>({
|
|
|
140
142
|
|
|
141
143
|
const formatPath = (path: string) => relative(process.cwd(), path)
|
|
142
144
|
|
|
143
|
-
ctx.on('start', async () => {
|
|
145
|
+
ctx.on('lifecycle:start', async () => {
|
|
144
146
|
logger.start('Starting Fabric run')
|
|
145
|
-
broadcast('start', { timestamp: Date.now() })
|
|
147
|
+
broadcast('lifecycle:start', { timestamp: Date.now() })
|
|
146
148
|
})
|
|
147
149
|
|
|
148
|
-
ctx.on('render', async () => {
|
|
150
|
+
ctx.on('lifecycle:render', async () => {
|
|
149
151
|
logger.info('Rendering application graph')
|
|
150
|
-
broadcast('render', { timestamp: Date.now() })
|
|
152
|
+
broadcast('lifecycle:render', { timestamp: Date.now() })
|
|
151
153
|
})
|
|
152
154
|
|
|
153
|
-
ctx.on('
|
|
155
|
+
ctx.on('files:added', async ({ files }) => {
|
|
154
156
|
if (!files.length) {
|
|
155
157
|
return
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
logger.info(`Queued ${pluralize('file', files.length)}`)
|
|
159
|
-
broadcast('
|
|
161
|
+
broadcast('files:added', {
|
|
160
162
|
files: files.map(serializeFile),
|
|
161
163
|
})
|
|
162
164
|
})
|
|
163
165
|
|
|
164
|
-
ctx.on('file:
|
|
166
|
+
ctx.on('file:path:resolving', async ({ file }) => {
|
|
165
167
|
logger.info(`Resolving path for ${formatPath(file.path)}`)
|
|
166
|
-
broadcast('file:
|
|
168
|
+
broadcast('file:path:resolving', { file: serializeFile(file) })
|
|
167
169
|
})
|
|
168
170
|
|
|
169
|
-
ctx.on('file:
|
|
171
|
+
ctx.on('file:name:resolving', async ({ file }) => {
|
|
170
172
|
logger.info(`Resolving name for ${formatPath(file.path)}`)
|
|
171
|
-
broadcast('file:
|
|
173
|
+
broadcast('file:name:resolving', { file: serializeFile(file) })
|
|
172
174
|
})
|
|
173
175
|
|
|
174
|
-
ctx.on('
|
|
176
|
+
ctx.on('files:processing:start', async ({ files }) => {
|
|
175
177
|
logger.start(`Processing ${pluralize('file', files.length)}`)
|
|
176
|
-
broadcast('
|
|
178
|
+
broadcast('files:processing:start', {
|
|
179
|
+
total: files.length,
|
|
180
|
+
timestamp: Date.now(),
|
|
181
|
+
})
|
|
177
182
|
|
|
178
183
|
if (progressBar) {
|
|
179
184
|
logger.pauseLogs()
|
|
@@ -181,20 +186,20 @@ export const loggerPlugin = createPlugin<Options>({
|
|
|
181
186
|
}
|
|
182
187
|
})
|
|
183
188
|
|
|
184
|
-
ctx.on('file:start', async ({ file, index, total }) => {
|
|
189
|
+
ctx.on('file:processing:start', async ({ file, index, total }) => {
|
|
185
190
|
logger.info(`Processing [${index + 1}/${total}] ${formatPath(file.path)}`)
|
|
186
|
-
broadcast('file:start', {
|
|
191
|
+
broadcast('file:processing:start', {
|
|
187
192
|
index,
|
|
188
193
|
total,
|
|
189
194
|
file: serializeFile(file),
|
|
190
195
|
})
|
|
191
196
|
})
|
|
192
197
|
|
|
193
|
-
ctx.on('
|
|
198
|
+
ctx.on('files:processing:update', async ({ processed, total, percentage, file }) => {
|
|
194
199
|
const formattedPercentage = Number.isFinite(percentage) ? percentage.toFixed(1) : '0.0'
|
|
195
200
|
|
|
196
201
|
logger.info(`Progress ${formattedPercentage}% (${processed}/${total}) → ${formatPath(file.path)}`)
|
|
197
|
-
broadcast('
|
|
202
|
+
broadcast('files:processing:update', {
|
|
198
203
|
processed,
|
|
199
204
|
total,
|
|
200
205
|
percentage,
|
|
@@ -202,36 +207,41 @@ export const loggerPlugin = createPlugin<Options>({
|
|
|
202
207
|
})
|
|
203
208
|
|
|
204
209
|
if (progressBar) {
|
|
205
|
-
progressBar.increment(1, {
|
|
210
|
+
progressBar.increment(1, {
|
|
211
|
+
message: `Writing ${formatPath(file.path)}`,
|
|
212
|
+
})
|
|
206
213
|
}
|
|
207
214
|
})
|
|
208
215
|
|
|
209
|
-
ctx.on('file:end', async ({ file, index, total }) => {
|
|
216
|
+
ctx.on('file:processing:end', async ({ file, index, total }) => {
|
|
210
217
|
logger.success(`Finished [${index + 1}/${total}] ${formatPath(file.path)}`)
|
|
211
|
-
broadcast('file:end', {
|
|
218
|
+
broadcast('file:processing:end', {
|
|
212
219
|
index,
|
|
213
220
|
total,
|
|
214
221
|
file: serializeFile(file),
|
|
215
222
|
})
|
|
216
223
|
})
|
|
217
224
|
|
|
218
|
-
ctx.on('
|
|
225
|
+
ctx.on('files:writing:start', async ({ files }) => {
|
|
219
226
|
logger.start(`Writing ${pluralize('file', files.length)} to disk`)
|
|
220
|
-
broadcast('
|
|
227
|
+
broadcast('files:writing:start', {
|
|
221
228
|
files: files.map(serializeFile),
|
|
222
229
|
})
|
|
223
230
|
})
|
|
224
231
|
|
|
225
|
-
ctx.on('
|
|
232
|
+
ctx.on('files:writing:end', async ({ files }) => {
|
|
226
233
|
logger.success(`Written ${pluralize('file', files.length)} to disk`)
|
|
227
|
-
broadcast('
|
|
234
|
+
broadcast('files:writing:end', {
|
|
228
235
|
files: files.map(serializeFile),
|
|
229
236
|
})
|
|
230
237
|
})
|
|
231
238
|
|
|
232
|
-
ctx.on('
|
|
239
|
+
ctx.on('files:processing:end', async ({ files }) => {
|
|
233
240
|
logger.success(`Processed ${pluralize('file', files.length)}`)
|
|
234
|
-
broadcast('
|
|
241
|
+
broadcast('files:processing:end', {
|
|
242
|
+
total: files.length,
|
|
243
|
+
timestamp: Date.now(),
|
|
244
|
+
})
|
|
235
245
|
|
|
236
246
|
if (progressBar) {
|
|
237
247
|
progressBar.update(files.length, { message: 'Done ✅' })
|
|
@@ -241,9 +251,9 @@ export const loggerPlugin = createPlugin<Options>({
|
|
|
241
251
|
}
|
|
242
252
|
})
|
|
243
253
|
|
|
244
|
-
ctx.on('end', async () => {
|
|
254
|
+
ctx.on('lifecycle:end', async () => {
|
|
245
255
|
logger.success('Fabric run completed')
|
|
246
|
-
broadcast('end', { timestamp: Date.now() })
|
|
256
|
+
broadcast('lifecycle:end', { timestamp: Date.now() })
|
|
247
257
|
|
|
248
258
|
if (progressBar) {
|
|
249
259
|
progressBar.stop()
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/parsers/createParser.ts
|
|
3
|
-
function createParser(parser) {
|
|
4
|
-
return {
|
|
5
|
-
type: "parser",
|
|
6
|
-
...parser
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
|
-
Object.defineProperty(exports, 'createParser', {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () {
|
|
14
|
-
return createParser;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
//# sourceMappingURL=createParser-C4IkyTs5.cjs.map
|