@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.
Files changed (40) hide show
  1. package/dist/{App-Dvetv2V_.d.ts → App-DVWD6TgC.d.cts} +17 -6
  2. package/dist/{App-Cplfh8QA.d.cts → App-_vPNh477.d.ts} +17 -6
  3. package/dist/defineProperty-BtekiGIK.js +332 -0
  4. package/dist/defineProperty-BtekiGIK.js.map +1 -0
  5. package/dist/defineProperty-CspRhtP3.cjs +364 -0
  6. package/dist/defineProperty-CspRhtP3.cjs.map +1 -0
  7. package/dist/{index-Agz-2M75.d.ts → index-CfV-59_M.d.ts} +5 -5
  8. package/dist/{index-C3GyFwE1.d.cts → index-DVok6g82.d.cts} +5 -5
  9. package/dist/index.cjs +32 -26
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +2 -2
  12. package/dist/index.d.ts +2 -2
  13. package/dist/index.js +32 -25
  14. package/dist/index.js.map +1 -1
  15. package/dist/parsers/typescript.d.cts +2 -2
  16. package/dist/parsers/typescript.d.ts +2 -2
  17. package/dist/parsers.d.cts +2 -2
  18. package/dist/parsers.d.ts +2 -2
  19. package/dist/plugins.cjs +66 -27
  20. package/dist/plugins.cjs.map +1 -1
  21. package/dist/plugins.d.cts +29 -12
  22. package/dist/plugins.d.ts +29 -12
  23. package/dist/plugins.js +65 -29
  24. package/dist/plugins.js.map +1 -1
  25. package/dist/types.d.cts +2 -2
  26. package/dist/types.d.ts +2 -2
  27. package/dist/{typescriptParser-CxGhFQXh.d.cts → typescriptParser-BM90H8Tx.d.cts} +2 -2
  28. package/dist/{typescriptParser-B49WHoGL.d.ts → typescriptParser-Chjs-RhT.d.ts} +2 -2
  29. package/package.json +4 -2
  30. package/src/App.ts +12 -3
  31. package/src/FileProcessor.ts +41 -17
  32. package/src/defineApp.ts +3 -3
  33. package/src/plugins/barrelPlugin.ts +24 -6
  34. package/src/plugins/fsPlugin.ts +30 -29
  35. package/src/plugins/index.ts +1 -0
  36. package/src/plugins/progressPlugin.ts +48 -0
  37. package/dist/defineProperty-3OJdpith.js +0 -168
  38. package/dist/defineProperty-3OJdpith.js.map +0 -1
  39. package/dist/defineProperty-CjCLDutJ.cjs +0 -201
  40. package/dist/defineProperty-CjCLDutJ.cjs.map +0 -1
package/dist/plugins.js CHANGED
@@ -1,9 +1,11 @@
1
- import { a as _classPrivateFieldInitSpec, i as _assertClassBrand, n as createFile, r as _classPrivateFieldGet2, t as _defineProperty } from "./defineProperty-3OJdpith.js";
1
+ import { a as _classPrivateFieldInitSpec, i as _assertClassBrand, n as createFile, r as _classPrivateFieldGet2, t as _defineProperty } from "./defineProperty-BtekiGIK.js";
2
2
  import "./trimExtName-CeOVQVbu.js";
3
3
  import { t as getRelativePath } from "./getRelativePath-CERJmYkp.js";
4
- import path, { resolve } from "node:path";
4
+ import path, { relative, resolve } from "node:path";
5
5
  import { switcher } from "js-runtime";
6
6
  import fs from "fs-extra";
7
+ import { Presets, SingleBar } from "cli-progress";
8
+ import process from "node:process";
7
9
 
8
10
  //#region src/plugins/createPlugin.ts
9
11
  function createPlugin(plugin) {
@@ -16,14 +18,14 @@ function createPlugin(plugin) {
16
18
  //#endregion
17
19
  //#region src/plugins/fsPlugin.ts
18
20
  async function write(path$1, data, options = {}) {
19
- if (data.trim() === "") return;
20
21
  return switcher({
21
22
  node: async (path$2, data$1, { sanity }) => {
23
+ if (!data$1 || (data$1 === null || data$1 === void 0 ? void 0 : data$1.trim()) === "") return;
22
24
  try {
23
25
  const oldContent = await fs.readFile(resolve(path$2), { encoding: "utf-8" });
24
26
  if ((oldContent === null || oldContent === void 0 ? void 0 : oldContent.toString()) === (data$1 === null || data$1 === void 0 ? void 0 : data$1.toString())) return;
25
27
  } catch (_err) {}
26
- await fs.outputFile(resolve(path$2), data$1, { encoding: "utf-8" });
28
+ await fs.outputFile(resolve(path$2), data$1.trim(), { encoding: "utf-8" });
27
29
  if (sanity) {
28
30
  const savedData = await fs.readFile(resolve(path$2), { encoding: "utf-8" });
29
31
  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`);
@@ -32,37 +34,33 @@ async function write(path$1, data, options = {}) {
32
34
  return data$1;
33
35
  },
34
36
  bun: async (path$2, data$1, { sanity }) => {
35
- try {
36
- await Bun.write(resolve(path$2), data$1);
37
- if (sanity) {
38
- const savedData = await Bun.file(resolve(path$2)).text();
39
- 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`);
40
- return savedData;
41
- }
42
- return data$1;
43
- } catch (e) {
44
- console.error(e);
37
+ if (!data$1 || (data$1 === null || data$1 === void 0 ? void 0 : data$1.trim()) === "") return;
38
+ await Bun.write(resolve(path$2), data$1.trim());
39
+ if (sanity) {
40
+ const savedData = await Bun.file(resolve(path$2)).text();
41
+ 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`);
42
+ return savedData;
45
43
  }
44
+ return data$1;
46
45
  }
47
- }, "node")(path$1, data.trim(), options);
46
+ }, "node")(path$1, data, options);
48
47
  }
49
48
  const fsPlugin = createPlugin({
50
49
  name: "fs",
51
- install(app, options) {
52
- if (options === null || options === void 0 ? void 0 : options.clean) fs.removeSync(options.clean.path);
50
+ install(app, options = {}) {
51
+ if (options.clean) fs.removeSync(options.clean.path);
53
52
  app.context.events.on("process:progress", async ({ file, source }) => {
54
- if (options === null || options === void 0 ? void 0 : options.onWrite) await options.onWrite(file.path, source);
53
+ if (options.onBeforeWrite) await options.onBeforeWrite(file.path, source);
55
54
  await write(file.path, source, { sanity: false });
56
55
  });
57
56
  },
58
- inject(app) {
59
- return { async write(options = {
60
- extension: { ".ts": ".ts" },
61
- dryRun: false
62
- }) {
57
+ inject(app, { dryRun } = {}) {
58
+ return { async write(options = { extension: { ".ts": ".ts" } }) {
59
+ var _app$context$options;
63
60
  await app.context.fileManager.write({
61
+ mode: (_app$context$options = app.context.options) === null || _app$context$options === void 0 ? void 0 : _app$context$options.mode,
64
62
  extension: options.extension,
65
- dryRun: options.dryRun,
63
+ dryRun,
66
64
  parsers: app.context.installedParsers
67
65
  });
68
66
  } };
@@ -218,6 +216,7 @@ const barrelPlugin = createPlugin({
218
216
  if (!options) throw new Error("Barrel plugin requires options.root and options.mode");
219
217
  if (!options.mode) return;
220
218
  app.context.events.onOnce("process:end", async ({ files }) => {
219
+ var _app$context$options;
221
220
  const root = options.root;
222
221
  const barrelFiles = getBarrelFiles({
223
222
  files,
@@ -225,14 +224,20 @@ const barrelPlugin = createPlugin({
225
224
  mode: options.mode
226
225
  });
227
226
  await app.context.fileManager.add(...barrelFiles);
228
- await app.context.fileManager.write({ parsers: app.context.installedParsers });
227
+ await app.context.fileManager.write({
228
+ mode: (_app$context$options = app.context.options) === null || _app$context$options === void 0 ? void 0 : _app$context$options.mode,
229
+ dryRun: options.dryRun,
230
+ parsers: app.context.installedParsers
231
+ });
229
232
  });
230
233
  },
231
- inject(app) {
234
+ inject(app, options) {
235
+ if (!options) throw new Error("Barrel plugin requires options.root and options.mode");
232
236
  return { async writeEntry({ root, mode }) {
237
+ var _app$context$options2;
233
238
  if (!mode || mode === "propagate") return;
234
239
  const rootPath = resolve(root, "index.ts");
235
- const rootFile = createFile({
240
+ const entryFile = createFile({
236
241
  path: rootPath,
237
242
  baseName: "index.ts",
238
243
  exports: app.files.filter((file) => {
@@ -251,11 +256,42 @@ const barrelPlugin = createPlugin({
251
256
  }).filter(Boolean),
252
257
  sources: []
253
258
  });
254
- await app.context.fileManager.add(rootFile);
259
+ await app.context.fileManager.add(entryFile);
260
+ await app.context.fileManager.write({
261
+ mode: (_app$context$options2 = app.context.options) === null || _app$context$options2 === void 0 ? void 0 : _app$context$options2.mode,
262
+ dryRun: options.dryRun,
263
+ parsers: app.context.installedParsers
264
+ });
255
265
  } };
256
266
  }
257
267
  });
258
268
 
259
269
  //#endregion
260
- export { barrelPlugin, createPlugin, fsPlugin };
270
+ //#region src/plugins/progressPlugin.ts
271
+ const progressPlugin = createPlugin({
272
+ name: "progress",
273
+ install(app) {
274
+ const progressBar = new SingleBar({
275
+ format: "{bar} {percentage}% | {value}/{total} | {message}",
276
+ barCompleteChar: "█",
277
+ barIncompleteChar: "░",
278
+ hideCursor: true,
279
+ clearOnComplete: true
280
+ }, Presets.shades_grey);
281
+ app.context.events.on("process:start", async ({ files }) => {
282
+ progressBar.start(files.length, 0, { message: "Starting..." });
283
+ });
284
+ app.context.events.on("process:progress", async ({ file }) => {
285
+ const message = `Writing ${relative(process.cwd(), file.path)}`;
286
+ progressBar.increment(1, { message });
287
+ });
288
+ app.context.events.on("process:end", async ({ files }) => {
289
+ progressBar.update(files.length, { message: "Done ✅" });
290
+ progressBar.stop();
291
+ });
292
+ }
293
+ });
294
+
295
+ //#endregion
296
+ export { barrelPlugin, createPlugin, fsPlugin, progressPlugin };
261
297
  //# sourceMappingURL=plugins.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","names":["path","data","stack: Array<TreeNode<TData>>","result: Array<TreeNode<TData>>","next: TreeNode<BarrelData> | undefined"],"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,QAAO,SACL;EACE,MAAM,OAAO,QAAc,QAAc,EAAE,aAAmC;AAC5E,OAAI;IACF,MAAM,aAAa,MAAM,GAAG,SAAS,QAAQA,OAAK,EAAE,EAClD,UAAU,SACX,CAAC;AACF,iEAAI,WAAY,UAA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AAGF,MAAI,QAAQ,OAAO,OAAO,eAAe,OAAO,EAAE,YAAY;GAC5D,MAAM,OAAO,QAAQ;GACrB,MAAM,cAAc,eAAe;IAAE;IAAO;IAAM,MAAM,QAAQ;IAAM,CAAC;AAEvE,SAAM,IAAI,QAAQ,YAAY,IAAI,GAAG,YAAY;AAEjD,SAAM,IAAI,QAAQ,YAAY,MAAM,EAClC,SAAS,IAAI,QAAQ,kBACtB,CAAC;IACF;;CAEJ,OAAO,KAAK;AACV,SAAO,EACL,MAAM,WAAW,EAAE,MAAM,QAAQ;AAC/B,OAAI,CAAC,QAAQ,SAAS,YACpB;GAGF,MAAM,WAAW,QAAQ,MAAM,WAAW;GAM1C,MAAM,WAAW,WAAW;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,MAAM,gBAAgB,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.js","names":["data","path","stack: Array<TreeNode<TData>>","result: Array<TreeNode<TData>>","next: TreeNode<BarrelData> | undefined"],"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,QAAO,SACL;EACE,MAAM,OAAO,QAAM,QAA0B,EAAE,aAAmC;AAChF,OAAI,CAACA,2DAAQA,OAAM,MAAM,MAAK,GAC5B;AAGF,OAAI;IACF,MAAM,aAAa,MAAM,GAAG,SAAS,QAAQC,OAAK,EAAE,EAClD,UAAU,SACX,CAAC;AACF,iEAAI,WAAY,UAAU,uDAAKD,OAAM,UAAU,EAC7C;YAEK,MAAM;AAIf,SAAM,GAAG,WAAW,QAAQC,OAAK,EAAED,OAAK,MAAM,EAAE,EAAE,UAAU,SAAS,CAAC;AAEtE,O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;CACN,QAAQ,KAAK;EACX,MAAM,cAAc,IAAI,UACtB;GACE,QAAQ;GACR,iBAAiB;GACjB,mBAAmB;GACnB,YAAY;GACZ,iBAAiB;GAClB,EACD,QAAQ,YACT;AAED,MAAI,QAAQ,OAAO,GAAG,iBAAiB,OAAO,EAAE,YAAY;AAC1D,eAAY,MAAM,MAAM,QAAQ,GAAG,EAAE,SAAS,eAAe,CAAC;IAC9D;AAEF,MAAI,QAAQ,OAAO,GAAG,oBAAoB,OAAO,EAAE,WAAW;GAC5D,MAAM,UAAU,WAAW,SAAS,QAAQ,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/types.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-Cplfh8QA.cjs";
2
- import { r as DefineApp } from "./index-C3GyFwE1.cjs";
1
+ import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-DVWD6TgC.cjs";
2
+ import { r as DefineApp } from "./index-DVok6g82.cjs";
3
3
  export { type App, type AppContext, type DefineApp, KubbFile_d_exports as KubbFile };
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-Dvetv2V_.js";
2
- import { r as DefineApp } from "./index-Agz-2M75.js";
1
+ import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-_vPNh477.js";
2
+ import { r as DefineApp } from "./index-CfV-59_M.js";
3
3
  export { type App, type AppContext, type DefineApp, KubbFile_d_exports as KubbFile };
@@ -1,4 +1,4 @@
1
- import { o as Parser } from "./App-Cplfh8QA.cjs";
1
+ import { o as Parser } from "./App-DVWD6TgC.cjs";
2
2
  import ts from "typescript";
3
3
 
4
4
  //#region src/parsers/typescriptParser.d.ts
@@ -47,4 +47,4 @@ declare function createExport({
47
47
  declare const typescriptParser: Parser<[], any>;
48
48
  //#endregion
49
49
  export { typescriptParser as i, createImport as n, print as r, createExport as t };
50
- //# sourceMappingURL=typescriptParser-CxGhFQXh.d.cts.map
50
+ //# sourceMappingURL=typescriptParser-BM90H8Tx.d.cts.map
@@ -1,4 +1,4 @@
1
- import { o as Parser } from "./App-Dvetv2V_.js";
1
+ import { o as Parser } from "./App-_vPNh477.js";
2
2
  import ts from "typescript";
3
3
 
4
4
  //#region src/parsers/typescriptParser.d.ts
@@ -47,4 +47,4 @@ declare function createExport({
47
47
  declare const typescriptParser: Parser<[], any>;
48
48
  //#endregion
49
49
  export { typescriptParser as i, createImport as n, print as r, createExport as t };
50
- //# sourceMappingURL=typescriptParser-B49WHoGL.d.ts.map
50
+ //# sourceMappingURL=typescriptParser-Chjs-RhT.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/fabric-core",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -72,15 +72,17 @@
72
72
  "!/**/__tests__/**"
73
73
  ],
74
74
  "dependencies": {
75
+ "cli-progress": "^3.12.0",
75
76
  "fs-extra": "^11.3.2",
76
77
  "js-runtime": "^0.0.8",
77
78
  "natural-orderby": "^5.0.0",
78
79
  "p-limit": "^7.2.0",
79
- "remeda": "^2.32.0",
80
80
  "typescript": "5.9.3"
81
81
  },
82
82
  "devDependencies": {
83
+ "@types/cli-progress": "^3.11.6",
83
84
  "@types/fs-extra": "^11.0.4",
85
+ "remeda": "^2.32.0",
84
86
  "tsdown": "^0.15.9",
85
87
  "typescript": "^5.9.3"
86
88
  },
package/src/App.ts CHANGED
@@ -12,6 +12,13 @@ declare global {
12
12
 
13
13
  export type Component = any
14
14
 
15
+ export type AppOptions = {
16
+ /**
17
+ * @default 'sequential'
18
+ */
19
+ mode?: AppMode
20
+ }
21
+
15
22
  export type AppEvents = {
16
23
  /**
17
24
  * Called in the beginning of the app lifecycle.
@@ -49,7 +56,7 @@ export type AppEvents = {
49
56
  processed: number
50
57
  total: number
51
58
  percentage: number
52
- source: string
59
+ source?: string
53
60
  file: KubbFile.ResolvedFile
54
61
  },
55
62
  ]
@@ -60,7 +67,7 @@ export type AppEvents = {
60
67
  'process:end': [{ files: KubbFile.ResolvedFile[] }]
61
68
  }
62
69
 
63
- export type AppContext<TOptions = unknown> = {
70
+ export type AppContext<TOptions extends AppOptions> = {
64
71
  options?: TOptions
65
72
  events: AsyncEventEmitter<AppEvents>
66
73
  fileManager: FileManager
@@ -68,6 +75,8 @@ export type AppContext<TOptions = unknown> = {
68
75
  installedParsers: Set<Parser>
69
76
  }
70
77
 
78
+ export type AppMode = 'sequential' | 'parallel'
79
+
71
80
  type AllOptional<T> = {} extends T ? true : false
72
81
 
73
82
  export type Install<TOptions = unknown> = TOptions extends any[]
@@ -82,7 +91,7 @@ export type Inject<TOptions = unknown, TAppExtension extends Record<string, any>
82
91
  ? (app: App, options: TOptions | undefined) => Partial<TAppExtension>
83
92
  : (app: App, options: TOptions) => Partial<TAppExtension>
84
93
 
85
- export interface App<TOptions = unknown> extends Kubb.App {
94
+ export interface App<TOptions extends AppOptions = AppOptions> extends Kubb.App {
86
95
  context: AppContext<TOptions>
87
96
  files: Array<KubbFile.ResolvedFile>
88
97
  use<TPluginOptions = unknown, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(
@@ -4,12 +4,16 @@ 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 { AppEvents } from './App.ts'
7
+ import type { AppEvents, AppMode } from './App.ts'
8
8
 
9
9
  export type ProcessFilesProps = {
10
10
  parsers?: Set<Parser>
11
11
  extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
12
12
  dryRun?: boolean
13
+ /**
14
+ * @default 'sequential'
15
+ */
16
+ mode?: AppMode
13
17
  }
14
18
 
15
19
  type GetParseOptions = {
@@ -59,31 +63,51 @@ export class FileProcessor {
59
63
  return parser.parse(file, { extname: parseExtName })
60
64
  }
61
65
 
62
- async run(files: Array<KubbFile.ResolvedFile>, { parsers, dryRun, extension }: ProcessFilesProps = {}): Promise<KubbFile.ResolvedFile[]> {
66
+ async run(
67
+ files: Array<KubbFile.ResolvedFile>,
68
+ { parsers, mode = 'sequential', dryRun, extension }: ProcessFilesProps = {},
69
+ ): Promise<KubbFile.ResolvedFile[]> {
63
70
  await this.events.emit('process:start', { files })
64
71
 
65
72
  let processed = 0
66
73
  const total = files.length
67
74
 
68
- const promises = files.map((resolvedFile, index) =>
69
- this.#limit(async () => {
70
- await this.events.emit('file:start', { file: resolvedFile, index, total })
75
+ const processOne = async (resolvedFile: KubbFile.ResolvedFile, index: number) => {
76
+ const percentage = (processed / total) * 100
71
77
 
72
- if (!dryRun) {
73
- const source = await this.parse(resolvedFile, { extension, parsers })
74
- const nextProcessed = processed + 1
75
- const percentage = (nextProcessed / total) * 100
76
- processed = nextProcessed
77
- await this.events.emit('process:progress', { file: resolvedFile, source, processed, percentage, total })
78
- }
78
+ await this.events.emit('file:start', { file: resolvedFile, index, total })
79
+
80
+ const source = dryRun ? undefined : await this.parse(resolvedFile, { extension, parsers })
81
+
82
+ await this.events.emit('process:progress', {
83
+ file: resolvedFile,
84
+ source,
85
+ processed,
86
+ percentage,
87
+ total,
88
+ })
79
89
 
80
- await this.events.emit('file:end', { file: resolvedFile, index, total })
90
+ processed++
91
+
92
+ await this.events.emit('file:end', { file: resolvedFile, index, total })
93
+ }
81
94
 
82
- processed++
83
- }),
84
- )
95
+ if (mode === 'sequential') {
96
+ async function* asyncFiles() {
97
+ for (let index = 0; index < files.length; index++) {
98
+ yield [files[index], index] as const
99
+ }
100
+ }
85
101
 
86
- await Promise.all(promises)
102
+ for await (const [file, index] of asyncFiles()) {
103
+ if (file) {
104
+ await processOne(file, index)
105
+ }
106
+ }
107
+ } else {
108
+ const promises = files.map((resolvedFile, index) => this.#limit(() => processOne(resolvedFile, index)))
109
+ await Promise.all(promises)
110
+ }
87
111
 
88
112
  await this.events.emit('process:end', { files })
89
113
 
package/src/defineApp.ts CHANGED
@@ -3,15 +3,15 @@ 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 { AppContext, Component, AppEvents } from './App.ts'
6
+ import type { AppContext, AppEvents, AppOptions } from './App.ts'
7
7
 
8
8
  import type { App } from './index.ts'
9
9
 
10
10
  type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>
11
11
 
12
- export type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App
12
+ export type DefineApp<TOptions> = (options?: TOptions) => App
13
13
 
14
- export function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions> {
14
+ export function defineApp<TOptions extends AppOptions>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions> {
15
15
  function createApp(options?: TOptions): App {
16
16
  const events = new AsyncEventEmitter<AppEvents>()
17
17
  const installedPlugins = new Set<Plugin<any>>()
@@ -12,24 +12,30 @@ type Mode = 'all' | 'named' | 'propagate' | false
12
12
  type Options = {
13
13
  root: string
14
14
  mode: Mode
15
+ dryRun?: boolean
16
+ }
17
+
18
+ type WriteEntryOptions = {
19
+ root: string
20
+ mode: Mode
15
21
  }
16
22
 
17
23
  type ExtendOptions = {
18
- writeEntry(options: Options): Promise<void>
24
+ writeEntry(options: WriteEntryOptions): Promise<void>
19
25
  }
20
26
 
21
27
  // biome-ignore lint/suspicious/noTsIgnore: production ready
22
28
  // @ts-ignore
23
29
  declare module '@kubb/fabric-core' {
24
30
  interface App {
25
- writeEntry(options: Options): Promise<void>
31
+ writeEntry(options: WriteEntryOptions): Promise<void>
26
32
  }
27
33
  }
28
34
 
29
35
  declare global {
30
36
  namespace Kubb {
31
37
  interface App {
32
- writeEntry(options: Options): Promise<void>
38
+ writeEntry(options: WriteEntryOptions): Promise<void>
33
39
  }
34
40
  }
35
41
  }
@@ -140,11 +146,17 @@ export const barrelPlugin = createPlugin<Options, ExtendOptions>({
140
146
  await app.context.fileManager.add(...barrelFiles)
141
147
 
142
148
  await app.context.fileManager.write({
149
+ mode: app.context.options?.mode,
150
+ dryRun: options.dryRun,
143
151
  parsers: app.context.installedParsers,
144
152
  })
145
153
  })
146
154
  },
147
- inject(app) {
155
+ inject(app, options) {
156
+ if (!options) {
157
+ throw new Error('Barrel plugin requires options.root and options.mode')
158
+ }
159
+
148
160
  return {
149
161
  async writeEntry({ root, mode }) {
150
162
  if (!mode || mode === 'propagate') {
@@ -157,7 +169,7 @@ export const barrelPlugin = createPlugin<Options, ExtendOptions>({
157
169
  return file.sources.some((source) => source.isIndexable)
158
170
  })
159
171
 
160
- const rootFile = createFile({
172
+ const entryFile = createFile({
161
173
  path: rootPath,
162
174
  baseName: 'index.ts',
163
175
  exports: barrelFiles
@@ -182,7 +194,13 @@ export const barrelPlugin = createPlugin<Options, ExtendOptions>({
182
194
  sources: [],
183
195
  })
184
196
 
185
- await app.context.fileManager.add(rootFile)
197
+ await app.context.fileManager.add(entryFile)
198
+
199
+ await app.context.fileManager.write({
200
+ mode: app.context.options?.mode,
201
+ dryRun: options.dryRun,
202
+ parsers: app.context.installedParsers,
203
+ })
186
204
  },
187
205
  }
188
206
  },