@kubb/fabric-core 0.0.0-canary-20251024133602 → 0.0.0-canary-20251027095849
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 +273 -26
- 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 +3 -5
- 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/TreeNode.ts +1 -0
- 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/src/FileManager.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { orderBy } from 'natural-orderby'
|
|
|
5
5
|
import { createFile } from './createFile.ts'
|
|
6
6
|
import { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'
|
|
7
7
|
import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
|
|
8
|
-
import type {
|
|
8
|
+
import type { FabricEvents } from './Fabric.ts'
|
|
9
9
|
|
|
10
10
|
function mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {
|
|
11
11
|
return {
|
|
@@ -17,15 +17,15 @@ function mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: Ku
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
type Options = {
|
|
20
|
-
events?: AsyncEventEmitter<
|
|
20
|
+
events?: AsyncEventEmitter<FabricEvents>
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export class FileManager {
|
|
24
24
|
#cache = new Cache<KubbFile.ResolvedFile>()
|
|
25
|
-
events: AsyncEventEmitter<
|
|
25
|
+
events: AsyncEventEmitter<FabricEvents>
|
|
26
26
|
processor: FileProcessor
|
|
27
27
|
|
|
28
|
-
constructor({ events = new AsyncEventEmitter<
|
|
28
|
+
constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {
|
|
29
29
|
this.processor = new FileProcessor({ events })
|
|
30
30
|
|
|
31
31
|
this.events = events
|
package/src/FileProcessor.ts
CHANGED
|
@@ -4,7 +4,7 @@ import pLimit from 'p-limit'
|
|
|
4
4
|
import type { Parser } from './parsers/types.ts'
|
|
5
5
|
import { defaultParser } from './parsers/defaultParser.ts'
|
|
6
6
|
import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
|
|
7
|
-
import type {
|
|
7
|
+
import type { FabricEvents, FabricMode } from './Fabric.ts'
|
|
8
8
|
|
|
9
9
|
export type ProcessFilesProps = {
|
|
10
10
|
parsers?: Set<Parser>
|
|
@@ -13,7 +13,7 @@ export type ProcessFilesProps = {
|
|
|
13
13
|
/**
|
|
14
14
|
* @default 'sequential'
|
|
15
15
|
*/
|
|
16
|
-
mode?:
|
|
16
|
+
mode?: FabricMode
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
type GetParseOptions = {
|
|
@@ -22,14 +22,14 @@ type GetParseOptions = {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
type Options = {
|
|
25
|
-
events?: AsyncEventEmitter<
|
|
25
|
+
events?: AsyncEventEmitter<FabricEvents>
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export class FileProcessor {
|
|
29
29
|
#limit = pLimit(100)
|
|
30
|
-
events: AsyncEventEmitter<
|
|
30
|
+
events: AsyncEventEmitter<FabricEvents>
|
|
31
31
|
|
|
32
|
-
constructor({ events = new AsyncEventEmitter<
|
|
32
|
+
constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {
|
|
33
33
|
this.events = events
|
|
34
34
|
|
|
35
35
|
return this
|
|
@@ -3,17 +3,17 @@ import { isFunction } from 'remeda'
|
|
|
3
3
|
import type { Plugin } from './plugins/types.ts'
|
|
4
4
|
import type { Parser } from './parsers/types.ts'
|
|
5
5
|
import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
|
|
6
|
-
import type {
|
|
6
|
+
import type { FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { Fabric } from './index.ts'
|
|
9
9
|
|
|
10
|
-
type RootRenderFunction<
|
|
10
|
+
type RootRenderFunction<TOptions extends FabricOptions> = (fabric: Fabric<TOptions>) => void | Promise<void>
|
|
11
11
|
|
|
12
|
-
export type
|
|
12
|
+
export type DefineFabric<TOptions> = (options?: TOptions) => Fabric
|
|
13
13
|
|
|
14
|
-
export function
|
|
15
|
-
function
|
|
16
|
-
const events = new AsyncEventEmitter<
|
|
14
|
+
export function defineFabric<TOptions extends FabricOptions>(instance?: RootRenderFunction<TOptions>): DefineFabric<TOptions> {
|
|
15
|
+
function createFabric(options?: TOptions): Fabric {
|
|
16
|
+
const events = new AsyncEventEmitter<FabricEvents>()
|
|
17
17
|
const installedPlugins = new Set<Plugin<any>>()
|
|
18
18
|
const installedParsers = new Set<Parser<any>>()
|
|
19
19
|
const fileManager = new FileManager({ events })
|
|
@@ -23,9 +23,9 @@ export function defineApp<TOptions extends AppOptions>(instance?: RootRenderFunc
|
|
|
23
23
|
fileManager,
|
|
24
24
|
installedPlugins,
|
|
25
25
|
installedParsers,
|
|
26
|
-
} as
|
|
26
|
+
} as FabricContext<TOptions>
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const fabric = {
|
|
29
29
|
context,
|
|
30
30
|
get files() {
|
|
31
31
|
return fileManager.files
|
|
@@ -38,7 +38,7 @@ export function defineApp<TOptions extends AppOptions>(instance?: RootRenderFunc
|
|
|
38
38
|
|
|
39
39
|
if (pluginOrParser.type === 'plugin') {
|
|
40
40
|
if (installedPlugins.has(pluginOrParser)) {
|
|
41
|
-
console.warn(
|
|
41
|
+
console.warn(`Plugin ${pluginOrParser.name} has already been applied to target fabric.`)
|
|
42
42
|
} else {
|
|
43
43
|
installedPlugins.add(pluginOrParser)
|
|
44
44
|
}
|
|
@@ -46,13 +46,13 @@ export function defineApp<TOptions extends AppOptions>(instance?: RootRenderFunc
|
|
|
46
46
|
if (pluginOrParser.inject && isFunction(pluginOrParser.inject)) {
|
|
47
47
|
const injecter = pluginOrParser.inject
|
|
48
48
|
|
|
49
|
-
const extraApp = (injecter as any)(
|
|
50
|
-
Object.assign(
|
|
49
|
+
const extraApp = (injecter as any)(fabric, ...args)
|
|
50
|
+
Object.assign(fabric, extraApp)
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
if (pluginOrParser.type === 'parser') {
|
|
54
54
|
if (installedParsers.has(pluginOrParser)) {
|
|
55
|
-
console.warn(
|
|
55
|
+
console.warn(`Parser ${pluginOrParser.name} has already been applied to target fabric.`)
|
|
56
56
|
} else {
|
|
57
57
|
installedParsers.add(pluginOrParser)
|
|
58
58
|
}
|
|
@@ -61,19 +61,19 @@ export function defineApp<TOptions extends AppOptions>(instance?: RootRenderFunc
|
|
|
61
61
|
if (pluginOrParser && isFunction(pluginOrParser.install)) {
|
|
62
62
|
const installer = pluginOrParser.install
|
|
63
63
|
|
|
64
|
-
await (installer as any)(
|
|
64
|
+
await (installer as any)(fabric, ...args)
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
return
|
|
67
|
+
return fabric
|
|
68
68
|
},
|
|
69
|
-
} as
|
|
69
|
+
} as Fabric<TOptions>
|
|
70
70
|
|
|
71
71
|
if (instance) {
|
|
72
|
-
instance(
|
|
72
|
+
instance(fabric)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
return
|
|
75
|
+
return fabric
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
return
|
|
78
|
+
return createFabric
|
|
79
79
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { createFabric } from './createFabric.ts'
|
|
2
|
+
export { defineFabric } from './defineFabric.ts'
|
|
3
3
|
export { FileManager } from './FileManager.ts'
|
|
4
4
|
export { createFile } from './createFile.ts'
|
|
5
5
|
export { FileProcessor } from './FileProcessor.ts'
|
|
6
|
-
export type {
|
|
6
|
+
export type { Fabric } from './Fabric.ts'
|
package/src/parsers/types.ts
CHANGED
|
@@ -27,14 +27,14 @@ type ExtendOptions = {
|
|
|
27
27
|
// biome-ignore lint/suspicious/noTsIgnore: production ready
|
|
28
28
|
// @ts-ignore
|
|
29
29
|
declare module '@kubb/fabric-core' {
|
|
30
|
-
interface
|
|
30
|
+
interface Fabric {
|
|
31
31
|
writeEntry(options: WriteEntryOptions): Promise<void>
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
declare global {
|
|
36
36
|
namespace Kubb {
|
|
37
|
-
interface
|
|
37
|
+
interface Fabric {
|
|
38
38
|
writeEntry(options: WriteEntryOptions): Promise<void>
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/plugins/fsPlugin.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createPlugin } from './createPlugin.ts'
|
|
2
|
-
import { switcher } from 'js-runtime'
|
|
3
2
|
import fs from 'fs-extra'
|
|
4
3
|
import { resolve } from 'node:path'
|
|
5
4
|
import type * as KubbFile from '../KubbFile.ts'
|
|
@@ -25,76 +24,70 @@ type ExtendOptions = {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export async function write(path: string, data: string | undefined, options: { sanity?: boolean } = {}): Promise<string | undefined> {
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return undefined
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const oldContent = await fs.readFile(resolve(path), {
|
|
37
|
-
encoding: 'utf-8',
|
|
38
|
-
})
|
|
39
|
-
if (oldContent?.toString() === data?.toString()) {
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
} catch (_err) {
|
|
43
|
-
/* empty */
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
await fs.outputFile(resolve(path), data.trim(), { encoding: 'utf-8' })
|
|
47
|
-
|
|
48
|
-
if (sanity) {
|
|
49
|
-
const savedData = await fs.readFile(resolve(path), {
|
|
50
|
-
encoding: 'utf-8',
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
if (savedData?.toString() !== data?.toString()) {
|
|
54
|
-
throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return savedData
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return data
|
|
61
|
-
},
|
|
62
|
-
bun: async (path: string, data: string | undefined, { sanity }: { sanity?: boolean }) => {
|
|
63
|
-
if (!data || data?.trim() === '') {
|
|
64
|
-
return undefined
|
|
65
|
-
}
|
|
27
|
+
if (typeof Bun !== 'undefined') {
|
|
28
|
+
if (!data || data?.trim() === '') {
|
|
29
|
+
return undefined
|
|
30
|
+
}
|
|
66
31
|
|
|
67
|
-
|
|
32
|
+
await Bun.write(resolve(path), data.trim())
|
|
68
33
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
34
|
+
if (options?.sanity) {
|
|
35
|
+
const file = Bun.file(resolve(path))
|
|
36
|
+
const savedData = await file.text()
|
|
72
37
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
38
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
39
|
+
throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`)
|
|
40
|
+
}
|
|
76
41
|
|
|
77
|
-
|
|
78
|
-
|
|
42
|
+
return savedData
|
|
43
|
+
}
|
|
79
44
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
45
|
+
return data
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!data || data?.trim() === '') {
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const oldContent = await fs.readFile(resolve(path), {
|
|
54
|
+
encoding: 'utf-8',
|
|
55
|
+
})
|
|
56
|
+
if (oldContent?.toString() === data?.toString()) {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
} catch (_err) {
|
|
60
|
+
/* empty */
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
await fs.outputFile(resolve(path), data.trim(), { encoding: 'utf-8' })
|
|
64
|
+
|
|
65
|
+
if (options?.sanity) {
|
|
66
|
+
const savedData = await fs.readFile(resolve(path), {
|
|
67
|
+
encoding: 'utf-8',
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
71
|
+
throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return savedData
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return data
|
|
85
78
|
}
|
|
86
79
|
|
|
87
80
|
// biome-ignore lint/suspicious/noTsIgnore: production ready
|
|
88
81
|
// @ts-ignore
|
|
89
82
|
declare module '@kubb/fabric-core' {
|
|
90
|
-
interface
|
|
83
|
+
interface Fabric {
|
|
91
84
|
write(options?: WriteOptions): Promise<void>
|
|
92
85
|
}
|
|
93
86
|
}
|
|
94
87
|
|
|
95
88
|
declare global {
|
|
96
89
|
namespace Kubb {
|
|
97
|
-
interface
|
|
90
|
+
interface Fabric {
|
|
98
91
|
write(options?: WriteOptions): Promise<void>
|
|
99
92
|
}
|
|
100
93
|
}
|
|
@@ -3,9 +3,9 @@ import type * as KubbFile from '../KubbFile.ts'
|
|
|
3
3
|
import { type Graph, TreeNode } from '../utils/TreeNode.ts'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import http from 'node:http'
|
|
6
|
-
import open from 'tiny-open'
|
|
7
6
|
import type { AddressInfo } from 'node:net'
|
|
8
7
|
import handler from 'serve-handler'
|
|
8
|
+
import { open } from '../utils/open.ts'
|
|
9
9
|
|
|
10
10
|
import { createFile } from '../createFile.ts'
|
|
11
11
|
|
package/src/plugins/types.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
export * as KubbFile from './KubbFile.ts'
|
|
2
|
-
export type {
|
|
3
|
-
export type {
|
|
4
|
-
|
|
5
|
-
export type { App } from './App.ts'
|
|
2
|
+
export type { DefineFabric } from './defineFabric.ts'
|
|
3
|
+
export type { FabricContext, Fabric, FabricMode } from './Fabric.ts'
|
package/src/utils/TreeNode.ts
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
|
|
3
|
+
const spawnBin = (bin: string, args: string[]): Promise<boolean> => {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
const process = spawn(bin, args, {
|
|
6
|
+
detached: true,
|
|
7
|
+
shell: false,
|
|
8
|
+
windowsHide: true,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
process.on('close', (code) => {
|
|
12
|
+
resolve(!code)
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type Options = {
|
|
18
|
+
app?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function open(path: string, options?: Options): Promise<boolean> {
|
|
22
|
+
const app = options?.app
|
|
23
|
+
|
|
24
|
+
if (process.platform === 'win32') {
|
|
25
|
+
return spawnBin('cmd.exe', ['/c', 'start', app || '', path.replace(/[&^]/g, '^$&')])
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (process.platform === 'linux') {
|
|
29
|
+
return spawnBin(app || 'xdg-open', [path])
|
|
30
|
+
}
|
|
31
|
+
if (process.platform === 'darwin') {
|
|
32
|
+
return spawnBin('open', app ? ['-a', app, path] : [path])
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw new Error(`Unsupported platform, could not open "${path}"`)
|
|
36
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { d as File, p as ResolvedFile, r as AppOptions, t as App } from "./App-Cjd-lGfW.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/defineApp.d.ts
|
|
4
|
-
type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>;
|
|
5
|
-
type DefineApp<TOptions> = (options?: TOptions) => App;
|
|
6
|
-
declare function defineApp<TOptions extends AppOptions>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions>;
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/createApp.d.ts
|
|
9
|
-
declare const createApp: DefineApp<AppOptions>;
|
|
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 { defineApp as i, createApp as n, DefineApp as r, createFile as t };
|
|
18
|
-
//# sourceMappingURL=index-BUERYeq7.d.cts.map
|
package/dist/index-DfaD7Pj_.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { d as File, p as ResolvedFile, r as AppOptions, t as App } from "./App-ztRQpZS9.js";
|
|
2
|
-
|
|
3
|
-
//#region src/defineApp.d.ts
|
|
4
|
-
type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>;
|
|
5
|
-
type DefineApp<TOptions> = (options?: TOptions) => App;
|
|
6
|
-
declare function defineApp<TOptions extends AppOptions>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions>;
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/createApp.d.ts
|
|
9
|
-
declare const createApp: DefineApp<AppOptions>;
|
|
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 { defineApp as i, createApp as n, DefineApp as r, createFile as t };
|
|
18
|
-
//# sourceMappingURL=index-DfaD7Pj_.d.ts.map
|
package/src/createApp.ts
DELETED