@kubb/fabric-core 0.2.0 → 0.2.2
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 +49 -78
- package/dist/{App-ztRQpZS9.d.ts → Fabric-CCPgegwe.d.cts} +29 -29
- package/dist/{App-Cjd-lGfW.d.cts → Fabric-Cu_YHe4S.d.ts} +29 -29
- package/dist/index-BUculP1D.d.cts +18 -0
- package/dist/index-CvkyZHXK.d.ts +18 -0
- package/dist/index.cjs +17 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/parsers/typescript.d.cts +2 -2
- package/dist/parsers/typescript.d.ts +2 -2
- package/dist/parsers.d.cts +2 -2
- package/dist/parsers.d.ts +2 -2
- package/dist/plugins.cjs +54 -30
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +5 -5
- package/dist/plugins.d.ts +5 -5
- package/dist/plugins.js +54 -29
- package/dist/plugins.js.map +1 -1
- package/dist/types.d.cts +3 -3
- package/dist/types.d.ts +3 -3
- package/dist/{typescriptParser-DDr_EXfe.d.ts → typescriptParser-CCbr9PD6.d.cts} +2 -2
- package/dist/{typescriptParser-CBt00C7L.d.cts → typescriptParser-DHu674Vq.d.ts} +2 -2
- package/package.json +2 -4
- package/src/{App.ts → Fabric.ts} +16 -16
- package/src/FileManager.ts +4 -4
- package/src/FileProcessor.ts +5 -5
- package/src/createFabric.ts +3 -0
- package/src/{defineApp.ts → defineFabric.ts} +19 -19
- package/src/index.ts +3 -3
- package/src/parsers/types.ts +1 -1
- package/src/plugins/barrelPlugin.ts +2 -2
- package/src/plugins/fsPlugin.ts +48 -55
- package/src/plugins/graphPlugin.ts +1 -1
- package/src/plugins/types.ts +1 -1
- package/src/types.ts +2 -4
- package/src/utils/open.ts +36 -0
- package/dist/index-BUERYeq7.d.cts +0 -18
- package/dist/index-DfaD7Pj_.d.ts +0 -18
- package/src/createApp.ts +0 -3
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ It offers a lightweight layer for file generation while orchestrating the overal
|
|
|
28
28
|
> [!WARNING]
|
|
29
29
|
> Fabric is under active development. Until a stable 1.0 release, minor versions may occasionally include breaking changes. Please check release notes and PR titles for breaking changes.
|
|
30
30
|
|
|
31
|
+
|
|
31
32
|
# Features
|
|
32
33
|
|
|
33
34
|
- 🎨 Declarative file generation — Create files effortlessly using JSX or JavaScript syntax.
|
|
@@ -37,16 +38,16 @@ It offers a lightweight layer for file generation while orchestrating the overal
|
|
|
37
38
|
|
|
38
39
|
## Write a TypeScript file
|
|
39
40
|
|
|
40
|
-
Below is a minimal example showing how `
|
|
41
|
+
Below is a minimal example showing how `createFabric` works together with plugins and parsers via `fabric.use`.
|
|
41
42
|
|
|
42
43
|
```ts
|
|
43
|
-
import {
|
|
44
|
+
import { createFabric } from '@kubb/fabric-core'
|
|
44
45
|
import { fsPlugin } from '@kubb/fabric-core/plugins'
|
|
45
46
|
import { typescriptParser, createParser } from '@kubb/fabric-core/parsers'
|
|
46
47
|
|
|
47
|
-
const
|
|
48
|
+
const fabric = createFabric()
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
fabric.use(fsPlugin, {
|
|
50
51
|
dryRun: false,
|
|
51
52
|
onBeforeWrite: (path, data) => {
|
|
52
53
|
console.log('About to write:', path)
|
|
@@ -54,9 +55,9 @@ app.use(fsPlugin, {
|
|
|
54
55
|
clean: { path: './generated' },
|
|
55
56
|
})
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
fabric.use(typescriptParser)
|
|
58
59
|
|
|
59
|
-
await
|
|
60
|
+
await fabric.addFile({
|
|
60
61
|
baseName: 'index.ts',
|
|
61
62
|
path: './generated/index.ts',
|
|
62
63
|
sources: [
|
|
@@ -64,27 +65,27 @@ await app.addFile({
|
|
|
64
65
|
],
|
|
65
66
|
})
|
|
66
67
|
|
|
67
|
-
await
|
|
68
|
+
await fabric.write()
|
|
68
69
|
|
|
69
70
|
```
|
|
70
71
|
|
|
71
72
|
# API Reference
|
|
72
73
|
|
|
73
74
|
## Core
|
|
74
|
-
### `
|
|
75
|
-
Returns
|
|
76
|
-
- `
|
|
77
|
-
- `
|
|
78
|
-
- `
|
|
79
|
-
- `
|
|
75
|
+
### `createFabric(options?): Fabric`
|
|
76
|
+
Returns a Fabric instance with:
|
|
77
|
+
- `fabric.use(pluginOrParser, ...options) => Fabric` — register plugins and parsers.
|
|
78
|
+
- `fabric.addFile(...files)` — queue in-memory files to generate.
|
|
79
|
+
- `fabric.files` — getter with all queued files.
|
|
80
|
+
- `fabric.context` — internal context holding events, options, FileManager, installed plugins/parsers.
|
|
80
81
|
|
|
81
|
-
### `
|
|
82
|
-
Factory to create your own `
|
|
82
|
+
### `defineFabric(instance?): () => Fabric`
|
|
83
|
+
Factory to create your own `createFabric` with an optional bootstrap `instance(fabric)` called on creation.
|
|
83
84
|
|
|
84
|
-
###
|
|
85
|
+
### Events (emitted by the core during processing)
|
|
85
86
|
- `start`
|
|
86
87
|
- `end`
|
|
87
|
-
- `render {
|
|
88
|
+
- `render { fabric }`
|
|
88
89
|
- `file:add { files }`
|
|
89
90
|
- `write:start { files }`
|
|
90
91
|
- `write:end { files }`
|
|
@@ -109,7 +110,7 @@ import { fsPlugin } from '@kubb/fabric-core/plugins'
|
|
|
109
110
|
| onBeforeWrite | `(path: string, data: string \| undefined) => void \| Promise<void>` | — | Called right before each file write on `process:progress`. |
|
|
110
111
|
| clean | `{ path: string }` | — | If provided, removes the directory at `path` before writing any files. |
|
|
111
112
|
|
|
112
|
-
Injected `
|
|
113
|
+
Injected `fabric.write` options (via `fsPlugin`):
|
|
113
114
|
|
|
114
115
|
| Option | Type | Default | Description |
|
|
115
116
|
|---|----------------------------------|---|---|
|
|
@@ -128,7 +129,7 @@ import { barrelPlugin } from '@kubb/fabric-core/plugins'
|
|
|
128
129
|
| mode | `'all' \| 'named' \| 'propagate' \| false` | — | Controls how exports are generated: all exports, only named exports, propagate (skip barrels), or disabled. |
|
|
129
130
|
| dryRun | `boolean` | `false` | If true, computes barrels but skips writing. |
|
|
130
131
|
|
|
131
|
-
Injected `
|
|
132
|
+
Injected `fabric.writeEntry` parameters (via `barrelPlugin`):
|
|
132
133
|
|
|
133
134
|
| Param | Type | Description |
|
|
134
135
|
|---|--------------------------------------------|---|
|
|
@@ -184,28 +185,28 @@ Injected methods (via `reactPlugin`):
|
|
|
184
185
|
|
|
185
186
|
#### `createPlugin`
|
|
186
187
|
|
|
187
|
-
Factory to declare a plugin that can be registered via `
|
|
188
|
+
Factory to declare a plugin that can be registered via `fabric.use`.
|
|
188
189
|
|
|
189
|
-
| Field
|
|
190
|
-
|
|
191
|
-
| `name`
|
|
192
|
-
| `install(
|
|
193
|
-
| `inject?(
|
|
190
|
+
| Field | Required | Description |
|
|
191
|
+
|----------------------------|---|------------------------------------------------------------------------------------------------------------------------------|
|
|
192
|
+
| `name` | Yes | String identifier of your plugin. |
|
|
193
|
+
| `install(fabric, options)` | Yes | Called when the plugin is registered. You can subscribe to core events and perform side effects here. |
|
|
194
|
+
| `inject?(fabric, options)` | No | Return synchronously the runtime methods/properties to merge into `fabric` (e.g. `write`, `render`). This must not be async. |
|
|
194
195
|
|
|
195
196
|
Example:
|
|
196
197
|
|
|
197
198
|
```ts
|
|
198
|
-
import {
|
|
199
|
+
import { createFabric } from '@kubb/fabric-core'
|
|
199
200
|
import { createPlugin } from '@kubb/fabric-core/plugins'
|
|
200
201
|
|
|
201
202
|
const helloPlugin = createPlugin<{ name?: string }, { sayHello: (msg?: string) => void }>({
|
|
202
203
|
name: 'helloPlugin',
|
|
203
|
-
install(
|
|
204
|
-
|
|
205
|
-
console.log('
|
|
204
|
+
install(fabric, options) {
|
|
205
|
+
fabric.context.events.on('start', () => {
|
|
206
|
+
console.log('Fabric started')
|
|
206
207
|
})
|
|
207
208
|
},
|
|
208
|
-
inject(
|
|
209
|
+
inject(fabric, options) {
|
|
209
210
|
return {
|
|
210
211
|
sayHello(msg = options?.name ?? 'world') {
|
|
211
212
|
console.log(`Hello ${msg}!`)
|
|
@@ -214,9 +215,9 @@ const helloPlugin = createPlugin<{ name?: string }, { sayHello: (msg?: string) =
|
|
|
214
215
|
},
|
|
215
216
|
})
|
|
216
217
|
|
|
217
|
-
const
|
|
218
|
-
await
|
|
219
|
-
|
|
218
|
+
const fabric = createFabric()
|
|
219
|
+
await fabric.use(helloPlugin, { name: 'Fabric' })
|
|
220
|
+
fabric.sayHello() // -> Hello Fabric!
|
|
220
221
|
```
|
|
221
222
|
|
|
222
223
|
## Parsers
|
|
@@ -248,7 +249,7 @@ import { tsxParser } from '@kubb/fabric-core/parsers'
|
|
|
248
249
|
|
|
249
250
|
#### `defaultParser`
|
|
250
251
|
|
|
251
|
-
Fallback parser used when no extension mapping is provided to `
|
|
252
|
+
Fallback parser used when no extension mapping is provided to `fabric.write`.
|
|
252
253
|
|
|
253
254
|
```
|
|
254
255
|
import { defaultParser } @kubb/fabric-core/parsers`
|
|
@@ -259,25 +260,25 @@ import { defaultParser } @kubb/fabric-core/parsers`
|
|
|
259
260
|
| file | `KubbFile.File` | -| File that will be used to be parsed. |
|
|
260
261
|
|
|
261
262
|
#### `createParser`
|
|
262
|
-
Factory to declare a parser that can be registered via `
|
|
263
|
+
Factory to declare a parser that can be registered via `fabric.use` and selected by `extNames` during `fabirc.write`.
|
|
263
264
|
|
|
264
|
-
| Field
|
|
265
|
-
|
|
266
|
-
| `name`
|
|
267
|
-
| `extNames`
|
|
268
|
-
| `install(
|
|
265
|
+
| Field | Required | Description |
|
|
266
|
+
|----------------------------|---|-----------------------------------------------------------------------------------------------------------------|
|
|
267
|
+
| `name` | Yes | String identifier of your parser. |
|
|
268
|
+
| `extNames` | Yes | List of file extensions this parser can handle (e.g. ['.ts']). Use `undefined` for the default parser fallback. |
|
|
269
|
+
| `install(fabric, options)` | No | Optional setup when the parser is registered (subscribe to events, set state, etc.). |
|
|
269
270
|
| `parse(file, { extname })` | Yes | Must return the final string that will be written for the given file. |
|
|
270
271
|
|
|
271
272
|
Example:
|
|
272
273
|
|
|
273
274
|
```ts
|
|
274
|
-
import {
|
|
275
|
+
import { createFabric } from '@kubb/fabric-core'
|
|
275
276
|
import { createParser } from '@kubb/fabric-core/parsers'
|
|
276
277
|
|
|
277
278
|
const vueParser = createParser<{ banner?: string }>({
|
|
278
279
|
name: 'vueParser',
|
|
279
280
|
extNames: ['.vue'],
|
|
280
|
-
async install(
|
|
281
|
+
async install(fabric, options) {
|
|
281
282
|
// Optional setup
|
|
282
283
|
},
|
|
283
284
|
async parse(file, { extname }) {
|
|
@@ -287,43 +288,13 @@ const vueParser = createParser<{ banner?: string }>({
|
|
|
287
288
|
},
|
|
288
289
|
})
|
|
289
290
|
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
291
|
+
const fabric = createFabric()
|
|
292
|
+
fabric.use(vueParser)
|
|
293
|
+
fabric.use(fsPlugin); // make it possible to write to the filesystem
|
|
293
294
|
|
|
294
|
-
|
|
295
|
+
fabric.write({ extension: { '.vue': '.ts' } })
|
|
295
296
|
```
|
|
296
297
|
|
|
297
298
|
> [!NOTE]
|
|
298
|
-
> - `
|
|
299
|
-
> - When extension mapping is provided to `
|
|
300
|
-
|
|
301
|
-
## Supporting Kubb
|
|
302
|
-
|
|
303
|
-
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
304
|
-
|
|
305
|
-
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
306
|
-
|
|
307
|
-
<p align="center">
|
|
308
|
-
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
309
|
-
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
310
|
-
</a>
|
|
311
|
-
</p>
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
<!-- Badges -->
|
|
315
|
-
|
|
316
|
-
[npm-version-src]: https://img.shields.io/npm/v/@kubb/fabric-core?flat&colorA=18181B&colorB=f58517
|
|
317
|
-
[npm-version-href]: https://npmjs.com/package/@kubb/fabric-core
|
|
318
|
-
[npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/fabric-core?flat&colorA=18181B&colorB=f58517
|
|
319
|
-
[npm-downloads-href]: https://npmjs.com/package/@kubb/fabric-core
|
|
320
|
-
[license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
|
|
321
|
-
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
322
|
-
[build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
|
|
323
|
-
[build-href]: https://www.npmjs.com/package/@kubb/fabric-core
|
|
324
|
-
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/fabric-core?style=flat&colorA=18181B&colorB=f58517
|
|
325
|
-
[minified-href]: https://www.npmjs.com/package/@kubb/fabric-core
|
|
326
|
-
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
327
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/fabric-core
|
|
328
|
-
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
329
|
-
[sponsors-href]: https://github.com/sponsors/stijnvanhulle/
|
|
299
|
+
> - `fabric.use` accepts both plugins and parsers. The `fsPlugin` handles I/O and adds `fabric.write`. Parsers decide how files are converted to strings for specific extensions.
|
|
300
|
+
> - When extension mapping is provided to `fabric.write`, Fabric picks a parser whose `extNames` include the file’s extension. Otherwise, the default parser is used.
|
|
@@ -77,7 +77,7 @@ type BaseName = `${string}.${string}`;
|
|
|
77
77
|
type Path = string;
|
|
78
78
|
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
79
79
|
type OptionalPath = Path | undefined | null;
|
|
80
|
-
type File<TMeta
|
|
80
|
+
type File<TMeta extends object = object> = {
|
|
81
81
|
/**
|
|
82
82
|
* Name to be used to create the path
|
|
83
83
|
* Based on UNIX basename, `${name}.extname`
|
|
@@ -94,13 +94,13 @@ type File<TMeta$1 extends object = object> = {
|
|
|
94
94
|
/**
|
|
95
95
|
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
96
96
|
*/
|
|
97
|
-
meta?: TMeta
|
|
97
|
+
meta?: TMeta;
|
|
98
98
|
banner?: string;
|
|
99
99
|
footer?: string;
|
|
100
100
|
};
|
|
101
101
|
type ResolvedImport = Import;
|
|
102
102
|
type ResolvedExport = Export;
|
|
103
|
-
type ResolvedFile<TMeta
|
|
103
|
+
type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
|
|
104
104
|
/**
|
|
105
105
|
* @default hash
|
|
106
106
|
*/
|
|
@@ -116,7 +116,7 @@ type ResolvedFile<TMeta$1 extends object = object> = File<TMeta$1> & {
|
|
|
116
116
|
};
|
|
117
117
|
//#endregion
|
|
118
118
|
//#region src/plugins/types.d.ts
|
|
119
|
-
type Plugin<TOptions = unknown, TAppExtension
|
|
119
|
+
type Plugin<TOptions = unknown, TAppExtension extends Record<string, any> = {}> = {
|
|
120
120
|
name: string;
|
|
121
121
|
type: 'plugin';
|
|
122
122
|
install: Install<TOptions>;
|
|
@@ -125,15 +125,15 @@ type Plugin<TOptions = unknown, TAppExtension$1 extends Record<string, any> = {}
|
|
|
125
125
|
* Merged into the app instance after install.
|
|
126
126
|
* This cannot be async
|
|
127
127
|
*/
|
|
128
|
-
inject?: Inject<TOptions, TAppExtension
|
|
128
|
+
inject?: Inject<TOptions, TAppExtension>;
|
|
129
129
|
};
|
|
130
|
-
type UserPlugin<TOptions = unknown, TAppExtension
|
|
130
|
+
type UserPlugin<TOptions = unknown, TAppExtension extends Record<string, any> = {}> = Omit<Plugin<TOptions, TAppExtension>, 'type'>;
|
|
131
131
|
//#endregion
|
|
132
132
|
//#region src/parsers/types.d.ts
|
|
133
133
|
type PrintOptions = {
|
|
134
134
|
extname?: Extname;
|
|
135
135
|
};
|
|
136
|
-
type Parser<TOptions = unknown, TMeta
|
|
136
|
+
type Parser<TOptions = unknown, TMeta extends object = any> = {
|
|
137
137
|
name: string;
|
|
138
138
|
type: 'parser';
|
|
139
139
|
/**
|
|
@@ -144,9 +144,9 @@ type Parser<TOptions = unknown, TMeta$1 extends object = any> = {
|
|
|
144
144
|
/**
|
|
145
145
|
* Convert a file to string
|
|
146
146
|
*/
|
|
147
|
-
parse(file: ResolvedFile<TMeta
|
|
147
|
+
parse(file: ResolvedFile<TMeta>, options: PrintOptions): Promise<string>;
|
|
148
148
|
};
|
|
149
|
-
type UserParser<TOptions = unknown, TMeta
|
|
149
|
+
type UserParser<TOptions = unknown, TMeta extends object = any> = Omit<Parser<TOptions, TMeta>, 'type'>;
|
|
150
150
|
//#endregion
|
|
151
151
|
//#region src/utils/AsyncEventEmitter.d.ts
|
|
152
152
|
declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
|
|
@@ -167,18 +167,18 @@ type ProcessFilesProps = {
|
|
|
167
167
|
/**
|
|
168
168
|
* @default 'sequential'
|
|
169
169
|
*/
|
|
170
|
-
mode?:
|
|
170
|
+
mode?: FabricMode;
|
|
171
171
|
};
|
|
172
172
|
type GetParseOptions = {
|
|
173
173
|
parsers?: Set<Parser>;
|
|
174
174
|
extension?: Record<Extname, Extname | ''>;
|
|
175
175
|
};
|
|
176
176
|
type Options$1 = {
|
|
177
|
-
events?: AsyncEventEmitter<
|
|
177
|
+
events?: AsyncEventEmitter<FabricEvents>;
|
|
178
178
|
};
|
|
179
179
|
declare class FileProcessor {
|
|
180
180
|
#private;
|
|
181
|
-
events: AsyncEventEmitter<
|
|
181
|
+
events: AsyncEventEmitter<FabricEvents>;
|
|
182
182
|
constructor({
|
|
183
183
|
events
|
|
184
184
|
}?: Options$1);
|
|
@@ -196,11 +196,11 @@ declare class FileProcessor {
|
|
|
196
196
|
//#endregion
|
|
197
197
|
//#region src/FileManager.d.ts
|
|
198
198
|
type Options = {
|
|
199
|
-
events?: AsyncEventEmitter<
|
|
199
|
+
events?: AsyncEventEmitter<FabricEvents>;
|
|
200
200
|
};
|
|
201
201
|
declare class FileManager {
|
|
202
202
|
#private;
|
|
203
|
-
events: AsyncEventEmitter<
|
|
203
|
+
events: AsyncEventEmitter<FabricEvents>;
|
|
204
204
|
processor: FileProcessor;
|
|
205
205
|
constructor({
|
|
206
206
|
events
|
|
@@ -214,19 +214,19 @@ declare class FileManager {
|
|
|
214
214
|
write(options: ProcessFilesProps): Promise<ResolvedFile[]>;
|
|
215
215
|
}
|
|
216
216
|
//#endregion
|
|
217
|
-
//#region src/
|
|
217
|
+
//#region src/Fabric.d.ts
|
|
218
218
|
declare global {
|
|
219
219
|
namespace Kubb {
|
|
220
|
-
interface
|
|
220
|
+
interface Fabric {}
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
-
type
|
|
223
|
+
type FabricOptions = {
|
|
224
224
|
/**
|
|
225
225
|
* @default 'sequential'
|
|
226
226
|
*/
|
|
227
|
-
mode?:
|
|
227
|
+
mode?: FabricMode;
|
|
228
228
|
};
|
|
229
|
-
type
|
|
229
|
+
type FabricEvents = {
|
|
230
230
|
/**
|
|
231
231
|
* Called in the beginning of the app lifecycle.
|
|
232
232
|
*/
|
|
@@ -239,7 +239,7 @@ type AppEvents = {
|
|
|
239
239
|
* Called when being rendered
|
|
240
240
|
*/
|
|
241
241
|
render: [{
|
|
242
|
-
|
|
242
|
+
fabric: Fabric;
|
|
243
243
|
}];
|
|
244
244
|
/**
|
|
245
245
|
* Called once before processing any files.
|
|
@@ -293,23 +293,23 @@ type AppEvents = {
|
|
|
293
293
|
files: ResolvedFile[];
|
|
294
294
|
}];
|
|
295
295
|
};
|
|
296
|
-
type
|
|
296
|
+
type FabricContext<TOptions extends FabricOptions> = {
|
|
297
297
|
options?: TOptions;
|
|
298
|
-
events: AsyncEventEmitter<
|
|
298
|
+
events: AsyncEventEmitter<FabricEvents>;
|
|
299
299
|
fileManager: FileManager;
|
|
300
300
|
installedPlugins: Set<Plugin>;
|
|
301
301
|
installedParsers: Set<Parser>;
|
|
302
302
|
};
|
|
303
|
-
type
|
|
303
|
+
type FabricMode = 'sequential' | 'parallel';
|
|
304
304
|
type AllOptional<T> = {} extends T ? true : false;
|
|
305
|
-
type Install<TOptions = unknown> = TOptions extends any[] ? (app:
|
|
306
|
-
type Inject<TOptions = unknown, TAppExtension
|
|
307
|
-
interface
|
|
308
|
-
context:
|
|
305
|
+
type Install<TOptions = unknown> = TOptions extends any[] ? (app: Fabric, ...options: TOptions) => void | Promise<void> : AllOptional<TOptions> extends true ? (app: Fabric, options: TOptions | undefined) => void | Promise<void> : (app: Fabric, options: TOptions) => void | Promise<void>;
|
|
306
|
+
type Inject<TOptions = unknown, TAppExtension extends Record<string, any> = {}> = TOptions extends any[] ? (app: Fabric, ...options: TOptions) => Partial<TAppExtension> : AllOptional<TOptions> extends true ? (app: Fabric, options: TOptions | undefined) => Partial<TAppExtension> : (app: Fabric, options: TOptions) => Partial<TAppExtension>;
|
|
307
|
+
interface Fabric<TOptions extends FabricOptions = FabricOptions> extends Kubb.Fabric {
|
|
308
|
+
context: FabricContext<TOptions>;
|
|
309
309
|
files: Array<ResolvedFile>;
|
|
310
310
|
use<TPluginOptions = unknown, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TPluginOptions, TAppExtension> | Parser<TPluginOptions, TMeta>, ...options: TPluginOptions extends any[] ? NoInfer<TPluginOptions> : AllOptional<TPluginOptions> extends true ? [NoInfer<TPluginOptions>?] : [NoInfer<TPluginOptions>]): (this & TAppExtension) | Promise<this & TAppExtension>;
|
|
311
311
|
addFile(...files: Array<File>): Promise<void>;
|
|
312
312
|
}
|
|
313
313
|
//#endregion
|
|
314
|
-
export {
|
|
315
|
-
//# sourceMappingURL=
|
|
314
|
+
export { FileManager as a, UserParser as c, Extname as d, File as f, FabricOptions as i, Plugin as l, ResolvedFile as m, FabricContext as n, FileProcessor as o, KubbFile_d_exports as p, FabricMode as r, Parser as s, Fabric as t, UserPlugin as u };
|
|
315
|
+
//# sourceMappingURL=Fabric-CCPgegwe.d.cts.map
|
|
@@ -77,7 +77,7 @@ type BaseName = `${string}.${string}`;
|
|
|
77
77
|
type Path = string;
|
|
78
78
|
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
79
79
|
type OptionalPath = Path | undefined | null;
|
|
80
|
-
type File<TMeta
|
|
80
|
+
type File<TMeta extends object = object> = {
|
|
81
81
|
/**
|
|
82
82
|
* Name to be used to create the path
|
|
83
83
|
* Based on UNIX basename, `${name}.extname`
|
|
@@ -94,13 +94,13 @@ type File<TMeta$1 extends object = object> = {
|
|
|
94
94
|
/**
|
|
95
95
|
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
96
96
|
*/
|
|
97
|
-
meta?: TMeta
|
|
97
|
+
meta?: TMeta;
|
|
98
98
|
banner?: string;
|
|
99
99
|
footer?: string;
|
|
100
100
|
};
|
|
101
101
|
type ResolvedImport = Import;
|
|
102
102
|
type ResolvedExport = Export;
|
|
103
|
-
type ResolvedFile<TMeta
|
|
103
|
+
type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
|
|
104
104
|
/**
|
|
105
105
|
* @default hash
|
|
106
106
|
*/
|
|
@@ -116,7 +116,7 @@ type ResolvedFile<TMeta$1 extends object = object> = File<TMeta$1> & {
|
|
|
116
116
|
};
|
|
117
117
|
//#endregion
|
|
118
118
|
//#region src/plugins/types.d.ts
|
|
119
|
-
type Plugin<TOptions = unknown, TAppExtension
|
|
119
|
+
type Plugin<TOptions = unknown, TAppExtension extends Record<string, any> = {}> = {
|
|
120
120
|
name: string;
|
|
121
121
|
type: 'plugin';
|
|
122
122
|
install: Install<TOptions>;
|
|
@@ -125,15 +125,15 @@ type Plugin<TOptions = unknown, TAppExtension$1 extends Record<string, any> = {}
|
|
|
125
125
|
* Merged into the app instance after install.
|
|
126
126
|
* This cannot be async
|
|
127
127
|
*/
|
|
128
|
-
inject?: Inject<TOptions, TAppExtension
|
|
128
|
+
inject?: Inject<TOptions, TAppExtension>;
|
|
129
129
|
};
|
|
130
|
-
type UserPlugin<TOptions = unknown, TAppExtension
|
|
130
|
+
type UserPlugin<TOptions = unknown, TAppExtension extends Record<string, any> = {}> = Omit<Plugin<TOptions, TAppExtension>, 'type'>;
|
|
131
131
|
//#endregion
|
|
132
132
|
//#region src/parsers/types.d.ts
|
|
133
133
|
type PrintOptions = {
|
|
134
134
|
extname?: Extname;
|
|
135
135
|
};
|
|
136
|
-
type Parser<TOptions = unknown, TMeta
|
|
136
|
+
type Parser<TOptions = unknown, TMeta extends object = any> = {
|
|
137
137
|
name: string;
|
|
138
138
|
type: 'parser';
|
|
139
139
|
/**
|
|
@@ -144,9 +144,9 @@ type Parser<TOptions = unknown, TMeta$1 extends object = any> = {
|
|
|
144
144
|
/**
|
|
145
145
|
* Convert a file to string
|
|
146
146
|
*/
|
|
147
|
-
parse(file: ResolvedFile<TMeta
|
|
147
|
+
parse(file: ResolvedFile<TMeta>, options: PrintOptions): Promise<string>;
|
|
148
148
|
};
|
|
149
|
-
type UserParser<TOptions = unknown, TMeta
|
|
149
|
+
type UserParser<TOptions = unknown, TMeta extends object = any> = Omit<Parser<TOptions, TMeta>, 'type'>;
|
|
150
150
|
//#endregion
|
|
151
151
|
//#region src/utils/AsyncEventEmitter.d.ts
|
|
152
152
|
declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
|
|
@@ -167,18 +167,18 @@ type ProcessFilesProps = {
|
|
|
167
167
|
/**
|
|
168
168
|
* @default 'sequential'
|
|
169
169
|
*/
|
|
170
|
-
mode?:
|
|
170
|
+
mode?: FabricMode;
|
|
171
171
|
};
|
|
172
172
|
type GetParseOptions = {
|
|
173
173
|
parsers?: Set<Parser>;
|
|
174
174
|
extension?: Record<Extname, Extname | ''>;
|
|
175
175
|
};
|
|
176
176
|
type Options$1 = {
|
|
177
|
-
events?: AsyncEventEmitter<
|
|
177
|
+
events?: AsyncEventEmitter<FabricEvents>;
|
|
178
178
|
};
|
|
179
179
|
declare class FileProcessor {
|
|
180
180
|
#private;
|
|
181
|
-
events: AsyncEventEmitter<
|
|
181
|
+
events: AsyncEventEmitter<FabricEvents>;
|
|
182
182
|
constructor({
|
|
183
183
|
events
|
|
184
184
|
}?: Options$1);
|
|
@@ -196,11 +196,11 @@ declare class FileProcessor {
|
|
|
196
196
|
//#endregion
|
|
197
197
|
//#region src/FileManager.d.ts
|
|
198
198
|
type Options = {
|
|
199
|
-
events?: AsyncEventEmitter<
|
|
199
|
+
events?: AsyncEventEmitter<FabricEvents>;
|
|
200
200
|
};
|
|
201
201
|
declare class FileManager {
|
|
202
202
|
#private;
|
|
203
|
-
events: AsyncEventEmitter<
|
|
203
|
+
events: AsyncEventEmitter<FabricEvents>;
|
|
204
204
|
processor: FileProcessor;
|
|
205
205
|
constructor({
|
|
206
206
|
events
|
|
@@ -214,19 +214,19 @@ declare class FileManager {
|
|
|
214
214
|
write(options: ProcessFilesProps): Promise<ResolvedFile[]>;
|
|
215
215
|
}
|
|
216
216
|
//#endregion
|
|
217
|
-
//#region src/
|
|
217
|
+
//#region src/Fabric.d.ts
|
|
218
218
|
declare global {
|
|
219
219
|
namespace Kubb {
|
|
220
|
-
interface
|
|
220
|
+
interface Fabric {}
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
-
type
|
|
223
|
+
type FabricOptions = {
|
|
224
224
|
/**
|
|
225
225
|
* @default 'sequential'
|
|
226
226
|
*/
|
|
227
|
-
mode?:
|
|
227
|
+
mode?: FabricMode;
|
|
228
228
|
};
|
|
229
|
-
type
|
|
229
|
+
type FabricEvents = {
|
|
230
230
|
/**
|
|
231
231
|
* Called in the beginning of the app lifecycle.
|
|
232
232
|
*/
|
|
@@ -239,7 +239,7 @@ type AppEvents = {
|
|
|
239
239
|
* Called when being rendered
|
|
240
240
|
*/
|
|
241
241
|
render: [{
|
|
242
|
-
|
|
242
|
+
fabric: Fabric;
|
|
243
243
|
}];
|
|
244
244
|
/**
|
|
245
245
|
* Called once before processing any files.
|
|
@@ -293,23 +293,23 @@ type AppEvents = {
|
|
|
293
293
|
files: ResolvedFile[];
|
|
294
294
|
}];
|
|
295
295
|
};
|
|
296
|
-
type
|
|
296
|
+
type FabricContext<TOptions extends FabricOptions> = {
|
|
297
297
|
options?: TOptions;
|
|
298
|
-
events: AsyncEventEmitter<
|
|
298
|
+
events: AsyncEventEmitter<FabricEvents>;
|
|
299
299
|
fileManager: FileManager;
|
|
300
300
|
installedPlugins: Set<Plugin>;
|
|
301
301
|
installedParsers: Set<Parser>;
|
|
302
302
|
};
|
|
303
|
-
type
|
|
303
|
+
type FabricMode = 'sequential' | 'parallel';
|
|
304
304
|
type AllOptional<T> = {} extends T ? true : false;
|
|
305
|
-
type Install<TOptions = unknown> = TOptions extends any[] ? (app:
|
|
306
|
-
type Inject<TOptions = unknown, TAppExtension
|
|
307
|
-
interface
|
|
308
|
-
context:
|
|
305
|
+
type Install<TOptions = unknown> = TOptions extends any[] ? (app: Fabric, ...options: TOptions) => void | Promise<void> : AllOptional<TOptions> extends true ? (app: Fabric, options: TOptions | undefined) => void | Promise<void> : (app: Fabric, options: TOptions) => void | Promise<void>;
|
|
306
|
+
type Inject<TOptions = unknown, TAppExtension extends Record<string, any> = {}> = TOptions extends any[] ? (app: Fabric, ...options: TOptions) => Partial<TAppExtension> : AllOptional<TOptions> extends true ? (app: Fabric, options: TOptions | undefined) => Partial<TAppExtension> : (app: Fabric, options: TOptions) => Partial<TAppExtension>;
|
|
307
|
+
interface Fabric<TOptions extends FabricOptions = FabricOptions> extends Kubb.Fabric {
|
|
308
|
+
context: FabricContext<TOptions>;
|
|
309
309
|
files: Array<ResolvedFile>;
|
|
310
310
|
use<TPluginOptions = unknown, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TPluginOptions, TAppExtension> | Parser<TPluginOptions, TMeta>, ...options: TPluginOptions extends any[] ? NoInfer<TPluginOptions> : AllOptional<TPluginOptions> extends true ? [NoInfer<TPluginOptions>?] : [NoInfer<TPluginOptions>]): (this & TAppExtension) | Promise<this & TAppExtension>;
|
|
311
311
|
addFile(...files: Array<File>): Promise<void>;
|
|
312
312
|
}
|
|
313
313
|
//#endregion
|
|
314
|
-
export {
|
|
315
|
-
//# sourceMappingURL=
|
|
314
|
+
export { FileManager as a, UserParser as c, Extname as d, File as f, FabricOptions as i, Plugin as l, ResolvedFile as m, FabricContext as n, FileProcessor as o, KubbFile_d_exports as p, FabricMode as r, Parser as s, Fabric as t, UserPlugin as u };
|
|
315
|
+
//# sourceMappingURL=Fabric-Cu_YHe4S.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { f as File, i as FabricOptions, m as ResolvedFile, t as Fabric } from "./Fabric-CCPgegwe.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/defineFabric.d.ts
|
|
4
|
+
type RootRenderFunction<TOptions extends FabricOptions> = (fabric: Fabric<TOptions>) => void | Promise<void>;
|
|
5
|
+
type DefineFabric<TOptions> = (options?: TOptions) => Fabric;
|
|
6
|
+
declare function defineFabric<TOptions extends FabricOptions>(instance?: RootRenderFunction<TOptions>): DefineFabric<TOptions>;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/createFabric.d.ts
|
|
9
|
+
declare const createFabric: DefineFabric<FabricOptions>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/createFile.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Helper to create a file with name and id set
|
|
14
|
+
*/
|
|
15
|
+
declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { defineFabric as i, createFabric as n, DefineFabric as r, createFile as t };
|
|
18
|
+
//# sourceMappingURL=index-BUculP1D.d.cts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { f as File, i as FabricOptions, m as ResolvedFile, t as Fabric } from "./Fabric-Cu_YHe4S.js";
|
|
2
|
+
|
|
3
|
+
//#region src/defineFabric.d.ts
|
|
4
|
+
type RootRenderFunction<TOptions extends FabricOptions> = (fabric: Fabric<TOptions>) => void | Promise<void>;
|
|
5
|
+
type DefineFabric<TOptions> = (options?: TOptions) => Fabric;
|
|
6
|
+
declare function defineFabric<TOptions extends FabricOptions>(instance?: RootRenderFunction<TOptions>): DefineFabric<TOptions>;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/createFabric.d.ts
|
|
9
|
+
declare const createFabric: DefineFabric<FabricOptions>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/createFile.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Helper to create a file with name and id set
|
|
14
|
+
*/
|
|
15
|
+
declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { defineFabric as i, createFabric as n, DefineFabric as r, createFile as t };
|
|
18
|
+
//# sourceMappingURL=index-CvkyZHXK.d.ts.map
|