@kubb/core 0.35.0 → 0.36.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.d.ts CHANGED
@@ -1,92 +1,6 @@
1
1
  import EventEmitter from 'events';
2
2
  import { DirectoryTreeOptions } from 'directory-tree';
3
3
 
4
- /**
5
- * @deprecated Use userFile instead
6
- */
7
- type EmittedFile = {
8
- /**
9
- * equal to importee when getting passed through resolveId
10
- */
11
- id: string;
12
- /**
13
- * The importer is the fully resolved id of the importing module.
14
- */
15
- importer?: string;
16
- /**
17
- * Name to be used to dynamicly create the fileName(based on input.path)
18
- */
19
- name?: string;
20
- /**
21
- * FileName will be the end result so no input.path will not be added
22
- */
23
- fileName?: string;
24
- source?: string;
25
- options?: Record<string, any>;
26
- };
27
- type File = {
28
- /**
29
- * Name to be used to dynamicly create the fileName(based on input.path)
30
- */
31
- fileName: string;
32
- /**
33
- * Path will be full qualified path to a specified file
34
- */
35
- path: string;
36
- source: string;
37
- };
38
- type UUID = string;
39
- type CacheStore = {
40
- id: UUID;
41
- file: File;
42
- status: Status;
43
- };
44
- type Status = 'new' | 'success' | 'removed';
45
-
46
- declare class FileManager {
47
- private cache;
48
- emitter: EventEmitter;
49
- events: {
50
- emitFile: (id: string, file: File) => void;
51
- emitStatusChange: (file: File) => void;
52
- emitStatusChangeById: (id: string, status: Status) => void;
53
- emitSuccess: () => void;
54
- emitRemove: (id: string, file: File) => void;
55
- onAdd: (callback: (id: string, file: File) => void) => () => void;
56
- onStatusChange: (callback: (file: File) => void) => () => void;
57
- onStatusChangeById: (id: string, callback: (status: Status) => void) => () => void;
58
- onSuccess: (callback: () => void) => () => void;
59
- onRemove: (id: string, callback: (file: File) => void) => () => void;
60
- };
61
- constructor();
62
- private getCache;
63
- private getCacheByPath;
64
- private getCountByStatus;
65
- get files(): File[];
66
- add(file: File): Promise<File>;
67
- addOrAppend(file: File): Promise<File>;
68
- setStatus(id: UUID, status: Status): void;
69
- get(id: UUID): File | undefined;
70
- remove(id: UUID): void;
71
- }
72
-
73
- declare class TreeNode<T = unknown> {
74
- data: T;
75
- parent?: TreeNode<T>;
76
- children: Array<TreeNode<T>>;
77
- constructor(data: T, parent?: TreeNode<T>);
78
- addChild(data: T): any;
79
- find(data: T): any;
80
- leaves(): this[];
81
- root(): any;
82
- forEach(callback: (treeNode: TreeNode<T>) => void): this;
83
- static build(path: string, options?: DirectoryTreeOptions): TreeNode<{
84
- name: string;
85
- path: string;
86
- type: "file" | "directory";
87
- }> | undefined;
88
- }
89
-
90
4
  interface Cache<TCache = any> {
91
5
  delete(id: string): boolean;
92
6
  get<T = TCache>(id: string): T;
@@ -96,13 +10,14 @@ interface Cache<TCache = any> {
96
10
  declare function createPluginCache(cache: any): Cache;
97
11
 
98
12
  type MaybePromise<T> = Promise<T> | T;
99
- type KubbUserConfig = Omit<KubbConfig, 'root'> & {
13
+ type KubbUserConfig<IsJSON = false> = Omit<KubbConfig, 'root'> & {
100
14
  /**
101
15
  * Project root directory. Can be an absolute path, or a path relative from
102
16
  * the location of the config file itself.
103
17
  * @default process.cwd()
104
18
  */
105
19
  root?: string;
20
+ plugins?: IsJSON extends true ? KubbJSONPlugin[] : KubbPlugin[];
106
21
  };
107
22
  /**
108
23
  * Global/internal config used through out the full generation.
@@ -120,11 +35,10 @@ type KubbConfig = {
120
35
  * the defined root option.
121
36
  */
122
37
  path: string;
123
- };
38
+ } | string;
124
39
  output: {
125
40
  /**
126
- * Path to be used to export all generated files. Can be an absolute path, or a path relative from
127
- * the defined root option.
41
+ * Path to be used to export all generated files. Can be an absolute path, or a path relative based of the defined root option.
128
42
  */
129
43
  path: string;
130
44
  /**
@@ -159,6 +73,7 @@ type CLIOptions = {
159
73
  watch?: string;
160
74
  };
161
75
  type KubbPluginKind = 'schema' | 'controller';
76
+ type KubbJSONPlugin = [string, Record<string, any>];
162
77
  type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
163
78
  /**
164
79
  * Unique name used for the plugin
@@ -254,7 +169,112 @@ type FileName = string | null | undefined;
254
169
  type LogType = 'error' | 'warn' | 'info';
255
170
  type LogLevel = LogType | 'silent';
256
171
 
257
- type BuildOutput = void;
172
+ declare const isPromise: <T>(result: MaybePromise<T>) => result is Promise<T>;
173
+
174
+ type WriteOptions = {
175
+ format: boolean;
176
+ };
177
+ declare const write: (data: string, path: string, options?: WriteOptions) => Promise<void>;
178
+ declare const clean: (path: string) => Promise<void>;
179
+
180
+ declare const format: (text: string) => string;
181
+
182
+ declare const getRelativePath: (root?: string | null, file?: string | null) => string;
183
+ type PathMode = 'file' | 'directory';
184
+ declare const getPathMode: (path: string | undefined | null) => PathMode | undefined;
185
+ declare const read: (path: string, encoding?: string) => Promise<string>;
186
+
187
+ /**
188
+ * @deprecated Use userFile instead
189
+ */
190
+ type EmittedFile = {
191
+ /**
192
+ * equal to importee when getting passed through resolveId
193
+ */
194
+ id: string;
195
+ /**
196
+ * The importer is the fully resolved id of the importing module.
197
+ */
198
+ importer?: string;
199
+ /**
200
+ * Name to be used to dynamicly create the fileName(based on input.path)
201
+ */
202
+ name?: string;
203
+ /**
204
+ * FileName will be the end result so no input.path will not be added
205
+ */
206
+ fileName?: string;
207
+ source?: string;
208
+ options?: Record<string, any>;
209
+ };
210
+ type File = {
211
+ /**
212
+ * Name to be used to dynamicly create the fileName(based on input.path)
213
+ */
214
+ fileName: string;
215
+ /**
216
+ * Path will be full qualified path to a specified file
217
+ */
218
+ path: string;
219
+ source: string;
220
+ };
221
+ type UUID = string;
222
+ type CacheStore = {
223
+ id: UUID;
224
+ file: File;
225
+ status: Status;
226
+ };
227
+ type Status = 'new' | 'success' | 'removed';
228
+
229
+ declare class FileManager {
230
+ private cache;
231
+ emitter: EventEmitter;
232
+ events: {
233
+ emitFile: (id: string, file: File) => void;
234
+ emitStatusChange: (file: File) => void;
235
+ emitStatusChangeById: (id: string, status: Status) => void;
236
+ emitSuccess: () => void;
237
+ emitRemove: (id: string, file: File) => void;
238
+ onAdd: (callback: (id: string, file: File) => void) => () => void;
239
+ onStatusChange: (callback: (file: File) => void) => () => void;
240
+ onStatusChangeById: (id: string, callback: (status: Status) => void) => () => void;
241
+ onSuccess: (callback: () => void) => () => void;
242
+ onRemove: (id: string, callback: (file: File) => void) => () => void;
243
+ };
244
+ constructor();
245
+ private getCache;
246
+ private getCacheByPath;
247
+ private getCountByStatus;
248
+ get files(): File[];
249
+ add(file: File): Promise<File>;
250
+ addOrAppend(file: File): Promise<File>;
251
+ setStatus(id: UUID, status: Status): void;
252
+ get(id: UUID): File | undefined;
253
+ remove(id: UUID): void;
254
+ write(...params: Parameters<typeof write>): Promise<void>;
255
+ read(...params: Parameters<typeof read>): Promise<string>;
256
+ }
257
+
258
+ declare class TreeNode<T = unknown> {
259
+ data: T;
260
+ parent?: TreeNode<T>;
261
+ children: Array<TreeNode<T>>;
262
+ constructor(data: T, parent?: TreeNode<T>);
263
+ addChild(data: T): any;
264
+ find(data: T): any;
265
+ leaves(): this[];
266
+ root(): any;
267
+ forEach(callback: (treeNode: TreeNode<T>) => void): this;
268
+ static build(path: string, options?: DirectoryTreeOptions): TreeNode<{
269
+ name: string;
270
+ path: string;
271
+ type: "file" | "directory";
272
+ }> | undefined;
273
+ }
274
+
275
+ type BuildOutput = {
276
+ fileManager: FileManager;
277
+ };
258
278
  type Spinner = {
259
279
  start: (text?: string) => Spinner;
260
280
  succeed: (text: string) => Spinner;
@@ -275,6 +295,7 @@ type BuildOptions = {
275
295
  mode: 'development' | 'production';
276
296
  logger?: Logger;
277
297
  };
298
+ type KubbBuild = (options: BuildOptions) => Promise<BuildOutput>;
278
299
  declare function build(options: BuildOptions): Promise<BuildOutput>;
279
300
 
280
301
  /**
@@ -282,7 +303,7 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
282
303
  * accepts a direct {@link KubbConfig} object, or a function that returns it.
283
304
  * The function receives a {@link ConfigEnv} object that exposes two properties:
284
305
  */
285
- declare const defineConfig: (options: MaybePromise<KubbUserConfig> | ((cliOptions: CLIOptions) => MaybePromise<KubbUserConfig>)) => MaybePromise<KubbUserConfig> | ((cliOptions: CLIOptions) => MaybePromise<KubbUserConfig>);
306
+ declare const defineConfig: (options: MaybePromise<KubbUserConfig<false>> | ((cliOptions: CLIOptions) => MaybePromise<KubbUserConfig>)) => MaybePromise<KubbUserConfig<false>> | ((cliOptions: CLIOptions) => MaybePromise<KubbUserConfig>);
286
307
 
287
308
  type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>;
288
309
  declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => T["nested"] extends true ? KubbPlugin<T>[] : KubbPlugin<T>;
@@ -294,19 +315,6 @@ type Options = {
294
315
  };
295
316
  type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>;
296
317
 
297
- declare const isPromise: <T>(result: MaybePromise<T>) => result is Promise<T>;
298
-
299
- type WriteOptions = {
300
- format: boolean;
301
- };
302
- declare const write: (data: string, path: string, options?: WriteOptions) => Promise<void>;
303
-
304
- declare const format: (text: string) => string;
305
-
306
- declare const getRelativePath: (root?: string | null, file?: string | null) => string;
307
- type PathMode = 'file' | 'directory';
308
- declare const getPathMode: (path: string | undefined | null) => PathMode | undefined;
309
-
310
318
  /**
311
319
  * Get the type of the first argument in a function.
312
320
  * @example Arg0<(a: string, b: number) => void> -> string
@@ -372,4 +380,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
372
380
  abstract build(schema: TInput, name: string, description?: string): TOutput;
373
381
  }
374
382
 
375
- export { Argument0, CLIOptions, Cache, CacheStore, CorePluginOptions, EmittedFile, File, FileManager, FileName, Generator, KubbConfig, KubbPlugin, KubbPluginKind, KubbUserConfig, LogLevel, LogType, Logger, MaybePromise, OptionalPath, Path, PathMode, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, ResolveIdParams, SchemaGenerator, Status, Strategy, TransformResult, TreeNode, UUID, ValidationPluginError, build, createPlugin, createPluginCache, build as default, defineConfig, format, getPathMode, getRelativePath, hooks, isPromise, validatePlugins, write };
383
+ export { Argument0, CLIOptions, Cache, CacheStore, CorePluginOptions, EmittedFile, File, FileManager, FileName, Generator, KubbBuild, KubbConfig, KubbJSONPlugin, KubbPlugin, KubbPluginKind, KubbUserConfig, LogLevel, LogType, Logger, MaybePromise, OptionalPath, Path, PathMode, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, ResolveIdParams, SchemaGenerator, Status, Strategy, TransformResult, TreeNode, UUID, ValidationPluginError, build, clean, createPlugin, createPluginCache, build as default, defineConfig, format, getPathMode, getRelativePath, hooks, isPromise, read, validatePlugins, write };
package/dist/index.js CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var fse = require('fs-extra');
6
5
  var pathParser = require('path');
6
+ var fse = require('fs-extra');
7
7
  var prettier = require('prettier');
8
8
  var EventEmitter = require('events');
9
9
  var crypto = require('crypto');
10
10
  var dirTree = require('directory-tree');
11
11
 
12
- // src/build.ts
12
+ // src/plugin.ts
13
13
 
14
14
  // src/utils/isPromise.ts
15
15
  var isPromise = (result) => {
@@ -38,9 +38,12 @@ var write = async (data, path, options = { format: false }) => {
38
38
  return;
39
39
  }
40
40
  } catch (_err) {
41
- return fse.outputFile(path, formattedData);
41
+ return fse.outputFile(path, formattedData, { encoding: "utf-8" });
42
42
  }
43
- return fse.outputFile(path, formattedData);
43
+ return fse.outputFile(path, formattedData, { encoding: "utf-8" });
44
+ };
45
+ var clean = async (path) => {
46
+ return fse.remove(path);
44
47
  };
45
48
 
46
49
  // src/utils/cache.ts
@@ -81,6 +84,14 @@ var getPathMode = (path) => {
81
84
  }
82
85
  return pathParser.extname(path) ? "file" : "directory";
83
86
  };
87
+ var read = async (path, encoding = "utf8") => {
88
+ try {
89
+ return fse.readFile(path, encoding);
90
+ } catch (err) {
91
+ console.error(err);
92
+ throw err;
93
+ }
94
+ };
84
95
 
85
96
  // src/plugin.ts
86
97
  function createPlugin(factory) {
@@ -270,6 +281,12 @@ ${file.source}`
270
281
  this.setStatus(id, "removed");
271
282
  this.events.emitRemove(id, cacheItem.file);
272
283
  }
284
+ async write(...params) {
285
+ return write(...params);
286
+ }
287
+ async read(...params) {
288
+ return read(...params);
289
+ }
273
290
  };
274
291
  var TreeNode = class {
275
292
  data;
@@ -537,7 +554,7 @@ async function transformReducer(_previousCode, result, _plugin) {
537
554
  async function buildImplementation(options, done) {
538
555
  const { config, logger } = options;
539
556
  if (config.output.clean) {
540
- await fse.remove(config.output.path);
557
+ await clean(config.output.path);
541
558
  }
542
559
  const pluginManager = new PluginManager(config, { logger });
543
560
  const { plugins, fileManager } = pluginManager;
@@ -549,7 +566,7 @@ async function buildImplementation(options, done) {
549
566
  fileManager.events.onSuccess(async () => {
550
567
  await pluginManager.hookParallel("buildEnd");
551
568
  setTimeout(() => {
552
- done();
569
+ done({ fileManager });
553
570
  }, 1e3);
554
571
  });
555
572
  fileManager.events.onAdd(async (id, file) => {
@@ -561,7 +578,9 @@ async function buildImplementation(options, done) {
561
578
  }
562
579
  if (code) {
563
580
  const transformedCode = await pluginManager.hookReduceArg0("transform", [code, path], transformReducer);
564
- await pluginManager.hookParallel("writeFile", [transformedCode, path]);
581
+ if (typeof config.input === "object") {
582
+ await pluginManager.hookParallel("writeFile", [transformedCode, path]);
583
+ }
565
584
  fileManager.setStatus(id, "success");
566
585
  fileManager.remove(id);
567
586
  }
@@ -612,6 +631,7 @@ exports.SchemaGenerator = SchemaGenerator;
612
631
  exports.TreeNode = TreeNode;
613
632
  exports.ValidationPluginError = ValidationPluginError;
614
633
  exports.build = build;
634
+ exports.clean = clean;
615
635
  exports.createPlugin = createPlugin;
616
636
  exports.createPluginCache = createPluginCache;
617
637
  exports.default = src_default;
@@ -621,6 +641,7 @@ exports.getPathMode = getPathMode;
621
641
  exports.getRelativePath = getRelativePath;
622
642
  exports.hooks = hooks;
623
643
  exports.isPromise = isPromise;
644
+ exports.read = read;
624
645
  exports.validatePlugins = validatePlugins;
625
646
  exports.write = write;
626
647
  //# sourceMappingURL=out.js.map
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/format.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":["fse","pathParser","options","file","argument0"],"mappings":";AAAA,OAAOA,UAAS;;;ACAhB,OAAOC,iBAAgB;;;ACEhB,IAAM,YAAY,CAAI,WAAkD;AAC7E,SAAO,OAAQ,QAAgB,SAAS;AAC1C;;;ACHA,OAAO,SAAS;;;ACDhB,SAAS,UAAU,sBAAsB;AAIzC,IAAM,gBAAyB;AAAA,EAC7B,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,WAAW;AACb;AACO,IAAM,SAAS,CAAC,SAAiB;AACtC,SAAO,eAAe,MAAM,aAAa;AAC3C;;;ADNO,IAAM,QAAQ,OAAO,MAAc,MAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,OAAO,IAAI,IAAI;AAEtD,MAAI;AACF,UAAM,IAAI,KAAK,IAAI;AACnB,UAAM,aAAa,MAAM,IAAI,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AACjE,QAAI,YAAY,SAAS,MAAM,eAAe;AAC5C;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO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C;AACrE,kBAAY,UAAU,IAAI,SAAS;AACnC,kBAAY,OAAO,EAAE;AAAA,IACvB;AAAA,EACF,CAAC;AAED,QAAM,cAAc,aAAa,cAAc,CAAC,MAAM,CAAC;AACzD;AAEO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI;AACF,0BAAoB,SAAS,OAAO;AAAA,IACtC,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AYjFO,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":["import fse from 'fs-extra'\n\nimport { PluginManager } from './managers/pluginManager'\n\nimport type { PluginContext, TransformResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = void\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 fse.remove(config.output.path)\n }\n\n const pluginManager = new PluginManager(config, { logger })\n const { plugins, fileManager } = pluginManager\n\n try {\n await pluginManager.hookParallel<'validate', true>('validate', [plugins])\n } catch (e: any) {\n return\n }\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n let { source: code } = 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 await pluginManager.hookParallel('writeFile', [transformedCode, path])\n fileManager.setStatus(id, 'success')\n fileManager.remove(id)\n }\n })\n\n await pluginManager.hookParallel('buildStart', [config])\n}\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n 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 fse from 'fs-extra'\n\nimport { format } from './format'\n\ntype WriteOptions = {\n format: boolean\n}\n\nexport const write = async (data: string, path: string, options: WriteOptions = { format: false }) => {\n const formattedData = options.format ? format(data) : data\n\n try {\n await fse.stat(path)\n const oldContent = await fse.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === formattedData) {\n return\n }\n } catch (_err) {\n return fse.outputFile(path, formattedData)\n }\n\n return fse.outputFile(path, formattedData)\n}\n","import { format as prettierFormat } from 'prettier'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n}\nexport const format = (text: string) => {\n return prettierFormat(text, formatOptions)\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'\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","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\n\nimport { getFileManagerEvents } from './events'\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: randomUUID(), 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 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 })\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","import type EventEmitter from 'events'\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) => this.catcher<H>(e, plugin, hookName))\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 if (this.logger?.spinner) {\n this.logger.spinner.fail(text)\n throw e\n }\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 } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport * from './generators'\nexport default build\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.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/build.ts","../src/config.ts","../src/generators/Generator.ts","../src/generators/SchemaGenerator.ts","../src/index.ts"],"names":["pathParser","fse","options","file","argument0"],"mappings":";AAAA,OAAOA,iBAAgB;;;ACEhB,IAAM,YAAY,CAAI,WAAkD;AAC7E,SAAO,OAAQ,QAAgB,SAAS;AAC1C;;;ACHA,OAAO,SAAS;;;ACDhB,SAAS,UAAU,sBAAsB;AAIzC,IAAM,gBAAyB;AAAA,EAC7B,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,WAAW;AACb;AACO,IAAM,SAAS,CAAC,SAAiB;AACtC,SAAO,eAAe,MAAM,aAAa;AAC3C;;;ADNO,IAAM,QAAQ,OAAO,MAAc,MAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,OAAO,IAAI,IAAI;AAEtD,MAAI;AACF,UAAM,IAAI,KAAK,IAAI;AACnB,UAAM,aAAa,MAAM,IAAI,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AACjE,QAAI,YAAY,SAAS,MAAM,eAAe;AAC5C;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO,IAAI,WAAW,MAAM,eAAe,EAAE,UAAU,QAAQ,CAAC;AAAA,EAClE;AAEA,SAAO,IAAI,WAAW,MAAM,eAAe,EAAE,UAAU,QAAQ,CAAC;AAClE;AAEO,IAAM,QAAQ,OAAO,SAAiB;AAC3C,SAAO,IAAI,OAAO,IAAI;AACxB;;;AEjBO,SAAS,kBAAkB,OAAmB;AACnD,SAAO;AAAA,IACL,OAAO,IAAY;AACjB,aAAO,OAAO,MAAM;AAAA,IACtB;AAAA,IACA,IAAI,IAAY;AACd,YAAM,OAAO,MAAM;AACnB,UAAI,CAAC;AAAM;AACX,WA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a,CAAC,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;AACzD;AAIO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI;AACF,0BAAoB,SAAS,OAAO;AAAA,IACtC,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;ACxFO,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":["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 fse from 'fs-extra'\n\nimport { format } from './format'\n\ntype WriteOptions = {\n format: boolean\n}\n\nexport const write = async (data: string, path: string, options: WriteOptions = { format: false }) => {\n const formattedData = options.format ? format(data) : data\n\n try {\n await fse.stat(path)\n const oldContent = await fse.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === formattedData) {\n return\n }\n } catch (_err) {\n return fse.outputFile(path, formattedData, { encoding: 'utf-8' })\n }\n\n return fse.outputFile(path, formattedData, { encoding: 'utf-8' })\n}\n\nexport const clean = async (path: string) => {\n return fse.remove(path)\n}\n","import { format as prettierFormat } from 'prettier'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n}\nexport const format = (text: string) => {\n return prettierFormat(text, formatOptions)\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'\n\nimport fse from 'fs-extra'\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, encoding = 'utf8') => {\n try {\n return fse.readFile(path, encoding)\n } catch (err) {\n console.error(err)\n throw err\n }\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\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: randomUUID(), 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 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 })\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 'events'\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) => this.catcher<H>(e, plugin, hookName))\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 if (this.logger?.spinner) {\n this.logger.spinner.fail(text)\n throw e\n }\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 { PluginManager } from './managers/pluginManager'\nimport { clean } from './utils/write'\n\nimport type { FileManager } from './managers/fileManager'\nimport type { PluginContext, TransformResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = {\n fileManager: FileManager\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 try {\n await pluginManager.hookParallel<'validate', true>('validate', [plugins])\n } catch (e: any) {\n return\n }\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done({ fileManager })\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n let { source: code } = 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\nexport type KubbBuild = (options: BuildOptions) => Promise<BuildOutput>\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n buildImplementation(options, resolve)\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 } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport * from './generators'\nexport default build\n"]}
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
- import fse from 'fs-extra';
2
1
  import pathParser from 'path';
2
+ import fse from 'fs-extra';
3
3
  import { format as format$1 } from 'prettier';
4
4
  import EventEmitter from 'events';
5
5
  import { randomUUID } from 'crypto';
6
6
  import dirTree from 'directory-tree';
7
7
 
8
- // src/build.ts
8
+ // src/plugin.ts
9
9
 
10
10
  // src/utils/isPromise.ts
11
11
  var isPromise = (result) => {
@@ -34,9 +34,12 @@ var write = async (data, path, options = { format: false }) => {
34
34
  return;
35
35
  }
36
36
  } catch (_err) {
37
- return fse.outputFile(path, formattedData);
37
+ return fse.outputFile(path, formattedData, { encoding: "utf-8" });
38
38
  }
39
- return fse.outputFile(path, formattedData);
39
+ return fse.outputFile(path, formattedData, { encoding: "utf-8" });
40
+ };
41
+ var clean = async (path) => {
42
+ return fse.remove(path);
40
43
  };
41
44
 
42
45
  // src/utils/cache.ts
@@ -77,6 +80,14 @@ var getPathMode = (path) => {
77
80
  }
78
81
  return pathParser.extname(path) ? "file" : "directory";
79
82
  };
83
+ var read = async (path, encoding = "utf8") => {
84
+ try {
85
+ return fse.readFile(path, encoding);
86
+ } catch (err) {
87
+ console.error(err);
88
+ throw err;
89
+ }
90
+ };
80
91
 
81
92
  // src/plugin.ts
82
93
  function createPlugin(factory) {
@@ -266,6 +277,12 @@ ${file.source}`
266
277
  this.setStatus(id, "removed");
267
278
  this.events.emitRemove(id, cacheItem.file);
268
279
  }
280
+ async write(...params) {
281
+ return write(...params);
282
+ }
283
+ async read(...params) {
284
+ return read(...params);
285
+ }
269
286
  };
270
287
  var TreeNode = class {
271
288
  data;
@@ -533,7 +550,7 @@ async function transformReducer(_previousCode, result, _plugin) {
533
550
  async function buildImplementation(options, done) {
534
551
  const { config, logger } = options;
535
552
  if (config.output.clean) {
536
- await fse.remove(config.output.path);
553
+ await clean(config.output.path);
537
554
  }
538
555
  const pluginManager = new PluginManager(config, { logger });
539
556
  const { plugins, fileManager } = pluginManager;
@@ -545,7 +562,7 @@ async function buildImplementation(options, done) {
545
562
  fileManager.events.onSuccess(async () => {
546
563
  await pluginManager.hookParallel("buildEnd");
547
564
  setTimeout(() => {
548
- done();
565
+ done({ fileManager });
549
566
  }, 1e3);
550
567
  });
551
568
  fileManager.events.onAdd(async (id, file) => {
@@ -557,7 +574,9 @@ async function buildImplementation(options, done) {
557
574
  }
558
575
  if (code) {
559
576
  const transformedCode = await pluginManager.hookReduceArg0("transform", [code, path], transformReducer);
560
- await pluginManager.hookParallel("writeFile", [transformedCode, path]);
577
+ if (typeof config.input === "object") {
578
+ await pluginManager.hookParallel("writeFile", [transformedCode, path]);
579
+ }
561
580
  fileManager.setStatus(id, "success");
562
581
  fileManager.remove(id);
563
582
  }
@@ -601,6 +620,6 @@ var SchemaGenerator = class extends Generator {
601
620
  // src/index.ts
602
621
  var src_default = build;
603
622
 
604
- export { FileManager, Generator, PluginManager, SchemaGenerator, TreeNode, ValidationPluginError, build, createPlugin, createPluginCache, src_default as default, defineConfig, format, getPathMode, getRelativePath, hooks, isPromise, validatePlugins, write };
623
+ export { FileManager, Generator, PluginManager, SchemaGenerator, TreeNode, ValidationPluginError, build, clean, createPlugin, createPluginCache, src_default as default, defineConfig, format, getPathMode, getRelativePath, hooks, isPromise, read, validatePlugins, write };
605
624
  //# sourceMappingURL=out.js.map
606
625
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/build.ts","../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.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":["fse","pathParser","options","file","argument0"],"mappings":";AAAA,OAAOA,UAAS;;;ACAhB,OAAOC,iBAAgB;;;ACEhB,IAAM,YAAY,CAAI,WAAkD;AAC7E,SAAO,OAAQ,QAAgB,SAAS;AAC1C;;;ACHA,OAAO,SAAS;;;ACDhB,SAAS,UAAU,sBAAsB;AAIzC,IAAM,gBAAyB;AAAA,EAC7B,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,WAAW;AACb;AACO,IAAM,SAAS,CAAC,SAAiB;AACtC,SAAO,eAAe,MAAM,aAAa;AAC3C;;;ADNO,IAAM,QAAQ,OAAO,MAAc,MAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,OAAO,IAAI,IAAI;AAEtD,MAAI;AACF,UAAM,IAAI,KAAK,IAAI;AACnB,UAAM,aAAa,MAAM,IAAI,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AACjE,QAAI,YAAY,SAAS,MAAM,eAAe;AAC5C;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO,IAAI,WAAW,MAAM,aAAa;AAAA,EAC3C;AAEA,SAAO,IAAI,WAAW,MAAM,aAAa;AAC3C;;;AEbO,SAAS,kBAAkB,OAAmB;AACnD,SAAO;AAAA,IACL,OAAO,IAAY;AACjB,aAAO,OAAO,MAAM;AAAA,IACtB;AAAA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Q,CAAC,SAAS,WAAW;AACtC,QAAI;AACF,0BAAoB,SAAS,OAAO;AAAA,IACtC,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AYjFO,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":["import fse from 'fs-extra'\n\nimport { PluginManager } from './managers/pluginManager'\n\nimport type { PluginContext, TransformResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = void\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 fse.remove(config.output.path)\n }\n\n const pluginManager = new PluginManager(config, { logger })\n const { plugins, fileManager } = pluginManager\n\n try {\n await pluginManager.hookParallel<'validate', true>('validate', [plugins])\n } catch (e: any) {\n return\n }\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n let { source: code } = 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 await pluginManager.hookParallel('writeFile', [transformedCode, path])\n fileManager.setStatus(id, 'success')\n fileManager.remove(id)\n }\n })\n\n await pluginManager.hookParallel('buildStart', [config])\n}\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n 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 fse from 'fs-extra'\n\nimport { format } from './format'\n\ntype WriteOptions = {\n format: boolean\n}\n\nexport const write = async (data: string, path: string, options: WriteOptions = { format: false }) => {\n const formattedData = options.format ? format(data) : data\n\n try {\n await fse.stat(path)\n const oldContent = await fse.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === formattedData) {\n return\n }\n } catch (_err) {\n return fse.outputFile(path, formattedData)\n }\n\n return fse.outputFile(path, formattedData)\n}\n","import { format as prettierFormat } from 'prettier'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n}\nexport const format = (text: string) => {\n return prettierFormat(text, formatOptions)\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'\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","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\n\nimport { getFileManagerEvents } from './events'\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: randomUUID(), 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 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 })\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","import type EventEmitter from 'events'\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) => this.catcher<H>(e, plugin, hookName))\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 if (this.logger?.spinner) {\n this.logger.spinner.fail(text)\n throw e\n }\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 } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport * from './generators'\nexport default build\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.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/build.ts","../src/config.ts","../src/generators/Generator.ts","../src/generators/SchemaGenerator.ts","../src/index.ts"],"names":["pathParser","fse","options","file","argument0"],"mappings":";AAAA,OAAOA,iBAAgB;;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AO,EAAE;AAAA,IACvB;AAAA,EACF,CAAC;AAED,QAAM,cAAc,aAAa,cAAc,CAAC,MAAM,CAAC;AACzD;AAIO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI;AACF,0BAAoB,SAAS,OAAO;AAAA,IACtC,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;ACxFO,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":["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 fse from 'fs-extra'\n\nimport { format } from './format'\n\ntype WriteOptions = {\n format: boolean\n}\n\nexport const write = async (data: string, path: string, options: WriteOptions = { format: false }) => {\n const formattedData = options.format ? format(data) : data\n\n try {\n await fse.stat(path)\n const oldContent = await fse.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === formattedData) {\n return\n }\n } catch (_err) {\n return fse.outputFile(path, formattedData, { encoding: 'utf-8' })\n }\n\n return fse.outputFile(path, formattedData, { encoding: 'utf-8' })\n}\n\nexport const clean = async (path: string) => {\n return fse.remove(path)\n}\n","import { format as prettierFormat } from 'prettier'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n}\nexport const format = (text: string) => {\n return prettierFormat(text, formatOptions)\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'\n\nimport fse from 'fs-extra'\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, encoding = 'utf8') => {\n try {\n return fse.readFile(path, encoding)\n } catch (err) {\n console.error(err)\n throw err\n }\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\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: randomUUID(), 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 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 })\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 'events'\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) => this.catcher<H>(e, plugin, hookName))\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 if (this.logger?.spinner) {\n this.logger.spinner.fail(text)\n throw e\n }\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 { PluginManager } from './managers/pluginManager'\nimport { clean } from './utils/write'\n\nimport type { FileManager } from './managers/fileManager'\nimport type { PluginContext, TransformResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = {\n fileManager: FileManager\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 try {\n await pluginManager.hookParallel<'validate', true>('validate', [plugins])\n } catch (e: any) {\n return\n }\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done({ fileManager })\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n let { source: code } = 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\nexport type KubbBuild = (options: BuildOptions) => Promise<BuildOutput>\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n buildImplementation(options, resolve)\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 } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport * from './generators'\nexport default build\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "description": "Generator core",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,7 +36,7 @@
36
36
  "directory-tree": "^3.5.1",
37
37
  "events": "^3.3.0",
38
38
  "fs-extra": "^11.1.0",
39
- "prettier": "^2.8.1",
39
+ "prettier": "^2.8.2",
40
40
  "typescript": "^4.9.4"
41
41
  },
42
42
  "devDependencies": {
@@ -19,11 +19,6 @@
19
19
  }
20
20
  }
21
21
  },
22
- "mode": {
23
- "type": "string",
24
- "description": "Mode type",
25
- "enum": ["single"]
26
- },
27
22
  "hooks": {
28
23
  "type": "object",
29
24
  "description": "Hooks that can be called when a specific action is done in Kubb.",