@kubb/core 0.40.0 → 0.41.0

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.js CHANGED
@@ -7,6 +7,7 @@ var pathParser = require('path');
7
7
  var fs = require('fs');
8
8
  var rimraf = require('rimraf');
9
9
  var EventEmitter = require('eventemitter3');
10
+ var uniq = require('lodash.uniq');
10
11
  var uuid = require('uuid');
11
12
  var dirTree = require('directory-tree');
12
13
 
@@ -15,6 +16,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
16
  var pathParser__default = /*#__PURE__*/_interopDefault(pathParser);
16
17
  var rimraf__default = /*#__PURE__*/_interopDefault(rimraf);
17
18
  var EventEmitter__default = /*#__PURE__*/_interopDefault(EventEmitter);
19
+ var uniq__default = /*#__PURE__*/_interopDefault(uniq);
18
20
  var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
19
21
 
20
22
  module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href)));
@@ -115,9 +117,6 @@ function createPlugin(factory) {
115
117
  };
116
118
  }
117
119
  var name = "core";
118
- var isEmittedFile = (result) => {
119
- return !!result.id;
120
- };
121
120
  var definePlugin = createPlugin((options) => {
122
121
  const { fileManager, resolveId, load } = options;
123
122
  const api = {
@@ -125,17 +124,7 @@ var definePlugin = createPlugin((options) => {
125
124
  return options.config;
126
125
  },
127
126
  fileManager,
128
- async addFile(file, options2) {
129
- if (isEmittedFile(file)) {
130
- const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options });
131
- const path = resolvedId || file.importer || file.id;
132
- return fileManager.add({
133
- path,
134
- fileName: file.name || file.id,
135
- source: file.source || ""
136
- });
137
- }
138
- if (options2?.root) ;
127
+ async addFile(file) {
139
128
  return fileManager.addOrAppend(file);
140
129
  },
141
130
  resolveId,
@@ -144,6 +133,7 @@ var definePlugin = createPlugin((options) => {
144
133
  };
145
134
  return {
146
135
  name,
136
+ options,
147
137
  api,
148
138
  resolveId(fileName, directory) {
149
139
  if (!directory) {
@@ -241,32 +231,16 @@ var FileManager = class {
241
231
  });
242
232
  return count;
243
233
  }
244
- get files() {
245
- const files = [];
246
- this.cache.forEach((item) => {
247
- files.push(item.file);
248
- });
249
- return files;
250
- }
251
- add(file) {
252
- const cacheItem = { id: uuid.v4(), file, status: "new" };
253
- this.cache.set(cacheItem.id, cacheItem);
254
- this.events.emitFile(cacheItem.id, file);
255
- return new Promise((resolve) => {
256
- const unsubscribe = this.events.onRemove(cacheItem.id, (file2) => {
257
- resolve(file2);
258
- unsubscribe();
259
- });
260
- });
261
- }
262
- build(file) {
234
+ getSource(file) {
263
235
  const imports = [];
264
236
  file.imports?.forEach((curr) => {
265
237
  const exists = imports.find((imp) => imp.path === curr.path);
266
- if (exists) {
267
- exists.name = [...exists.name, ...curr.name];
268
- } else {
238
+ if (!exists) {
269
239
  imports.push(curr);
240
+ return;
241
+ }
242
+ if (exists && Array.isArray(curr.name)) {
243
+ exists.name = uniq__default.default([...exists.name, ...curr.name]);
270
244
  }
271
245
  });
272
246
  const importSource = imports.reduce((prev, curr) => {
@@ -283,6 +257,27 @@ ${file.source}`;
283
257
  }
284
258
  return file.source;
285
259
  }
260
+ get files() {
261
+ const files = [];
262
+ this.cache.forEach((item) => {
263
+ files.push(item.file);
264
+ });
265
+ return files;
266
+ }
267
+ add(file) {
268
+ const cacheItem = { id: uuid.v4(), file, status: "new" };
269
+ this.cache.set(cacheItem.id, cacheItem);
270
+ this.events.emitFile(cacheItem.id, file);
271
+ return new Promise((resolve) => {
272
+ const unsubscribe = this.events.onRemove(cacheItem.id, (file2) => {
273
+ resolve(file2);
274
+ unsubscribe();
275
+ });
276
+ });
277
+ }
278
+ build(file) {
279
+ return this.getSource(file);
280
+ }
286
281
  addOrAppend(file) {
287
282
  const previousCache = this.getCacheByPath(file.path);
288
283
  if (previousCache) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/build.ts","../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/events.ts","../src/managers/fileManager/TreeNode.ts","../src/managers/pluginManager/PluginManager.ts","../src/managers/pluginManager/validate.ts","../src/config.ts","../src/generators/Generator.ts","../src/generators/SchemaGenerator.ts","../src/index.ts"],"names":["pathParser","fs","options","file","argument0"],"mappings":";;;AACA,OAAOA,iBAAgB;;;ACDvB,OAAOA,iBAAgB;;;ACEhB,IAAM,YAAY,CAAI,WAAkD;AAC7E,SAAO,OAAQ,QAAgB,SAAS;AAC1C;;;ACHA,SAAS,YAAY,UAAU;AAC/B,OAAO,gBAAgB;AAEvB,OAAO,YAAY;AAEnB,IAAM,sBAAsB,OAAO,MAAc,SAAc;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;AAEO,IAAM,QAAQ,OAAO,MAAc,SAAiB;AACzD,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;AAEO,IAAM,QAAQ,OAAO,SAAiB;AAC3C,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,WAAO,MAAM,CAAC,QAAQ;AACpB,UAAI,KAAK;AACP,eAAO,GAAG;AAAA,MACZ,OAAO;AACL,gBAAQ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C,MAAM,IAAI,GAAG,gBAAgB;AAEtG,UAAI,OAAO,OAAO,UAAU,UAAU;AACpC,cAAM,cAAc,aAAa,aAAa,CAAC,iBAAiB,IAAI,CAAC;AAAA,MACvE;AAEA,kBAAY,UAAU,IAAI,SAAS;AACnC,kBAAY,OAAO,EAAE;AAAA,IACvB;AAAA,EACF,CAAC;AAED,QAAM,cAAc,aAAa,cAAc,CAAC,MAAM,CAAC;AAEvD,gBAAc,YAAY,IAAI;AAAA,IAC5B,MAAM,OAAO,OAAO,UAAU,WAAW,UAAUJ,YAAW,QAAQ,OAAO,MAAM,OAAO,MAAM,IAAI;AAAA,IACpG,UAAU,OAAO,OAAO,UAAU,WAAW,UAAU,OAAO,MAAM;AAAA,IACpE,QAAQ,OAAO,OAAO,UAAU,WAAW,OAAO,QAAQ,MAAM,KAAKA,YAAW,QAAQ,OAAO,MAAM,OAAO,MAAM,IAAI,CAAC;AAAA,EACzH,CAAC;AACH;AAIO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,QAAI;AACF,YAAM,oBAAoB,SAAS,OAAO;AAAA,IAC5C,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AW9FO,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;;;ACIA,IAAO,cAAQ","sourcesContent":["/* eslint-disable no-async-promise-executor */\nimport pathParser from 'path'\n\nimport { PluginManager } from './managers/pluginManager'\nimport { clean, read } from './utils'\n\nimport type { FileManager } from './managers/fileManager'\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 mode: 'development' | 'production'\n logger?: Logger\n}\n\nasync function transformReducer(this: PluginContext, _previousCode: string, result: TransformResult, _plugin: KubbPlugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions, done: (output: BuildOutput) => void) {\n const { config, logger } = options\n\n if (config.output.clean) {\n await clean(config.output.path)\n }\n\n const pluginManager = new PluginManager(config, { logger })\n const { plugins, fileManager } = pluginManager\n\n await pluginManager.hookParallel<'validate', true>('validate', [plugins])\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done({ files: fileManager.files })\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n \n let code =fileManager.build(file)\n\n const loadedResult = await pluginManager.hookFirst('load', [path])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0('transform', [code, path], transformReducer)\n\n if (typeof config.input === 'object') {\n await pluginManager.hookParallel('writeFile', [transformedCode, path])\n }\n\n fileManager.setStatus(id, 'success')\n fileManager.remove(id)\n }\n })\n\n await pluginManager.hookParallel('buildStart', [config])\n\n pluginManager.fileManager.add({\n path: typeof config.input === 'string' ? 'input' : pathParser.resolve(config.root, config.input.path),\n fileName: typeof config.input === 'string' ? 'input' : config.input.path,\n source: typeof config.input === 'string' ? config.input : await read(pathParser.resolve(config.root, config.input.path)),\n })\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 await buildImplementation(options, resolve)\n } catch (e) {\n reject(e)\n }\n })\n}\n","import pathParser from 'path'\n\nimport { createPluginCache } from './utils'\n\nimport type { FileManager, EmittedFile, File } 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 resolveId: PluginContext['resolveId']\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\nconst isEmittedFile = (result: EmittedFile | File): result is EmittedFile => {\n return !!(result as any).id\n}\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolveId, load } = options\n const indexFiles: File[] = []\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(file, options) {\n if (isEmittedFile(file)) {\n const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options })\n const path = resolvedId || file.importer || file.id\n\n return fileManager.add({\n path,\n fileName: file.name || file.id,\n source: file.source || '',\n })\n }\n\n if (options?.root) {\n indexFiles.push(file)\n }\n\n return fileManager.addOrAppend(file)\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n resolveId(fileName, directory) {\n if (!directory) {\n return null\n }\n return pathParser.resolve(directory, fileName)\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport const isPromise = <T>(result: MaybePromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport { promises as fs } from 'fs'\nimport pathParser from 'path'\n\nimport rimraf from 'rimraf'\n\nconst safeWriteFileToPath = async (path: string, data: any) => {\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 const write = async (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\nexport const clean = async (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","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<TCache = any> {\n delete(id: string): boolean\n get<T = TCache>(id: string): T\n has(id: string): boolean\n set<T = TCache>(id: string, value: T): void\n}\n\nexport function createPluginCache(cache: any): Cache {\n return {\n delete(id: string) {\n return delete cache[id]\n },\n get(id: string) {\n const item = cache[id]\n if (!item) return\n item[0] = 0\n return item[1]\n },\n has(id: string) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id: string, value: any) {\n cache[id] = [0, value]\n },\n }\n}\n","import pathParser from 'path'\nimport { promises as fs } from 'fs'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (root?: string | null, file?: string | null) => {\n if (!root || !file) {\n throw new Error('Root and file should be filled in when retrieving the relativePath')\n }\n const newPath = pathParser.relative(root, file).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n\nexport type PathMode = 'file' | 'directory'\n\nexport const getPathMode = (path: string | undefined | null): PathMode | undefined => {\n if (!path) {\n return undefined\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n\nexport const read = async (path: string) => {\n try {\n return fs.readFile(path, { encoding: 'utf8' })\n } catch (err) {\n console.error(err)\n throw err\n }\n}\n","import EventEmitter from 'eventemitter3'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { getFileManagerEvents } from './events'\n\nimport { write, read } from '../../utils'\n\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n emitter = new EventEmitter()\n\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountByStatus('removed') === this.cache.size) {\n // all files are been resolved and written to the file system\n this.events.emitSuccess()\n }\n })\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n private 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 CacheStore\n }\n\n private getCountByStatus(status: Status) {\n let count = 0\n\n this.cache.forEach((item) => {\n if (item.status === status) {\n count++\n }\n })\n return count\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 add(file: File) {\n const cacheItem = { id: uuidv4(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n this.events.emitFile(cacheItem.id, file)\n\n return new Promise<File>((resolve) => {\n const unsubscribe = this.events.onRemove(cacheItem.id, (file) => {\n resolve(file)\n unsubscribe()\n })\n })\n }\n\n build(file: File){\n const imports: File[\"imports\"]=[]\n\n file.imports?.forEach((curr)=>{\n const exists = imports.find(imp=>imp.path===curr.path)\n if(exists){\n exists.name=[...exists.name, ...curr.name]\n }else{\n imports.push(curr)\n }\n })\n\n\n const importSource= imports.reduce(((prev, curr)=>{\n if(Array.isArray(curr.name)){\n return `${prev}\\nimport ${curr.type? \"type \": \"\"}{ ${curr.name.join(',')} } from \"${curr.path}\";`\n } \n\n return `${prev}\\nimport ${curr.type? \"type \": \"\"}${curr.name} from \"${curr.path}\";`\n }),\"\")\n\n if(importSource){\n return `${importSource}\\n${file.source}`\n }\n\n return file.source\n }\n\n addOrAppend(file: File) {\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n this.remove(previousCache.id)\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n imports: [...(previousCache.file.imports|| []), ...(file.imports || [])]\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 this.events.emitStatusChange(cacheItem.file)\n this.events.emitStatusChangeById(id, status)\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 this.events.emitRemove(id, cacheItem.file)\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 type EventEmitter from 'eventemitter3'\nimport type { File, Status, UUID } from './types'\n\nconst keys = {\n getFileKey: () => `file`,\n getStatusChangeKey: () => `status-change`,\n getStatusChangeByIdKey: (id: string) => `${id}-status-change`,\n getSuccessKey: () => `success`,\n getRemoveKey: (id: string) => `${id}remove`,\n} as const\n\ntype VoidFunction = () => void\n\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getFileKey(), id, file)\n },\n emitStatusChange: (file: File): void => {\n emitter.emit(keys.getStatusChangeKey(), file)\n },\n emitStatusChangeById: (id: UUID, status: Status): void => {\n emitter.emit(keys.getStatusChangeByIdKey(id), status)\n },\n emitSuccess: (): void => {\n emitter.emit(keys.getSuccessKey())\n },\n emitRemove: (id: UUID, file: File): void => {\n emitter.emit(keys.getRemoveKey(id), file)\n },\n /**\n * Listeners\n */\n\n onAdd: (callback: (id: UUID, file: File) => void): VoidFunction => {\n emitter.on(keys.getFileKey(), callback)\n return () => emitter.removeListener(keys.getFileKey(), callback)\n },\n onStatusChange: (callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeKey(), callback)\n return () => emitter.removeListener(keys.getStatusChangeKey(), callback)\n },\n onStatusChangeById: (id: UUID, callback: (status: Status) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeByIdKey(id), callback)\n return () => emitter.removeListener(keys.getStatusChangeByIdKey(id), callback)\n },\n onSuccess: (callback: () => void): VoidFunction => {\n emitter.on(keys.getSuccessKey(), callback)\n return () => emitter.removeListener(keys.getSuccessKey(), callback)\n },\n onRemove: (id: UUID, callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getRemoveKey(id), callback)\n return () => emitter.removeListener(keys.getRemoveKey(id), callback)\n },\n }\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\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) {\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: any = 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() {\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 = []\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() {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void) {\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(path: string, options: DirectoryTreeOptions = {}) {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n\n if (!filteredTree) {\n return\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\n }\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\n\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolveIdParams } 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 resolveId: 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 constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.fileManager = new FileManager()\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: this.resolveId,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (params: ResolveIdParams) => {\n if (params.pluginName) {\n return this.hookForPlugin(params.pluginName, 'resolveId', [params.fileName, params.directory, params.options])\n }\n return this.hookFirst('resolveId', [params.fileName, params.directory, params.options])\n }\n\n load = async (id: string) => {\n return this.hookFirst('load', [id])\n }\n\n // run only hook for a specific plugin name\n hookForPlugin<H extends PluginLifecycleHooks>(\n pluginName: string,\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName, pluginName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // chains, first non-null result stops and returns\n hookFirst<H extends PluginLifecycleHooks>(\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\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('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined) {\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('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.run('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: H,\n [argument0, ...rest]: Parameters<PluginLifecycle[H]>,\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n ): Promise<Argument0<H>> {\n let promise = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.core.api, argument0, result, plugin)\n )\n )\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>(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(() => this.run('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(hookName: keyof PluginLifecycle, pluginName?: string): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n if (pluginName) {\n const pluginsByPluginName = plugins.filter((item) => item.name === pluginName && item[hookName])\n if (pluginsByPluginName.length === 0) {\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 pluginsByPluginName\n }\n\n return plugins\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: 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 any).apply(this.core.api, parameters)\n\n if (!hookResult?.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 })\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>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: KubbPlugin): 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 return (hook as Function).apply(this.core.api, parameters)\n } catch (error: any) {\n return error\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 const 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","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'\nexport default build\n"]}
1
+ {"version":3,"sources":["../src/build.ts","../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/events.ts","../src/managers/fileManager/TreeNode.ts","../src/managers/pluginManager/PluginManager.ts","../src/managers/pluginManager/validate.ts","../src/config.ts","../src/generators/Generator.ts","../src/generators/SchemaGenerator.ts","../src/index.ts"],"names":["pathParser","fs","file","argument0"],"mappings":";;;AACA,OAAOA,iBAAgB;;;ACDvB,OAAOA,iBAAgB;;;ACEhB,IAAM,YAAY,CAAI,WAAkD;AAC7E,SAAO,OAAQ,QAAgB,SAAS;AAC1C;;;ACHA,SAAS,YAAY,UAAU;AAC/B,OAAO,gBAAgB;AAEvB,OAAO,YAAY;AAEnB,IAAM,sBAAsB,OAAO,MAAc,SAAc;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;AAEO,IAAM,QAAQ,OAAO,MAAc,SAAiB;AACzD,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;AAEO,IAAM,QAAQ,OAAO,SAAiB;AAC3C,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,W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,CAAC;AAED,QAAM,cAAc,aAAa,cAAc,CAAC,MAAM,CAAC;AAEvD,gBAAc,YAAY,IAAI;AAAA,IAC5B,MAAM,OAAO,OAAO,UAAU,WAAW,UAAUH,YAAW,QAAQ,OAAO,MAAM,OAAO,MAAM,IAAI;AAAA,IACpG,UAAU,OAAO,OAAO,UAAU,WAAW,UAAU,OAAO,MAAM;AAAA,IACpE,QAAQ,OAAO,OAAO,UAAU,WAAW,OAAO,QAAQ,MAAM,KAAKA,YAAW,QAAQ,OAAO,MAAM,OAAO,MAAM,IAAI,CAAC;AAAA,EACzH,CAAC;AACH;AAIO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,QAAI;AACF,YAAM,oBAAoB,SAAS,OAAO;AAAA,IAC5C,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AW9FO,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;;;ACIA,IAAO,cAAQ","sourcesContent":["/* eslint-disable no-async-promise-executor */\nimport pathParser from 'path'\n\nimport { PluginManager } from './managers/pluginManager'\nimport { clean, read } from './utils'\n\nimport type { FileManager } from './managers/fileManager'\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 mode: 'development' | 'production'\n logger?: Logger\n}\n\nasync function transformReducer(this: PluginContext, _previousCode: string, result: TransformResult, _plugin: KubbPlugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions, done: (output: BuildOutput) => void) {\n const { config, logger } = options\n\n if (config.output.clean) {\n await clean(config.output.path)\n }\n\n const pluginManager = new PluginManager(config, { logger })\n const { plugins, fileManager } = pluginManager\n\n await pluginManager.hookParallel<'validate', true>('validate', [plugins])\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done({ files: fileManager.files })\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n\n let code = fileManager.build(file)\n\n const loadedResult = await pluginManager.hookFirst('load', [path])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0('transform', [code, path], transformReducer)\n\n if (typeof config.input === 'object') {\n await pluginManager.hookParallel('writeFile', [transformedCode, path])\n }\n\n fileManager.setStatus(id, 'success')\n fileManager.remove(id)\n }\n })\n\n await pluginManager.hookParallel('buildStart', [config])\n\n pluginManager.fileManager.add({\n path: typeof config.input === 'string' ? 'input' : pathParser.resolve(config.root, config.input.path),\n fileName: typeof config.input === 'string' ? 'input' : config.input.path,\n source: typeof config.input === 'string' ? config.input : await read(pathParser.resolve(config.root, config.input.path)),\n })\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 await buildImplementation(options, resolve)\n } catch (e) {\n reject(e)\n }\n })\n}\n","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 resolveId: PluginContext['resolveId']\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, resolveId, load } = options\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(file) {\n return fileManager.addOrAppend(file)\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n options,\n api,\n resolveId(fileName, directory) {\n if (!directory) {\n return null\n }\n return pathParser.resolve(directory, fileName)\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport const isPromise = <T>(result: MaybePromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport { promises as fs } from 'fs'\nimport pathParser from 'path'\n\nimport rimraf from 'rimraf'\n\nconst safeWriteFileToPath = async (path: string, data: any) => {\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 const write = async (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\nexport const clean = async (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","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<TCache = any> {\n delete(id: string): boolean\n get<T = TCache>(id: string): T\n has(id: string): boolean\n set<T = TCache>(id: string, value: T): void\n}\n\nexport function createPluginCache(cache: any): Cache {\n return {\n delete(id: string) {\n return delete cache[id]\n },\n get(id: string) {\n const item = cache[id]\n if (!item) return\n item[0] = 0\n return item[1]\n },\n has(id: string) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id: string, value: any) {\n cache[id] = [0, value]\n },\n }\n}\n","import pathParser from 'path'\nimport { promises as fs } from 'fs'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (root?: string | null, file?: string | null) => {\n if (!root || !file) {\n throw new Error('Root and file should be filled in when retrieving the relativePath')\n }\n const newPath = pathParser.relative(root, file).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n\nexport type PathMode = 'file' | 'directory'\n\nexport const getPathMode = (path: string | undefined | null): PathMode | undefined => {\n if (!path) {\n return undefined\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n\nexport const read = async (path: string) => {\n try {\n return fs.readFile(path, { encoding: 'utf8' })\n } catch (err) {\n console.error(err)\n throw err\n }\n}\n","import EventEmitter from 'eventemitter3'\nimport uniq from 'lodash.uniq'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { getFileManagerEvents } from './events'\n\nimport { write, read } from '../../utils'\n\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n emitter = new EventEmitter()\n\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountByStatus('removed') === this.cache.size) {\n // all files are been resolved and written to the file system\n this.events.emitSuccess()\n }\n })\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n private 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 CacheStore\n }\n\n private getCountByStatus(status: Status) {\n let count = 0\n\n this.cache.forEach((item) => {\n if (item.status === status) {\n count++\n }\n })\n return count\n }\n\n private getSource(file: File) {\n const imports: File['imports'] = []\n\n file.imports?.forEach((curr) => {\n const exists = imports.find((imp) => imp.path === curr.path)\n if (!exists) {\n imports.push(curr)\n return\n }\n\n if (exists && Array.isArray(curr.name)) {\n exists.name = uniq([...exists.name, ...curr.name])\n }\n })\n\n const importSource = imports.reduce((prev, curr) => {\n if (Array.isArray(curr.name)) {\n return `${prev}\\nimport ${curr.type ? 'type ' : ''}{ ${curr.name.join(',')} } from \"${curr.path}\";`\n }\n\n return `${prev}\\nimport ${curr.type ? 'type ' : ''}${curr.name} from \"${curr.path}\";`\n }, '')\n\n if (importSource) {\n return `${importSource}\\n${file.source}`\n }\n\n return file.source\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 add(file: File) {\n const cacheItem = { id: uuidv4(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n this.events.emitFile(cacheItem.id, file)\n\n return new Promise<File>((resolve) => {\n const unsubscribe = this.events.onRemove(cacheItem.id, (file) => {\n resolve(file)\n unsubscribe()\n })\n })\n }\n\n build(file: File) {\n return this.getSource(file)\n }\n\n addOrAppend(file: File) {\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n this.remove(previousCache.id)\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n imports: [...(previousCache.file.imports || []), ...(file.imports || [])],\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 this.events.emitStatusChange(cacheItem.file)\n this.events.emitStatusChangeById(id, status)\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 this.events.emitRemove(id, cacheItem.file)\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 type EventEmitter from 'eventemitter3'\nimport type { File, Status, UUID } from './types'\n\nconst keys = {\n getFileKey: () => `file`,\n getStatusChangeKey: () => `status-change`,\n getStatusChangeByIdKey: (id: string) => `${id}-status-change`,\n getSuccessKey: () => `success`,\n getRemoveKey: (id: string) => `${id}remove`,\n} as const\n\ntype VoidFunction = () => void\n\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getFileKey(), id, file)\n },\n emitStatusChange: (file: File): void => {\n emitter.emit(keys.getStatusChangeKey(), file)\n },\n emitStatusChangeById: (id: UUID, status: Status): void => {\n emitter.emit(keys.getStatusChangeByIdKey(id), status)\n },\n emitSuccess: (): void => {\n emitter.emit(keys.getSuccessKey())\n },\n emitRemove: (id: UUID, file: File): void => {\n emitter.emit(keys.getRemoveKey(id), file)\n },\n /**\n * Listeners\n */\n\n onAdd: (callback: (id: UUID, file: File) => void): VoidFunction => {\n emitter.on(keys.getFileKey(), callback)\n return () => emitter.removeListener(keys.getFileKey(), callback)\n },\n onStatusChange: (callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeKey(), callback)\n return () => emitter.removeListener(keys.getStatusChangeKey(), callback)\n },\n onStatusChangeById: (id: UUID, callback: (status: Status) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeByIdKey(id), callback)\n return () => emitter.removeListener(keys.getStatusChangeByIdKey(id), callback)\n },\n onSuccess: (callback: () => void): VoidFunction => {\n emitter.on(keys.getSuccessKey(), callback)\n return () => emitter.removeListener(keys.getSuccessKey(), callback)\n },\n onRemove: (id: UUID, callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getRemoveKey(id), callback)\n return () => emitter.removeListener(keys.getRemoveKey(id), callback)\n },\n }\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\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) {\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: any = 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() {\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 = []\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() {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void) {\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(path: string, options: DirectoryTreeOptions = {}) {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n\n if (!filteredTree) {\n return\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\n }\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\n\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolveIdParams } 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 resolveId: 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 constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.fileManager = new FileManager()\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: this.resolveId,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (params: ResolveIdParams) => {\n if (params.pluginName) {\n return this.hookForPlugin(params.pluginName, 'resolveId', [params.fileName, params.directory, params.options])\n }\n return this.hookFirst('resolveId', [params.fileName, params.directory, params.options])\n }\n\n load = async (id: string) => {\n return this.hookFirst('load', [id])\n }\n\n // run only hook for a specific plugin name\n hookForPlugin<H extends PluginLifecycleHooks>(\n pluginName: string,\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName, pluginName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // chains, first non-null result stops and returns\n hookFirst<H extends PluginLifecycleHooks>(\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\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('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined) {\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('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.run('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: H,\n [argument0, ...rest]: Parameters<PluginLifecycle[H]>,\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n ): Promise<Argument0<H>> {\n let promise = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.core.api, argument0, result, plugin)\n )\n )\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>(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(() => this.run('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(hookName: keyof PluginLifecycle, pluginName?: string): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n if (pluginName) {\n const pluginsByPluginName = plugins.filter((item) => item.name === pluginName && item[hookName])\n if (pluginsByPluginName.length === 0) {\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 pluginsByPluginName\n }\n\n return plugins\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: 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 any).apply(this.core.api, parameters)\n\n if (!hookResult?.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 })\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>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: KubbPlugin): 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 return (hook as Function).apply(this.core.api, parameters)\n } catch (error: any) {\n return error\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 const 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","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'\nexport default build\n"]}
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ import pathParser from 'path';
3
3
  import { promises } from 'fs';
4
4
  import rimraf from 'rimraf';
5
5
  import EventEmitter from 'eventemitter3';
6
+ import uniq from 'lodash.uniq';
6
7
  import { v4 } from 'uuid';
7
8
  import dirTree from 'directory-tree';
8
9
 
@@ -104,9 +105,6 @@ function createPlugin(factory) {
104
105
  };
105
106
  }
106
107
  var name = "core";
107
- var isEmittedFile = (result) => {
108
- return !!result.id;
109
- };
110
108
  var definePlugin = createPlugin((options) => {
111
109
  const { fileManager, resolveId, load } = options;
112
110
  const api = {
@@ -114,17 +112,7 @@ var definePlugin = createPlugin((options) => {
114
112
  return options.config;
115
113
  },
116
114
  fileManager,
117
- async addFile(file, options2) {
118
- if (isEmittedFile(file)) {
119
- const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options });
120
- const path = resolvedId || file.importer || file.id;
121
- return fileManager.add({
122
- path,
123
- fileName: file.name || file.id,
124
- source: file.source || ""
125
- });
126
- }
127
- if (options2?.root) ;
115
+ async addFile(file) {
128
116
  return fileManager.addOrAppend(file);
129
117
  },
130
118
  resolveId,
@@ -133,6 +121,7 @@ var definePlugin = createPlugin((options) => {
133
121
  };
134
122
  return {
135
123
  name,
124
+ options,
136
125
  api,
137
126
  resolveId(fileName, directory) {
138
127
  if (!directory) {
@@ -230,32 +219,16 @@ var FileManager = class {
230
219
  });
231
220
  return count;
232
221
  }
233
- get files() {
234
- const files = [];
235
- this.cache.forEach((item) => {
236
- files.push(item.file);
237
- });
238
- return files;
239
- }
240
- add(file) {
241
- const cacheItem = { id: v4(), file, status: "new" };
242
- this.cache.set(cacheItem.id, cacheItem);
243
- this.events.emitFile(cacheItem.id, file);
244
- return new Promise((resolve) => {
245
- const unsubscribe = this.events.onRemove(cacheItem.id, (file2) => {
246
- resolve(file2);
247
- unsubscribe();
248
- });
249
- });
250
- }
251
- build(file) {
222
+ getSource(file) {
252
223
  const imports = [];
253
224
  file.imports?.forEach((curr) => {
254
225
  const exists = imports.find((imp) => imp.path === curr.path);
255
- if (exists) {
256
- exists.name = [...exists.name, ...curr.name];
257
- } else {
226
+ if (!exists) {
258
227
  imports.push(curr);
228
+ return;
229
+ }
230
+ if (exists && Array.isArray(curr.name)) {
231
+ exists.name = uniq([...exists.name, ...curr.name]);
259
232
  }
260
233
  });
261
234
  const importSource = imports.reduce((prev, curr) => {
@@ -272,6 +245,27 @@ ${file.source}`;
272
245
  }
273
246
  return file.source;
274
247
  }
248
+ get files() {
249
+ const files = [];
250
+ this.cache.forEach((item) => {
251
+ files.push(item.file);
252
+ });
253
+ return files;
254
+ }
255
+ add(file) {
256
+ const cacheItem = { id: v4(), file, status: "new" };
257
+ this.cache.set(cacheItem.id, cacheItem);
258
+ this.events.emitFile(cacheItem.id, file);
259
+ return new Promise((resolve) => {
260
+ const unsubscribe = this.events.onRemove(cacheItem.id, (file2) => {
261
+ resolve(file2);
262
+ unsubscribe();
263
+ });
264
+ });
265
+ }
266
+ build(file) {
267
+ return this.getSource(file);
268
+ }
275
269
  addOrAppend(file) {
276
270
  const previousCache = this.getCacheByPath(file.path);
277
271
  if (previousCache) {