@kubb/fabric-core 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{App-Dvetv2V_.d.ts → App-DVWD6TgC.d.cts} +17 -6
- package/dist/{App-Cplfh8QA.d.cts → App-_vPNh477.d.ts} +17 -6
- package/dist/defineProperty-BtekiGIK.js +332 -0
- package/dist/defineProperty-BtekiGIK.js.map +1 -0
- package/dist/defineProperty-CspRhtP3.cjs +364 -0
- package/dist/defineProperty-CspRhtP3.cjs.map +1 -0
- package/dist/{index-Agz-2M75.d.ts → index-CfV-59_M.d.ts} +5 -5
- package/dist/{index-C3GyFwE1.d.cts → index-DVok6g82.d.cts} +5 -5
- package/dist/index.cjs +32 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +32 -25
- 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 +66 -27
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +29 -12
- package/dist/plugins.d.ts +29 -12
- package/dist/plugins.js +65 -29
- package/dist/plugins.js.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/{typescriptParser-CxGhFQXh.d.cts → typescriptParser-BM90H8Tx.d.cts} +2 -2
- package/dist/{typescriptParser-B49WHoGL.d.ts → typescriptParser-Chjs-RhT.d.ts} +2 -2
- package/package.json +4 -2
- package/src/App.ts +12 -3
- package/src/FileProcessor.ts +41 -17
- package/src/defineApp.ts +3 -3
- package/src/plugins/barrelPlugin.ts +24 -6
- package/src/plugins/fsPlugin.ts +30 -29
- package/src/plugins/index.ts +1 -0
- package/src/plugins/progressPlugin.ts +48 -0
- package/dist/defineProperty-3OJdpith.js +0 -168
- package/dist/defineProperty-3OJdpith.js.map +0 -1
- package/dist/defineProperty-CjCLDutJ.cjs +0 -201
- package/dist/defineProperty-CjCLDutJ.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { a as _classPrivateFieldInitSpec, n as createFile, r as _classPrivateFieldGet2, t as _defineProperty } from "./defineProperty-
|
|
1
|
+
import { a as _classPrivateFieldInitSpec, n as createFile, r as _classPrivateFieldGet2, t as _defineProperty } from "./defineProperty-BtekiGIK.js";
|
|
2
2
|
import { t as trimExtName } from "./trimExtName-CeOVQVbu.js";
|
|
3
3
|
import "./createParser-17uGjfu3.js";
|
|
4
4
|
import { t as defaultParser } from "./defaultParser--HzU9LPa.js";
|
|
5
5
|
import { orderBy } from "natural-orderby";
|
|
6
|
-
import { isFunction } from "remeda";
|
|
7
6
|
import pLimit from "p-limit";
|
|
8
7
|
import { EventEmitter } from "node:events";
|
|
9
8
|
|
|
@@ -35,6 +34,10 @@ var Cache = class {
|
|
|
35
34
|
flush() {}
|
|
36
35
|
};
|
|
37
36
|
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region ../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/isFunction-BJjFuZR7.js
|
|
39
|
+
const e = (e$1) => typeof e$1 == `function`;
|
|
40
|
+
|
|
38
41
|
//#endregion
|
|
39
42
|
//#region src/utils/AsyncEventEmitter.ts
|
|
40
43
|
var _emitter = /* @__PURE__ */ new WeakMap();
|
|
@@ -100,40 +103,44 @@ var FileProcessor = class {
|
|
|
100
103
|
if (!parser) return defaultParser.parse(file, { extname: parseExtName });
|
|
101
104
|
return parser.parse(file, { extname: parseExtName });
|
|
102
105
|
}
|
|
103
|
-
async run(files, { parsers, dryRun, extension } = {}) {
|
|
106
|
+
async run(files, { parsers, mode = "sequential", dryRun, extension } = {}) {
|
|
104
107
|
await this.events.emit("process:start", { files });
|
|
105
108
|
let processed = 0;
|
|
106
109
|
const total = files.length;
|
|
107
|
-
const
|
|
110
|
+
const processOne = async (resolvedFile, index) => {
|
|
111
|
+
const percentage = processed / total * 100;
|
|
108
112
|
await this.events.emit("file:start", {
|
|
109
113
|
file: resolvedFile,
|
|
110
114
|
index,
|
|
111
115
|
total
|
|
112
116
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
processed
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
percentage,
|
|
126
|
-
total
|
|
127
|
-
});
|
|
128
|
-
}
|
|
117
|
+
const source = dryRun ? void 0 : await this.parse(resolvedFile, {
|
|
118
|
+
extension,
|
|
119
|
+
parsers
|
|
120
|
+
});
|
|
121
|
+
await this.events.emit("process:progress", {
|
|
122
|
+
file: resolvedFile,
|
|
123
|
+
source,
|
|
124
|
+
processed,
|
|
125
|
+
percentage,
|
|
126
|
+
total
|
|
127
|
+
});
|
|
128
|
+
processed++;
|
|
129
129
|
await this.events.emit("file:end", {
|
|
130
130
|
file: resolvedFile,
|
|
131
131
|
index,
|
|
132
132
|
total
|
|
133
133
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
};
|
|
135
|
+
if (mode === "sequential") {
|
|
136
|
+
async function* asyncFiles() {
|
|
137
|
+
for (let index = 0; index < files.length; index++) yield [files[index], index];
|
|
138
|
+
}
|
|
139
|
+
for await (const [file, index] of asyncFiles()) if (file) await processOne(file, index);
|
|
140
|
+
} else {
|
|
141
|
+
const promises = files.map((resolvedFile, index) => _classPrivateFieldGet2(_limit, this).call(this, () => processOne(resolvedFile, index)));
|
|
142
|
+
await Promise.all(promises);
|
|
143
|
+
}
|
|
137
144
|
await this.events.emit("process:end", { files });
|
|
138
145
|
return files;
|
|
139
146
|
}
|
|
@@ -225,7 +232,7 @@ function defineApp(instance) {
|
|
|
225
232
|
if (pluginOrParser.type === "plugin") {
|
|
226
233
|
if (installedPlugins.has(pluginOrParser)) console.warn("Plugin has already been applied to target app.");
|
|
227
234
|
else installedPlugins.add(pluginOrParser);
|
|
228
|
-
if (pluginOrParser.inject &&
|
|
235
|
+
if (pluginOrParser.inject && e(pluginOrParser.inject)) {
|
|
229
236
|
const injecter = pluginOrParser.inject;
|
|
230
237
|
const extraApp = injecter(app, ...args);
|
|
231
238
|
Object.assign(app, extraApp);
|
|
@@ -233,7 +240,7 @@ function defineApp(instance) {
|
|
|
233
240
|
}
|
|
234
241
|
if (pluginOrParser.type === "parser") if (installedParsers.has(pluginOrParser)) console.warn("Parser has already been applied to target app.");
|
|
235
242
|
else installedParsers.add(pluginOrParser);
|
|
236
|
-
if (pluginOrParser &&
|
|
243
|
+
if (pluginOrParser && e(pluginOrParser.install)) {
|
|
237
244
|
const installer = pluginOrParser.install;
|
|
238
245
|
await installer(app, ...args);
|
|
239
246
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["NodeEventEmitter","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","createApp","options"],"sources":["../src/utils/Cache.ts","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/FileManager.ts","../src/defineApp.ts","../src/createApp.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\n\nexport class AsyncEventEmitter<TEvents extends Record<string, any>> {\n constructor(maxListener = 100) {\n this.#emitter.setMaxListeners(maxListener)\n }\n #emitter = new NodeEventEmitter()\n\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<(...args: TEvents[TEventName]) => any>\n\n if (listeners.length === 0) {\n return undefined\n }\n\n await Promise.all(\n listeners.map(async (listener) => {\n try {\n return await listener(...eventArgs)\n } catch (err) {\n console.error(`Error in async listener for \"${eventName}\":`, err)\n }\n }),\n )\n }\n\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.on(eventName, handler as any)\n }\n\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void {\n const wrapper = (...args: TEvents[TEventName]) => {\n this.off(eventName, wrapper)\n handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.off(eventName, handler as any)\n }\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport pLimit from 'p-limit'\n\nimport type { Parser } from './parsers/types.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<AppEvents>\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers, extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!parsers) {\n console.warn('No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.')\n\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n if (!file.extname) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n let parser: Parser | undefined\n for (const item of parsers) {\n if (item.extNames?.includes(file.extname)) {\n parser = item\n break\n }\n }\n\n if (!parser) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n return parser.parse(file, { extname: parseExtName })\n }\n\n async run(files: Array<KubbFile.ResolvedFile>, { parsers, dryRun, extension }: ProcessFilesProps = {}): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const promises = files.map((resolvedFile, index) =>\n this.#limit(async () => {\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n if (!dryRun) {\n const source = await this.parse(resolvedFile, { extension, parsers })\n const nextProcessed = processed + 1\n const percentage = (nextProcessed / total) * 100\n processed = nextProcessed\n await this.events.emit('process:progress', { file: resolvedFile, source, processed, percentage, total })\n }\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n\n processed++\n }),\n )\n\n await Promise.all(promises)\n\n await this.events.emit('process:end', { files })\n\n return files\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n events: AsyncEventEmitter<AppEvents>\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n\n this.events = events\n return this\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n return resolvedFiles\n }\n\n flush() {\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n }\n\n clear(): void {\n this.#cache.clear()\n }\n\n get files(): Array<KubbFile.ResolvedFile> {\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files = keys.map((key) => this.#cache.get(key))\n\n return files.filter(Boolean)\n }\n\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n const resolvedFiles = await this.processor.run(this.files, options)\n\n this.clear()\n\n return resolvedFiles\n }\n}\n","import { FileManager } from './FileManager.ts'\nimport { isFunction } from 'remeda'\nimport type { Plugin } from './plugins/types.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppContext, Component, AppEvents } from './App.ts'\n\nimport type { App } from './index.ts'\n\ntype RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>\n\nexport type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App\n\nexport function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions> {\n function createApp(options?: TOptions): App {\n const events = new AsyncEventEmitter<AppEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Set<Parser<any>>()\n const fileManager = new FileManager({ events })\n const context = {\n events,\n options,\n fileManager,\n installedPlugins,\n installedParsers,\n } as AppContext<TOptions>\n\n const app = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n async use(pluginOrParser, ...options) {\n const args = options\n\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn('Plugin has already been applied to target app.')\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (pluginOrParser.inject && isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const extraApp = (injecter as any)(app, ...args)\n Object.assign(app, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn('Parser has already been applied to target app.')\n } else {\n installedParsers.add(pluginOrParser)\n }\n }\n\n if (pluginOrParser && isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n await (installer as any)(app, ...args)\n }\n\n return app\n },\n } as App<TOptions>\n\n if (instance) {\n instance(app)\n }\n\n return app\n }\n\n return createApp\n}\n","import { defineApp } from './defineApp.ts'\n\nexport const createApp = defineApp()\n"],"mappings":";;;;;;;;;;;AAAA,IAAa,QAAb,MAAsB;;4DACV,IAAI,KAAgB;;CAE9B,IAAI,KAAuB;;AACzB,6DAAO,KAAY,CAAC,IAAI,IAAI,+DAAI;;CAGlC,IAAI,KAAa,OAAgB;AAC/B,uCAAY,CAAC,IAAI,KAAK,MAAM;;CAG9B,OAAO,KAAmB;AACxB,uCAA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AC3ET,MAAa,YAAY,WAAW"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["e","NodeEventEmitter","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","createApp","options","isFunction"],"sources":["../src/utils/Cache.ts","../../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/isFunction-BJjFuZR7.js","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/FileManager.ts","../src/defineApp.ts","../src/createApp.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","const e=e=>typeof e==`function`;export{e as isFunction};\n//# sourceMappingURL=isFunction-BJjFuZR7.js.map","import { EventEmitter as NodeEventEmitter } from 'node:events'\n\nexport class AsyncEventEmitter<TEvents extends Record<string, any>> {\n constructor(maxListener = 100) {\n this.#emitter.setMaxListeners(maxListener)\n }\n #emitter = new NodeEventEmitter()\n\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<(...args: TEvents[TEventName]) => any>\n\n if (listeners.length === 0) {\n return undefined\n }\n\n await Promise.all(\n listeners.map(async (listener) => {\n try {\n return await listener(...eventArgs)\n } catch (err) {\n console.error(`Error in async listener for \"${eventName}\":`, err)\n }\n }),\n )\n }\n\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.on(eventName, handler as any)\n }\n\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void {\n const wrapper = (...args: TEvents[TEventName]) => {\n this.off(eventName, wrapper)\n handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.off(eventName, handler as any)\n }\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport pLimit from 'p-limit'\n\nimport type { Parser } from './parsers/types.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents, AppMode } from './App.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n /**\n * @default 'sequential'\n */\n mode?: AppMode\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<AppEvents>\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers, extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!parsers) {\n console.warn('No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.')\n\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n if (!file.extname) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n let parser: Parser | undefined\n for (const item of parsers) {\n if (item.extNames?.includes(file.extname)) {\n parser = item\n break\n }\n }\n\n if (!parser) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n return parser.parse(file, { extname: parseExtName })\n }\n\n async run(\n files: Array<KubbFile.ResolvedFile>,\n { parsers, mode = 'sequential', dryRun, extension }: ProcessFilesProps = {},\n ): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const processOne = async (resolvedFile: KubbFile.ResolvedFile, index: number) => {\n const percentage = (processed / total) * 100\n\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n const source = dryRun ? undefined : await this.parse(resolvedFile, { extension, parsers })\n\n await this.events.emit('process:progress', {\n file: resolvedFile,\n source,\n processed,\n percentage,\n total,\n })\n\n processed++\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n }\n\n if (mode === 'sequential') {\n async function* asyncFiles() {\n for (let index = 0; index < files.length; index++) {\n yield [files[index], index] as const\n }\n }\n\n for await (const [file, index] of asyncFiles()) {\n if (file) {\n await processOne(file, index)\n }\n }\n } else {\n const promises = files.map((resolvedFile, index) => this.#limit(() => processOne(resolvedFile, index)))\n await Promise.all(promises)\n }\n\n await this.events.emit('process:end', { files })\n\n return files\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n events: AsyncEventEmitter<AppEvents>\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n\n this.events = events\n return this\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n return resolvedFiles\n }\n\n flush() {\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n }\n\n clear(): void {\n this.#cache.clear()\n }\n\n get files(): Array<KubbFile.ResolvedFile> {\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files = keys.map((key) => this.#cache.get(key))\n\n return files.filter(Boolean)\n }\n\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n const resolvedFiles = await this.processor.run(this.files, options)\n\n this.clear()\n\n return resolvedFiles\n }\n}\n","import { FileManager } from './FileManager.ts'\nimport { isFunction } from 'remeda'\nimport type { Plugin } from './plugins/types.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppContext, AppEvents, AppOptions } from './App.ts'\n\nimport type { App } from './index.ts'\n\ntype RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>\n\nexport type DefineApp<TOptions> = (options?: TOptions) => App\n\nexport function defineApp<TOptions extends AppOptions>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions> {\n function createApp(options?: TOptions): App {\n const events = new AsyncEventEmitter<AppEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Set<Parser<any>>()\n const fileManager = new FileManager({ events })\n const context = {\n events,\n options,\n fileManager,\n installedPlugins,\n installedParsers,\n } as AppContext<TOptions>\n\n const app = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n async use(pluginOrParser, ...options) {\n const args = options\n\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn('Plugin has already been applied to target app.')\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (pluginOrParser.inject && isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const extraApp = (injecter as any)(app, ...args)\n Object.assign(app, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn('Parser has already been applied to target app.')\n } else {\n installedParsers.add(pluginOrParser)\n }\n }\n\n if (pluginOrParser && isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n await (installer as any)(app, ...args)\n }\n\n return app\n },\n } as App<TOptions>\n\n if (instance) {\n instance(app)\n }\n\n return app\n }\n\n return createApp\n}\n","import { defineApp } from './defineApp.ts'\n\nexport const createApp = defineApp()\n"],"x_google_ignoreList":[1],"mappings":";;;;;;;;;;AAAA,IAAa,QAAb,MAAsB;;4DACV,IAAI,KAAgB;;CAE9B,IAAI,KAAuB;;AACzB,6DAAO,KAAY,CAAC,IAAI,IAAI,+DAAI;;CAGlC,IAAI,KAAa,OAAgB;AAC/B,uCAAY,CAAC,IAAI,KAAK,MAAM;;CAG9B,OAAO,KAAmB;AACxB,uCAAY,CAAC,OAAO,IAAI;;CAG1B,QAAc;AACZ,uCAAY,CAAC,OAAO;;CAGtB,OAAiB;AACf,SAAO,CAAC,mCAAG,KAAY,CAAC,MAAM,CAAC;;CAGjC,SAAmB;AACjB,SAAO,CAAC,mCAAG,KAAY,CAAC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KAAK,GAAG,KAAK;;AAGxC,WAAO;;GAEV;AAED,MAAI,SACF,UAAS,IAAI;AAGf,SAAO;;AAGT,QAAOF;;;;;AC3ET,MAAa,YAAY,WAAW"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../App-
|
|
2
|
-
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-
|
|
1
|
+
import "../App-DVWD6TgC.cjs";
|
|
2
|
+
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-BM90H8Tx.cjs";
|
|
3
3
|
export { createExport, createImport, print, typescriptParser };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../App-
|
|
2
|
-
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-
|
|
1
|
+
import "../App-_vPNh477.js";
|
|
2
|
+
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-Chjs-RhT.js";
|
|
3
3
|
export { createExport, createImport, print, typescriptParser };
|
package/dist/parsers.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as Parser, s as UserParser } from "./App-
|
|
2
|
-
import { i as typescriptParser } from "./typescriptParser-
|
|
1
|
+
import { o as Parser, s as UserParser } from "./App-DVWD6TgC.cjs";
|
|
2
|
+
import { i as typescriptParser } from "./typescriptParser-BM90H8Tx.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/parsers/createParser.d.ts
|
|
5
5
|
declare function createParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta>;
|
package/dist/parsers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as Parser, s as UserParser } from "./App-
|
|
2
|
-
import { i as typescriptParser } from "./typescriptParser-
|
|
1
|
+
import { o as Parser, s as UserParser } from "./App-_vPNh477.js";
|
|
2
|
+
import { i as typescriptParser } from "./typescriptParser-Chjs-RhT.js";
|
|
3
3
|
|
|
4
4
|
//#region src/parsers/createParser.d.ts
|
|
5
5
|
declare function createParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta>;
|
package/dist/plugins.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_trimExtName = require('./trimExtName-Bb4zGVF1.cjs');
|
|
2
|
-
const require_defineProperty = require('./defineProperty-
|
|
2
|
+
const require_defineProperty = require('./defineProperty-CspRhtP3.cjs');
|
|
3
3
|
const require_getRelativePath = require('./getRelativePath-C6lvNCs7.cjs');
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_trimExtName.__toESM(node_path);
|
|
@@ -7,6 +7,10 @@ let js_runtime = require("js-runtime");
|
|
|
7
7
|
js_runtime = require_trimExtName.__toESM(js_runtime);
|
|
8
8
|
let fs_extra = require("fs-extra");
|
|
9
9
|
fs_extra = require_trimExtName.__toESM(fs_extra);
|
|
10
|
+
let cli_progress = require("cli-progress");
|
|
11
|
+
cli_progress = require_trimExtName.__toESM(cli_progress);
|
|
12
|
+
let node_process = require("node:process");
|
|
13
|
+
node_process = require_trimExtName.__toESM(node_process);
|
|
10
14
|
|
|
11
15
|
//#region src/plugins/createPlugin.ts
|
|
12
16
|
function createPlugin(plugin) {
|
|
@@ -19,14 +23,14 @@ function createPlugin(plugin) {
|
|
|
19
23
|
//#endregion
|
|
20
24
|
//#region src/plugins/fsPlugin.ts
|
|
21
25
|
async function write(path$1, data, options = {}) {
|
|
22
|
-
if (data.trim() === "") return;
|
|
23
26
|
return (0, js_runtime.switcher)({
|
|
24
27
|
node: async (path$2, data$1, { sanity }) => {
|
|
28
|
+
if (!data$1 || (data$1 === null || data$1 === void 0 ? void 0 : data$1.trim()) === "") return;
|
|
25
29
|
try {
|
|
26
30
|
const oldContent = await fs_extra.default.readFile((0, node_path.resolve)(path$2), { encoding: "utf-8" });
|
|
27
31
|
if ((oldContent === null || oldContent === void 0 ? void 0 : oldContent.toString()) === (data$1 === null || data$1 === void 0 ? void 0 : data$1.toString())) return;
|
|
28
32
|
} catch (_err) {}
|
|
29
|
-
await fs_extra.default.outputFile((0, node_path.resolve)(path$2), data$1, { encoding: "utf-8" });
|
|
33
|
+
await fs_extra.default.outputFile((0, node_path.resolve)(path$2), data$1.trim(), { encoding: "utf-8" });
|
|
30
34
|
if (sanity) {
|
|
31
35
|
const savedData = await fs_extra.default.readFile((0, node_path.resolve)(path$2), { encoding: "utf-8" });
|
|
32
36
|
if ((savedData === null || savedData === void 0 ? void 0 : savedData.toString()) !== (data$1 === null || data$1 === void 0 ? void 0 : data$1.toString())) throw new Error(`Sanity check failed for ${path$2}\n\nData[${data$1.length}]:\n${data$1}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
|
|
@@ -35,37 +39,33 @@ async function write(path$1, data, options = {}) {
|
|
|
35
39
|
return data$1;
|
|
36
40
|
},
|
|
37
41
|
bun: async (path$2, data$1, { sanity }) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
return data$1;
|
|
46
|
-
} catch (e) {
|
|
47
|
-
console.error(e);
|
|
42
|
+
if (!data$1 || (data$1 === null || data$1 === void 0 ? void 0 : data$1.trim()) === "") return;
|
|
43
|
+
await Bun.write((0, node_path.resolve)(path$2), data$1.trim());
|
|
44
|
+
if (sanity) {
|
|
45
|
+
const savedData = await Bun.file((0, node_path.resolve)(path$2)).text();
|
|
46
|
+
if ((savedData === null || savedData === void 0 ? void 0 : savedData.toString()) !== (data$1 === null || data$1 === void 0 ? void 0 : data$1.toString())) throw new Error(`Sanity check failed for ${path$2}\n\nData[${path$2.length}]:\n${path$2}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
|
|
47
|
+
return savedData;
|
|
48
48
|
}
|
|
49
|
+
return data$1;
|
|
49
50
|
}
|
|
50
|
-
}, "node")(path$1, data
|
|
51
|
+
}, "node")(path$1, data, options);
|
|
51
52
|
}
|
|
52
53
|
const fsPlugin = createPlugin({
|
|
53
54
|
name: "fs",
|
|
54
|
-
install(app, options) {
|
|
55
|
-
if (options
|
|
55
|
+
install(app, options = {}) {
|
|
56
|
+
if (options.clean) fs_extra.default.removeSync(options.clean.path);
|
|
56
57
|
app.context.events.on("process:progress", async ({ file, source }) => {
|
|
57
|
-
if (options
|
|
58
|
+
if (options.onBeforeWrite) await options.onBeforeWrite(file.path, source);
|
|
58
59
|
await write(file.path, source, { sanity: false });
|
|
59
60
|
});
|
|
60
61
|
},
|
|
61
|
-
inject(app) {
|
|
62
|
-
return { async write(options = {
|
|
63
|
-
|
|
64
|
-
dryRun: false
|
|
65
|
-
}) {
|
|
62
|
+
inject(app, { dryRun } = {}) {
|
|
63
|
+
return { async write(options = { extension: { ".ts": ".ts" } }) {
|
|
64
|
+
var _app$context$options;
|
|
66
65
|
await app.context.fileManager.write({
|
|
66
|
+
mode: (_app$context$options = app.context.options) === null || _app$context$options === void 0 ? void 0 : _app$context$options.mode,
|
|
67
67
|
extension: options.extension,
|
|
68
|
-
dryRun
|
|
68
|
+
dryRun,
|
|
69
69
|
parsers: app.context.installedParsers
|
|
70
70
|
});
|
|
71
71
|
} };
|
|
@@ -221,6 +221,7 @@ const barrelPlugin = createPlugin({
|
|
|
221
221
|
if (!options) throw new Error("Barrel plugin requires options.root and options.mode");
|
|
222
222
|
if (!options.mode) return;
|
|
223
223
|
app.context.events.onOnce("process:end", async ({ files }) => {
|
|
224
|
+
var _app$context$options;
|
|
224
225
|
const root = options.root;
|
|
225
226
|
const barrelFiles = getBarrelFiles({
|
|
226
227
|
files,
|
|
@@ -228,14 +229,20 @@ const barrelPlugin = createPlugin({
|
|
|
228
229
|
mode: options.mode
|
|
229
230
|
});
|
|
230
231
|
await app.context.fileManager.add(...barrelFiles);
|
|
231
|
-
await app.context.fileManager.write({
|
|
232
|
+
await app.context.fileManager.write({
|
|
233
|
+
mode: (_app$context$options = app.context.options) === null || _app$context$options === void 0 ? void 0 : _app$context$options.mode,
|
|
234
|
+
dryRun: options.dryRun,
|
|
235
|
+
parsers: app.context.installedParsers
|
|
236
|
+
});
|
|
232
237
|
});
|
|
233
238
|
},
|
|
234
|
-
inject(app) {
|
|
239
|
+
inject(app, options) {
|
|
240
|
+
if (!options) throw new Error("Barrel plugin requires options.root and options.mode");
|
|
235
241
|
return { async writeEntry({ root, mode }) {
|
|
242
|
+
var _app$context$options2;
|
|
236
243
|
if (!mode || mode === "propagate") return;
|
|
237
244
|
const rootPath = (0, node_path.resolve)(root, "index.ts");
|
|
238
|
-
const
|
|
245
|
+
const entryFile = require_defineProperty.createFile({
|
|
239
246
|
path: rootPath,
|
|
240
247
|
baseName: "index.ts",
|
|
241
248
|
exports: app.files.filter((file) => {
|
|
@@ -254,13 +261,45 @@ const barrelPlugin = createPlugin({
|
|
|
254
261
|
}).filter(Boolean),
|
|
255
262
|
sources: []
|
|
256
263
|
});
|
|
257
|
-
await app.context.fileManager.add(
|
|
264
|
+
await app.context.fileManager.add(entryFile);
|
|
265
|
+
await app.context.fileManager.write({
|
|
266
|
+
mode: (_app$context$options2 = app.context.options) === null || _app$context$options2 === void 0 ? void 0 : _app$context$options2.mode,
|
|
267
|
+
dryRun: options.dryRun,
|
|
268
|
+
parsers: app.context.installedParsers
|
|
269
|
+
});
|
|
258
270
|
} };
|
|
259
271
|
}
|
|
260
272
|
});
|
|
261
273
|
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/plugins/progressPlugin.ts
|
|
276
|
+
const progressPlugin = createPlugin({
|
|
277
|
+
name: "progress",
|
|
278
|
+
install(app) {
|
|
279
|
+
const progressBar = new cli_progress.SingleBar({
|
|
280
|
+
format: "{bar} {percentage}% | {value}/{total} | {message}",
|
|
281
|
+
barCompleteChar: "█",
|
|
282
|
+
barIncompleteChar: "░",
|
|
283
|
+
hideCursor: true,
|
|
284
|
+
clearOnComplete: true
|
|
285
|
+
}, cli_progress.Presets.shades_grey);
|
|
286
|
+
app.context.events.on("process:start", async ({ files }) => {
|
|
287
|
+
progressBar.start(files.length, 0, { message: "Starting..." });
|
|
288
|
+
});
|
|
289
|
+
app.context.events.on("process:progress", async ({ file }) => {
|
|
290
|
+
const message = `Writing ${(0, node_path.relative)(node_process.default.cwd(), file.path)}`;
|
|
291
|
+
progressBar.increment(1, { message });
|
|
292
|
+
});
|
|
293
|
+
app.context.events.on("process:end", async ({ files }) => {
|
|
294
|
+
progressBar.update(files.length, { message: "Done ✅" });
|
|
295
|
+
progressBar.stop();
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
262
300
|
//#endregion
|
|
263
301
|
exports.barrelPlugin = barrelPlugin;
|
|
264
302
|
exports.createPlugin = createPlugin;
|
|
265
303
|
exports.fsPlugin = fsPlugin;
|
|
304
|
+
exports.progressPlugin = progressPlugin;
|
|
266
305
|
//# sourceMappingURL=plugins.cjs.map
|
package/dist/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["fs","path","data","stack: Array<TreeNode<TData>>","result: Array<TreeNode<TData>>","next: TreeNode<BarrelData> | undefined","path","createFile","getRelativePath"],"sources":["../src/plugins/createPlugin.ts","../src/plugins/fsPlugin.ts","../src/utils/TreeNode.ts","../src/plugins/barrelPlugin.ts"],"sourcesContent":["import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<Options = unknown, TAppExtension extends Record<string, any> = {}>(\n plugin: UserPlugin<Options, TAppExtension>,\n): Plugin<Options, TAppExtension> {\n return {\n type: 'plugin',\n ...plugin,\n }\n}\n","import { createPlugin } from './createPlugin.ts'\nimport { switcher } from 'js-runtime'\nimport fs from 'fs-extra'\nimport { resolve } from 'node:path'\nimport type * as KubbFile from '../KubbFile.ts'\n\ntype WriteOptions = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ntype Options = {\n /**\n * Optional callback that is invoked whenever a file is written by the plugin.\n * Useful for tests to observe write operations without spying on internal functions.\n */\n onWrite?: (path: string, data: string) => void | Promise<void>\n clean?: {\n path: string\n }\n}\n\ntype ExtendOptions = {\n write(options?: WriteOptions): Promise<void>\n}\n\nexport async function write(path: string, data: string, options: { sanity?: boolean } = {}): Promise<string | undefined> {\n if (data.trim() === '') {\n return undefined\n }\n return switcher(\n {\n node: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n const oldContent = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n if (oldContent?.toString() === data?.toString()) {\n return\n }\n } catch (_err) {\n /* empty */\n }\n\n await fs.outputFile(resolve(path), data, { encoding: 'utf-8' })\n\n if (sanity) {\n const savedData = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n },\n bun: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n await Bun.write(resolve(path), data)\n\n if (sanity) {\n const file = Bun.file(resolve(path))\n const savedData = await file.text()\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${path.length}]:\\n${path}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n } catch (e) {\n console.error(e)\n }\n },\n },\n 'node',\n )(path, data.trim(), options)\n}\n\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n }\n}\n\nexport const fsPlugin = createPlugin<Options, ExtendOptions>({\n name: 'fs',\n install(app, options) {\n if (options?.clean) {\n fs.removeSync(options.clean.path)\n }\n\n app.context.events.on('process:progress', async ({ file, source }) => {\n if (options?.onWrite) {\n await options.onWrite(file.path, source)\n }\n await write(file.path, source, { sanity: false })\n })\n },\n inject(app) {\n return {\n async write(\n options = {\n extension: { '.ts': '.ts' },\n dryRun: false,\n },\n ) {\n await app.context.fileManager.write({\n extension: options.extension,\n dryRun: options.dryRun,\n parsers: app.context.installedParsers,\n })\n },\n }\n },\n})\n","import type * as KubbFile from '../KubbFile.ts'\n\ntype BarrelData = {\n file?: KubbFile.File\n path: string\n name: string\n}\n\nexport class TreeNode<TData = unknown> {\n data: TData\n parent?: TreeNode<TData>\n children: Array<TreeNode<TData>> = []\n #cachedLeaves?: Array<TreeNode<TData>>\n\n constructor(data: TData, parent?: TreeNode<TData>) {\n this.data = data\n this.parent = parent\n }\n\n addChild(data: TData): TreeNode<TData> {\n const child = new TreeNode(data, this)\n this.children.push(child)\n this.#cachedLeaves = undefined // invalidate cached leaves\n return child\n }\n\n get leaves(): Array<TreeNode<TData>> {\n if (this.#cachedLeaves) return this.#cachedLeaves\n if (this.children.length === 0) return [this]\n\n const stack: Array<TreeNode<TData>> = [...this.children]\n const result: Array<TreeNode<TData>> = []\n\n for (const node of stack) {\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n } else {\n result.push(node)\n }\n }\n\n this.#cachedLeaves = result\n return result\n }\n\n forEach(callback: (node: TreeNode<TData>) => void): this {\n const stack: Array<TreeNode<TData>> = [this]\n\n for (const node of stack) {\n callback(node)\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n }\n }\n return this\n }\n\n findDeep(predicate: (node: TreeNode<TData>) => boolean): TreeNode<TData> | undefined {\n for (const leaf of this.leaves) {\n if (predicate(leaf)) return leaf\n }\n return undefined\n }\n\n static fromFiles(files: Array<KubbFile.File>, rootFolder = ''): TreeNode<BarrelData> | null {\n const normalizePath = (p: string): string => p.replace(/\\\\/g, '/')\n const normalizedRoot = normalizePath(rootFolder)\n const rootPrefix = normalizedRoot.endsWith('/') ? normalizedRoot : `${normalizedRoot}/`\n\n const filteredFiles = files.filter((file) => {\n const filePath = normalizePath(file.path)\n return !filePath.endsWith('.json') && (!rootFolder || filePath.startsWith(rootPrefix))\n })\n\n if (filteredFiles.length === 0) {\n return null\n }\n\n const treeNode = new TreeNode<BarrelData>({\n name: rootFolder || '',\n path: rootFolder || '',\n file: undefined,\n })\n\n for (const file of filteredFiles) {\n const relPath = normalizePath(file.path).slice(rootPrefix.length)\n const parts = relPath.split('/')\n\n let current = treeNode\n let currentPath = rootFolder\n\n for (const [index, part] of parts.entries()) {\n const isLast = index === parts.length - 1\n currentPath += (currentPath.endsWith('/') ? '' : '/') + part\n\n let next: TreeNode<BarrelData> | undefined\n for (const child of current.children) {\n if ((child.data as BarrelData).name === part) {\n next = child\n break\n }\n }\n\n if (!next) {\n next = current.addChild({\n name: part,\n path: currentPath,\n file: isLast ? file : undefined,\n })\n }\n\n current = next\n }\n }\n\n return treeNode\n }\n}\n","/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */\n\nimport { createPlugin } from './createPlugin.ts'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { TreeNode } from '../utils/TreeNode.ts'\nimport path, { resolve } from 'node:path'\nimport { getRelativePath } from '../utils/getRelativePath.ts'\nimport { createFile } from '../createFile.ts'\n\ntype Mode = 'all' | 'named' | 'propagate' | false\n\ntype Options = {\n root: string\n mode: Mode\n}\n\ntype ExtendOptions = {\n writeEntry(options: Options): Promise<void>\n}\n\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface App {\n writeEntry(options: Options): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface App {\n writeEntry(options: Options): Promise<void>\n }\n }\n}\n\ntype GetBarrelFilesOptions = {\n files: KubbFile.File[]\n root: string\n mode: Mode\n}\n\nexport function getBarrelFiles({ files, root, mode }: GetBarrelFilesOptions): Array<KubbFile.File> {\n // Do not generate when propagating or disabled\n if (mode === 'propagate' || mode === false) {\n return []\n }\n\n const cachedFiles = new Map<KubbFile.Path, KubbFile.File>()\n const dedupe = new Map<KubbFile.Path, Set<string>>()\n\n const tree = TreeNode.fromFiles(files, root)\n tree?.forEach((node) => {\n // Only create a barrel for directory-like nodes that have a parent with a path\n if (!node?.children || !node.parent?.data.path) {\n return\n }\n\n const parentPath = node.parent.data.path as KubbFile.Path\n const barrelPath = path.join(parentPath, 'index.ts') as KubbFile.Path\n\n let barrelFile = cachedFiles.get(barrelPath)\n if (!barrelFile) {\n barrelFile = createFile({\n path: barrelPath,\n baseName: 'index.ts',\n exports: [],\n sources: [],\n })\n cachedFiles.set(barrelPath, barrelFile)\n dedupe.set(barrelPath, new Set<string>())\n }\n\n const seen = dedupe.get(barrelPath)!\n\n // Collect all leaves under the current directory node\n node.leaves.forEach((leaf) => {\n const file = leaf.data.file\n if (!file) {\n return\n }\n\n const sources = file.sources || []\n sources.forEach((source) => {\n if (!file.path || !source.isIndexable || !source.name) {\n return\n }\n\n const key = `${source.name}|${source.isTypeOnly ? '1' : '0'}`\n if (seen.has(key)) {\n return\n }\n seen.add(key)\n\n // Always compute relative path from the parent directory to the file path\n barrelFile!.exports!.push({\n name: [source.name],\n path: getRelativePath(parentPath, file.path),\n isTypeOnly: source.isTypeOnly,\n })\n\n barrelFile!.sources.push({\n name: source.name,\n isTypeOnly: source.isTypeOnly,\n value: '', // TODO use parser to generate import\n isExportable: mode === 'all' || mode === 'named',\n isIndexable: mode === 'all' || mode === 'named',\n })\n })\n })\n })\n\n const result = [...cachedFiles.values()]\n\n if (mode === 'all') {\n return result.map((file) => ({\n ...file,\n exports: file.exports?.map((e) => ({ ...e, name: undefined })),\n }))\n }\n\n return result\n}\n\nexport const barrelPlugin = createPlugin<Options, ExtendOptions>({\n name: 'barrel',\n install(app, options) {\n if (!options) {\n throw new Error('Barrel plugin requires options.root and options.mode')\n }\n\n if (!options.mode) {\n return undefined\n }\n\n app.context.events.onOnce('process:end', async ({ files }) => {\n const root = options.root\n const barrelFiles = getBarrelFiles({ files, root, mode: options.mode })\n\n await app.context.fileManager.add(...barrelFiles)\n\n await app.context.fileManager.write({\n parsers: app.context.installedParsers,\n })\n })\n },\n inject(app) {\n return {\n async writeEntry({ root, mode }) {\n if (!mode || mode === 'propagate') {\n return undefined\n }\n\n const rootPath = resolve(root, 'index.ts')\n\n const barrelFiles = app.files.filter((file) => {\n return file.sources.some((source) => source.isIndexable)\n })\n\n const rootFile = createFile({\n path: rootPath,\n baseName: 'index.ts',\n exports: barrelFiles\n .flatMap((file) => {\n const containsOnlyTypes = file.sources.every((source) => source.isTypeOnly)\n\n return file.sources\n ?.map((source) => {\n if (!file.path || !source.isIndexable) {\n return undefined\n }\n\n return {\n name: mode === 'all' ? undefined : [source.name],\n path: getRelativePath(rootPath, file.path),\n isTypeOnly: mode === 'all' ? containsOnlyTypes : source.isTypeOnly,\n } as KubbFile.Export\n })\n .filter(Boolean)\n })\n .filter(Boolean),\n sources: [],\n })\n\n await app.context.fileManager.add(rootFile)\n },\n }\n },\n})\n"],"mappings":";;;;;;;;;;;AAEA,SAAgB,aACd,QACgC;AAChC,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;;ACkBH,eAAsB,MAAM,QAAc,MAAc,UAAgC,EAAE,EAA+B;AACvH,KAAI,KAAK,MAAM,KAAK,GAClB;AAEF,iCACE;EACE,MAAM,OAAO,QAAc,QAAc,EAAE,aAAmC;AAC5E,OAAI;IACF,MAAM,aAAa,MAAMA,iBAAG,gCAAiBC,OAAK,EAAE,EAClD,UAAU,SACX,CAAC;AACF,iEAAI,WAAY,UAAU,uDAAKC,OAAM,UAAU,EAC7C;YAEK,MAAM;AAIf,SAAMF,iBAAG,kCAAmBC,OAAK,EAAEC,QAAM,EAAE,UAAU,SAAS,CAAC;AAE/D,OAAI,QAAQ;IACV,MAAM,YAAY,MAAMF,iBAAG,gCAAiBC,OAAK,EAAE,EACjD,UAAU,SACX,CAAC;AAEF,+DAAI,UAAW,UAAU,uDAAKC,OAAM,UAAU,EAC5C,OAAM,IAAI,MAAM,2B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OAAO,KAAK;AACV,SAAO,EACL,MAAM,WAAW,EAAE,MAAM,QAAQ;AAC/B,OAAI,CAAC,QAAQ,SAAS,YACpB;GAGF,MAAM,kCAAmB,MAAM,WAAW;GAM1C,MAAM,WAAWD,kCAAW;IAC1B,MAAM;IACN,UAAU;IACV,SAPkB,IAAI,MAAM,QAAQ,SAAS;AAC7C,YAAO,KAAK,QAAQ,MAAM,WAAW,OAAO,YAAY;MACxD,CAMG,SAAS,SAAS;;KACjB,MAAM,oBAAoB,KAAK,QAAQ,OAAO,WAAW,OAAO,WAAW;AAE3E,6BAAO,KAAK,uEACR,KAAK,WAAW;AAChB,UAAI,CAAC,KAAK,QAAQ,CAAC,OAAO,YACxB;AAGF,aAAO;OACL,MAAM,SAAS,QAAQ,SAAY,CAAC,OAAO,KAAK;OAChD,MAAMC,wCAAgB,UAAU,KAAK,KAAK;OAC1C,YAAY,SAAS,QAAQ,oBAAoB,OAAO;OACzD;OACD,CACD,OAAO,QAAQ;MAClB,CACD,OAAO,QAAQ;IAClB,SAAS,EAAE;IACZ,CAAC;AAEF,SAAM,IAAI,QAAQ,YAAY,IAAI,SAAS;KAE9C;;CAEJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"plugins.cjs","names":["data","fs","path","stack: Array<TreeNode<TData>>","result: Array<TreeNode<TData>>","next: TreeNode<BarrelData> | undefined","path","createFile","getRelativePath","SingleBar","Presets","process"],"sources":["../src/plugins/createPlugin.ts","../src/plugins/fsPlugin.ts","../src/utils/TreeNode.ts","../src/plugins/barrelPlugin.ts","../src/plugins/progressPlugin.ts"],"sourcesContent":["import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<Options = unknown, TAppExtension extends Record<string, any> = {}>(\n plugin: UserPlugin<Options, TAppExtension>,\n): Plugin<Options, TAppExtension> {\n return {\n type: 'plugin',\n ...plugin,\n }\n}\n","import { createPlugin } from './createPlugin.ts'\nimport { switcher } from 'js-runtime'\nimport fs from 'fs-extra'\nimport { resolve } from 'node:path'\nimport type * as KubbFile from '../KubbFile.ts'\n\ntype WriteOptions = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n dryRun?: boolean\n /**\n * Optional callback that is invoked whenever a file is written by the plugin.\n * Useful for tests to observe write operations without spying on internal functions.\n */\n onBeforeWrite?: (path: string, data: string | undefined) => void | Promise<void>\n clean?: {\n path: string\n }\n}\n\ntype ExtendOptions = {\n write(options?: WriteOptions): Promise<void>\n}\n\nexport async function write(path: string, data: string | undefined, options: { sanity?: boolean } = {}): Promise<string | undefined> {\n return switcher(\n {\n node: async (path, data: string | undefined, { sanity }: { sanity?: boolean }) => {\n if (!data || data?.trim() === '') {\n return undefined\n }\n\n try {\n const oldContent = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n if (oldContent?.toString() === data?.toString()) {\n return\n }\n } catch (_err) {\n /* empty */\n }\n\n await fs.outputFile(resolve(path), data.trim(), { encoding: 'utf-8' })\n\n if (sanity) {\n const savedData = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n },\n bun: async (path: string, data: string | undefined, { sanity }: { sanity?: boolean }) => {\n if (!data || data?.trim() === '') {\n return undefined\n }\n\n await Bun.write(resolve(path), data.trim())\n\n if (sanity) {\n const file = Bun.file(resolve(path))\n const savedData = await file.text()\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${path.length}]:\\n${path}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n },\n },\n 'node',\n )(path, data, options)\n}\n\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n }\n}\n\nexport const fsPlugin = createPlugin<Options, ExtendOptions>({\n name: 'fs',\n install(app, options = {}) {\n if (options.clean) {\n fs.removeSync(options.clean.path)\n }\n\n app.context.events.on('process:progress', async ({ file, source }) => {\n if (options.onBeforeWrite) {\n await options.onBeforeWrite(file.path, source)\n }\n await write(file.path, source, { sanity: false })\n })\n },\n inject(app, { dryRun } = {}) {\n return {\n async write(\n options = {\n extension: { '.ts': '.ts' },\n },\n ) {\n await app.context.fileManager.write({\n mode: app.context.options?.mode,\n extension: options.extension,\n dryRun,\n parsers: app.context.installedParsers,\n })\n },\n }\n },\n})\n","import type * as KubbFile from '../KubbFile.ts'\n\ntype BarrelData = {\n file?: KubbFile.File\n path: string\n name: string\n}\n\nexport class TreeNode<TData = unknown> {\n data: TData\n parent?: TreeNode<TData>\n children: Array<TreeNode<TData>> = []\n #cachedLeaves?: Array<TreeNode<TData>>\n\n constructor(data: TData, parent?: TreeNode<TData>) {\n this.data = data\n this.parent = parent\n }\n\n addChild(data: TData): TreeNode<TData> {\n const child = new TreeNode(data, this)\n this.children.push(child)\n this.#cachedLeaves = undefined // invalidate cached leaves\n return child\n }\n\n get leaves(): Array<TreeNode<TData>> {\n if (this.#cachedLeaves) return this.#cachedLeaves\n if (this.children.length === 0) return [this]\n\n const stack: Array<TreeNode<TData>> = [...this.children]\n const result: Array<TreeNode<TData>> = []\n\n for (const node of stack) {\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n } else {\n result.push(node)\n }\n }\n\n this.#cachedLeaves = result\n return result\n }\n\n forEach(callback: (node: TreeNode<TData>) => void): this {\n const stack: Array<TreeNode<TData>> = [this]\n\n for (const node of stack) {\n callback(node)\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n }\n }\n return this\n }\n\n findDeep(predicate: (node: TreeNode<TData>) => boolean): TreeNode<TData> | undefined {\n for (const leaf of this.leaves) {\n if (predicate(leaf)) return leaf\n }\n return undefined\n }\n\n static fromFiles(files: Array<KubbFile.File>, rootFolder = ''): TreeNode<BarrelData> | null {\n const normalizePath = (p: string): string => p.replace(/\\\\/g, '/')\n const normalizedRoot = normalizePath(rootFolder)\n const rootPrefix = normalizedRoot.endsWith('/') ? normalizedRoot : `${normalizedRoot}/`\n\n const filteredFiles = files.filter((file) => {\n const filePath = normalizePath(file.path)\n return !filePath.endsWith('.json') && (!rootFolder || filePath.startsWith(rootPrefix))\n })\n\n if (filteredFiles.length === 0) {\n return null\n }\n\n const treeNode = new TreeNode<BarrelData>({\n name: rootFolder || '',\n path: rootFolder || '',\n file: undefined,\n })\n\n for (const file of filteredFiles) {\n const relPath = normalizePath(file.path).slice(rootPrefix.length)\n const parts = relPath.split('/')\n\n let current = treeNode\n let currentPath = rootFolder\n\n for (const [index, part] of parts.entries()) {\n const isLast = index === parts.length - 1\n currentPath += (currentPath.endsWith('/') ? '' : '/') + part\n\n let next: TreeNode<BarrelData> | undefined\n for (const child of current.children) {\n if ((child.data as BarrelData).name === part) {\n next = child\n break\n }\n }\n\n if (!next) {\n next = current.addChild({\n name: part,\n path: currentPath,\n file: isLast ? file : undefined,\n })\n }\n\n current = next\n }\n }\n\n return treeNode\n }\n}\n","/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */\n\nimport { createPlugin } from './createPlugin.ts'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { TreeNode } from '../utils/TreeNode.ts'\nimport path, { resolve } from 'node:path'\nimport { getRelativePath } from '../utils/getRelativePath.ts'\nimport { createFile } from '../createFile.ts'\n\ntype Mode = 'all' | 'named' | 'propagate' | false\n\ntype Options = {\n root: string\n mode: Mode\n dryRun?: boolean\n}\n\ntype WriteEntryOptions = {\n root: string\n mode: Mode\n}\n\ntype ExtendOptions = {\n writeEntry(options: WriteEntryOptions): Promise<void>\n}\n\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface App {\n writeEntry(options: WriteEntryOptions): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface App {\n writeEntry(options: WriteEntryOptions): Promise<void>\n }\n }\n}\n\ntype GetBarrelFilesOptions = {\n files: KubbFile.File[]\n root: string\n mode: Mode\n}\n\nexport function getBarrelFiles({ files, root, mode }: GetBarrelFilesOptions): Array<KubbFile.File> {\n // Do not generate when propagating or disabled\n if (mode === 'propagate' || mode === false) {\n return []\n }\n\n const cachedFiles = new Map<KubbFile.Path, KubbFile.File>()\n const dedupe = new Map<KubbFile.Path, Set<string>>()\n\n const tree = TreeNode.fromFiles(files, root)\n tree?.forEach((node) => {\n // Only create a barrel for directory-like nodes that have a parent with a path\n if (!node?.children || !node.parent?.data.path) {\n return\n }\n\n const parentPath = node.parent.data.path as KubbFile.Path\n const barrelPath = path.join(parentPath, 'index.ts') as KubbFile.Path\n\n let barrelFile = cachedFiles.get(barrelPath)\n if (!barrelFile) {\n barrelFile = createFile({\n path: barrelPath,\n baseName: 'index.ts',\n exports: [],\n sources: [],\n })\n cachedFiles.set(barrelPath, barrelFile)\n dedupe.set(barrelPath, new Set<string>())\n }\n\n const seen = dedupe.get(barrelPath)!\n\n // Collect all leaves under the current directory node\n node.leaves.forEach((leaf) => {\n const file = leaf.data.file\n if (!file) {\n return\n }\n\n const sources = file.sources || []\n sources.forEach((source) => {\n if (!file.path || !source.isIndexable || !source.name) {\n return\n }\n\n const key = `${source.name}|${source.isTypeOnly ? '1' : '0'}`\n if (seen.has(key)) {\n return\n }\n seen.add(key)\n\n // Always compute relative path from the parent directory to the file path\n barrelFile!.exports!.push({\n name: [source.name],\n path: getRelativePath(parentPath, file.path),\n isTypeOnly: source.isTypeOnly,\n })\n\n barrelFile!.sources.push({\n name: source.name,\n isTypeOnly: source.isTypeOnly,\n value: '', // TODO use parser to generate import\n isExportable: mode === 'all' || mode === 'named',\n isIndexable: mode === 'all' || mode === 'named',\n })\n })\n })\n })\n\n const result = [...cachedFiles.values()]\n\n if (mode === 'all') {\n return result.map((file) => ({\n ...file,\n exports: file.exports?.map((e) => ({ ...e, name: undefined })),\n }))\n }\n\n return result\n}\n\nexport const barrelPlugin = createPlugin<Options, ExtendOptions>({\n name: 'barrel',\n install(app, options) {\n if (!options) {\n throw new Error('Barrel plugin requires options.root and options.mode')\n }\n\n if (!options.mode) {\n return undefined\n }\n\n app.context.events.onOnce('process:end', async ({ files }) => {\n const root = options.root\n const barrelFiles = getBarrelFiles({ files, root, mode: options.mode })\n\n await app.context.fileManager.add(...barrelFiles)\n\n await app.context.fileManager.write({\n mode: app.context.options?.mode,\n dryRun: options.dryRun,\n parsers: app.context.installedParsers,\n })\n })\n },\n inject(app, options) {\n if (!options) {\n throw new Error('Barrel plugin requires options.root and options.mode')\n }\n\n return {\n async writeEntry({ root, mode }) {\n if (!mode || mode === 'propagate') {\n return undefined\n }\n\n const rootPath = resolve(root, 'index.ts')\n\n const barrelFiles = app.files.filter((file) => {\n return file.sources.some((source) => source.isIndexable)\n })\n\n const entryFile = createFile({\n path: rootPath,\n baseName: 'index.ts',\n exports: barrelFiles\n .flatMap((file) => {\n const containsOnlyTypes = file.sources.every((source) => source.isTypeOnly)\n\n return file.sources\n ?.map((source) => {\n if (!file.path || !source.isIndexable) {\n return undefined\n }\n\n return {\n name: mode === 'all' ? undefined : [source.name],\n path: getRelativePath(rootPath, file.path),\n isTypeOnly: mode === 'all' ? containsOnlyTypes : source.isTypeOnly,\n } as KubbFile.Export\n })\n .filter(Boolean)\n })\n .filter(Boolean),\n sources: [],\n })\n\n await app.context.fileManager.add(entryFile)\n\n await app.context.fileManager.write({\n mode: app.context.options?.mode,\n dryRun: options.dryRun,\n parsers: app.context.installedParsers,\n })\n },\n }\n },\n})\n","import { Presets, SingleBar } from 'cli-progress'\nimport { createPlugin } from './createPlugin.ts'\nimport { relative } from 'node:path'\nimport process from 'node:process'\n\ntype Options = {}\n\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface App {}\n}\n\ndeclare global {\n namespace Kubb {\n interface App {}\n }\n}\n\nexport const progressPlugin = createPlugin<Options>({\n name: 'progress',\n install(app) {\n const progressBar = new SingleBar(\n {\n format: '{bar} {percentage}% | {value}/{total} | {message}',\n barCompleteChar: '█',\n barIncompleteChar: '░',\n hideCursor: true,\n clearOnComplete: true,\n },\n Presets.shades_grey,\n )\n\n app.context.events.on('process:start', async ({ files }) => {\n progressBar.start(files.length, 0, { message: 'Starting...' })\n })\n\n app.context.events.on('process:progress', async ({ file }) => {\n const message = `Writing ${relative(process.cwd(), file.path)}`\n progressBar.increment(1, { message })\n })\n\n app.context.events.on('process:end', async ({ files }) => {\n progressBar.update(files.length, { message: 'Done ✅' })\n progressBar.stop()\n })\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAEA,SAAgB,aACd,QACgC;AAChC,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;;ACkBH,eAAsB,MAAM,QAAc,MAA0B,UAAgC,EAAE,EAA+B;AACnI,iCACE;EACE,MAAM,OAAO,QAAM,QAA0B,EAAE,aAAmC;AAChF,OAAI,CAACA,2DAAQA,OAAM,MAAM,MAAK,GAC5B;AAGF,OAAI;IACF,MAAM,aAAa,MAAMC,iBAAG,gCAAiBC,OAAK,EAAE,EAClD,UAAU,SACX,CAAC;AACF,iEAAI,WAAY,UAAU,uDAAKF,OAAM,UAAU,EAC7C;YAEK,MAAM;AAIf,SAAMC,iBAAG,kCAAmBC,OAAK,EAAEF,OAAK,MAAM,EAAE,EAAE,UAAU,SAAS,CAAC;AAEtE,OAAI,QAAQ;IACV,MAAM,YAAY,MAAMC,iBAAG,gCAAiBC,OAAK,EAAE,EACjD,UAAU,SACX,CAAC;AAEF,+DAAI,UAAW,UAAU,uDAAKF,OAAM,UAAU,EAC5C,OAAM,IAAI,MAAM,2BAA2BE,OAAK,WAAWF,OAAK,OAAO,MAAMA,OAAK,YAAY,UAAU,OAAO,MAAM,UAAU,IAAI;AAGr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Ae,CAAC;IAC9D;AAEF,MAAI,QAAQ,OAAO,GAAG,oBAAoB,OAAO,EAAE,WAAW;GAC5D,MAAM,UAAU,mCAAoBC,qBAAQ,KAAK,EAAE,KAAK,KAAK;AAC7D,eAAY,UAAU,GAAG,EAAE,SAAS,CAAC;IACrC;AAEF,MAAI,QAAQ,OAAO,GAAG,eAAe,OAAO,EAAE,YAAY;AACxD,eAAY,OAAO,MAAM,QAAQ,EAAE,SAAS,UAAU,CAAC;AACvD,eAAY,MAAM;IAClB;;CAEL,CAAC"}
|
package/dist/plugins.d.cts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { c as Plugin, l as UserPlugin, u as Extname } from "./App-
|
|
1
|
+
import { c as Plugin, l as UserPlugin, u as Extname } from "./App-DVWD6TgC.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/createPlugin.d.ts
|
|
4
|
-
declare function createPlugin<Options$
|
|
4
|
+
declare function createPlugin<Options$3 = unknown, TAppExtension extends Record<string, any> = {}>(plugin: UserPlugin<Options$3, TAppExtension>): Plugin<Options$3, TAppExtension>;
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region src/plugins/fsPlugin.d.ts
|
|
7
7
|
type WriteOptions = {
|
|
8
8
|
extension?: Record<Extname, Extname | ''>;
|
|
9
|
-
dryRun?: boolean;
|
|
10
9
|
};
|
|
11
|
-
type Options$
|
|
10
|
+
type Options$2 = {
|
|
11
|
+
dryRun?: boolean;
|
|
12
12
|
/**
|
|
13
13
|
* Optional callback that is invoked whenever a file is written by the plugin.
|
|
14
14
|
* Useful for tests to observe write operations without spying on internal functions.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
onBeforeWrite?: (path: string, data: string | undefined) => void | Promise<void>;
|
|
17
17
|
clean?: {
|
|
18
18
|
path: string;
|
|
19
19
|
};
|
|
@@ -33,30 +33,47 @@ declare global {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
declare const fsPlugin: Plugin<Options$
|
|
36
|
+
declare const fsPlugin: Plugin<Options$2, ExtendOptions$1>;
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/plugins/barrelPlugin.d.ts
|
|
39
39
|
type Mode = 'all' | 'named' | 'propagate' | false;
|
|
40
|
-
type Options = {
|
|
40
|
+
type Options$1 = {
|
|
41
|
+
root: string;
|
|
42
|
+
mode: Mode;
|
|
43
|
+
dryRun?: boolean;
|
|
44
|
+
};
|
|
45
|
+
type WriteEntryOptions = {
|
|
41
46
|
root: string;
|
|
42
47
|
mode: Mode;
|
|
43
48
|
};
|
|
44
49
|
type ExtendOptions = {
|
|
45
|
-
writeEntry(options:
|
|
50
|
+
writeEntry(options: WriteEntryOptions): Promise<void>;
|
|
46
51
|
};
|
|
47
52
|
declare module '@kubb/fabric-core' {
|
|
48
53
|
interface App {
|
|
49
|
-
writeEntry(options:
|
|
54
|
+
writeEntry(options: WriteEntryOptions): Promise<void>;
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
declare global {
|
|
53
58
|
namespace Kubb {
|
|
54
59
|
interface App {
|
|
55
|
-
writeEntry(options:
|
|
60
|
+
writeEntry(options: WriteEntryOptions): Promise<void>;
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
|
-
declare const barrelPlugin: Plugin<Options, ExtendOptions>;
|
|
64
|
+
declare const barrelPlugin: Plugin<Options$1, ExtendOptions>;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/plugins/progressPlugin.d.ts
|
|
67
|
+
type Options = {};
|
|
68
|
+
declare module '@kubb/fabric-core' {
|
|
69
|
+
interface App {}
|
|
70
|
+
}
|
|
71
|
+
declare global {
|
|
72
|
+
namespace Kubb {
|
|
73
|
+
interface App {}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
declare const progressPlugin: Plugin<Options, {}>;
|
|
60
77
|
//#endregion
|
|
61
|
-
export { barrelPlugin, createPlugin, fsPlugin };
|
|
78
|
+
export { barrelPlugin, createPlugin, fsPlugin, progressPlugin };
|
|
62
79
|
//# sourceMappingURL=plugins.d.cts.map
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { c as Plugin, l as UserPlugin, u as Extname } from "./App-
|
|
1
|
+
import { c as Plugin, l as UserPlugin, u as Extname } from "./App-_vPNh477.js";
|
|
2
2
|
|
|
3
3
|
//#region src/plugins/createPlugin.d.ts
|
|
4
|
-
declare function createPlugin<Options$
|
|
4
|
+
declare function createPlugin<Options$3 = unknown, TAppExtension extends Record<string, any> = {}>(plugin: UserPlugin<Options$3, TAppExtension>): Plugin<Options$3, TAppExtension>;
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region src/plugins/fsPlugin.d.ts
|
|
7
7
|
type WriteOptions = {
|
|
8
8
|
extension?: Record<Extname, Extname | ''>;
|
|
9
|
-
dryRun?: boolean;
|
|
10
9
|
};
|
|
11
|
-
type Options$
|
|
10
|
+
type Options$2 = {
|
|
11
|
+
dryRun?: boolean;
|
|
12
12
|
/**
|
|
13
13
|
* Optional callback that is invoked whenever a file is written by the plugin.
|
|
14
14
|
* Useful for tests to observe write operations without spying on internal functions.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
onBeforeWrite?: (path: string, data: string | undefined) => void | Promise<void>;
|
|
17
17
|
clean?: {
|
|
18
18
|
path: string;
|
|
19
19
|
};
|
|
@@ -33,30 +33,47 @@ declare global {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
declare const fsPlugin: Plugin<Options$
|
|
36
|
+
declare const fsPlugin: Plugin<Options$2, ExtendOptions$1>;
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/plugins/barrelPlugin.d.ts
|
|
39
39
|
type Mode = 'all' | 'named' | 'propagate' | false;
|
|
40
|
-
type Options = {
|
|
40
|
+
type Options$1 = {
|
|
41
|
+
root: string;
|
|
42
|
+
mode: Mode;
|
|
43
|
+
dryRun?: boolean;
|
|
44
|
+
};
|
|
45
|
+
type WriteEntryOptions = {
|
|
41
46
|
root: string;
|
|
42
47
|
mode: Mode;
|
|
43
48
|
};
|
|
44
49
|
type ExtendOptions = {
|
|
45
|
-
writeEntry(options:
|
|
50
|
+
writeEntry(options: WriteEntryOptions): Promise<void>;
|
|
46
51
|
};
|
|
47
52
|
declare module '@kubb/fabric-core' {
|
|
48
53
|
interface App {
|
|
49
|
-
writeEntry(options:
|
|
54
|
+
writeEntry(options: WriteEntryOptions): Promise<void>;
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
declare global {
|
|
53
58
|
namespace Kubb {
|
|
54
59
|
interface App {
|
|
55
|
-
writeEntry(options:
|
|
60
|
+
writeEntry(options: WriteEntryOptions): Promise<void>;
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
|
-
declare const barrelPlugin: Plugin<Options, ExtendOptions>;
|
|
64
|
+
declare const barrelPlugin: Plugin<Options$1, ExtendOptions>;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/plugins/progressPlugin.d.ts
|
|
67
|
+
type Options = {};
|
|
68
|
+
declare module '@kubb/fabric-core' {
|
|
69
|
+
interface App {}
|
|
70
|
+
}
|
|
71
|
+
declare global {
|
|
72
|
+
namespace Kubb {
|
|
73
|
+
interface App {}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
declare const progressPlugin: Plugin<Options, {}>;
|
|
60
77
|
//#endregion
|
|
61
|
-
export { barrelPlugin, createPlugin, fsPlugin };
|
|
78
|
+
export { barrelPlugin, createPlugin, fsPlugin, progressPlugin };
|
|
62
79
|
//# sourceMappingURL=plugins.d.ts.map
|