@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/README.md
CHANGED
|
@@ -83,26 +83,24 @@ Returns a Fabric instance with:
|
|
|
83
83
|
- `fabric.files` — getter with all queued files.
|
|
84
84
|
- `fabric.context` — internal context holding events, options, FileManager, installed plugins/parsers.
|
|
85
85
|
|
|
86
|
-
### `defineFabric(instance?): () => Fabric`
|
|
87
|
-
Factory to create your own `createFabric` with an optional bootstrap `instance(fabric)` called on creation.
|
|
88
86
|
|
|
89
87
|
### Events (emitted by the core during processing)
|
|
90
|
-
- `start`
|
|
91
|
-
- `end`
|
|
92
|
-
- `render { fabric }`
|
|
93
|
-
- `
|
|
94
|
-
- `
|
|
95
|
-
- `
|
|
96
|
-
- `file:start { file, index, total }`
|
|
97
|
-
- `file:end { file, index, total }`
|
|
98
|
-
- `
|
|
99
|
-
- `
|
|
100
|
-
- `
|
|
88
|
+
- `lifecycle:start`
|
|
89
|
+
- `lifecycle:end`
|
|
90
|
+
- `lifecycle:render { fabric }`
|
|
91
|
+
- `files:added { files }`
|
|
92
|
+
- `files:writing:start { files }`
|
|
93
|
+
- `files:writing:end { files }`
|
|
94
|
+
- `file:processing:start { file, index, total }`
|
|
95
|
+
- `file:processing:end { file, index, total }`
|
|
96
|
+
- `files:processing:start { files }`
|
|
97
|
+
- `files:processing:update { file, source, processed, percentage, total }`
|
|
98
|
+
- `files:processing:end { files }`
|
|
101
99
|
|
|
102
100
|
|
|
103
101
|
## Plugins
|
|
104
102
|
#### `fsPlugin`
|
|
105
|
-
Writes files to disk on `
|
|
103
|
+
Writes files to disk on `files:processing:update`, supports dry runs and cleaning an output folder before writing.
|
|
106
104
|
|
|
107
105
|
```
|
|
108
106
|
import { fsPlugin } from '@kubb/fabric-core/plugins'
|
|
@@ -111,7 +109,7 @@ import { fsPlugin } from '@kubb/fabric-core/plugins'
|
|
|
111
109
|
| Option | Type | Default | Description |
|
|
112
110
|
|---|----------------------------------------------------------------------|---|-----------------------------------------------------------------------|
|
|
113
111
|
| dryRun | `boolean` | `false` | If true, do not write files to disk. |
|
|
114
|
-
| onBeforeWrite | `(path: string, data: string \| undefined) => void \| Promise<void>` | — | Called right before each file write on `
|
|
112
|
+
| onBeforeWrite | `(path: string, data: string \| undefined) => void \| Promise<void>` | — | Called right before each file write on `files:processing:update`. |
|
|
115
113
|
| clean | `{ path: string }` | — | If provided, removes the directory at `path` before writing any files. |
|
|
116
114
|
|
|
117
115
|
Injected `fabric.write` options (via `fsPlugin`):
|
|
@@ -121,7 +119,7 @@ Injected `fabric.write` options (via `fsPlugin`):
|
|
|
121
119
|
| extension | `Record<Extname, Extname \| ''>` | — | Maps input file extensions to output extensions. When set, the matching parser (by extNames) is used. |
|
|
122
120
|
|
|
123
121
|
#### `barrelPlugin`
|
|
124
|
-
Generates `index.ts` barrel files per folder
|
|
122
|
+
Generates `index.ts` barrel files per folder when `files:writing:start` is triggered. `writeEntry` creates a single entry barrel at `root`.
|
|
125
123
|
|
|
126
124
|
```
|
|
127
125
|
import { barrelPlugin } from '@kubb/fabric-core/plugins'
|
|
@@ -191,7 +189,7 @@ Injected methods (via `reactPlugin`):
|
|
|
191
189
|
| `renderToString` | `(App: React.ElementType) => Promise<string> \| string` | Render a React component tree and return the final output as a string (without writing to stdout). |
|
|
192
190
|
| `waitUntilExit` | `() => Promise<void>` | Wait until the rendered app exits, resolves when unmounted and emits the core `end` event. |
|
|
193
191
|
|
|
194
|
-
#### `
|
|
192
|
+
#### `definePlugin`
|
|
195
193
|
|
|
196
194
|
Factory to declare a plugin that can be registered via `fabric.use`.
|
|
197
195
|
|
|
@@ -205,12 +203,12 @@ Example:
|
|
|
205
203
|
|
|
206
204
|
```ts
|
|
207
205
|
import { createFabric } from '@kubb/fabric-core'
|
|
208
|
-
import {
|
|
206
|
+
import { definePlugin } from '@kubb/fabric-core/plugins'
|
|
209
207
|
|
|
210
|
-
const helloPlugin =
|
|
208
|
+
const helloPlugin = definePlugin<{ name?: string }, { sayHello: (msg?: string) => void }>({
|
|
211
209
|
name: 'helloPlugin',
|
|
212
210
|
install(fabric, options) {
|
|
213
|
-
fabric.context.events.on('start', () => {
|
|
211
|
+
fabric.context.events.on('lifecycle:start', () => {
|
|
214
212
|
console.log('Fabric started')
|
|
215
213
|
})
|
|
216
214
|
},
|
|
@@ -267,7 +265,7 @@ import { defaultParser } @kubb/fabric-core/parsers`
|
|
|
267
265
|
|---|---|---|--------------------------------------------------------------------------|
|
|
268
266
|
| file | `KubbFile.File` | -| File that will be used to be parsed. |
|
|
269
267
|
|
|
270
|
-
#### `
|
|
268
|
+
#### `defineParser`
|
|
271
269
|
Factory to declare a parser that can be registered via `fabric.use` and selected by `extNames` during `fabirc.write`.
|
|
272
270
|
|
|
273
271
|
| Field | Required | Description |
|
|
@@ -281,9 +279,9 @@ Example:
|
|
|
281
279
|
|
|
282
280
|
```ts
|
|
283
281
|
import { createFabric } from '@kubb/fabric-core'
|
|
284
|
-
import {
|
|
282
|
+
import { defineParser } from '@kubb/fabric-core/parsers'
|
|
285
283
|
|
|
286
|
-
const vueParser =
|
|
284
|
+
const vueParser = defineParser<{ banner?: string }>({
|
|
287
285
|
name: 'vueParser',
|
|
288
286
|
extNames: ['.vue'],
|
|
289
287
|
async install(fabric, options) {
|
|
@@ -254,52 +254,51 @@ type FabricMode = 'sequential' | 'parallel';
|
|
|
254
254
|
*/
|
|
255
255
|
interface FabricEvents {
|
|
256
256
|
/** Called at the beginning of the app lifecycle. */
|
|
257
|
-
start: [];
|
|
257
|
+
'lifecycle:start': [];
|
|
258
258
|
/** Called at the end of the app lifecycle. */
|
|
259
|
-
end: [];
|
|
260
|
-
/** Called when Fabric is rendering. */
|
|
261
|
-
render: [{
|
|
259
|
+
'lifecycle:end': [];
|
|
260
|
+
/** Called when Fabric is rendering. Provides the Fabric instance. */
|
|
261
|
+
'lifecycle:render': [{
|
|
262
262
|
fabric: Fabric;
|
|
263
263
|
}];
|
|
264
|
-
/** Called once before any files are processed. */
|
|
265
|
-
'
|
|
264
|
+
/** Called once before any files are processed. Provides all files that will be processed. */
|
|
265
|
+
'files:processing:start': [{
|
|
266
266
|
files: ResolvedFile[];
|
|
267
267
|
}];
|
|
268
|
-
/**
|
|
269
|
-
|
|
270
|
-
*/
|
|
271
|
-
'file:add': [{
|
|
268
|
+
/** Called when FileManager is adding files to its cache. */
|
|
269
|
+
'files:added': [{
|
|
272
270
|
files: ResolvedFile[];
|
|
273
271
|
}];
|
|
274
|
-
'file
|
|
272
|
+
/** Called when resolving a file's path. Allows modification of the file path. */
|
|
273
|
+
'file:path:resolving': [{
|
|
275
274
|
file: File;
|
|
276
275
|
}];
|
|
277
|
-
'file
|
|
276
|
+
/** Called when resolving a file's name. Allows modification of the file name. */
|
|
277
|
+
'file:name:resolving': [{
|
|
278
278
|
file: File;
|
|
279
279
|
}];
|
|
280
|
-
|
|
280
|
+
/** Called before writing files to disk. Provides all files that will be written. */
|
|
281
|
+
'files:writing:start': [{
|
|
281
282
|
files: ResolvedFile[];
|
|
282
283
|
}];
|
|
283
|
-
|
|
284
|
+
/** Called after writing files to disk. Provides all files that were written. */
|
|
285
|
+
'files:writing:end': [{
|
|
284
286
|
files: ResolvedFile[];
|
|
285
287
|
}];
|
|
286
|
-
/** Called
|
|
287
|
-
'file:start': [{
|
|
288
|
+
/** Called when processing of an individual file begins. Provides file, current index, and total count. */
|
|
289
|
+
'file:processing:start': [{
|
|
288
290
|
file: ResolvedFile;
|
|
289
291
|
index: number;
|
|
290
292
|
total: number;
|
|
291
293
|
}];
|
|
292
|
-
/** Called
|
|
293
|
-
'file:end': [{
|
|
294
|
+
/** Called when processing of an individual file completes. Provides file, current index, and total count. */
|
|
295
|
+
'file:processing:end': [{
|
|
294
296
|
file: ResolvedFile;
|
|
295
297
|
index: number;
|
|
296
298
|
total: number;
|
|
297
299
|
}];
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
* Useful for progress bars or logging.
|
|
301
|
-
*/
|
|
302
|
-
'process:progress': [{
|
|
300
|
+
/** Called periodically to indicate processing progress. Useful for progress bars or logging. */
|
|
301
|
+
'files:processing:update': [{
|
|
303
302
|
processed: number;
|
|
304
303
|
total: number;
|
|
305
304
|
percentage: number;
|
|
@@ -307,7 +306,7 @@ interface FabricEvents {
|
|
|
307
306
|
file: ResolvedFile;
|
|
308
307
|
}];
|
|
309
308
|
/** Called once all files have been processed successfully. */
|
|
310
|
-
'
|
|
309
|
+
'files:processing:end': [{
|
|
311
310
|
files: ResolvedFile[];
|
|
312
311
|
}];
|
|
313
312
|
}
|
|
@@ -372,4 +371,4 @@ interface Fabric<T extends FabricOptions = FabricOptions> extends Kubb.Fabric {
|
|
|
372
371
|
}
|
|
373
372
|
//#endregion
|
|
374
373
|
export { FabricOptions as a, FileManager as c, UserParser as d, Extname as f, ResolvedFile as h, FabricMode as i, FileProcessor as l, KubbFile_d_exports as m, FabricConfig as n, Plugin as o, File as p, FabricContext as r, UserPlugin as s, Fabric as t, Parser as u };
|
|
375
|
-
//# sourceMappingURL=Fabric-
|
|
374
|
+
//# sourceMappingURL=Fabric-CtqeUUFU.d.ts.map
|
|
@@ -254,52 +254,51 @@ type FabricMode = 'sequential' | 'parallel';
|
|
|
254
254
|
*/
|
|
255
255
|
interface FabricEvents {
|
|
256
256
|
/** Called at the beginning of the app lifecycle. */
|
|
257
|
-
start: [];
|
|
257
|
+
'lifecycle:start': [];
|
|
258
258
|
/** Called at the end of the app lifecycle. */
|
|
259
|
-
end: [];
|
|
260
|
-
/** Called when Fabric is rendering. */
|
|
261
|
-
render: [{
|
|
259
|
+
'lifecycle:end': [];
|
|
260
|
+
/** Called when Fabric is rendering. Provides the Fabric instance. */
|
|
261
|
+
'lifecycle:render': [{
|
|
262
262
|
fabric: Fabric;
|
|
263
263
|
}];
|
|
264
|
-
/** Called once before any files are processed. */
|
|
265
|
-
'
|
|
264
|
+
/** Called once before any files are processed. Provides all files that will be processed. */
|
|
265
|
+
'files:processing:start': [{
|
|
266
266
|
files: ResolvedFile[];
|
|
267
267
|
}];
|
|
268
|
-
/**
|
|
269
|
-
|
|
270
|
-
*/
|
|
271
|
-
'file:add': [{
|
|
268
|
+
/** Called when FileManager is adding files to its cache. */
|
|
269
|
+
'files:added': [{
|
|
272
270
|
files: ResolvedFile[];
|
|
273
271
|
}];
|
|
274
|
-
'file
|
|
272
|
+
/** Called when resolving a file's path. Allows modification of the file path. */
|
|
273
|
+
'file:path:resolving': [{
|
|
275
274
|
file: File;
|
|
276
275
|
}];
|
|
277
|
-
'file
|
|
276
|
+
/** Called when resolving a file's name. Allows modification of the file name. */
|
|
277
|
+
'file:name:resolving': [{
|
|
278
278
|
file: File;
|
|
279
279
|
}];
|
|
280
|
-
|
|
280
|
+
/** Called before writing files to disk. Provides all files that will be written. */
|
|
281
|
+
'files:writing:start': [{
|
|
281
282
|
files: ResolvedFile[];
|
|
282
283
|
}];
|
|
283
|
-
|
|
284
|
+
/** Called after writing files to disk. Provides all files that were written. */
|
|
285
|
+
'files:writing:end': [{
|
|
284
286
|
files: ResolvedFile[];
|
|
285
287
|
}];
|
|
286
|
-
/** Called
|
|
287
|
-
'file:start': [{
|
|
288
|
+
/** Called when processing of an individual file begins. Provides file, current index, and total count. */
|
|
289
|
+
'file:processing:start': [{
|
|
288
290
|
file: ResolvedFile;
|
|
289
291
|
index: number;
|
|
290
292
|
total: number;
|
|
291
293
|
}];
|
|
292
|
-
/** Called
|
|
293
|
-
'file:end': [{
|
|
294
|
+
/** Called when processing of an individual file completes. Provides file, current index, and total count. */
|
|
295
|
+
'file:processing:end': [{
|
|
294
296
|
file: ResolvedFile;
|
|
295
297
|
index: number;
|
|
296
298
|
total: number;
|
|
297
299
|
}];
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
* Useful for progress bars or logging.
|
|
301
|
-
*/
|
|
302
|
-
'process:progress': [{
|
|
300
|
+
/** Called periodically to indicate processing progress. Useful for progress bars or logging. */
|
|
301
|
+
'files:processing:update': [{
|
|
303
302
|
processed: number;
|
|
304
303
|
total: number;
|
|
305
304
|
percentage: number;
|
|
@@ -307,7 +306,7 @@ interface FabricEvents {
|
|
|
307
306
|
file: ResolvedFile;
|
|
308
307
|
}];
|
|
309
308
|
/** Called once all files have been processed successfully. */
|
|
310
|
-
'
|
|
309
|
+
'files:processing:end': [{
|
|
311
310
|
files: ResolvedFile[];
|
|
312
311
|
}];
|
|
313
312
|
}
|
|
@@ -372,4 +371,4 @@ interface Fabric<T extends FabricOptions = FabricOptions> extends Kubb.Fabric {
|
|
|
372
371
|
}
|
|
373
372
|
//#endregion
|
|
374
373
|
export { FabricOptions as a, FileManager as c, UserParser as d, Extname as f, ResolvedFile as h, FabricMode as i, FileProcessor as l, KubbFile_d_exports as m, FabricConfig as n, Plugin as o, File as p, FabricContext as r, UserPlugin as s, Fabric as t, Parser as u };
|
|
375
|
-
//# sourceMappingURL=Fabric-
|
|
374
|
+
//# sourceMappingURL=Fabric-DlBN6CDR.d.cts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_defineParser = require('./defineParser-DODGK4rM.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/parsers/defaultParser.ts
|
|
4
|
-
const defaultParser =
|
|
4
|
+
const defaultParser = require_defineParser.defineParser({
|
|
5
5
|
name: "default",
|
|
6
6
|
extNames: [".json"],
|
|
7
7
|
install() {},
|
|
@@ -17,4 +17,4 @@ Object.defineProperty(exports, 'defaultParser', {
|
|
|
17
17
|
return defaultParser;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
//# sourceMappingURL=defaultParser-
|
|
20
|
+
//# sourceMappingURL=defaultParser-CIF-0xIK.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultParser-
|
|
1
|
+
{"version":3,"file":"defaultParser-CIF-0xIK.cjs","names":["defineParser"],"sources":["../src/parsers/defaultParser.ts"],"sourcesContent":["import { defineParser } from './defineParser.ts'\n\nexport const defaultParser = defineParser({\n name: 'default',\n extNames: ['.json'],\n install() {},\n async parse(file) {\n return file.sources.map((item) => item.value).join('\\n\\n')\n },\n})\n"],"mappings":";;;AAEA,MAAa,gBAAgBA,kCAAa;CACxC,MAAM;CACN,UAAU,CAAC,QAAQ;CACnB,UAAU;CACV,MAAM,MAAM,MAAM;AAChB,SAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;;CAE7D,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as defineParser } from "./defineParser-Bxv4mb-N.js";
|
|
2
2
|
|
|
3
3
|
//#region src/parsers/defaultParser.ts
|
|
4
|
-
const defaultParser =
|
|
4
|
+
const defaultParser = defineParser({
|
|
5
5
|
name: "default",
|
|
6
6
|
extNames: [".json"],
|
|
7
7
|
install() {},
|
|
@@ -12,4 +12,4 @@ const defaultParser = createParser({
|
|
|
12
12
|
|
|
13
13
|
//#endregion
|
|
14
14
|
export { defaultParser as t };
|
|
15
|
-
//# sourceMappingURL=defaultParser-
|
|
15
|
+
//# sourceMappingURL=defaultParser-DPHcM2NR.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultParser-
|
|
1
|
+
{"version":3,"file":"defaultParser-DPHcM2NR.js","names":[],"sources":["../src/parsers/defaultParser.ts"],"sourcesContent":["import { defineParser } from './defineParser.ts'\n\nexport const defaultParser = defineParser({\n name: 'default',\n extNames: ['.json'],\n install() {},\n async parse(file) {\n return file.sources.map((item) => item.value).join('\\n\\n')\n },\n})\n"],"mappings":";;;AAEA,MAAa,gBAAgB,aAAa;CACxC,MAAM;CACN,UAAU,CAAC,QAAQ;CACnB,UAAU;CACV,MAAM,MAAM,MAAM;AAChB,SAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;;CAE7D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"defineParser-Bxv4mb-N.js","names":[],"sources":["../src/parsers/defineParser.ts"],"sourcesContent":["import type { Parser, UserParser } from './types.ts'\n\nexport function defineParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta> {\n return {\n type: 'parser',\n ...parser,\n }\n}\n"],"mappings":";AAEA,SAAgB,aAA6D,QAA8D;AACzI,QAAO;EACL,MAAM;EACN,GAAG;EACJ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/parsers/defineParser.ts
|
|
3
|
+
function defineParser(parser) {
|
|
4
|
+
return {
|
|
5
|
+
type: "parser",
|
|
6
|
+
...parser
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
Object.defineProperty(exports, 'defineParser', {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return defineParser;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=defineParser-DODGK4rM.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"defineParser-DODGK4rM.cjs","names":[],"sources":["../src/parsers/defineParser.ts"],"sourcesContent":["import type { Parser, UserParser } from './types.ts'\n\nexport function defineParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta> {\n return {\n type: 'parser',\n ...parser,\n }\n}\n"],"mappings":";;AAEA,SAAgB,aAA6D,QAA8D;AACzI,QAAO;EACL,MAAM;EACN,GAAG;EACJ"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_trimExtName = require('./trimExtName-DaBSwMN-.cjs');
|
|
2
2
|
const require_defineProperty = require('./defineProperty-BOlj8-IY.cjs');
|
|
3
|
-
require('./
|
|
4
|
-
const require_defaultParser = require('./defaultParser-
|
|
3
|
+
require('./defineParser-DODGK4rM.cjs');
|
|
4
|
+
const require_defaultParser = require('./defaultParser-CIF-0xIK.cjs');
|
|
5
5
|
let natural_orderby = require("natural-orderby");
|
|
6
6
|
let p_limit = require("p-limit");
|
|
7
7
|
p_limit = require_trimExtName.__toESM(p_limit);
|
|
@@ -85,11 +85,11 @@ var FileProcessor = class {
|
|
|
85
85
|
return parser.parse(file, { extname: parseExtName });
|
|
86
86
|
}
|
|
87
87
|
async run(files, { parsers, mode = "sequential", dryRun, extension } = {}) {
|
|
88
|
-
await this.events.emit("
|
|
88
|
+
await this.events.emit("files:processing:start", { files });
|
|
89
89
|
const total = files.length;
|
|
90
90
|
let processed = 0;
|
|
91
91
|
const processOne = async (resolvedFile, index) => {
|
|
92
|
-
await this.events.emit("file:start", {
|
|
92
|
+
await this.events.emit("file:processing:start", {
|
|
93
93
|
file: resolvedFile,
|
|
94
94
|
index,
|
|
95
95
|
total
|
|
@@ -100,14 +100,14 @@ var FileProcessor = class {
|
|
|
100
100
|
});
|
|
101
101
|
const currentProcessed = ++processed;
|
|
102
102
|
const percentage = currentProcessed / total * 100;
|
|
103
|
-
await this.events.emit("
|
|
103
|
+
await this.events.emit("files:processing:update", {
|
|
104
104
|
file: resolvedFile,
|
|
105
105
|
source,
|
|
106
106
|
processed: currentProcessed,
|
|
107
107
|
percentage,
|
|
108
108
|
total
|
|
109
109
|
});
|
|
110
|
-
await this.events.emit("file:end", {
|
|
110
|
+
await this.events.emit("file:processing:end", {
|
|
111
111
|
file: resolvedFile,
|
|
112
112
|
index,
|
|
113
113
|
total
|
|
@@ -122,7 +122,7 @@ var FileProcessor = class {
|
|
|
122
122
|
const promises = files.map((resolvedFile, index) => require_defineProperty._classPrivateFieldGet2(_limit, this).call(this, () => processOne(resolvedFile, index)));
|
|
123
123
|
await Promise.all(promises);
|
|
124
124
|
}
|
|
125
|
-
await this.events.emit("
|
|
125
|
+
await this.events.emit("files:processing:end", { files });
|
|
126
126
|
return files;
|
|
127
127
|
}
|
|
128
128
|
};
|
|
@@ -202,7 +202,7 @@ var FileManager = class {
|
|
|
202
202
|
this.flush();
|
|
203
203
|
resolvedFiles.push(resolvedFile);
|
|
204
204
|
}
|
|
205
|
-
await this.events.emit("
|
|
205
|
+
await this.events.emit("files:added", { files: resolvedFiles });
|
|
206
206
|
return resolvedFiles;
|
|
207
207
|
}
|
|
208
208
|
async upsert(...files) {
|
|
@@ -222,7 +222,7 @@ var FileManager = class {
|
|
|
222
222
|
this.flush();
|
|
223
223
|
resolvedFiles.push(resolvedFile);
|
|
224
224
|
}
|
|
225
|
-
await this.events.emit("
|
|
225
|
+
await this.events.emit("files:added", { files: resolvedFiles });
|
|
226
226
|
return resolvedFiles;
|
|
227
227
|
}
|
|
228
228
|
flush() {
|
|
@@ -252,107 +252,97 @@ var FileManager = class {
|
|
|
252
252
|
return files;
|
|
253
253
|
}
|
|
254
254
|
async write(options) {
|
|
255
|
-
await this.events.emit("
|
|
255
|
+
await this.events.emit("files:writing:start", { files: this.files });
|
|
256
256
|
const resolvedFiles = await this.processor.run(this.files, options);
|
|
257
257
|
this.clear();
|
|
258
|
-
await this.events.emit("
|
|
258
|
+
await this.events.emit("files:writing:end", { files: resolvedFiles });
|
|
259
259
|
return resolvedFiles;
|
|
260
260
|
}
|
|
261
261
|
};
|
|
262
262
|
function _resolvePath(file) {
|
|
263
|
-
this.events.emit("file:
|
|
263
|
+
this.events.emit("file:path:resolving", { file });
|
|
264
264
|
return file;
|
|
265
265
|
}
|
|
266
266
|
function _resolveName(file) {
|
|
267
|
-
this.events.emit("file:
|
|
267
|
+
this.events.emit("file:name:resolving", { file });
|
|
268
268
|
return file;
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
//#endregion
|
|
272
|
-
//#region src/
|
|
272
|
+
//#region src/createFabric.ts
|
|
273
273
|
/**
|
|
274
|
-
*
|
|
274
|
+
* Creates a new Fabric instance
|
|
275
275
|
*
|
|
276
276
|
* @example
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* })
|
|
277
|
+
* const fabric = createFabric()
|
|
278
|
+
* fabric.use(myPlugin())
|
|
280
279
|
*/
|
|
281
|
-
function
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (pluginOrParser.
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
Object.assign(fabric, injected);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
if (pluginOrParser.type === "parser") {
|
|
327
|
-
if (installedParserNames.has(pluginOrParser.name)) console.warn(`Parser "${pluginOrParser.name}" already applied.`);
|
|
328
|
-
else installedParserNames.add(pluginOrParser.name);
|
|
329
|
-
if (pluginOrParser.extNames) for (const extName of pluginOrParser.extNames) {
|
|
330
|
-
const existing = installedParsers.get(extName);
|
|
331
|
-
if (existing && existing.name !== pluginOrParser.name) console.warn(`Parser "${pluginOrParser.name}" is overriding parser "${existing.name}" for extension "${extName}".`);
|
|
332
|
-
installedParsers.set(extName, pluginOrParser);
|
|
333
|
-
}
|
|
280
|
+
function createFabric(config = { mode: "sequential" }) {
|
|
281
|
+
const events = new AsyncEventEmitter();
|
|
282
|
+
const installedPlugins = /* @__PURE__ */ new Set();
|
|
283
|
+
const installedParsers = /* @__PURE__ */ new Map();
|
|
284
|
+
const installedParserNames = /* @__PURE__ */ new Set();
|
|
285
|
+
const fileManager = new FileManager({ events });
|
|
286
|
+
const context = {
|
|
287
|
+
get files() {
|
|
288
|
+
return fileManager.files;
|
|
289
|
+
},
|
|
290
|
+
async addFile(...files) {
|
|
291
|
+
await fileManager.add(...files);
|
|
292
|
+
},
|
|
293
|
+
config,
|
|
294
|
+
fileManager,
|
|
295
|
+
installedPlugins,
|
|
296
|
+
installedParsers,
|
|
297
|
+
on: events.on.bind(events),
|
|
298
|
+
off: events.off.bind(events),
|
|
299
|
+
onOnce: events.onOnce.bind(events),
|
|
300
|
+
removeAll: events.removeAll.bind(events),
|
|
301
|
+
emit: events.emit.bind(events)
|
|
302
|
+
};
|
|
303
|
+
const fabric = {
|
|
304
|
+
context,
|
|
305
|
+
get files() {
|
|
306
|
+
return fileManager.files;
|
|
307
|
+
},
|
|
308
|
+
async addFile(...files) {
|
|
309
|
+
await fileManager.add(...files);
|
|
310
|
+
},
|
|
311
|
+
async upsertFile(...files) {
|
|
312
|
+
await fileManager.upsert(...files);
|
|
313
|
+
},
|
|
314
|
+
async use(pluginOrParser, ...options) {
|
|
315
|
+
if (pluginOrParser.type === "plugin") {
|
|
316
|
+
if (installedPlugins.has(pluginOrParser)) console.warn(`Plugin "${pluginOrParser.name}" already applied.`);
|
|
317
|
+
else installedPlugins.add(pluginOrParser);
|
|
318
|
+
if (e(pluginOrParser.inject)) {
|
|
319
|
+
const injecter = pluginOrParser.inject;
|
|
320
|
+
const injected = injecter(context, ...options);
|
|
321
|
+
Object.assign(fabric, injected);
|
|
334
322
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
323
|
+
}
|
|
324
|
+
if (pluginOrParser.type === "parser") {
|
|
325
|
+
if (installedParserNames.has(pluginOrParser.name)) console.warn(`Parser "${pluginOrParser.name}" already applied.`);
|
|
326
|
+
else installedParserNames.add(pluginOrParser.name);
|
|
327
|
+
if (pluginOrParser.extNames) for (const extName of pluginOrParser.extNames) {
|
|
328
|
+
const existing = installedParsers.get(extName);
|
|
329
|
+
if (existing && existing.name !== pluginOrParser.name) console.warn(`Parser "${pluginOrParser.name}" is overriding parser "${existing.name}" for extension "${extName}".`);
|
|
330
|
+
installedParsers.set(extName, pluginOrParser);
|
|
338
331
|
}
|
|
339
|
-
return fabric;
|
|
340
332
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
333
|
+
if (e(pluginOrParser.install)) {
|
|
334
|
+
const installer = pluginOrParser.install;
|
|
335
|
+
await installer(context, ...options);
|
|
336
|
+
}
|
|
337
|
+
return fabric;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
return fabric;
|
|
346
341
|
}
|
|
347
342
|
|
|
348
|
-
//#endregion
|
|
349
|
-
//#region src/createFabric.ts
|
|
350
|
-
const createFabric = defineFabric();
|
|
351
|
-
|
|
352
343
|
//#endregion
|
|
353
344
|
exports.FileManager = FileManager;
|
|
354
345
|
exports.FileProcessor = FileProcessor;
|
|
355
346
|
exports.createFabric = createFabric;
|
|
356
347
|
exports.createFile = require_defineProperty.createFile;
|
|
357
|
-
exports.defineFabric = defineFabric;
|
|
358
348
|
//# sourceMappingURL=index.cjs.map
|