@kubb/core 1.0.0-beta.16 → 1.0.0-beta.18

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/index.cjs CHANGED
@@ -115,14 +115,15 @@ function isURL(data) {
115
115
 
116
116
  // src/utils/objectToParameters.ts
117
117
  function objectToParameters(data, options = {}) {
118
+ const { typed } = options;
118
119
  return data.reduce((acc, [key, value]) => {
119
- if (options.typed) {
120
- acc.push(`${key}: ${value}["${key}"], `);
120
+ if (typed) {
121
+ acc.push(`${key}: ${value}["${key}"]`);
121
122
  } else {
122
- acc.push(`${key}, `);
123
+ acc.push(`${key}`);
123
124
  }
124
125
  return acc;
125
- }, []).join("");
126
+ }, []).join(", ");
126
127
  }
127
128
 
128
129
  // src/utils/nameSorter.ts
@@ -304,6 +305,99 @@ var TreeNode = class {
304
305
  }
305
306
  };
306
307
 
308
+ // src/utils/transformReservedWord.ts
309
+ var reservedWords = [
310
+ "abstract",
311
+ "arguments",
312
+ "boolean",
313
+ "break",
314
+ "byte",
315
+ "case",
316
+ "catch",
317
+ "char",
318
+ "class",
319
+ "const",
320
+ "continue",
321
+ "debugger",
322
+ "default",
323
+ "delete",
324
+ "do",
325
+ "double",
326
+ "else",
327
+ "enum",
328
+ "eval",
329
+ "export",
330
+ "extends",
331
+ "false",
332
+ "final",
333
+ "finally",
334
+ "float",
335
+ "for",
336
+ "function",
337
+ "goto",
338
+ "if",
339
+ "implements",
340
+ "import",
341
+ "in",
342
+ "instanceof",
343
+ "int",
344
+ "interface",
345
+ "let",
346
+ "long",
347
+ "native",
348
+ "new",
349
+ "null",
350
+ "package",
351
+ "private",
352
+ "protected",
353
+ "public",
354
+ "return",
355
+ "short",
356
+ "static",
357
+ "super",
358
+ "switch",
359
+ "synchronized",
360
+ "this",
361
+ "throw",
362
+ "throws",
363
+ "transient",
364
+ "true",
365
+ "try",
366
+ "typeof",
367
+ "var",
368
+ "void",
369
+ "volatile",
370
+ "while",
371
+ "with",
372
+ "yield",
373
+ "Array",
374
+ "Date",
375
+ "eval",
376
+ "function",
377
+ "hasOwnProperty",
378
+ "Infinity",
379
+ "isFinite",
380
+ "isNaN",
381
+ "isPrototypeOf",
382
+ "length",
383
+ "Math",
384
+ "name",
385
+ "NaN",
386
+ "Number",
387
+ "Object",
388
+ "prototype",
389
+ "String",
390
+ "toString",
391
+ "undefined",
392
+ "valueOf"
393
+ ];
394
+ function transformReservedWord(word) {
395
+ if (reservedWords.includes(word)) {
396
+ return `_${word}`;
397
+ }
398
+ return word;
399
+ }
400
+
307
401
  // src/plugin.ts
308
402
  function createPlugin(factory) {
309
403
  return (options) => {
@@ -331,7 +425,10 @@ var definePlugin = createPlugin((options) => {
331
425
  return Promise.all(files.map((file) => file.override ? fileManager.add(file) : fileManager.addOrAppend(file)));
332
426
  },
333
427
  resolvePath,
334
- resolveName,
428
+ resolveName: (params) => {
429
+ const name2 = resolveName(params);
430
+ return transformReservedWord(name2);
431
+ },
335
432
  load,
336
433
  cache: createPluginCache(/* @__PURE__ */ Object.create(null))
337
434
  };
@@ -542,7 +639,7 @@ function getFileSource(file) {
542
639
  }
543
640
  });
544
641
  const importNodes = imports.reduce((prev, curr) => {
545
- return [...prev, tsCodegen.createImportDeclaration({ name: curr.name, path: curr.path, asType: curr.asType })];
642
+ return [...prev, tsCodegen.createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })];
546
643
  }, []);
547
644
  const importSource = tsCodegen.print(importNodes);
548
645
  const exportNodes = exports.reduce((prev, curr) => {
@@ -990,6 +1087,7 @@ exports.objectToParameters = objectToParameters;
990
1087
  exports.read = read;
991
1088
  exports.renderTemplate = renderTemplate;
992
1089
  exports.timeout = timeout;
1090
+ exports.transformReservedWord = transformReservedWord;
993
1091
  exports.validatePlugins = validatePlugins;
994
1092
  exports.write = write;
995
1093
  exports.writeIndexes = writeIndexes;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/utils/isURL.ts","../src/utils/objectToParameters.ts","../src/utils/nameSorter.ts","../src/utils/jsdoc.ts","../src/utils/getUniqueName.ts","../src/utils/timeout.ts","../src/utils/Queue.ts","../src/utils/getEncodedText.ts","../src/utils/renderTemplate.ts","../src/utils/clean.ts","../src/utils/TreeNode.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/utils.ts","../src/managers/pluginManager/PluginManager.ts","../src/managers/pluginManager/validate.ts","../src/build.ts","../src/config.ts","../src/generators/Generator.ts","../src/generators/SchemaGenerator.ts","../src/index.ts"],"names":["pathParser","fs","name","files","argument0"],"mappings":";;;AAAA,OAAOA,iBAAgB;;;ACEhB,SAAS,UAAa,QAA+C;AAC1E,SAAO,OAAQ,QAA6B,SAAS;AACvD;;;ACHA,SAAS,YAAY,UAAU;AAC/B,OAAO,gBAAgB;AAEvB,eAAe,oBAAoB,MAAc,MAAc;AAE7D,QAAM,aAAa,WAAW,QAAQ,WAAW,QAAQ,IAAI,CAAC;AAE9D,QAAM,GAAG,MAAM,YAAY,EAAE,WAAW,KAAK,CAAC;AAE9C,SAAO,GAAG,UAAU,WAAW,QAAQ,IAAI,GAAG,MAAM,EAAE,UAAU,QAAQ,CAAC;AAC3E;AAEA,eAAsB,MAAM,MAAc,MAAc;AACtD,MAAI;AACF,UAAM,GAAG,KAAK,IAAI;AAClB,UAAM,aAAa,MAAM,GAAG,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AAChE,QAAI,YAAY,SAAS,MAAM,MAAM;AACnC;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO,oBAAoB,MAAM,IAAI;AAAA,EACvC;AAEA,SAAO,oBAAoB,MAAM,IAAI;AACvC;;;ACfO,SAAS,kBAA+D,OAAoB;AACjG,SAAO;AAAA,IACL,OAAO,IAAa;AAClB,aAAO,OAAO,MAAM,EAAE;AAAA,IACxB;AAAA,IACA,IAAI,IAAI;AAC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SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,QAAI;AACF,YAAM,SAAS,MAAM,oBAAoB,OAAO;AAEhD,iBAAW,MAAM;AACf,gBAAQ,MAAM;AAAA,MAChB,GAAG,GAAG;AAAA,IACR,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AC7GO,IAAM,eAAe,CAC1B,YAMG;;;ACVE,IAAe,YAAf,MAA2D;AAAA,EACxD,WAAqB,CAAC;AAAA,EAE9B,YAAY,UAAoB,CAAC,GAAe;AAC9C,QAAI,SAAS;AACX,WAAK,WAAW;AAAA,QACd,GAAG,KAAK;AAAA,QACR,GAAG;AAAA,MACL;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,UAAU;AACZ,WAAO,KAAK;AAAA,EACd;AAGF;;;AClBO,IAAe,kBAAf,cAAiF,UAAoB;AAE5G;;;ACKA,IAAO,cAAQ","sourcesContent":["import pathParser from 'path'\n\nimport { createPluginCache } from './utils'\n\nimport type { FileManager } from './managers/fileManager'\nimport type { PluginContext, KubbPlugin, PluginFactoryOptions } from './types'\n\ntype KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (\n options: T['options']\n) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>\n\nexport function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>) {\n return (options: T['options']) => {\n const plugin = factory(options)\n if (Array.isArray(plugin)) {\n throw new Error('Not implemented')\n }\n\n // default transform\n if (!plugin.transform) {\n plugin.transform = function transform(code) {\n return code\n }\n }\n\n return plugin\n }\n}\n\ntype Options = {\n config: PluginContext['config']\n fileManager: FileManager\n resolvePath: PluginContext['resolvePath']\n resolveName: PluginContext['resolveName']\n load: PluginContext['load']\n}\n\n// not publicly exported\nexport type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>\n\nexport const name = 'core' as const\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolvePath, resolveName, load } = options\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(...files) {\n return Promise.all(files.map((file) => (file.override ? fileManager.add(file) : fileManager.addOrAppend(file))))\n },\n resolvePath,\n resolveName,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n options,\n api,\n resolvePath(fileName) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n\n return pathParser.resolve(root, fileName)\n },\n resolveName(name) {\n return name\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport function isPromise<T>(result: MaybePromise<T>): result is Promise<T> {\n return typeof (result as Promise<unknown>)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport { promises as fs } from 'fs'\nimport pathParser from 'path'\n\nasync function safeWriteFileToPath(path: string, data: string) {\n // resolve the full path and get just the directory, ignoring the file and extension\n const passedPath = pathParser.dirname(pathParser.resolve(path))\n // make the directory, recursively. Theoretically, if every directory in the path exists, this won't do anything.\n await fs.mkdir(passedPath, { recursive: true })\n // write the file to the newly created directory\n return fs.writeFile(pathParser.resolve(path), data, { encoding: 'utf-8' })\n}\n\nexport async function write(data: string, path: string) {\n try {\n await fs.stat(path)\n const oldContent = await fs.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === data) {\n return\n }\n } catch (_err) {\n return safeWriteFileToPath(path, data)\n }\n\n return safeWriteFileToPath(path, data)\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<T extends object = object> {\n delete(id: keyof T): boolean\n get(id: keyof T): T[keyof T] | null\n has(id: keyof T): boolean\n set(id: keyof T, value: unknown): void\n}\n\nexport function createPluginCache<T extends Record<string, [number, unknown]>>(cache: T): Cache<T> {\n return {\n delete(id: keyof T) {\n return delete cache[id]\n },\n get(id) {\n const item = cache[id]\n if (!item) return null\n item[0] = 0\n return item[1] as T[keyof T]\n },\n has(id) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id, value) {\n cache[id] = [0, value] as T[keyof T]\n },\n }\n}\n","import pathParser from 'path'\nimport { promises as fs } from 'fs'\n\nfunction slash(path: string) {\n const isExtendedLengthPath = /^\\\\\\\\\\?\\\\/.test(path)\n\n if (isExtendedLengthPath) {\n return path\n }\n\n return path.replace(/\\\\/g, '/')\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null) {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir} ${filePath}`)\n }\n\n const relativePath = pathParser.relative(rootDir, filePath)\n\n // On Windows, paths are separated with a \"\\\"\n // However, web browsers use \"/\" no matter the platform\n const path = slash(relativePath).replace('../', '').trimEnd()\n\n if (path.startsWith('../')) {\n return path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))\n }\n\n return `./${path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))}`\n}\n\nexport type PathMode = 'file' | 'directory'\n\nexport function getPathMode(path: string | undefined | null): PathMode {\n if (!path) {\n return 'directory'\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n\nexport async function read(path: string) {\n try {\n return fs.readFile(path, { encoding: 'utf8' })\n } catch (err) {\n console.error(err)\n throw err\n }\n}\n","export function isURL(data: string) {\n try {\n const url = new URL(data)\n if (url?.href) {\n return true\n }\n } catch (error) {\n return false\n }\n return false\n}\n","type Data = string[][]\n\ntype Options = {\n typed?: boolean\n}\n\nexport function objectToParameters(data: Data, options: Options = {}) {\n return data\n .reduce((acc, [key, value]) => {\n if (options.typed) {\n acc.push(`${key}: ${value}[\"${key}\"], `)\n } else {\n acc.push(`${key}, `)\n }\n\n return acc\n }, [] as string[])\n .join('')\n}\n","export function nameSorter<T extends { name: string }>(a: T, b: T) {\n if (a.name < b.name) {\n return -1\n }\n if (a.name > b.name) {\n return 1\n }\n return 0\n}\n","export function createJSDocBlockText({ comments }: { comments: Array<string> }): string {\n const filteredComments = comments.filter(Boolean)\n\n if (!filteredComments.length) {\n return ''\n }\n\n const text = filteredComments.reduce((acc, comment) => {\n return `${acc}\\n* ${comment}`\n }, '/**')\n\n return `${text}\\n*/`\n}\n","/* eslint-disable no-param-reassign */\nexport function getUniqueName(originalName: string, data: Record<string, number>) {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n originalName += used\n }\n data[originalName] = 1\n return originalName\n}\n","export async function timeout(ms: number) {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n","/* eslint-disable no-cond-assign */\n\nexport type QueueTask<T = unknown> = {\n (...args: unknown[]): Promise<T>\n}\n\ninterface QueueItem {\n reject: <T>(reason?: T) => void\n resolve: <T>(value: T | PromiseLike<T>) => void\n task: QueueTask<unknown>\n}\n\nexport class Queue {\n private readonly queue: QueueItem[] = []\n\n workerCount = 0\n\n private maxParallel: number\n\n constructor(maxParallel: number) {\n this.maxParallel = maxParallel\n }\n\n run<T>(task: QueueTask<T>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const item: QueueItem = { reject, resolve, task } as QueueItem\n this.queue.push(item)\n this.work()\n })\n }\n\n private async work(): Promise<void> {\n if (this.workerCount >= this.maxParallel) return\n this.workerCount++\n\n let entry: QueueItem | undefined\n while ((entry = this.queue.shift())) {\n const { reject, resolve, task } = entry\n task()\n .then((result) => resolve(result))\n .catch((err) => reject(err))\n }\n\n this.workerCount--\n }\n}\n","export function getEncodedText(text?: string): string {\n return text ? text.replaceAll('`', '\\\\`') : ''\n}\n","export function renderTemplate<TData extends Record<string, string> = Record<string, string>>(template: string, data: TData | undefined = undefined) {\n if (!data) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n return template.replace(/{{(.*?)}}/g, (match) => {\n const value = data[match.split(/{{|}}/).filter(Boolean)[0].trim()]\n\n return value || ''\n })\n}\n","import rimraf from 'rimraf'\n\nexport async function clean(path: string) {\n return new Promise((resolve, reject) => {\n rimraf(path, (err) => {\n if (err) {\n reject(err)\n } else {\n resolve(true)\n }\n })\n })\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\n\nexport type TreeNodeOptions = DirectoryTreeOptions\n\nexport class TreeNode<T = unknown> {\n public data: T\n\n public parent?: TreeNode<T>\n\n public children: Array<TreeNode<T>> = []\n\n constructor(data: T, parent?: TreeNode<T>) {\n this.data = data\n this.parent = parent\n return this\n }\n\n addChild(data: T): TreeNode<T> {\n const child = new TreeNode(data, this)\n if (!this.children) {\n this.children = []\n }\n this.children.push(child)\n return child\n }\n\n find(data: T) {\n if (data === this.data) {\n return this\n }\n\n if (this.children) {\n for (let i = 0, { length } = this.children, target: unknown = null; i < length; i++) {\n target = this.children[i].find(data)\n if (target) {\n return target\n }\n }\n }\n\n return null\n }\n\n leaves(): TreeNode<T>[] {\n if (!this.children || this.children.length === 0) {\n // this is a leaf\n return [this]\n }\n\n // if not a leaf, return all children's leaves recursively\n const leaves: TreeNode<T>[] = []\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n // eslint-disable-next-line prefer-spread\n leaves.push.apply(leaves, this.children[i].leaves())\n }\n }\n return leaves\n }\n\n root(): TreeNode<T> {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void): this {\n if (typeof callback !== 'function') {\n throw new TypeError('forEach() callback must be a function')\n }\n\n // run this node through function\n callback(this)\n\n // do the same for all children\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n this.children[i].forEach(callback)\n }\n }\n\n return this\n }\n\n public static build<T = unknown>(path: string, options: TreeNodeOptions = {}): TreeNode<T> | null {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n\n if (!filteredTree) {\n return null\n }\n\n const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type })\n\n const recurse = (node: typeof treeNode, item: DirectoryTree) => {\n const subNode = node.addChild({ name: item.name, path: item.path, type: item.type })\n\n if (item.children?.length) {\n item.children?.forEach((child) => {\n recurse(subNode, child)\n })\n }\n }\n\n filteredTree.children?.forEach((child) => recurse(treeNode, child))\n\n return treeNode as TreeNode<T>\n }\n}\n","import { v4 as uuidv4 } from 'uuid'\n\nimport { write, read } from '../../utils'\n\nimport type { QueueTask, Queue } from '../../utils'\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n private task?: QueueTask<unknown>\n\n private queue?: Queue\n\n constructor(options?: { queue: Queue; task: QueueTask<unknown> }) {\n if (options) {\n this.task = options.task\n this.queue = options.queue\n }\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n getCacheByPath(path: string | undefined): CacheStore | undefined {\n let cache\n\n this.cache.forEach((item) => {\n if (item.file.path === path) {\n cache = item\n }\n })\n return cache as unknown as CacheStore\n }\n\n get files() {\n const files: File[] = []\n this.cache.forEach((item) => {\n files.push(item.file)\n })\n\n return files\n }\n\n async add(file: File) {\n const cacheItem = { id: uuidv4(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n\n if (this.queue) {\n await this.queue.run(async () => {\n await this.task?.(cacheItem.id, file)\n })\n }\n\n return file\n }\n\n addOrAppend(file: File) {\n if (!file.path.endsWith(file.fileName)) {\n // console.warn(`Path ${file.path}(file.path) should end with the fileName ${file.fileName}(file.filename)`)\n }\n\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n // empty source will also return true when using includes\n const sourceAlreadyExists = file.source && previousCache.file.source.includes(file.source)\n\n if (sourceAlreadyExists) {\n return Promise.resolve(file)\n }\n\n this.cache.delete(previousCache.id)\n\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n imports: [...(previousCache.file.imports || []), ...(file.imports || [])],\n exports: [...(previousCache.file.exports || []), ...(file.exports || [])],\n })\n }\n return this.add(file)\n }\n\n setStatus(id: UUID, status: Status) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n cacheItem.status = status\n this.cache.set(id, cacheItem)\n }\n\n get(id: UUID) {\n const cacheItem = this.getCache(id)\n return cacheItem?.file\n }\n\n remove(id: UUID) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n this.setStatus(id, 'removed')\n }\n\n async write(...params: Parameters<typeof write>) {\n return write(...params)\n }\n\n async read(...params: Parameters<typeof read>) {\n return read(...params)\n }\n}\n","import pathParser from 'path'\n\nimport uniq from 'lodash.uniq'\n\nimport { createImportDeclaration, createExportDeclaration, print } from '@kubb/ts-codegen'\n\nimport { TreeNode } from '../../utils'\n\nimport type { PathMode, TreeNodeOptions } from '../../utils'\nimport type { Path } from '../../types'\nimport type ts from 'typescript'\nimport type { File } from './types'\n\nexport function writeIndexes(root: string, options: TreeNodeOptions) {\n const tree = TreeNode.build<{ type: PathMode; path: Path; name: string }>(root, { extensions: /\\.ts/, ...options })\n\n if (!tree) {\n return undefined\n }\n\n const fileReducer = (files: File[], item: typeof tree) => {\n if (!item.children) {\n return []\n }\n\n if (item.children?.length > 1) {\n const path = pathParser.resolve(item.data.path, 'index.ts')\n const exports = item.children\n .map((file) => {\n if (!file) {\n return undefined\n }\n\n const importPath: string = file.data.type === 'directory' ? `./${file.data.name}` : `./${file.data.name.replace(/\\.[^.]*$/, '')}`\n\n // TODO weird hacky fix\n if (importPath.includes('index') && path.includes('index')) {\n return undefined\n }\n\n return { path: importPath }\n })\n .filter(Boolean) as File['exports']\n\n files.push({\n path,\n fileName: 'index.ts',\n source: '',\n exports,\n })\n } else {\n item.children?.forEach((child) => {\n const path = pathParser.resolve(item.data.path, 'index.ts')\n const importPath = child.data.type === 'directory' ? `./${child.data.name}` : `./${child.data.name.replace(/\\.[^.]*$/, '')}`\n\n files.push({\n path,\n fileName: 'index.ts',\n source: '',\n exports: [{ path: importPath }],\n })\n })\n }\n\n item.children.forEach((childItem) => {\n fileReducer(files, childItem)\n })\n\n return files\n }\n\n const files = fileReducer([], tree)\n\n return files\n}\n\nexport function combineFiles(files: Array<File | null>) {\n return files.filter(Boolean).reduce((acc, curr: File | null) => {\n if (!curr) {\n return acc\n }\n const prevIndex = acc.findIndex((item) => item.path === curr.path)\n\n if (prevIndex !== -1) {\n const prev = acc[prevIndex]\n acc[prevIndex] = {\n ...curr,\n source: `${prev.source}\\n${curr.source}`,\n imports: [...(prev.imports || []), ...(curr.imports || [])],\n exports: [...(prev.exports || []), ...(curr.exports || [])],\n }\n } else {\n acc.push(curr)\n }\n\n return acc\n }, [] as File[])\n}\n\nexport function getFileSource(file: File) {\n let { source } = file\n\n // TODO make generic check\n if (!file.fileName.endsWith('.ts')) {\n return file.source\n }\n const imports: File['imports'] = []\n const exports: File['exports'] = []\n\n file.imports?.forEach((curr) => {\n const exists = imports.find((imp) => imp.path === curr.path)\n if (!exists) {\n imports.push({\n ...curr,\n name: Array.isArray(curr.name) ? uniq(curr.name) : curr.name,\n })\n }\n\n if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {\n imports.push(curr)\n }\n\n if (exists && Array.isArray(exists.name)) {\n if (Array.isArray(curr.name)) {\n exists.name = uniq([...exists.name, ...curr.name])\n }\n }\n })\n\n file.exports?.forEach((curr) => {\n const exists = exports.find((imp) => imp.path === curr.path)\n if (!exists) {\n exports.push({\n ...curr,\n name: Array.isArray(curr.name) ? uniq(curr.name) : curr.name,\n })\n }\n\n if (exists && !Array.isArray(exists.name) && exists.name !== curr.name && exists.asAlias === curr.asAlias) {\n exports.push(curr)\n }\n\n if (exists && Array.isArray(exists.name)) {\n if (Array.isArray(curr.name)) {\n exists.name = uniq([...exists.name, ...curr.name])\n }\n }\n })\n\n const importNodes = imports.reduce((prev, curr) => {\n return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, asType: curr.asType })]\n }, [] as ts.ImportDeclaration[])\n const importSource = print(importNodes)\n\n const exportNodes = exports.reduce((prev, curr) => {\n return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })]\n }, [] as ts.ExportDeclaration[])\n const exportSource = print(exportNodes)\n\n if (importSource) {\n source = `${importSource}\\n${source}`\n }\n\n if (exportSource) {\n source = `${exportSource}\\n${source}`\n }\n\n return source\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\nimport { Queue } from '../../utils/Queue'\n\nimport type { QueueTask } from '../../utils/Queue'\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolvePathParams, ResolveNameParams } from '../../types'\nimport type { Logger } from '../../build'\nimport type { CorePluginOptions } from '../../plugin'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\n// This will make sure no input hook is omitted\nconst hookNames: {\n [P in PluginLifecycleHooks]: 1\n} = {\n validate: 1,\n buildStart: 1,\n resolvePath: 1,\n resolveName: 1,\n load: 1,\n transform: 1,\n writeFile: 1,\n buildEnd: 1,\n}\nexport const hooks = Object.keys(hookNames) as [PluginLifecycleHooks]\n\nexport class PluginManager {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions>\n\n public queue: Queue\n\n constructor(config: KubbConfig, options: { logger?: Logger; task: QueueTask }) {\n this.logger = options.logger\n this.config = config\n this.queue = new Queue(10)\n\n this.fileManager = new FileManager({ task: options.task, queue: this.queue })\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolvePath: this.resolvePath,\n resolveName: this.resolveName,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolvePath = (params: ResolvePathParams) => {\n if (params.pluginName) {\n return this.hookForPluginSync({\n pluginName: params.pluginName,\n hookName: 'resolvePath',\n parameters: [params.fileName, params.directory, params.options],\n })\n }\n return this.hookFirstSync({\n hookName: 'resolvePath',\n parameters: [params.fileName, params.directory, params.options],\n })\n }\n\n resolveName = (params: ResolveNameParams) => {\n if (params.pluginName) {\n return this.hookForPluginSync({\n pluginName: params.pluginName,\n hookName: 'resolveName',\n parameters: [params.name],\n })\n }\n return this.hookFirstSync({\n hookName: 'resolveName',\n parameters: [params.name],\n })\n }\n\n load = async (id: string) => {\n return this.hookFirst({\n hookName: 'load',\n parameters: [id],\n })\n }\n\n /**\n *\n * Run only hook for a specific plugin name\n */\n hookForPlugin<H extends PluginLifecycleHooks>({\n pluginName,\n hookName,\n parameters,\n }: {\n pluginName: string\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n }): Promise<ReturnType<PluginLifecycle[H]> | null> {\n const plugin = this.getPlugin(hookName, pluginName)\n\n return this.run({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n }\n\n hookForPluginSync<H extends PluginLifecycleHooks>({\n pluginName,\n hookName,\n parameters,\n }: {\n pluginName: string\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n }): ReturnType<PluginLifecycle[H]> {\n const plugin = this.getPlugin(hookName, pluginName)\n\n return this.runSync({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n }\n\n /**\n *\n * Chains, first non-null result stops and returns\n */\n hookFirst<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n skipped,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n skipped?: ReadonlySet<KubbPlugin> | null\n }): Promise<ReturnType<PluginLifecycle[H]>> {\n let promise: Promise<ReturnType<PluginLifecycle[H]>> = Promise.resolve(null as ReturnType<PluginLifecycle[H]>)\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n }) as typeof result\n })\n }\n return promise\n }\n\n /**\n *\n * Chains, first non-null result stops and returns\n */\n hookFirstSync<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n skipped,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n skipped?: ReadonlySet<KubbPlugin> | null\n }): ReturnType<PluginLifecycle[H]> {\n let result = null\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n\n result = this.runSync<H>({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n\n if (result != null) {\n break\n }\n }\n return result as ReturnType<PluginLifecycle[H]>\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>({\n hookName,\n parameters,\n }: {\n hookName: H\n parameters?: Parameters<PluginLifecycle[H]> | undefined\n }): Promise<Awaited<TOuput>[]> {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run({\n strategy: 'hookParallel',\n hookName,\n parameters,\n plugin,\n })\n } else {\n const promise: Promise<TOuput> = this.run({ strategy: 'hookParallel', hookName, parameters, plugin })\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n reduce,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n }): Promise<Argument0<H>> {\n const [argument0, ...rest] = parameters\n\n let promise: Promise<Argument0<H>> = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run({\n strategy: 'hookReduceArg0',\n hookName,\n parameters: [argument0, ...rest] as Parameters<PluginLifecycle[H]>,\n plugin,\n }).then((result) => reduce.call(this.core.api, argument0, result as ReturnType<PluginLifecycle[H]>, plugin))\n ) as Promise<Argument0<H>>\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: { hookName: H; parameters?: Parameters<PluginLifecycle[H]> }) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() =>\n this.run({\n strategy: 'hookSeq',\n hookName,\n parameters,\n plugin,\n })\n )\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n return plugins\n }\n\n private getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin {\n const plugins = [...this.plugins]\n\n const pluginByPluginName = plugins.find((item) => item.name === pluginName && item[hookName])\n if (!pluginByPluginName) {\n // fallback on the core plugin when there is no match\n if (this.config.logLevel === 'warn' && this.logger?.spinner) {\n this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`)\n }\n return this.core\n }\n return pluginByPluginName\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private run<H extends PluginLifecycleHooks, TResult = void>({\n strategy,\n hookName,\n parameters,\n plugin,\n }: {\n strategy: Strategy\n hookName: H\n parameters: unknown[] | undefined\n plugin: KubbPlugin\n }): Promise<TResult> {\n const hook = plugin[hookName]!\n\n return Promise.resolve()\n .then(() => {\n if (typeof hook !== 'function') {\n return hook\n }\n\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`\n }\n\n const hookResult = (hook as Function).apply(this.core.api, parameters)\n\n if (!(hookResult as Promise<unknown>)?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n .catch((e: Error) => {\n this.catcher<H>(e, plugin, hookName)\n }) as Promise<TResult>\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>({\n strategy,\n hookName,\n parameters,\n plugin,\n }: {\n strategy: Strategy\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n plugin: KubbPlugin\n }): ReturnType<PluginLifecycle[H]> {\n const hook = plugin[hookName]!\n\n // const context = this.pluginContexts.get(plugin)!;\n\n try {\n // eslint-disable-next-line @typescript-eslint/ban-types\n if (typeof hook !== 'function') {\n return hook\n }\n\n return (hook as Function).apply(this.core.api, parameters)\n } catch (e) {\n this.catcher<H>(e as Error, plugin, hookName)\n return null as ReturnType<PluginLifecycle[H]>\n }\n }\n\n private catcher<H extends PluginLifecycleHooks>(e: Error, plugin: KubbPlugin, hookName: H) {\n const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})\\n`\n\n throw new Error(text, { cause: e })\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { KubbPlugin } from '../../types'\n\nexport class ValidationPluginError extends Error {}\n\nexport function validatePlugins(plugins: KubbPlugin[], dependedPluginNames: string | string[]): true {\n let pluginNames: string[] = []\n if (typeof dependedPluginNames === 'string') {\n pluginNames = [dependedPluginNames]\n } else {\n pluginNames = dependedPluginNames\n }\n\n pluginNames.forEach((pluginName) => {\n const exists = plugins.some((plugin) => plugin.name === pluginName)\n if (!exists) {\n throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`)\n }\n })\n\n return true\n}\n","/* eslint-disable no-async-promise-executor */\nimport pathParser from 'path'\n\nimport { isURL } from './utils/isURL'\nimport { PluginManager } from './managers/pluginManager'\nimport { clean, read } from './utils'\nimport { getFileSource } from './managers/fileManager'\n\nimport type { FileManager, File } from './managers/fileManager'\nimport type { QueueTask } from './utils'\nimport type { PluginContext, TransformResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = {\n files: FileManager['files']\n}\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n fail: (text?: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type Logger = {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n}\ntype BuildOptions = {\n config: PluginContext['config']\n logger?: Logger\n}\n\nasync function transformReducer(\n this: PluginContext,\n _previousCode: string,\n result: TransformResult | Promise<TransformResult>,\n _plugin: KubbPlugin\n): Promise<string | null> {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions): Promise<BuildOutput> {\n const { config, logger } = options\n\n if (config.output.clean) {\n await clean(config.output.path)\n }\n\n const queueTask = async (id: string, file: File) => {\n const { path } = file\n\n let code = getFileSource(file)\n\n const loadedResult = await pluginManager.hookFirst({\n hookName: 'load',\n parameters: [path],\n })\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0({\n hookName: 'transform',\n parameters: [code, path],\n reduce: transformReducer,\n })\n\n if (config.output.write || config.output.write === undefined) {\n await pluginManager.hookParallel({\n hookName: 'writeFile',\n parameters: [transformedCode, path],\n })\n }\n }\n }\n\n const pluginManager = new PluginManager(config, { logger, task: queueTask as QueueTask })\n const { plugins, fileManager } = pluginManager\n\n await pluginManager.hookParallel<'validate', true>({\n hookName: 'validate',\n parameters: [plugins],\n })\n\n await pluginManager.hookParallel({\n hookName: 'buildStart',\n parameters: [config],\n })\n\n await pluginManager.hookParallel({ hookName: 'buildEnd' })\n\n return { files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })) }\n}\n\nexport type KubbBuild = (options: BuildOptions) => Promise<BuildOutput>\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise(async (resolve, reject) => {\n try {\n const output = await buildImplementation(options)\n\n setTimeout(() => {\n resolve(output)\n }, 500)\n } catch (e) {\n reject(e)\n }\n })\n}\n","import type { MaybePromise, KubbUserConfig, CLIOptions } from './types'\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link KubbConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport const defineConfig = (\n options:\n | MaybePromise<KubbUserConfig>\n | ((\n /** The options derived from the CLI flags */\n cliOptions: CLIOptions\n ) => MaybePromise<KubbUserConfig>)\n) => options\n","/**\n * Abstract class that contains the building blocks for plugins to create their own Generator\n * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137\n */\nexport abstract class Generator<TOptions extends object = object> {\n private _options: TOptions = {} as TOptions\n\n constructor(options: TOptions = {} as TOptions) {\n if (options) {\n this._options = {\n ...this._options,\n ...options,\n }\n }\n return this\n }\n\n get options() {\n return this._options\n }\n\n abstract build(...params: unknown[]): unknown\n}\n","import { Generator } from './Generator'\n/**\n * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator\n */\nexport abstract class SchemaGenerator<TOptions extends object, TInput, TOutput> extends Generator<TOptions> {\n abstract build(schema: TInput, name: string, description?: string): TOutput\n}\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { CorePluginOptions, createPlugin, name } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport * from './generators'\n\nexport default build\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/utils/isURL.ts","../src/utils/objectToParameters.ts","../src/utils/nameSorter.ts","../src/utils/jsdoc.ts","../src/utils/getUniqueName.ts","../src/utils/timeout.ts","../src/utils/Queue.ts","../src/utils/getEncodedText.ts","../src/utils/renderTemplate.ts","../src/utils/clean.ts","../src/utils/TreeNode.ts","../src/utils/transformReservedWord.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/utils.ts","../src/managers/pluginManager/PluginManager.ts","../src/managers/pluginManager/validate.ts","../src/build.ts","../src/config.ts","../src/generators/Generator.ts","../src/generators/SchemaGenerator.ts","../src/index.ts"],"names":["pathParser","fs","name","files","argument0"],"mappings":";;;AAAA,OAAOA,iBAAgB;;;ACEhB,SAAS,UAAa,QAA+C;AAC1E,SAAO,OAAQ,QAA6B,SAAS;AACvD;;;ACHA,SAAS,YAAY,UAAU;AAC/B,OAAO,gBAAgB;AAEvB,eAAe,oBAAoB,MAAc,MAAc;AAE7D,QAAM,aAAa,WAAW,QAAQ,WAAW,QAAQ,IAAI,CAAC;AAE9D,QAAM,GAAG,MAAM,YAAY,EAAE,WAAW,KAAK,CAAC;AAE9C,SAAO,GAAG,UAAU,WAAW,QAAQ,IAAI,GAAG,MAAM,EAAE,UAAU,QAAQ,CAAC;AAC3E;AAEA,eAAsB,MAAM,MAAc,MAAc;AACtD,MAAI;AACF,UAAM,GAAG,KAAK,IAAI;AAClB,UAAM,aAAa,MAAM,GAAG,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AAChE,QAAI,YAAY,SAAS,MAAM,MAAM;AACnC;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO,oBAAoB,MAAM,IAAI;AAAA,EACvC;AAEA,SAAO,oBAAoB,MAAM,IAAI;AACvC;;;ACfO,SAAS,kBAA+D,OAAoB;AACjG,SAAO;AAAA,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AIO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,QAAI;AACF,YAAM,SAAS,MAAM,oBAAoB,OAAO;AAEhD,iBAAW,MAAM;AACf,gBAAQ,MAAM;AAAA,MAChB,GAAG,GAAG;AAAA,IACR,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AC7GO,IAAM,eAAe,CAC1B,YAMG;;;ACVE,IAAe,YAAf,MAA2D;AAAA,EACxD,WAAqB,CAAC;AAAA,EAE9B,YAAY,UAAoB,CAAC,GAAe;AAC9C,QAAI,SAAS;AACX,WAAK,WAAW;AAAA,QACd,GAAG,KAAK;AAAA,QACR,GAAG;AAAA,MACL;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,UAAU;AACZ,WAAO,KAAK;AAAA,EACd;AAGF;;;AClBO,IAAe,kBAAf,cAAiF,UAAoB;AAE5G;;;ACKA,IAAO,cAAQ","sourcesContent":["import pathParser from 'path'\n\nimport { createPluginCache, transformReservedWord } from './utils'\n\nimport type { FileManager } from './managers/fileManager'\nimport type { PluginContext, KubbPlugin, PluginFactoryOptions } from './types'\n\ntype KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (\n options: T['options']\n) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>\n\nexport function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>) {\n return (options: T['options']) => {\n const plugin = factory(options)\n if (Array.isArray(plugin)) {\n throw new Error('Not implemented')\n }\n\n // default transform\n if (!plugin.transform) {\n plugin.transform = function transform(code) {\n return code\n }\n }\n\n return plugin\n }\n}\n\ntype Options = {\n config: PluginContext['config']\n fileManager: FileManager\n resolvePath: PluginContext['resolvePath']\n resolveName: PluginContext['resolveName']\n load: PluginContext['load']\n}\n\n// not publicly exported\nexport type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>\n\nexport const name = 'core' as const\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolvePath, resolveName, load } = options\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(...files) {\n return Promise.all(files.map((file) => (file.override ? fileManager.add(file) : fileManager.addOrAppend(file))))\n },\n resolvePath,\n resolveName: (params) => {\n const name = resolveName(params)\n\n return transformReservedWord(name)\n },\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n options,\n api,\n resolvePath(fileName) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n\n return pathParser.resolve(root, fileName)\n },\n resolveName(name) {\n return name\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport function isPromise<T>(result: MaybePromise<T>): result is Promise<T> {\n return typeof (result as Promise<unknown>)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport { promises as fs } from 'fs'\nimport pathParser from 'path'\n\nasync function safeWriteFileToPath(path: string, data: string) {\n // resolve the full path and get just the directory, ignoring the file and extension\n const passedPath = pathParser.dirname(pathParser.resolve(path))\n // make the directory, recursively. Theoretically, if every directory in the path exists, this won't do anything.\n await fs.mkdir(passedPath, { recursive: true })\n // write the file to the newly created directory\n return fs.writeFile(pathParser.resolve(path), data, { encoding: 'utf-8' })\n}\n\nexport async function write(data: string, path: string) {\n try {\n await fs.stat(path)\n const oldContent = await fs.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === data) {\n return\n }\n } catch (_err) {\n return safeWriteFileToPath(path, data)\n }\n\n return safeWriteFileToPath(path, data)\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<T extends object = object> {\n delete(id: keyof T): boolean\n get(id: keyof T): T[keyof T] | null\n has(id: keyof T): boolean\n set(id: keyof T, value: unknown): void\n}\n\nexport function createPluginCache<T extends Record<string, [number, unknown]>>(cache: T): Cache<T> {\n return {\n delete(id: keyof T) {\n return delete cache[id]\n },\n get(id) {\n const item = cache[id]\n if (!item) return null\n item[0] = 0\n return item[1] as T[keyof T]\n },\n has(id) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id, value) {\n cache[id] = [0, value] as T[keyof T]\n },\n }\n}\n","import pathParser from 'path'\nimport { promises as fs } from 'fs'\n\nfunction slash(path: string) {\n const isExtendedLengthPath = /^\\\\\\\\\\?\\\\/.test(path)\n\n if (isExtendedLengthPath) {\n return path\n }\n\n return path.replace(/\\\\/g, '/')\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null) {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir} ${filePath}`)\n }\n\n const relativePath = pathParser.relative(rootDir, filePath)\n\n // On Windows, paths are separated with a \"\\\"\n // However, web browsers use \"/\" no matter the platform\n const path = slash(relativePath).replace('../', '').trimEnd()\n\n if (path.startsWith('../')) {\n return path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))\n }\n\n return `./${path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))}`\n}\n\nexport type PathMode = 'file' | 'directory'\n\nexport function getPathMode(path: string | undefined | null): PathMode {\n if (!path) {\n return 'directory'\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n\nexport async function read(path: string) {\n try {\n return fs.readFile(path, { encoding: 'utf8' })\n } catch (err) {\n console.error(err)\n throw err\n }\n}\n","export function isURL(data: string) {\n try {\n const url = new URL(data)\n if (url?.href) {\n return true\n }\n } catch (error) {\n return false\n }\n return false\n}\n","type Data = string[][]\n\ntype Options = {\n typed?: boolean\n}\n\nexport function objectToParameters(data: Data, options: Options = {}) {\n const { typed } = options\n\n return data\n .reduce((acc, [key, value]) => {\n if (typed) {\n acc.push(`${key}: ${value}[\"${key}\"]`)\n } else {\n acc.push(`${key}`)\n }\n\n return acc\n }, [] as string[])\n .join(', ')\n}\n","export function nameSorter<T extends { name: string }>(a: T, b: T) {\n if (a.name < b.name) {\n return -1\n }\n if (a.name > b.name) {\n return 1\n }\n return 0\n}\n","export function createJSDocBlockText({ comments }: { comments: Array<string> }): string {\n const filteredComments = comments.filter(Boolean)\n\n if (!filteredComments.length) {\n return ''\n }\n\n const text = filteredComments.reduce((acc, comment) => {\n return `${acc}\\n* ${comment}`\n }, '/**')\n\n return `${text}\\n*/`\n}\n","/* eslint-disable no-param-reassign */\nexport function getUniqueName(originalName: string, data: Record<string, number>) {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n originalName += used\n }\n data[originalName] = 1\n return originalName\n}\n","export async function timeout(ms: number) {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n","/* eslint-disable no-cond-assign */\n\nexport type QueueTask<T = unknown> = {\n (...args: unknown[]): Promise<T>\n}\n\ninterface QueueItem {\n reject: <T>(reason?: T) => void\n resolve: <T>(value: T | PromiseLike<T>) => void\n task: QueueTask<unknown>\n}\n\nexport class Queue {\n private readonly queue: QueueItem[] = []\n\n workerCount = 0\n\n private maxParallel: number\n\n constructor(maxParallel: number) {\n this.maxParallel = maxParallel\n }\n\n run<T>(task: QueueTask<T>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const item: QueueItem = { reject, resolve, task } as QueueItem\n this.queue.push(item)\n this.work()\n })\n }\n\n private async work(): Promise<void> {\n if (this.workerCount >= this.maxParallel) return\n this.workerCount++\n\n let entry: QueueItem | undefined\n while ((entry = this.queue.shift())) {\n const { reject, resolve, task } = entry\n task()\n .then((result) => resolve(result))\n .catch((err) => reject(err))\n }\n\n this.workerCount--\n }\n}\n","export function getEncodedText(text?: string): string {\n return text ? text.replaceAll('`', '\\\\`') : ''\n}\n","export function renderTemplate<TData extends Record<string, string> = Record<string, string>>(template: string, data: TData | undefined = undefined) {\n if (!data) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n return template.replace(/{{(.*?)}}/g, (match) => {\n const value = data[match.split(/{{|}}/).filter(Boolean)[0].trim()]\n\n return value || ''\n })\n}\n","import rimraf from 'rimraf'\n\nexport async function clean(path: string) {\n return new Promise((resolve, reject) => {\n rimraf(path, (err) => {\n if (err) {\n reject(err)\n } else {\n resolve(true)\n }\n })\n })\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\n\nexport type TreeNodeOptions = DirectoryTreeOptions\n\nexport class TreeNode<T = unknown> {\n public data: T\n\n public parent?: TreeNode<T>\n\n public children: Array<TreeNode<T>> = []\n\n constructor(data: T, parent?: TreeNode<T>) {\n this.data = data\n this.parent = parent\n return this\n }\n\n addChild(data: T): TreeNode<T> {\n const child = new TreeNode(data, this)\n if (!this.children) {\n this.children = []\n }\n this.children.push(child)\n return child\n }\n\n find(data: T) {\n if (data === this.data) {\n return this\n }\n\n if (this.children) {\n for (let i = 0, { length } = this.children, target: unknown = null; i < length; i++) {\n target = this.children[i].find(data)\n if (target) {\n return target\n }\n }\n }\n\n return null\n }\n\n leaves(): TreeNode<T>[] {\n if (!this.children || this.children.length === 0) {\n // this is a leaf\n return [this]\n }\n\n // if not a leaf, return all children's leaves recursively\n const leaves: TreeNode<T>[] = []\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n // eslint-disable-next-line prefer-spread\n leaves.push.apply(leaves, this.children[i].leaves())\n }\n }\n return leaves\n }\n\n root(): TreeNode<T> {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void): this {\n if (typeof callback !== 'function') {\n throw new TypeError('forEach() callback must be a function')\n }\n\n // run this node through function\n callback(this)\n\n // do the same for all children\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n this.children[i].forEach(callback)\n }\n }\n\n return this\n }\n\n public static build<T = unknown>(path: string, options: TreeNodeOptions = {}): TreeNode<T> | null {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n\n if (!filteredTree) {\n return null\n }\n\n const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type })\n\n const recurse = (node: typeof treeNode, item: DirectoryTree) => {\n const subNode = node.addChild({ name: item.name, path: item.path, type: item.type })\n\n if (item.children?.length) {\n item.children?.forEach((child) => {\n recurse(subNode, child)\n })\n }\n }\n\n filteredTree.children?.forEach((child) => recurse(treeNode, child))\n\n return treeNode as TreeNode<T>\n }\n}\n","/**\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = [\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n\n 'Array',\n 'Date',\n 'eval',\n 'function',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n]\n\nexport function transformReservedWord(word: string) {\n if (reservedWords.includes(word)) {\n return `_${word}`\n }\n\n return word\n}\n","import { v4 as uuidv4 } from 'uuid'\n\nimport { write, read } from '../../utils'\n\nimport type { QueueTask, Queue } from '../../utils'\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n private task?: QueueTask<unknown>\n\n private queue?: Queue\n\n constructor(options?: { queue: Queue; task: QueueTask<unknown> }) {\n if (options) {\n this.task = options.task\n this.queue = options.queue\n }\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n getCacheByPath(path: string | undefined): CacheStore | undefined {\n let cache\n\n this.cache.forEach((item) => {\n if (item.file.path === path) {\n cache = item\n }\n })\n return cache as unknown as CacheStore\n }\n\n get files() {\n const files: File[] = []\n this.cache.forEach((item) => {\n files.push(item.file)\n })\n\n return files\n }\n\n async add(file: File) {\n const cacheItem = { id: uuidv4(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n\n if (this.queue) {\n await this.queue.run(async () => {\n await this.task?.(cacheItem.id, file)\n })\n }\n\n return file\n }\n\n addOrAppend(file: File) {\n if (!file.path.endsWith(file.fileName)) {\n // console.warn(`Path ${file.path}(file.path) should end with the fileName ${file.fileName}(file.filename)`)\n }\n\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n // empty source will also return true when using includes\n const sourceAlreadyExists = file.source && previousCache.file.source.includes(file.source)\n\n if (sourceAlreadyExists) {\n return Promise.resolve(file)\n }\n\n this.cache.delete(previousCache.id)\n\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n imports: [...(previousCache.file.imports || []), ...(file.imports || [])],\n exports: [...(previousCache.file.exports || []), ...(file.exports || [])],\n })\n }\n return this.add(file)\n }\n\n setStatus(id: UUID, status: Status) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n cacheItem.status = status\n this.cache.set(id, cacheItem)\n }\n\n get(id: UUID) {\n const cacheItem = this.getCache(id)\n return cacheItem?.file\n }\n\n remove(id: UUID) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n this.setStatus(id, 'removed')\n }\n\n async write(...params: Parameters<typeof write>) {\n return write(...params)\n }\n\n async read(...params: Parameters<typeof read>) {\n return read(...params)\n }\n}\n","import pathParser from 'path'\n\nimport uniq from 'lodash.uniq'\n\nimport { createImportDeclaration, createExportDeclaration, print } from '@kubb/ts-codegen'\n\nimport { TreeNode } from '../../utils'\n\nimport type { PathMode, TreeNodeOptions } from '../../utils'\nimport type { Path } from '../../types'\nimport type ts from 'typescript'\nimport type { File } from './types'\n\nexport function writeIndexes(root: string, options: TreeNodeOptions) {\n const tree = TreeNode.build<{ type: PathMode; path: Path; name: string }>(root, { extensions: /\\.ts/, ...options })\n\n if (!tree) {\n return undefined\n }\n\n const fileReducer = (files: File[], item: typeof tree) => {\n if (!item.children) {\n return []\n }\n\n if (item.children?.length > 1) {\n const path = pathParser.resolve(item.data.path, 'index.ts')\n const exports = item.children\n .map((file) => {\n if (!file) {\n return undefined\n }\n\n const importPath: string = file.data.type === 'directory' ? `./${file.data.name}` : `./${file.data.name.replace(/\\.[^.]*$/, '')}`\n\n // TODO weird hacky fix\n if (importPath.includes('index') && path.includes('index')) {\n return undefined\n }\n\n return { path: importPath }\n })\n .filter(Boolean) as File['exports']\n\n files.push({\n path,\n fileName: 'index.ts',\n source: '',\n exports,\n })\n } else {\n item.children?.forEach((child) => {\n const path = pathParser.resolve(item.data.path, 'index.ts')\n const importPath = child.data.type === 'directory' ? `./${child.data.name}` : `./${child.data.name.replace(/\\.[^.]*$/, '')}`\n\n files.push({\n path,\n fileName: 'index.ts',\n source: '',\n exports: [{ path: importPath }],\n })\n })\n }\n\n item.children.forEach((childItem) => {\n fileReducer(files, childItem)\n })\n\n return files\n }\n\n const files = fileReducer([], tree)\n\n return files\n}\n\nexport function combineFiles(files: Array<File | null>) {\n return files.filter(Boolean).reduce((acc, curr: File | null) => {\n if (!curr) {\n return acc\n }\n const prevIndex = acc.findIndex((item) => item.path === curr.path)\n\n if (prevIndex !== -1) {\n const prev = acc[prevIndex]\n acc[prevIndex] = {\n ...curr,\n source: `${prev.source}\\n${curr.source}`,\n imports: [...(prev.imports || []), ...(curr.imports || [])],\n exports: [...(prev.exports || []), ...(curr.exports || [])],\n }\n } else {\n acc.push(curr)\n }\n\n return acc\n }, [] as File[])\n}\n\nexport function getFileSource(file: File) {\n let { source } = file\n\n // TODO make generic check\n if (!file.fileName.endsWith('.ts')) {\n return file.source\n }\n const imports: File['imports'] = []\n const exports: File['exports'] = []\n\n file.imports?.forEach((curr) => {\n const exists = imports.find((imp) => imp.path === curr.path)\n if (!exists) {\n imports.push({\n ...curr,\n name: Array.isArray(curr.name) ? uniq(curr.name) : curr.name,\n })\n }\n\n if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {\n imports.push(curr)\n }\n\n if (exists && Array.isArray(exists.name)) {\n if (Array.isArray(curr.name)) {\n exists.name = uniq([...exists.name, ...curr.name])\n }\n }\n })\n\n file.exports?.forEach((curr) => {\n const exists = exports.find((imp) => imp.path === curr.path)\n if (!exists) {\n exports.push({\n ...curr,\n name: Array.isArray(curr.name) ? uniq(curr.name) : curr.name,\n })\n }\n\n if (exists && !Array.isArray(exists.name) && exists.name !== curr.name && exists.asAlias === curr.asAlias) {\n exports.push(curr)\n }\n\n if (exists && Array.isArray(exists.name)) {\n if (Array.isArray(curr.name)) {\n exists.name = uniq([...exists.name, ...curr.name])\n }\n }\n })\n\n const importNodes = imports.reduce((prev, curr) => {\n return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })]\n }, [] as ts.ImportDeclaration[])\n const importSource = print(importNodes)\n\n const exportNodes = exports.reduce((prev, curr) => {\n return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })]\n }, [] as ts.ExportDeclaration[])\n const exportSource = print(exportNodes)\n\n if (importSource) {\n source = `${importSource}\\n${source}`\n }\n\n if (exportSource) {\n source = `${exportSource}\\n${source}`\n }\n\n return source\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\nimport { Queue } from '../../utils/Queue'\n\nimport type { QueueTask } from '../../utils/Queue'\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolvePathParams, ResolveNameParams } from '../../types'\nimport type { Logger } from '../../build'\nimport type { CorePluginOptions } from '../../plugin'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\n// This will make sure no input hook is omitted\nconst hookNames: {\n [P in PluginLifecycleHooks]: 1\n} = {\n validate: 1,\n buildStart: 1,\n resolvePath: 1,\n resolveName: 1,\n load: 1,\n transform: 1,\n writeFile: 1,\n buildEnd: 1,\n}\nexport const hooks = Object.keys(hookNames) as [PluginLifecycleHooks]\n\nexport class PluginManager {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions>\n\n public queue: Queue\n\n constructor(config: KubbConfig, options: { logger?: Logger; task: QueueTask }) {\n this.logger = options.logger\n this.config = config\n this.queue = new Queue(10)\n\n this.fileManager = new FileManager({ task: options.task, queue: this.queue })\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolvePath: this.resolvePath,\n resolveName: this.resolveName,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolvePath = (params: ResolvePathParams) => {\n if (params.pluginName) {\n return this.hookForPluginSync({\n pluginName: params.pluginName,\n hookName: 'resolvePath',\n parameters: [params.fileName, params.directory, params.options],\n })\n }\n return this.hookFirstSync({\n hookName: 'resolvePath',\n parameters: [params.fileName, params.directory, params.options],\n })\n }\n\n resolveName = (params: ResolveNameParams) => {\n if (params.pluginName) {\n return this.hookForPluginSync({\n pluginName: params.pluginName,\n hookName: 'resolveName',\n parameters: [params.name],\n })\n }\n return this.hookFirstSync({\n hookName: 'resolveName',\n parameters: [params.name],\n })\n }\n\n load = async (id: string) => {\n return this.hookFirst({\n hookName: 'load',\n parameters: [id],\n })\n }\n\n /**\n *\n * Run only hook for a specific plugin name\n */\n hookForPlugin<H extends PluginLifecycleHooks>({\n pluginName,\n hookName,\n parameters,\n }: {\n pluginName: string\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n }): Promise<ReturnType<PluginLifecycle[H]> | null> {\n const plugin = this.getPlugin(hookName, pluginName)\n\n return this.run({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n }\n\n hookForPluginSync<H extends PluginLifecycleHooks>({\n pluginName,\n hookName,\n parameters,\n }: {\n pluginName: string\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n }): ReturnType<PluginLifecycle[H]> {\n const plugin = this.getPlugin(hookName, pluginName)\n\n return this.runSync({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n }\n\n /**\n *\n * Chains, first non-null result stops and returns\n */\n hookFirst<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n skipped,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n skipped?: ReadonlySet<KubbPlugin> | null\n }): Promise<ReturnType<PluginLifecycle[H]>> {\n let promise: Promise<ReturnType<PluginLifecycle[H]>> = Promise.resolve(null as ReturnType<PluginLifecycle[H]>)\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n }) as typeof result\n })\n }\n return promise\n }\n\n /**\n *\n * Chains, first non-null result stops and returns\n */\n hookFirstSync<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n skipped,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n skipped?: ReadonlySet<KubbPlugin> | null\n }): ReturnType<PluginLifecycle[H]> {\n let result = null\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n\n result = this.runSync<H>({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n\n if (result != null) {\n break\n }\n }\n return result as ReturnType<PluginLifecycle[H]>\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>({\n hookName,\n parameters,\n }: {\n hookName: H\n parameters?: Parameters<PluginLifecycle[H]> | undefined\n }): Promise<Awaited<TOuput>[]> {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run({\n strategy: 'hookParallel',\n hookName,\n parameters,\n plugin,\n })\n } else {\n const promise: Promise<TOuput> = this.run({ strategy: 'hookParallel', hookName, parameters, plugin })\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n reduce,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n }): Promise<Argument0<H>> {\n const [argument0, ...rest] = parameters\n\n let promise: Promise<Argument0<H>> = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run({\n strategy: 'hookReduceArg0',\n hookName,\n parameters: [argument0, ...rest] as Parameters<PluginLifecycle[H]>,\n plugin,\n }).then((result) => reduce.call(this.core.api, argument0, result as ReturnType<PluginLifecycle[H]>, plugin))\n ) as Promise<Argument0<H>>\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: { hookName: H; parameters?: Parameters<PluginLifecycle[H]> }) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() =>\n this.run({\n strategy: 'hookSeq',\n hookName,\n parameters,\n plugin,\n })\n )\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n return plugins\n }\n\n private getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin {\n const plugins = [...this.plugins]\n\n const pluginByPluginName = plugins.find((item) => item.name === pluginName && item[hookName])\n if (!pluginByPluginName) {\n // fallback on the core plugin when there is no match\n if (this.config.logLevel === 'warn' && this.logger?.spinner) {\n this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`)\n }\n return this.core\n }\n return pluginByPluginName\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private run<H extends PluginLifecycleHooks, TResult = void>({\n strategy,\n hookName,\n parameters,\n plugin,\n }: {\n strategy: Strategy\n hookName: H\n parameters: unknown[] | undefined\n plugin: KubbPlugin\n }): Promise<TResult> {\n const hook = plugin[hookName]!\n\n return Promise.resolve()\n .then(() => {\n if (typeof hook !== 'function') {\n return hook\n }\n\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`\n }\n\n const hookResult = (hook as Function).apply(this.core.api, parameters)\n\n if (!(hookResult as Promise<unknown>)?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n .catch((e: Error) => {\n this.catcher<H>(e, plugin, hookName)\n }) as Promise<TResult>\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>({\n strategy,\n hookName,\n parameters,\n plugin,\n }: {\n strategy: Strategy\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n plugin: KubbPlugin\n }): ReturnType<PluginLifecycle[H]> {\n const hook = plugin[hookName]!\n\n // const context = this.pluginContexts.get(plugin)!;\n\n try {\n // eslint-disable-next-line @typescript-eslint/ban-types\n if (typeof hook !== 'function') {\n return hook\n }\n\n return (hook as Function).apply(this.core.api, parameters)\n } catch (e) {\n this.catcher<H>(e as Error, plugin, hookName)\n return null as ReturnType<PluginLifecycle[H]>\n }\n }\n\n private catcher<H extends PluginLifecycleHooks>(e: Error, plugin: KubbPlugin, hookName: H) {\n const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})\\n`\n\n throw new Error(text, { cause: e })\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { KubbPlugin } from '../../types'\n\nexport class ValidationPluginError extends Error {}\n\nexport function validatePlugins(plugins: KubbPlugin[], dependedPluginNames: string | string[]): true {\n let pluginNames: string[] = []\n if (typeof dependedPluginNames === 'string') {\n pluginNames = [dependedPluginNames]\n } else {\n pluginNames = dependedPluginNames\n }\n\n pluginNames.forEach((pluginName) => {\n const exists = plugins.some((plugin) => plugin.name === pluginName)\n if (!exists) {\n throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`)\n }\n })\n\n return true\n}\n","/* eslint-disable no-async-promise-executor */\nimport pathParser from 'path'\n\nimport { isURL } from './utils/isURL'\nimport { PluginManager } from './managers/pluginManager'\nimport { clean, read } from './utils'\nimport { getFileSource } from './managers/fileManager'\n\nimport type { FileManager, File } from './managers/fileManager'\nimport type { QueueTask } from './utils'\nimport type { PluginContext, TransformResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = {\n files: FileManager['files']\n}\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n fail: (text?: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type Logger = {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n}\ntype BuildOptions = {\n config: PluginContext['config']\n logger?: Logger\n}\n\nasync function transformReducer(\n this: PluginContext,\n _previousCode: string,\n result: TransformResult | Promise<TransformResult>,\n _plugin: KubbPlugin\n): Promise<string | null> {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions): Promise<BuildOutput> {\n const { config, logger } = options\n\n if (config.output.clean) {\n await clean(config.output.path)\n }\n\n const queueTask = async (id: string, file: File) => {\n const { path } = file\n\n let code = getFileSource(file)\n\n const loadedResult = await pluginManager.hookFirst({\n hookName: 'load',\n parameters: [path],\n })\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0({\n hookName: 'transform',\n parameters: [code, path],\n reduce: transformReducer,\n })\n\n if (config.output.write || config.output.write === undefined) {\n await pluginManager.hookParallel({\n hookName: 'writeFile',\n parameters: [transformedCode, path],\n })\n }\n }\n }\n\n const pluginManager = new PluginManager(config, { logger, task: queueTask as QueueTask })\n const { plugins, fileManager } = pluginManager\n\n await pluginManager.hookParallel<'validate', true>({\n hookName: 'validate',\n parameters: [plugins],\n })\n\n await pluginManager.hookParallel({\n hookName: 'buildStart',\n parameters: [config],\n })\n\n await pluginManager.hookParallel({ hookName: 'buildEnd' })\n\n return { files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })) }\n}\n\nexport type KubbBuild = (options: BuildOptions) => Promise<BuildOutput>\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise(async (resolve, reject) => {\n try {\n const output = await buildImplementation(options)\n\n setTimeout(() => {\n resolve(output)\n }, 500)\n } catch (e) {\n reject(e)\n }\n })\n}\n","import type { MaybePromise, KubbUserConfig, CLIOptions } from './types'\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link KubbConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport const defineConfig = (\n options:\n | MaybePromise<KubbUserConfig>\n | ((\n /** The options derived from the CLI flags */\n cliOptions: CLIOptions\n ) => MaybePromise<KubbUserConfig>)\n) => options\n","/**\n * Abstract class that contains the building blocks for plugins to create their own Generator\n * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137\n */\nexport abstract class Generator<TOptions extends object = object> {\n private _options: TOptions = {} as TOptions\n\n constructor(options: TOptions = {} as TOptions) {\n if (options) {\n this._options = {\n ...this._options,\n ...options,\n }\n }\n return this\n }\n\n get options() {\n return this._options\n }\n\n abstract build(...params: unknown[]): unknown\n}\n","import { Generator } from './Generator'\n/**\n * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator\n */\nexport abstract class SchemaGenerator<TOptions extends object, TInput, TOutput> extends Generator<TOptions> {\n abstract build(schema: TInput, name: string, description?: string): TOutput\n}\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { CorePluginOptions, createPlugin, name } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport * from './generators'\n\nexport default build\n"]}
package/dist/index.d.ts CHANGED
@@ -264,15 +264,17 @@ declare class TreeNode<T = unknown> {
264
264
  static build<T = unknown>(path: string, options?: TreeNodeOptions): TreeNode<T> | null;
265
265
  }
266
266
 
267
+ declare function transformReservedWord(word: string): string;
268
+
267
269
  type Import = {
268
270
  name: string | string[];
269
271
  path: string;
270
- asType?: boolean;
272
+ isTypeOnly?: boolean;
271
273
  };
272
274
  type Export = {
273
275
  name?: string | string[];
274
276
  path: string;
275
- asType?: boolean;
277
+ isTypeOnly?: boolean;
276
278
  asAlias?: boolean;
277
279
  };
278
280
  type File = {
@@ -478,4 +480,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
478
480
  abstract build(schema: TInput, name: string, description?: string): TOutput;
479
481
  }
480
482
 
481
- export { Argument0, CLIOptions, Cache, CacheStore, CorePluginOptions, File, FileManager, FileName, Generator, KubbBuild, KubbConfig, KubbJSONPlugin, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUserConfig, LogLevel, LogType, Logger, MaybePromise, OptionalPath, Path, PathMode, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, Queue, QueueTask, Register, ResolveNameParams, ResolvePathParams, SchemaGenerator, Status, Strategy, TransformResult, TreeNode, TreeNodeOptions, UUID, ValidationPluginError, build, clean, combineFiles, createJSDocBlockText, createPlugin, createPluginCache, build as default, defineConfig, getEncodedText, getFileSource, getPathMode, getRelativePath, getUniqueName, hooks, isPromise, isURL, name, nameSorter, objectToParameters, read, renderTemplate, timeout, validatePlugins, write, writeIndexes };
483
+ export { Argument0, CLIOptions, Cache, CacheStore, CorePluginOptions, File, FileManager, FileName, Generator, KubbBuild, KubbConfig, KubbJSONPlugin, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUserConfig, LogLevel, LogType, Logger, MaybePromise, OptionalPath, Path, PathMode, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, Queue, QueueTask, Register, ResolveNameParams, ResolvePathParams, SchemaGenerator, Status, Strategy, TransformResult, TreeNode, TreeNodeOptions, UUID, ValidationPluginError, build, clean, combineFiles, createJSDocBlockText, createPlugin, createPluginCache, build as default, defineConfig, getEncodedText, getFileSource, getPathMode, getRelativePath, getUniqueName, hooks, isPromise, isURL, name, nameSorter, objectToParameters, read, renderTemplate, timeout, transformReservedWord, validatePlugins, write, writeIndexes };
package/dist/index.js CHANGED
@@ -104,14 +104,15 @@ function isURL(data) {
104
104
 
105
105
  // src/utils/objectToParameters.ts
106
106
  function objectToParameters(data, options = {}) {
107
+ const { typed } = options;
107
108
  return data.reduce((acc, [key, value]) => {
108
- if (options.typed) {
109
- acc.push(`${key}: ${value}["${key}"], `);
109
+ if (typed) {
110
+ acc.push(`${key}: ${value}["${key}"]`);
110
111
  } else {
111
- acc.push(`${key}, `);
112
+ acc.push(`${key}`);
112
113
  }
113
114
  return acc;
114
- }, []).join("");
115
+ }, []).join(", ");
115
116
  }
116
117
 
117
118
  // src/utils/nameSorter.ts
@@ -293,6 +294,99 @@ var TreeNode = class {
293
294
  }
294
295
  };
295
296
 
297
+ // src/utils/transformReservedWord.ts
298
+ var reservedWords = [
299
+ "abstract",
300
+ "arguments",
301
+ "boolean",
302
+ "break",
303
+ "byte",
304
+ "case",
305
+ "catch",
306
+ "char",
307
+ "class",
308
+ "const",
309
+ "continue",
310
+ "debugger",
311
+ "default",
312
+ "delete",
313
+ "do",
314
+ "double",
315
+ "else",
316
+ "enum",
317
+ "eval",
318
+ "export",
319
+ "extends",
320
+ "false",
321
+ "final",
322
+ "finally",
323
+ "float",
324
+ "for",
325
+ "function",
326
+ "goto",
327
+ "if",
328
+ "implements",
329
+ "import",
330
+ "in",
331
+ "instanceof",
332
+ "int",
333
+ "interface",
334
+ "let",
335
+ "long",
336
+ "native",
337
+ "new",
338
+ "null",
339
+ "package",
340
+ "private",
341
+ "protected",
342
+ "public",
343
+ "return",
344
+ "short",
345
+ "static",
346
+ "super",
347
+ "switch",
348
+ "synchronized",
349
+ "this",
350
+ "throw",
351
+ "throws",
352
+ "transient",
353
+ "true",
354
+ "try",
355
+ "typeof",
356
+ "var",
357
+ "void",
358
+ "volatile",
359
+ "while",
360
+ "with",
361
+ "yield",
362
+ "Array",
363
+ "Date",
364
+ "eval",
365
+ "function",
366
+ "hasOwnProperty",
367
+ "Infinity",
368
+ "isFinite",
369
+ "isNaN",
370
+ "isPrototypeOf",
371
+ "length",
372
+ "Math",
373
+ "name",
374
+ "NaN",
375
+ "Number",
376
+ "Object",
377
+ "prototype",
378
+ "String",
379
+ "toString",
380
+ "undefined",
381
+ "valueOf"
382
+ ];
383
+ function transformReservedWord(word) {
384
+ if (reservedWords.includes(word)) {
385
+ return `_${word}`;
386
+ }
387
+ return word;
388
+ }
389
+
296
390
  // src/plugin.ts
297
391
  function createPlugin(factory) {
298
392
  return (options) => {
@@ -320,7 +414,10 @@ var definePlugin = createPlugin((options) => {
320
414
  return Promise.all(files.map((file) => file.override ? fileManager.add(file) : fileManager.addOrAppend(file)));
321
415
  },
322
416
  resolvePath,
323
- resolveName,
417
+ resolveName: (params) => {
418
+ const name2 = resolveName(params);
419
+ return transformReservedWord(name2);
420
+ },
324
421
  load,
325
422
  cache: createPluginCache(/* @__PURE__ */ Object.create(null))
326
423
  };
@@ -531,7 +628,7 @@ function getFileSource(file) {
531
628
  }
532
629
  });
533
630
  const importNodes = imports.reduce((prev, curr) => {
534
- return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, asType: curr.asType })];
631
+ return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })];
535
632
  }, []);
536
633
  const importSource = print(importNodes);
537
634
  const exportNodes = exports.reduce((prev, curr) => {
@@ -950,6 +1047,6 @@ var SchemaGenerator = class extends Generator {
950
1047
  // src/index.ts
951
1048
  var src_default = build;
952
1049
 
953
- export { FileManager, Generator, PluginManager, Queue, SchemaGenerator, TreeNode, ValidationPluginError, build, clean, combineFiles, createJSDocBlockText, createPlugin, createPluginCache, src_default as default, defineConfig, getEncodedText, getFileSource, getPathMode, getRelativePath, getUniqueName, hooks, isPromise, isURL, name, nameSorter, objectToParameters, read, renderTemplate, timeout, validatePlugins, write, writeIndexes };
1050
+ export { FileManager, Generator, PluginManager, Queue, SchemaGenerator, TreeNode, ValidationPluginError, build, clean, combineFiles, createJSDocBlockText, createPlugin, createPluginCache, src_default as default, defineConfig, getEncodedText, getFileSource, getPathMode, getRelativePath, getUniqueName, hooks, isPromise, isURL, name, nameSorter, objectToParameters, read, renderTemplate, timeout, transformReservedWord, validatePlugins, write, writeIndexes };
954
1051
  //# sourceMappingURL=out.js.map
955
1052
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/utils/isURL.ts","../src/utils/objectToParameters.ts","../src/utils/nameSorter.ts","../src/utils/jsdoc.ts","../src/utils/getUniqueName.ts","../src/utils/timeout.ts","../src/utils/Queue.ts","../src/utils/getEncodedText.ts","../src/utils/renderTemplate.ts","../src/utils/clean.ts","../src/utils/TreeNode.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/utils.ts","../src/managers/pluginManager/PluginManager.ts","../src/managers/pluginManager/validate.ts","../src/build.ts","../src/config.ts","../src/generators/Generator.ts","../src/generators/SchemaGenerator.ts","../src/index.ts"],"names":["pathParser","fs","name","files","argument0"],"mappings":";;;AAAA,OAAOA,iBAAgB;;;ACEhB,SAAS,UAAa,QAA+C;AAC1E,SAAO,OAAQ,QAA6B,SAAS;AACvD;;;ACHA,SAAS,YAAY,UAAU;AAC/B,OAAO,gBAAgB;AAEvB,eAAe,oBAAoB,MAAc,MAAc;AAE7D,QAAM,aAAa,WAAW,QAAQ,WAAW,QAAQ,IAAI,CAAC;AAE9D,QAAM,GAAG,MAAM,YAAY,EAAE,WAAW,KAAK,CAAC;AAE9C,SAAO,GAAG,UAAU,WAAW,QAAQ,IAAI,GAAG,MAAM,EAAE,UAAU,QAAQ,CAAC;AAC3E;AAEA,eAAsB,MAAM,MAAc,MAAc;AACtD,MAAI;AACF,UAAM,GAAG,KAAK,IAAI;AAClB,UAAM,aAAa,MAAM,GAAG,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AAChE,QAAI,YAAY,SAAS,MAAM,MAAM;AACnC;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO,oBAAoB,MAAM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;AAAA,EACrB,CAAC;AAED,QAAM,cAAc,aAAa,EAAE,UAAU,WAAW,CAAC;AAEzD,SAAO,EAAE,OAAO,YAAY,MAAM,IAAI,CAAC,UAAU,EAAE,GAAG,MAAM,QAAQ,cAAc,IAAI,EAAE,EAAE,EAAE;AAC9F;AAIO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,QAAI;AACF,YAAM,SAAS,MAAM,oBAAoB,OAAO;AAEhD,iBAAW,MAAM;AACf,gBAAQ,MAAM;AAAA,MAChB,GAAG,GAAG;AAAA,IACR,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AC7GO,IAAM,eAAe,CAC1B,YAMG;;;ACVE,IAAe,YAAf,MAA2D;AAAA,EACxD,WAAqB,CAAC;AAAA,EAE9B,YAAY,UAAoB,CAAC,GAAe;AAC9C,QAAI,SAAS;AACX,WAAK,WAAW;AAAA,QACd,GAAG,KAAK;AAAA,QACR,GAAG;AAAA,MACL;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,UAAU;AACZ,WAAO,KAAK;AAAA,EACd;AAGF;;;AClBO,IAAe,kBAAf,cAAiF,UAAoB;AAE5G;;;ACKA,IAAO,cAAQ","sourcesContent":["import pathParser from 'path'\n\nimport { createPluginCache } from './utils'\n\nimport type { FileManager } from './managers/fileManager'\nimport type { PluginContext, KubbPlugin, PluginFactoryOptions } from './types'\n\ntype KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (\n options: T['options']\n) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>\n\nexport function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>) {\n return (options: T['options']) => {\n const plugin = factory(options)\n if (Array.isArray(plugin)) {\n throw new Error('Not implemented')\n }\n\n // default transform\n if (!plugin.transform) {\n plugin.transform = function transform(code) {\n return code\n }\n }\n\n return plugin\n }\n}\n\ntype Options = {\n config: PluginContext['config']\n fileManager: FileManager\n resolvePath: PluginContext['resolvePath']\n resolveName: PluginContext['resolveName']\n load: PluginContext['load']\n}\n\n// not publicly exported\nexport type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>\n\nexport const name = 'core' as const\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolvePath, resolveName, load } = options\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(...files) {\n return Promise.all(files.map((file) => (file.override ? fileManager.add(file) : fileManager.addOrAppend(file))))\n },\n resolvePath,\n resolveName,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n options,\n api,\n resolvePath(fileName) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n\n return pathParser.resolve(root, fileName)\n },\n resolveName(name) {\n return name\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport function isPromise<T>(result: MaybePromise<T>): result is Promise<T> {\n return typeof (result as Promise<unknown>)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport { promises as fs } from 'fs'\nimport pathParser from 'path'\n\nasync function safeWriteFileToPath(path: string, data: string) {\n // resolve the full path and get just the directory, ignoring the file and extension\n const passedPath = pathParser.dirname(pathParser.resolve(path))\n // make the directory, recursively. Theoretically, if every directory in the path exists, this won't do anything.\n await fs.mkdir(passedPath, { recursive: true })\n // write the file to the newly created directory\n return fs.writeFile(pathParser.resolve(path), data, { encoding: 'utf-8' })\n}\n\nexport async function write(data: string, path: string) {\n try {\n await fs.stat(path)\n const oldContent = await fs.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === data) {\n return\n }\n } catch (_err) {\n return safeWriteFileToPath(path, data)\n }\n\n return safeWriteFileToPath(path, data)\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<T extends object = object> {\n delete(id: keyof T): boolean\n get(id: keyof T): T[keyof T] | null\n has(id: keyof T): boolean\n set(id: keyof T, value: unknown): void\n}\n\nexport function createPluginCache<T extends Record<string, [number, unknown]>>(cache: T): Cache<T> {\n return {\n delete(id: keyof T) {\n return delete cache[id]\n },\n get(id) {\n const item = cache[id]\n if (!item) return null\n item[0] = 0\n return item[1] as T[keyof T]\n },\n has(id) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id, value) {\n cache[id] = [0, value] as T[keyof T]\n },\n }\n}\n","import pathParser from 'path'\nimport { promises as fs } from 'fs'\n\nfunction slash(path: string) {\n const isExtendedLengthPath = /^\\\\\\\\\\?\\\\/.test(path)\n\n if (isExtendedLengthPath) {\n return path\n }\n\n return path.replace(/\\\\/g, '/')\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null) {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir} ${filePath}`)\n }\n\n const relativePath = pathParser.relative(rootDir, filePath)\n\n // On Windows, paths are separated with a \"\\\"\n // However, web browsers use \"/\" no matter the platform\n const path = slash(relativePath).replace('../', '').trimEnd()\n\n if (path.startsWith('../')) {\n return path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))\n }\n\n return `./${path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))}`\n}\n\nexport type PathMode = 'file' | 'directory'\n\nexport function getPathMode(path: string | undefined | null): PathMode {\n if (!path) {\n return 'directory'\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n\nexport async function read(path: string) {\n try {\n return fs.readFile(path, { encoding: 'utf8' })\n } catch (err) {\n console.error(err)\n throw err\n }\n}\n","export function isURL(data: string) {\n try {\n const url = new URL(data)\n if (url?.href) {\n return true\n }\n } catch (error) {\n return false\n }\n return false\n}\n","type Data = string[][]\n\ntype Options = {\n typed?: boolean\n}\n\nexport function objectToParameters(data: Data, options: Options = {}) {\n return data\n .reduce((acc, [key, value]) => {\n if (options.typed) {\n acc.push(`${key}: ${value}[\"${key}\"], `)\n } else {\n acc.push(`${key}, `)\n }\n\n return acc\n }, [] as string[])\n .join('')\n}\n","export function nameSorter<T extends { name: string }>(a: T, b: T) {\n if (a.name < b.name) {\n return -1\n }\n if (a.name > b.name) {\n return 1\n }\n return 0\n}\n","export function createJSDocBlockText({ comments }: { comments: Array<string> }): string {\n const filteredComments = comments.filter(Boolean)\n\n if (!filteredComments.length) {\n return ''\n }\n\n const text = filteredComments.reduce((acc, comment) => {\n return `${acc}\\n* ${comment}`\n }, '/**')\n\n return `${text}\\n*/`\n}\n","/* eslint-disable no-param-reassign */\nexport function getUniqueName(originalName: string, data: Record<string, number>) {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n originalName += used\n }\n data[originalName] = 1\n return originalName\n}\n","export async function timeout(ms: number) {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n","/* eslint-disable no-cond-assign */\n\nexport type QueueTask<T = unknown> = {\n (...args: unknown[]): Promise<T>\n}\n\ninterface QueueItem {\n reject: <T>(reason?: T) => void\n resolve: <T>(value: T | PromiseLike<T>) => void\n task: QueueTask<unknown>\n}\n\nexport class Queue {\n private readonly queue: QueueItem[] = []\n\n workerCount = 0\n\n private maxParallel: number\n\n constructor(maxParallel: number) {\n this.maxParallel = maxParallel\n }\n\n run<T>(task: QueueTask<T>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const item: QueueItem = { reject, resolve, task } as QueueItem\n this.queue.push(item)\n this.work()\n })\n }\n\n private async work(): Promise<void> {\n if (this.workerCount >= this.maxParallel) return\n this.workerCount++\n\n let entry: QueueItem | undefined\n while ((entry = this.queue.shift())) {\n const { reject, resolve, task } = entry\n task()\n .then((result) => resolve(result))\n .catch((err) => reject(err))\n }\n\n this.workerCount--\n }\n}\n","export function getEncodedText(text?: string): string {\n return text ? text.replaceAll('`', '\\\\`') : ''\n}\n","export function renderTemplate<TData extends Record<string, string> = Record<string, string>>(template: string, data: TData | undefined = undefined) {\n if (!data) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n return template.replace(/{{(.*?)}}/g, (match) => {\n const value = data[match.split(/{{|}}/).filter(Boolean)[0].trim()]\n\n return value || ''\n })\n}\n","import rimraf from 'rimraf'\n\nexport async function clean(path: string) {\n return new Promise((resolve, reject) => {\n rimraf(path, (err) => {\n if (err) {\n reject(err)\n } else {\n resolve(true)\n }\n })\n })\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\n\nexport type TreeNodeOptions = DirectoryTreeOptions\n\nexport class TreeNode<T = unknown> {\n public data: T\n\n public parent?: TreeNode<T>\n\n public children: Array<TreeNode<T>> = []\n\n constructor(data: T, parent?: TreeNode<T>) {\n this.data = data\n this.parent = parent\n return this\n }\n\n addChild(data: T): TreeNode<T> {\n const child = new TreeNode(data, this)\n if (!this.children) {\n this.children = []\n }\n this.children.push(child)\n return child\n }\n\n find(data: T) {\n if (data === this.data) {\n return this\n }\n\n if (this.children) {\n for (let i = 0, { length } = this.children, target: unknown = null; i < length; i++) {\n target = this.children[i].find(data)\n if (target) {\n return target\n }\n }\n }\n\n return null\n }\n\n leaves(): TreeNode<T>[] {\n if (!this.children || this.children.length === 0) {\n // this is a leaf\n return [this]\n }\n\n // if not a leaf, return all children's leaves recursively\n const leaves: TreeNode<T>[] = []\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n // eslint-disable-next-line prefer-spread\n leaves.push.apply(leaves, this.children[i].leaves())\n }\n }\n return leaves\n }\n\n root(): TreeNode<T> {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void): this {\n if (typeof callback !== 'function') {\n throw new TypeError('forEach() callback must be a function')\n }\n\n // run this node through function\n callback(this)\n\n // do the same for all children\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n this.children[i].forEach(callback)\n }\n }\n\n return this\n }\n\n public static build<T = unknown>(path: string, options: TreeNodeOptions = {}): TreeNode<T> | null {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n\n if (!filteredTree) {\n return null\n }\n\n const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type })\n\n const recurse = (node: typeof treeNode, item: DirectoryTree) => {\n const subNode = node.addChild({ name: item.name, path: item.path, type: item.type })\n\n if (item.children?.length) {\n item.children?.forEach((child) => {\n recurse(subNode, child)\n })\n }\n }\n\n filteredTree.children?.forEach((child) => recurse(treeNode, child))\n\n return treeNode as TreeNode<T>\n }\n}\n","import { v4 as uuidv4 } from 'uuid'\n\nimport { write, read } from '../../utils'\n\nimport type { QueueTask, Queue } from '../../utils'\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n private task?: QueueTask<unknown>\n\n private queue?: Queue\n\n constructor(options?: { queue: Queue; task: QueueTask<unknown> }) {\n if (options) {\n this.task = options.task\n this.queue = options.queue\n }\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n getCacheByPath(path: string | undefined): CacheStore | undefined {\n let cache\n\n this.cache.forEach((item) => {\n if (item.file.path === path) {\n cache = item\n }\n })\n return cache as unknown as CacheStore\n }\n\n get files() {\n const files: File[] = []\n this.cache.forEach((item) => {\n files.push(item.file)\n })\n\n return files\n }\n\n async add(file: File) {\n const cacheItem = { id: uuidv4(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n\n if (this.queue) {\n await this.queue.run(async () => {\n await this.task?.(cacheItem.id, file)\n })\n }\n\n return file\n }\n\n addOrAppend(file: File) {\n if (!file.path.endsWith(file.fileName)) {\n // console.warn(`Path ${file.path}(file.path) should end with the fileName ${file.fileName}(file.filename)`)\n }\n\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n // empty source will also return true when using includes\n const sourceAlreadyExists = file.source && previousCache.file.source.includes(file.source)\n\n if (sourceAlreadyExists) {\n return Promise.resolve(file)\n }\n\n this.cache.delete(previousCache.id)\n\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n imports: [...(previousCache.file.imports || []), ...(file.imports || [])],\n exports: [...(previousCache.file.exports || []), ...(file.exports || [])],\n })\n }\n return this.add(file)\n }\n\n setStatus(id: UUID, status: Status) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n cacheItem.status = status\n this.cache.set(id, cacheItem)\n }\n\n get(id: UUID) {\n const cacheItem = this.getCache(id)\n return cacheItem?.file\n }\n\n remove(id: UUID) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n this.setStatus(id, 'removed')\n }\n\n async write(...params: Parameters<typeof write>) {\n return write(...params)\n }\n\n async read(...params: Parameters<typeof read>) {\n return read(...params)\n }\n}\n","import pathParser from 'path'\n\nimport uniq from 'lodash.uniq'\n\nimport { createImportDeclaration, createExportDeclaration, print } from '@kubb/ts-codegen'\n\nimport { TreeNode } from '../../utils'\n\nimport type { PathMode, TreeNodeOptions } from '../../utils'\nimport type { Path } from '../../types'\nimport type ts from 'typescript'\nimport type { File } from './types'\n\nexport function writeIndexes(root: string, options: TreeNodeOptions) {\n const tree = TreeNode.build<{ type: PathMode; path: Path; name: string }>(root, { extensions: /\\.ts/, ...options })\n\n if (!tree) {\n return undefined\n }\n\n const fileReducer = (files: File[], item: typeof tree) => {\n if (!item.children) {\n return []\n }\n\n if (item.children?.length > 1) {\n const path = pathParser.resolve(item.data.path, 'index.ts')\n const exports = item.children\n .map((file) => {\n if (!file) {\n return undefined\n }\n\n const importPath: string = file.data.type === 'directory' ? `./${file.data.name}` : `./${file.data.name.replace(/\\.[^.]*$/, '')}`\n\n // TODO weird hacky fix\n if (importPath.includes('index') && path.includes('index')) {\n return undefined\n }\n\n return { path: importPath }\n })\n .filter(Boolean) as File['exports']\n\n files.push({\n path,\n fileName: 'index.ts',\n source: '',\n exports,\n })\n } else {\n item.children?.forEach((child) => {\n const path = pathParser.resolve(item.data.path, 'index.ts')\n const importPath = child.data.type === 'directory' ? `./${child.data.name}` : `./${child.data.name.replace(/\\.[^.]*$/, '')}`\n\n files.push({\n path,\n fileName: 'index.ts',\n source: '',\n exports: [{ path: importPath }],\n })\n })\n }\n\n item.children.forEach((childItem) => {\n fileReducer(files, childItem)\n })\n\n return files\n }\n\n const files = fileReducer([], tree)\n\n return files\n}\n\nexport function combineFiles(files: Array<File | null>) {\n return files.filter(Boolean).reduce((acc, curr: File | null) => {\n if (!curr) {\n return acc\n }\n const prevIndex = acc.findIndex((item) => item.path === curr.path)\n\n if (prevIndex !== -1) {\n const prev = acc[prevIndex]\n acc[prevIndex] = {\n ...curr,\n source: `${prev.source}\\n${curr.source}`,\n imports: [...(prev.imports || []), ...(curr.imports || [])],\n exports: [...(prev.exports || []), ...(curr.exports || [])],\n }\n } else {\n acc.push(curr)\n }\n\n return acc\n }, [] as File[])\n}\n\nexport function getFileSource(file: File) {\n let { source } = file\n\n // TODO make generic check\n if (!file.fileName.endsWith('.ts')) {\n return file.source\n }\n const imports: File['imports'] = []\n const exports: File['exports'] = []\n\n file.imports?.forEach((curr) => {\n const exists = imports.find((imp) => imp.path === curr.path)\n if (!exists) {\n imports.push({\n ...curr,\n name: Array.isArray(curr.name) ? uniq(curr.name) : curr.name,\n })\n }\n\n if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {\n imports.push(curr)\n }\n\n if (exists && Array.isArray(exists.name)) {\n if (Array.isArray(curr.name)) {\n exists.name = uniq([...exists.name, ...curr.name])\n }\n }\n })\n\n file.exports?.forEach((curr) => {\n const exists = exports.find((imp) => imp.path === curr.path)\n if (!exists) {\n exports.push({\n ...curr,\n name: Array.isArray(curr.name) ? uniq(curr.name) : curr.name,\n })\n }\n\n if (exists && !Array.isArray(exists.name) && exists.name !== curr.name && exists.asAlias === curr.asAlias) {\n exports.push(curr)\n }\n\n if (exists && Array.isArray(exists.name)) {\n if (Array.isArray(curr.name)) {\n exists.name = uniq([...exists.name, ...curr.name])\n }\n }\n })\n\n const importNodes = imports.reduce((prev, curr) => {\n return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, asType: curr.asType })]\n }, [] as ts.ImportDeclaration[])\n const importSource = print(importNodes)\n\n const exportNodes = exports.reduce((prev, curr) => {\n return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })]\n }, [] as ts.ExportDeclaration[])\n const exportSource = print(exportNodes)\n\n if (importSource) {\n source = `${importSource}\\n${source}`\n }\n\n if (exportSource) {\n source = `${exportSource}\\n${source}`\n }\n\n return source\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\nimport { Queue } from '../../utils/Queue'\n\nimport type { QueueTask } from '../../utils/Queue'\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolvePathParams, ResolveNameParams } from '../../types'\nimport type { Logger } from '../../build'\nimport type { CorePluginOptions } from '../../plugin'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\n// This will make sure no input hook is omitted\nconst hookNames: {\n [P in PluginLifecycleHooks]: 1\n} = {\n validate: 1,\n buildStart: 1,\n resolvePath: 1,\n resolveName: 1,\n load: 1,\n transform: 1,\n writeFile: 1,\n buildEnd: 1,\n}\nexport const hooks = Object.keys(hookNames) as [PluginLifecycleHooks]\n\nexport class PluginManager {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions>\n\n public queue: Queue\n\n constructor(config: KubbConfig, options: { logger?: Logger; task: QueueTask }) {\n this.logger = options.logger\n this.config = config\n this.queue = new Queue(10)\n\n this.fileManager = new FileManager({ task: options.task, queue: this.queue })\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolvePath: this.resolvePath,\n resolveName: this.resolveName,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolvePath = (params: ResolvePathParams) => {\n if (params.pluginName) {\n return this.hookForPluginSync({\n pluginName: params.pluginName,\n hookName: 'resolvePath',\n parameters: [params.fileName, params.directory, params.options],\n })\n }\n return this.hookFirstSync({\n hookName: 'resolvePath',\n parameters: [params.fileName, params.directory, params.options],\n })\n }\n\n resolveName = (params: ResolveNameParams) => {\n if (params.pluginName) {\n return this.hookForPluginSync({\n pluginName: params.pluginName,\n hookName: 'resolveName',\n parameters: [params.name],\n })\n }\n return this.hookFirstSync({\n hookName: 'resolveName',\n parameters: [params.name],\n })\n }\n\n load = async (id: string) => {\n return this.hookFirst({\n hookName: 'load',\n parameters: [id],\n })\n }\n\n /**\n *\n * Run only hook for a specific plugin name\n */\n hookForPlugin<H extends PluginLifecycleHooks>({\n pluginName,\n hookName,\n parameters,\n }: {\n pluginName: string\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n }): Promise<ReturnType<PluginLifecycle[H]> | null> {\n const plugin = this.getPlugin(hookName, pluginName)\n\n return this.run({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n }\n\n hookForPluginSync<H extends PluginLifecycleHooks>({\n pluginName,\n hookName,\n parameters,\n }: {\n pluginName: string\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n }): ReturnType<PluginLifecycle[H]> {\n const plugin = this.getPlugin(hookName, pluginName)\n\n return this.runSync({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n }\n\n /**\n *\n * Chains, first non-null result stops and returns\n */\n hookFirst<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n skipped,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n skipped?: ReadonlySet<KubbPlugin> | null\n }): Promise<ReturnType<PluginLifecycle[H]>> {\n let promise: Promise<ReturnType<PluginLifecycle[H]>> = Promise.resolve(null as ReturnType<PluginLifecycle[H]>)\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n }) as typeof result\n })\n }\n return promise\n }\n\n /**\n *\n * Chains, first non-null result stops and returns\n */\n hookFirstSync<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n skipped,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n skipped?: ReadonlySet<KubbPlugin> | null\n }): ReturnType<PluginLifecycle[H]> {\n let result = null\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n\n result = this.runSync<H>({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n\n if (result != null) {\n break\n }\n }\n return result as ReturnType<PluginLifecycle[H]>\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>({\n hookName,\n parameters,\n }: {\n hookName: H\n parameters?: Parameters<PluginLifecycle[H]> | undefined\n }): Promise<Awaited<TOuput>[]> {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run({\n strategy: 'hookParallel',\n hookName,\n parameters,\n plugin,\n })\n } else {\n const promise: Promise<TOuput> = this.run({ strategy: 'hookParallel', hookName, parameters, plugin })\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n reduce,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n }): Promise<Argument0<H>> {\n const [argument0, ...rest] = parameters\n\n let promise: Promise<Argument0<H>> = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run({\n strategy: 'hookReduceArg0',\n hookName,\n parameters: [argument0, ...rest] as Parameters<PluginLifecycle[H]>,\n plugin,\n }).then((result) => reduce.call(this.core.api, argument0, result as ReturnType<PluginLifecycle[H]>, plugin))\n ) as Promise<Argument0<H>>\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: { hookName: H; parameters?: Parameters<PluginLifecycle[H]> }) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() =>\n this.run({\n strategy: 'hookSeq',\n hookName,\n parameters,\n plugin,\n })\n )\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n return plugins\n }\n\n private getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin {\n const plugins = [...this.plugins]\n\n const pluginByPluginName = plugins.find((item) => item.name === pluginName && item[hookName])\n if (!pluginByPluginName) {\n // fallback on the core plugin when there is no match\n if (this.config.logLevel === 'warn' && this.logger?.spinner) {\n this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`)\n }\n return this.core\n }\n return pluginByPluginName\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private run<H extends PluginLifecycleHooks, TResult = void>({\n strategy,\n hookName,\n parameters,\n plugin,\n }: {\n strategy: Strategy\n hookName: H\n parameters: unknown[] | undefined\n plugin: KubbPlugin\n }): Promise<TResult> {\n const hook = plugin[hookName]!\n\n return Promise.resolve()\n .then(() => {\n if (typeof hook !== 'function') {\n return hook\n }\n\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`\n }\n\n const hookResult = (hook as Function).apply(this.core.api, parameters)\n\n if (!(hookResult as Promise<unknown>)?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n .catch((e: Error) => {\n this.catcher<H>(e, plugin, hookName)\n }) as Promise<TResult>\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>({\n strategy,\n hookName,\n parameters,\n plugin,\n }: {\n strategy: Strategy\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n plugin: KubbPlugin\n }): ReturnType<PluginLifecycle[H]> {\n const hook = plugin[hookName]!\n\n // const context = this.pluginContexts.get(plugin)!;\n\n try {\n // eslint-disable-next-line @typescript-eslint/ban-types\n if (typeof hook !== 'function') {\n return hook\n }\n\n return (hook as Function).apply(this.core.api, parameters)\n } catch (e) {\n this.catcher<H>(e as Error, plugin, hookName)\n return null as ReturnType<PluginLifecycle[H]>\n }\n }\n\n private catcher<H extends PluginLifecycleHooks>(e: Error, plugin: KubbPlugin, hookName: H) {\n const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})\\n`\n\n throw new Error(text, { cause: e })\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { KubbPlugin } from '../../types'\n\nexport class ValidationPluginError extends Error {}\n\nexport function validatePlugins(plugins: KubbPlugin[], dependedPluginNames: string | string[]): true {\n let pluginNames: string[] = []\n if (typeof dependedPluginNames === 'string') {\n pluginNames = [dependedPluginNames]\n } else {\n pluginNames = dependedPluginNames\n }\n\n pluginNames.forEach((pluginName) => {\n const exists = plugins.some((plugin) => plugin.name === pluginName)\n if (!exists) {\n throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`)\n }\n })\n\n return true\n}\n","/* eslint-disable no-async-promise-executor */\nimport pathParser from 'path'\n\nimport { isURL } from './utils/isURL'\nimport { PluginManager } from './managers/pluginManager'\nimport { clean, read } from './utils'\nimport { getFileSource } from './managers/fileManager'\n\nimport type { FileManager, File } from './managers/fileManager'\nimport type { QueueTask } from './utils'\nimport type { PluginContext, TransformResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = {\n files: FileManager['files']\n}\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n fail: (text?: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type Logger = {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n}\ntype BuildOptions = {\n config: PluginContext['config']\n logger?: Logger\n}\n\nasync function transformReducer(\n this: PluginContext,\n _previousCode: string,\n result: TransformResult | Promise<TransformResult>,\n _plugin: KubbPlugin\n): Promise<string | null> {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions): Promise<BuildOutput> {\n const { config, logger } = options\n\n if (config.output.clean) {\n await clean(config.output.path)\n }\n\n const queueTask = async (id: string, file: File) => {\n const { path } = file\n\n let code = getFileSource(file)\n\n const loadedResult = await pluginManager.hookFirst({\n hookName: 'load',\n parameters: [path],\n })\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0({\n hookName: 'transform',\n parameters: [code, path],\n reduce: transformReducer,\n })\n\n if (config.output.write || config.output.write === undefined) {\n await pluginManager.hookParallel({\n hookName: 'writeFile',\n parameters: [transformedCode, path],\n })\n }\n }\n }\n\n const pluginManager = new PluginManager(config, { logger, task: queueTask as QueueTask })\n const { plugins, fileManager } = pluginManager\n\n await pluginManager.hookParallel<'validate', true>({\n hookName: 'validate',\n parameters: [plugins],\n })\n\n await pluginManager.hookParallel({\n hookName: 'buildStart',\n parameters: [config],\n })\n\n await pluginManager.hookParallel({ hookName: 'buildEnd' })\n\n return { files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })) }\n}\n\nexport type KubbBuild = (options: BuildOptions) => Promise<BuildOutput>\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise(async (resolve, reject) => {\n try {\n const output = await buildImplementation(options)\n\n setTimeout(() => {\n resolve(output)\n }, 500)\n } catch (e) {\n reject(e)\n }\n })\n}\n","import type { MaybePromise, KubbUserConfig, CLIOptions } from './types'\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link KubbConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport const defineConfig = (\n options:\n | MaybePromise<KubbUserConfig>\n | ((\n /** The options derived from the CLI flags */\n cliOptions: CLIOptions\n ) => MaybePromise<KubbUserConfig>)\n) => options\n","/**\n * Abstract class that contains the building blocks for plugins to create their own Generator\n * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137\n */\nexport abstract class Generator<TOptions extends object = object> {\n private _options: TOptions = {} as TOptions\n\n constructor(options: TOptions = {} as TOptions) {\n if (options) {\n this._options = {\n ...this._options,\n ...options,\n }\n }\n return this\n }\n\n get options() {\n return this._options\n }\n\n abstract build(...params: unknown[]): unknown\n}\n","import { Generator } from './Generator'\n/**\n * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator\n */\nexport abstract class SchemaGenerator<TOptions extends object, TInput, TOutput> extends Generator<TOptions> {\n abstract build(schema: TInput, name: string, description?: string): TOutput\n}\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { CorePluginOptions, createPlugin, name } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport * from './generators'\n\nexport default build\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/utils/isURL.ts","../src/utils/objectToParameters.ts","../src/utils/nameSorter.ts","../src/utils/jsdoc.ts","../src/utils/getUniqueName.ts","../src/utils/timeout.ts","../src/utils/Queue.ts","../src/utils/getEncodedText.ts","../src/utils/renderTemplate.ts","../src/utils/clean.ts","../src/utils/TreeNode.ts","../src/utils/transformReservedWord.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/utils.ts","../src/managers/pluginManager/PluginManager.ts","../src/managers/pluginManager/validate.ts","../src/build.ts","../src/config.ts","../src/generators/Generator.ts","../src/generators/SchemaGenerator.ts","../src/index.ts"],"names":["pathParser","fs","name","files","argument0"],"mappings":";;;AAAA,OAAOA,iBAAgB;;;ACEhB,SAAS,UAAa,QAA+C;AAC1E,SAAO,OAAQ,QAA6B,SAAS;AACvD;;;ACHA,SAAS,YAAY,UAAU;AAC/B,OAAO,gBAAgB;AAEvB,eAAe,oBAAoB,MAAc,MAAc;AAE7D,QAAM,aAAa,WAAW,QAAQ,WAAW,QAAQ,IAAI,CAAC;AAE9D,QAAM,GAAG,MAAM,YAAY,EAAE,WAAW,KAAK,CAAC;AAE9C,SAAO,GAAG,UAAU,WAAW,QAAQ,IAAI,GAAG,MAAM,EAAE,UAAU,QAAQ,CAAC;AAC3E;AAEA,eAAsB,MAAM,MAAc,MAAc;AACtD,MAAI;AACF,UAAM,GAAG,KAAK,IAAI;AAClB,UAAM,aAAa,MAAM,GAAG,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AAChE,QAAI,YAA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MAAM;AAAA,EACrB,CAAC;AAED,QAAM,cAAc,aAAa,EAAE,UAAU,WAAW,CAAC;AAEzD,SAAO,EAAE,OAAO,YAAY,MAAM,IAAI,CAAC,UAAU,EAAE,GAAG,MAAM,QAAQ,cAAc,IAAI,EAAE,EAAE,EAAE;AAC9F;AAIO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,QAAI;AACF,YAAM,SAAS,MAAM,oBAAoB,OAAO;AAEhD,iBAAW,MAAM;AACf,gBAAQ,MAAM;AAAA,MAChB,GAAG,GAAG;AAAA,IACR,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AC7GO,IAAM,eAAe,CAC1B,YAMG;;;ACVE,IAAe,YAAf,MAA2D;AAAA,EACxD,WAAqB,CAAC;AAAA,EAE9B,YAAY,UAAoB,CAAC,GAAe;AAC9C,QAAI,SAAS;AACX,WAAK,WAAW;AAAA,QACd,GAAG,KAAK;AAAA,QACR,GAAG;AAAA,MACL;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,UAAU;AACZ,WAAO,KAAK;AAAA,EACd;AAGF;;;AClBO,IAAe,kBAAf,cAAiF,UAAoB;AAE5G;;;ACKA,IAAO,cAAQ","sourcesContent":["import pathParser from 'path'\n\nimport { createPluginCache, transformReservedWord } from './utils'\n\nimport type { FileManager } from './managers/fileManager'\nimport type { PluginContext, KubbPlugin, PluginFactoryOptions } from './types'\n\ntype KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (\n options: T['options']\n) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>\n\nexport function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>) {\n return (options: T['options']) => {\n const plugin = factory(options)\n if (Array.isArray(plugin)) {\n throw new Error('Not implemented')\n }\n\n // default transform\n if (!plugin.transform) {\n plugin.transform = function transform(code) {\n return code\n }\n }\n\n return plugin\n }\n}\n\ntype Options = {\n config: PluginContext['config']\n fileManager: FileManager\n resolvePath: PluginContext['resolvePath']\n resolveName: PluginContext['resolveName']\n load: PluginContext['load']\n}\n\n// not publicly exported\nexport type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>\n\nexport const name = 'core' as const\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolvePath, resolveName, load } = options\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(...files) {\n return Promise.all(files.map((file) => (file.override ? fileManager.add(file) : fileManager.addOrAppend(file))))\n },\n resolvePath,\n resolveName: (params) => {\n const name = resolveName(params)\n\n return transformReservedWord(name)\n },\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n options,\n api,\n resolvePath(fileName) {\n const root = pathParser.resolve(this.config.root, this.config.output.path)\n\n return pathParser.resolve(root, fileName)\n },\n resolveName(name) {\n return name\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport function isPromise<T>(result: MaybePromise<T>): result is Promise<T> {\n return typeof (result as Promise<unknown>)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport { promises as fs } from 'fs'\nimport pathParser from 'path'\n\nasync function safeWriteFileToPath(path: string, data: string) {\n // resolve the full path and get just the directory, ignoring the file and extension\n const passedPath = pathParser.dirname(pathParser.resolve(path))\n // make the directory, recursively. Theoretically, if every directory in the path exists, this won't do anything.\n await fs.mkdir(passedPath, { recursive: true })\n // write the file to the newly created directory\n return fs.writeFile(pathParser.resolve(path), data, { encoding: 'utf-8' })\n}\n\nexport async function write(data: string, path: string) {\n try {\n await fs.stat(path)\n const oldContent = await fs.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === data) {\n return\n }\n } catch (_err) {\n return safeWriteFileToPath(path, data)\n }\n\n return safeWriteFileToPath(path, data)\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<T extends object = object> {\n delete(id: keyof T): boolean\n get(id: keyof T): T[keyof T] | null\n has(id: keyof T): boolean\n set(id: keyof T, value: unknown): void\n}\n\nexport function createPluginCache<T extends Record<string, [number, unknown]>>(cache: T): Cache<T> {\n return {\n delete(id: keyof T) {\n return delete cache[id]\n },\n get(id) {\n const item = cache[id]\n if (!item) return null\n item[0] = 0\n return item[1] as T[keyof T]\n },\n has(id) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id, value) {\n cache[id] = [0, value] as T[keyof T]\n },\n }\n}\n","import pathParser from 'path'\nimport { promises as fs } from 'fs'\n\nfunction slash(path: string) {\n const isExtendedLengthPath = /^\\\\\\\\\\?\\\\/.test(path)\n\n if (isExtendedLengthPath) {\n return path\n }\n\n return path.replace(/\\\\/g, '/')\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null) {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir} ${filePath}`)\n }\n\n const relativePath = pathParser.relative(rootDir, filePath)\n\n // On Windows, paths are separated with a \"\\\"\n // However, web browsers use \"/\" no matter the platform\n const path = slash(relativePath).replace('../', '').trimEnd()\n\n if (path.startsWith('../')) {\n return path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))\n }\n\n return `./${path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))}`\n}\n\nexport type PathMode = 'file' | 'directory'\n\nexport function getPathMode(path: string | undefined | null): PathMode {\n if (!path) {\n return 'directory'\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n\nexport async function read(path: string) {\n try {\n return fs.readFile(path, { encoding: 'utf8' })\n } catch (err) {\n console.error(err)\n throw err\n }\n}\n","export function isURL(data: string) {\n try {\n const url = new URL(data)\n if (url?.href) {\n return true\n }\n } catch (error) {\n return false\n }\n return false\n}\n","type Data = string[][]\n\ntype Options = {\n typed?: boolean\n}\n\nexport function objectToParameters(data: Data, options: Options = {}) {\n const { typed } = options\n\n return data\n .reduce((acc, [key, value]) => {\n if (typed) {\n acc.push(`${key}: ${value}[\"${key}\"]`)\n } else {\n acc.push(`${key}`)\n }\n\n return acc\n }, [] as string[])\n .join(', ')\n}\n","export function nameSorter<T extends { name: string }>(a: T, b: T) {\n if (a.name < b.name) {\n return -1\n }\n if (a.name > b.name) {\n return 1\n }\n return 0\n}\n","export function createJSDocBlockText({ comments }: { comments: Array<string> }): string {\n const filteredComments = comments.filter(Boolean)\n\n if (!filteredComments.length) {\n return ''\n }\n\n const text = filteredComments.reduce((acc, comment) => {\n return `${acc}\\n* ${comment}`\n }, '/**')\n\n return `${text}\\n*/`\n}\n","/* eslint-disable no-param-reassign */\nexport function getUniqueName(originalName: string, data: Record<string, number>) {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n originalName += used\n }\n data[originalName] = 1\n return originalName\n}\n","export async function timeout(ms: number) {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n","/* eslint-disable no-cond-assign */\n\nexport type QueueTask<T = unknown> = {\n (...args: unknown[]): Promise<T>\n}\n\ninterface QueueItem {\n reject: <T>(reason?: T) => void\n resolve: <T>(value: T | PromiseLike<T>) => void\n task: QueueTask<unknown>\n}\n\nexport class Queue {\n private readonly queue: QueueItem[] = []\n\n workerCount = 0\n\n private maxParallel: number\n\n constructor(maxParallel: number) {\n this.maxParallel = maxParallel\n }\n\n run<T>(task: QueueTask<T>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const item: QueueItem = { reject, resolve, task } as QueueItem\n this.queue.push(item)\n this.work()\n })\n }\n\n private async work(): Promise<void> {\n if (this.workerCount >= this.maxParallel) return\n this.workerCount++\n\n let entry: QueueItem | undefined\n while ((entry = this.queue.shift())) {\n const { reject, resolve, task } = entry\n task()\n .then((result) => resolve(result))\n .catch((err) => reject(err))\n }\n\n this.workerCount--\n }\n}\n","export function getEncodedText(text?: string): string {\n return text ? text.replaceAll('`', '\\\\`') : ''\n}\n","export function renderTemplate<TData extends Record<string, string> = Record<string, string>>(template: string, data: TData | undefined = undefined) {\n if (!data) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n return template.replace(/{{(.*?)}}/g, (match) => {\n const value = data[match.split(/{{|}}/).filter(Boolean)[0].trim()]\n\n return value || ''\n })\n}\n","import rimraf from 'rimraf'\n\nexport async function clean(path: string) {\n return new Promise((resolve, reject) => {\n rimraf(path, (err) => {\n if (err) {\n reject(err)\n } else {\n resolve(true)\n }\n })\n })\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\n\nexport type TreeNodeOptions = DirectoryTreeOptions\n\nexport class TreeNode<T = unknown> {\n public data: T\n\n public parent?: TreeNode<T>\n\n public children: Array<TreeNode<T>> = []\n\n constructor(data: T, parent?: TreeNode<T>) {\n this.data = data\n this.parent = parent\n return this\n }\n\n addChild(data: T): TreeNode<T> {\n const child = new TreeNode(data, this)\n if (!this.children) {\n this.children = []\n }\n this.children.push(child)\n return child\n }\n\n find(data: T) {\n if (data === this.data) {\n return this\n }\n\n if (this.children) {\n for (let i = 0, { length } = this.children, target: unknown = null; i < length; i++) {\n target = this.children[i].find(data)\n if (target) {\n return target\n }\n }\n }\n\n return null\n }\n\n leaves(): TreeNode<T>[] {\n if (!this.children || this.children.length === 0) {\n // this is a leaf\n return [this]\n }\n\n // if not a leaf, return all children's leaves recursively\n const leaves: TreeNode<T>[] = []\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n // eslint-disable-next-line prefer-spread\n leaves.push.apply(leaves, this.children[i].leaves())\n }\n }\n return leaves\n }\n\n root(): TreeNode<T> {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void): this {\n if (typeof callback !== 'function') {\n throw new TypeError('forEach() callback must be a function')\n }\n\n // run this node through function\n callback(this)\n\n // do the same for all children\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n this.children[i].forEach(callback)\n }\n }\n\n return this\n }\n\n public static build<T = unknown>(path: string, options: TreeNodeOptions = {}): TreeNode<T> | null {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n\n if (!filteredTree) {\n return null\n }\n\n const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type })\n\n const recurse = (node: typeof treeNode, item: DirectoryTree) => {\n const subNode = node.addChild({ name: item.name, path: item.path, type: item.type })\n\n if (item.children?.length) {\n item.children?.forEach((child) => {\n recurse(subNode, child)\n })\n }\n }\n\n filteredTree.children?.forEach((child) => recurse(treeNode, child))\n\n return treeNode as TreeNode<T>\n }\n}\n","/**\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = [\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n\n 'Array',\n 'Date',\n 'eval',\n 'function',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n]\n\nexport function transformReservedWord(word: string) {\n if (reservedWords.includes(word)) {\n return `_${word}`\n }\n\n return word\n}\n","import { v4 as uuidv4 } from 'uuid'\n\nimport { write, read } from '../../utils'\n\nimport type { QueueTask, Queue } from '../../utils'\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n private task?: QueueTask<unknown>\n\n private queue?: Queue\n\n constructor(options?: { queue: Queue; task: QueueTask<unknown> }) {\n if (options) {\n this.task = options.task\n this.queue = options.queue\n }\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n getCacheByPath(path: string | undefined): CacheStore | undefined {\n let cache\n\n this.cache.forEach((item) => {\n if (item.file.path === path) {\n cache = item\n }\n })\n return cache as unknown as CacheStore\n }\n\n get files() {\n const files: File[] = []\n this.cache.forEach((item) => {\n files.push(item.file)\n })\n\n return files\n }\n\n async add(file: File) {\n const cacheItem = { id: uuidv4(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n\n if (this.queue) {\n await this.queue.run(async () => {\n await this.task?.(cacheItem.id, file)\n })\n }\n\n return file\n }\n\n addOrAppend(file: File) {\n if (!file.path.endsWith(file.fileName)) {\n // console.warn(`Path ${file.path}(file.path) should end with the fileName ${file.fileName}(file.filename)`)\n }\n\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n // empty source will also return true when using includes\n const sourceAlreadyExists = file.source && previousCache.file.source.includes(file.source)\n\n if (sourceAlreadyExists) {\n return Promise.resolve(file)\n }\n\n this.cache.delete(previousCache.id)\n\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n imports: [...(previousCache.file.imports || []), ...(file.imports || [])],\n exports: [...(previousCache.file.exports || []), ...(file.exports || [])],\n })\n }\n return this.add(file)\n }\n\n setStatus(id: UUID, status: Status) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n cacheItem.status = status\n this.cache.set(id, cacheItem)\n }\n\n get(id: UUID) {\n const cacheItem = this.getCache(id)\n return cacheItem?.file\n }\n\n remove(id: UUID) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n this.setStatus(id, 'removed')\n }\n\n async write(...params: Parameters<typeof write>) {\n return write(...params)\n }\n\n async read(...params: Parameters<typeof read>) {\n return read(...params)\n }\n}\n","import pathParser from 'path'\n\nimport uniq from 'lodash.uniq'\n\nimport { createImportDeclaration, createExportDeclaration, print } from '@kubb/ts-codegen'\n\nimport { TreeNode } from '../../utils'\n\nimport type { PathMode, TreeNodeOptions } from '../../utils'\nimport type { Path } from '../../types'\nimport type ts from 'typescript'\nimport type { File } from './types'\n\nexport function writeIndexes(root: string, options: TreeNodeOptions) {\n const tree = TreeNode.build<{ type: PathMode; path: Path; name: string }>(root, { extensions: /\\.ts/, ...options })\n\n if (!tree) {\n return undefined\n }\n\n const fileReducer = (files: File[], item: typeof tree) => {\n if (!item.children) {\n return []\n }\n\n if (item.children?.length > 1) {\n const path = pathParser.resolve(item.data.path, 'index.ts')\n const exports = item.children\n .map((file) => {\n if (!file) {\n return undefined\n }\n\n const importPath: string = file.data.type === 'directory' ? `./${file.data.name}` : `./${file.data.name.replace(/\\.[^.]*$/, '')}`\n\n // TODO weird hacky fix\n if (importPath.includes('index') && path.includes('index')) {\n return undefined\n }\n\n return { path: importPath }\n })\n .filter(Boolean) as File['exports']\n\n files.push({\n path,\n fileName: 'index.ts',\n source: '',\n exports,\n })\n } else {\n item.children?.forEach((child) => {\n const path = pathParser.resolve(item.data.path, 'index.ts')\n const importPath = child.data.type === 'directory' ? `./${child.data.name}` : `./${child.data.name.replace(/\\.[^.]*$/, '')}`\n\n files.push({\n path,\n fileName: 'index.ts',\n source: '',\n exports: [{ path: importPath }],\n })\n })\n }\n\n item.children.forEach((childItem) => {\n fileReducer(files, childItem)\n })\n\n return files\n }\n\n const files = fileReducer([], tree)\n\n return files\n}\n\nexport function combineFiles(files: Array<File | null>) {\n return files.filter(Boolean).reduce((acc, curr: File | null) => {\n if (!curr) {\n return acc\n }\n const prevIndex = acc.findIndex((item) => item.path === curr.path)\n\n if (prevIndex !== -1) {\n const prev = acc[prevIndex]\n acc[prevIndex] = {\n ...curr,\n source: `${prev.source}\\n${curr.source}`,\n imports: [...(prev.imports || []), ...(curr.imports || [])],\n exports: [...(prev.exports || []), ...(curr.exports || [])],\n }\n } else {\n acc.push(curr)\n }\n\n return acc\n }, [] as File[])\n}\n\nexport function getFileSource(file: File) {\n let { source } = file\n\n // TODO make generic check\n if (!file.fileName.endsWith('.ts')) {\n return file.source\n }\n const imports: File['imports'] = []\n const exports: File['exports'] = []\n\n file.imports?.forEach((curr) => {\n const exists = imports.find((imp) => imp.path === curr.path)\n if (!exists) {\n imports.push({\n ...curr,\n name: Array.isArray(curr.name) ? uniq(curr.name) : curr.name,\n })\n }\n\n if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {\n imports.push(curr)\n }\n\n if (exists && Array.isArray(exists.name)) {\n if (Array.isArray(curr.name)) {\n exists.name = uniq([...exists.name, ...curr.name])\n }\n }\n })\n\n file.exports?.forEach((curr) => {\n const exists = exports.find((imp) => imp.path === curr.path)\n if (!exists) {\n exports.push({\n ...curr,\n name: Array.isArray(curr.name) ? uniq(curr.name) : curr.name,\n })\n }\n\n if (exists && !Array.isArray(exists.name) && exists.name !== curr.name && exists.asAlias === curr.asAlias) {\n exports.push(curr)\n }\n\n if (exists && Array.isArray(exists.name)) {\n if (Array.isArray(curr.name)) {\n exists.name = uniq([...exists.name, ...curr.name])\n }\n }\n })\n\n const importNodes = imports.reduce((prev, curr) => {\n return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })]\n }, [] as ts.ImportDeclaration[])\n const importSource = print(importNodes)\n\n const exportNodes = exports.reduce((prev, curr) => {\n return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })]\n }, [] as ts.ExportDeclaration[])\n const exportSource = print(exportNodes)\n\n if (importSource) {\n source = `${importSource}\\n${source}`\n }\n\n if (exportSource) {\n source = `${exportSource}\\n${source}`\n }\n\n return source\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\nimport { Queue } from '../../utils/Queue'\n\nimport type { QueueTask } from '../../utils/Queue'\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolvePathParams, ResolveNameParams } from '../../types'\nimport type { Logger } from '../../build'\nimport type { CorePluginOptions } from '../../plugin'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\n// This will make sure no input hook is omitted\nconst hookNames: {\n [P in PluginLifecycleHooks]: 1\n} = {\n validate: 1,\n buildStart: 1,\n resolvePath: 1,\n resolveName: 1,\n load: 1,\n transform: 1,\n writeFile: 1,\n buildEnd: 1,\n}\nexport const hooks = Object.keys(hookNames) as [PluginLifecycleHooks]\n\nexport class PluginManager {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions>\n\n public queue: Queue\n\n constructor(config: KubbConfig, options: { logger?: Logger; task: QueueTask }) {\n this.logger = options.logger\n this.config = config\n this.queue = new Queue(10)\n\n this.fileManager = new FileManager({ task: options.task, queue: this.queue })\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolvePath: this.resolvePath,\n resolveName: this.resolveName,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolvePath = (params: ResolvePathParams) => {\n if (params.pluginName) {\n return this.hookForPluginSync({\n pluginName: params.pluginName,\n hookName: 'resolvePath',\n parameters: [params.fileName, params.directory, params.options],\n })\n }\n return this.hookFirstSync({\n hookName: 'resolvePath',\n parameters: [params.fileName, params.directory, params.options],\n })\n }\n\n resolveName = (params: ResolveNameParams) => {\n if (params.pluginName) {\n return this.hookForPluginSync({\n pluginName: params.pluginName,\n hookName: 'resolveName',\n parameters: [params.name],\n })\n }\n return this.hookFirstSync({\n hookName: 'resolveName',\n parameters: [params.name],\n })\n }\n\n load = async (id: string) => {\n return this.hookFirst({\n hookName: 'load',\n parameters: [id],\n })\n }\n\n /**\n *\n * Run only hook for a specific plugin name\n */\n hookForPlugin<H extends PluginLifecycleHooks>({\n pluginName,\n hookName,\n parameters,\n }: {\n pluginName: string\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n }): Promise<ReturnType<PluginLifecycle[H]> | null> {\n const plugin = this.getPlugin(hookName, pluginName)\n\n return this.run({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n }\n\n hookForPluginSync<H extends PluginLifecycleHooks>({\n pluginName,\n hookName,\n parameters,\n }: {\n pluginName: string\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n }): ReturnType<PluginLifecycle[H]> {\n const plugin = this.getPlugin(hookName, pluginName)\n\n return this.runSync({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n }\n\n /**\n *\n * Chains, first non-null result stops and returns\n */\n hookFirst<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n skipped,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n skipped?: ReadonlySet<KubbPlugin> | null\n }): Promise<ReturnType<PluginLifecycle[H]>> {\n let promise: Promise<ReturnType<PluginLifecycle[H]>> = Promise.resolve(null as ReturnType<PluginLifecycle[H]>)\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n }) as typeof result\n })\n }\n return promise\n }\n\n /**\n *\n * Chains, first non-null result stops and returns\n */\n hookFirstSync<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n skipped,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n skipped?: ReadonlySet<KubbPlugin> | null\n }): ReturnType<PluginLifecycle[H]> {\n let result = null\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n\n result = this.runSync<H>({\n strategy: 'hookFirst',\n hookName,\n parameters,\n plugin,\n })\n\n if (result != null) {\n break\n }\n }\n return result as ReturnType<PluginLifecycle[H]>\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>({\n hookName,\n parameters,\n }: {\n hookName: H\n parameters?: Parameters<PluginLifecycle[H]> | undefined\n }): Promise<Awaited<TOuput>[]> {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run({\n strategy: 'hookParallel',\n hookName,\n parameters,\n plugin,\n })\n } else {\n const promise: Promise<TOuput> = this.run({ strategy: 'hookParallel', hookName, parameters, plugin })\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>({\n hookName,\n parameters,\n reduce,\n }: {\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n }): Promise<Argument0<H>> {\n const [argument0, ...rest] = parameters\n\n let promise: Promise<Argument0<H>> = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run({\n strategy: 'hookReduceArg0',\n hookName,\n parameters: [argument0, ...rest] as Parameters<PluginLifecycle[H]>,\n plugin,\n }).then((result) => reduce.call(this.core.api, argument0, result as ReturnType<PluginLifecycle[H]>, plugin))\n ) as Promise<Argument0<H>>\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: { hookName: H; parameters?: Parameters<PluginLifecycle[H]> }) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() =>\n this.run({\n strategy: 'hookSeq',\n hookName,\n parameters,\n plugin,\n })\n )\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n return plugins\n }\n\n private getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin {\n const plugins = [...this.plugins]\n\n const pluginByPluginName = plugins.find((item) => item.name === pluginName && item[hookName])\n if (!pluginByPluginName) {\n // fallback on the core plugin when there is no match\n if (this.config.logLevel === 'warn' && this.logger?.spinner) {\n this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`)\n }\n return this.core\n }\n return pluginByPluginName\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private run<H extends PluginLifecycleHooks, TResult = void>({\n strategy,\n hookName,\n parameters,\n plugin,\n }: {\n strategy: Strategy\n hookName: H\n parameters: unknown[] | undefined\n plugin: KubbPlugin\n }): Promise<TResult> {\n const hook = plugin[hookName]!\n\n return Promise.resolve()\n .then(() => {\n if (typeof hook !== 'function') {\n return hook\n }\n\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`\n }\n\n const hookResult = (hook as Function).apply(this.core.api, parameters)\n\n if (!(hookResult as Promise<unknown>)?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n .catch((e: Error) => {\n this.catcher<H>(e, plugin, hookName)\n }) as Promise<TResult>\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>({\n strategy,\n hookName,\n parameters,\n plugin,\n }: {\n strategy: Strategy\n hookName: H\n parameters: Parameters<PluginLifecycle[H]>\n plugin: KubbPlugin\n }): ReturnType<PluginLifecycle[H]> {\n const hook = plugin[hookName]!\n\n // const context = this.pluginContexts.get(plugin)!;\n\n try {\n // eslint-disable-next-line @typescript-eslint/ban-types\n if (typeof hook !== 'function') {\n return hook\n }\n\n return (hook as Function).apply(this.core.api, parameters)\n } catch (e) {\n this.catcher<H>(e as Error, plugin, hookName)\n return null as ReturnType<PluginLifecycle[H]>\n }\n }\n\n private catcher<H extends PluginLifecycleHooks>(e: Error, plugin: KubbPlugin, hookName: H) {\n const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})\\n`\n\n throw new Error(text, { cause: e })\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { KubbPlugin } from '../../types'\n\nexport class ValidationPluginError extends Error {}\n\nexport function validatePlugins(plugins: KubbPlugin[], dependedPluginNames: string | string[]): true {\n let pluginNames: string[] = []\n if (typeof dependedPluginNames === 'string') {\n pluginNames = [dependedPluginNames]\n } else {\n pluginNames = dependedPluginNames\n }\n\n pluginNames.forEach((pluginName) => {\n const exists = plugins.some((plugin) => plugin.name === pluginName)\n if (!exists) {\n throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`)\n }\n })\n\n return true\n}\n","/* eslint-disable no-async-promise-executor */\nimport pathParser from 'path'\n\nimport { isURL } from './utils/isURL'\nimport { PluginManager } from './managers/pluginManager'\nimport { clean, read } from './utils'\nimport { getFileSource } from './managers/fileManager'\n\nimport type { FileManager, File } from './managers/fileManager'\nimport type { QueueTask } from './utils'\nimport type { PluginContext, TransformResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = {\n files: FileManager['files']\n}\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n fail: (text?: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type Logger = {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n}\ntype BuildOptions = {\n config: PluginContext['config']\n logger?: Logger\n}\n\nasync function transformReducer(\n this: PluginContext,\n _previousCode: string,\n result: TransformResult | Promise<TransformResult>,\n _plugin: KubbPlugin\n): Promise<string | null> {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions): Promise<BuildOutput> {\n const { config, logger } = options\n\n if (config.output.clean) {\n await clean(config.output.path)\n }\n\n const queueTask = async (id: string, file: File) => {\n const { path } = file\n\n let code = getFileSource(file)\n\n const loadedResult = await pluginManager.hookFirst({\n hookName: 'load',\n parameters: [path],\n })\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0({\n hookName: 'transform',\n parameters: [code, path],\n reduce: transformReducer,\n })\n\n if (config.output.write || config.output.write === undefined) {\n await pluginManager.hookParallel({\n hookName: 'writeFile',\n parameters: [transformedCode, path],\n })\n }\n }\n }\n\n const pluginManager = new PluginManager(config, { logger, task: queueTask as QueueTask })\n const { plugins, fileManager } = pluginManager\n\n await pluginManager.hookParallel<'validate', true>({\n hookName: 'validate',\n parameters: [plugins],\n })\n\n await pluginManager.hookParallel({\n hookName: 'buildStart',\n parameters: [config],\n })\n\n await pluginManager.hookParallel({ hookName: 'buildEnd' })\n\n return { files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })) }\n}\n\nexport type KubbBuild = (options: BuildOptions) => Promise<BuildOutput>\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise(async (resolve, reject) => {\n try {\n const output = await buildImplementation(options)\n\n setTimeout(() => {\n resolve(output)\n }, 500)\n } catch (e) {\n reject(e)\n }\n })\n}\n","import type { MaybePromise, KubbUserConfig, CLIOptions } from './types'\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link KubbConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport const defineConfig = (\n options:\n | MaybePromise<KubbUserConfig>\n | ((\n /** The options derived from the CLI flags */\n cliOptions: CLIOptions\n ) => MaybePromise<KubbUserConfig>)\n) => options\n","/**\n * Abstract class that contains the building blocks for plugins to create their own Generator\n * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137\n */\nexport abstract class Generator<TOptions extends object = object> {\n private _options: TOptions = {} as TOptions\n\n constructor(options: TOptions = {} as TOptions) {\n if (options) {\n this._options = {\n ...this._options,\n ...options,\n }\n }\n return this\n }\n\n get options() {\n return this._options\n }\n\n abstract build(...params: unknown[]): unknown\n}\n","import { Generator } from './Generator'\n/**\n * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator\n */\nexport abstract class SchemaGenerator<TOptions extends object, TInput, TOutput> extends Generator<TOptions> {\n abstract build(schema: TInput, name: string, description?: string): TOutput\n}\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { CorePluginOptions, createPlugin, name } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport * from './generators'\n\nexport default build\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.18",
4
4
  "description": "Generator core",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,7 +40,7 @@
40
40
  "!/**/__tests__/**"
41
41
  ],
42
42
  "dependencies": {
43
- "@kubb/ts-codegen": "1.0.0-beta.16",
43
+ "@kubb/ts-codegen": "1.0.0-beta.18",
44
44
  "change-case": "^4.1.2",
45
45
  "directory-tree": "^3.5.1",
46
46
  "lodash.uniq": "^4.5.0",
@@ -1,13 +1,13 @@
1
1
  type Import = {
2
2
  name: string | string[]
3
3
  path: string
4
- asType?: boolean
4
+ isTypeOnly?: boolean
5
5
  }
6
6
 
7
7
  type Export = {
8
8
  name?: string | string[]
9
9
  path: string
10
- asType?: boolean
10
+ isTypeOnly?: boolean
11
11
  asAlias?: boolean
12
12
  }
13
13
 
@@ -148,7 +148,7 @@ export function getFileSource(file: File) {
148
148
  })
149
149
 
150
150
  const importNodes = imports.reduce((prev, curr) => {
151
- return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, asType: curr.asType })]
151
+ return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })]
152
152
  }, [] as ts.ImportDeclaration[])
153
153
  const importSource = print(importNodes)
154
154
 
package/src/plugin.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import pathParser from 'path'
2
2
 
3
- import { createPluginCache } from './utils'
3
+ import { createPluginCache, transformReservedWord } from './utils'
4
4
 
5
5
  import type { FileManager } from './managers/fileManager'
6
6
  import type { PluginContext, KubbPlugin, PluginFactoryOptions } from './types'
@@ -52,7 +52,11 @@ export const definePlugin = createPlugin<CorePluginOptions>((options) => {
52
52
  return Promise.all(files.map((file) => (file.override ? fileManager.add(file) : fileManager.addOrAppend(file))))
53
53
  },
54
54
  resolvePath,
55
- resolveName,
55
+ resolveName: (params) => {
56
+ const name = resolveName(params)
57
+
58
+ return transformReservedWord(name)
59
+ },
56
60
  load,
57
61
  cache: createPluginCache(Object.create(null)),
58
62
  }
@@ -13,3 +13,4 @@ export * from './getEncodedText'
13
13
  export * from './renderTemplate'
14
14
  export * from './clean'
15
15
  export * from './TreeNode'
16
+ export * from './transformReservedWord'
@@ -5,15 +5,17 @@ type Options = {
5
5
  }
6
6
 
7
7
  export function objectToParameters(data: Data, options: Options = {}) {
8
+ const { typed } = options
9
+
8
10
  return data
9
11
  .reduce((acc, [key, value]) => {
10
- if (options.typed) {
11
- acc.push(`${key}: ${value}["${key}"], `)
12
+ if (typed) {
13
+ acc.push(`${key}: ${value}["${key}"]`)
12
14
  } else {
13
- acc.push(`${key}, `)
15
+ acc.push(`${key}`)
14
16
  }
15
17
 
16
18
  return acc
17
19
  }, [] as string[])
18
- .join('')
20
+ .join(', ')
19
21
  }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
3
+ */
4
+ const reservedWords = [
5
+ 'abstract',
6
+ 'arguments',
7
+ 'boolean',
8
+ 'break',
9
+ 'byte',
10
+ 'case',
11
+ 'catch',
12
+ 'char',
13
+ 'class',
14
+ 'const',
15
+ 'continue',
16
+ 'debugger',
17
+ 'default',
18
+ 'delete',
19
+ 'do',
20
+ 'double',
21
+ 'else',
22
+ 'enum',
23
+ 'eval',
24
+ 'export',
25
+ 'extends',
26
+ 'false',
27
+ 'final',
28
+ 'finally',
29
+ 'float',
30
+ 'for',
31
+ 'function',
32
+ 'goto',
33
+ 'if',
34
+ 'implements',
35
+ 'import',
36
+ 'in',
37
+ 'instanceof',
38
+ 'int',
39
+ 'interface',
40
+ 'let',
41
+ 'long',
42
+ 'native',
43
+ 'new',
44
+ 'null',
45
+ 'package',
46
+ 'private',
47
+ 'protected',
48
+ 'public',
49
+ 'return',
50
+ 'short',
51
+ 'static',
52
+ 'super',
53
+ 'switch',
54
+ 'synchronized',
55
+ 'this',
56
+ 'throw',
57
+ 'throws',
58
+ 'transient',
59
+ 'true',
60
+ 'try',
61
+ 'typeof',
62
+ 'var',
63
+ 'void',
64
+ 'volatile',
65
+ 'while',
66
+ 'with',
67
+ 'yield',
68
+
69
+ 'Array',
70
+ 'Date',
71
+ 'eval',
72
+ 'function',
73
+ 'hasOwnProperty',
74
+ 'Infinity',
75
+ 'isFinite',
76
+ 'isNaN',
77
+ 'isPrototypeOf',
78
+ 'length',
79
+ 'Math',
80
+ 'name',
81
+ 'NaN',
82
+ 'Number',
83
+ 'Object',
84
+ 'prototype',
85
+ 'String',
86
+ 'toString',
87
+ 'undefined',
88
+ 'valueOf',
89
+ ]
90
+
91
+ export function transformReservedWord(word: string) {
92
+ if (reservedWords.includes(word)) {
93
+ return `_${word}`
94
+ }
95
+
96
+ return word
97
+ }