@kubb/core 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +128 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +65 -20
- package/dist/index.js +128 -56
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -34,8 +34,6 @@ type PathMode = 'file' | 'directory';
|
|
|
34
34
|
declare function getPathMode(path: string | undefined | null): PathMode;
|
|
35
35
|
declare function read(path: string): Promise<string>;
|
|
36
36
|
|
|
37
|
-
declare function isURL(data: string): boolean;
|
|
38
|
-
|
|
39
37
|
type Data = string[][];
|
|
40
38
|
type Options$2 = {
|
|
41
39
|
typed?: boolean;
|
|
@@ -138,6 +136,45 @@ declare const defaultColours: readonly ["black", "blue", "darkBlue", "cyan", "gr
|
|
|
138
136
|
declare function randomColour(text?: string, colours?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
|
|
139
137
|
declare function randomPicoColour(text?: string, colors?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
|
|
140
138
|
|
|
139
|
+
declare class URLPath {
|
|
140
|
+
path: string;
|
|
141
|
+
constructor(path: string);
|
|
142
|
+
/**
|
|
143
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
144
|
+
* @example /pet/{petId} => /pet/:petId
|
|
145
|
+
*/
|
|
146
|
+
get URL(): string;
|
|
147
|
+
get isUrl(): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
150
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
151
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
152
|
+
* @example /account/userID => `/account/${userId}`
|
|
153
|
+
*/
|
|
154
|
+
get template(): string;
|
|
155
|
+
/**
|
|
156
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
157
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
158
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
159
|
+
* @example /account/userID => `/account/${userId}`
|
|
160
|
+
*/
|
|
161
|
+
toTemplateString(): string;
|
|
162
|
+
/**
|
|
163
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
164
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
165
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
166
|
+
* @example /account/userID => `/account/${userId}`
|
|
167
|
+
*/
|
|
168
|
+
static toTemplateString(path: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
171
|
+
* @example /pet/{petId} => /pet/:petId
|
|
172
|
+
*/
|
|
173
|
+
toURLPath(): string;
|
|
174
|
+
static toURLPath(path: string): string;
|
|
175
|
+
static isURL(path: string): boolean;
|
|
176
|
+
}
|
|
177
|
+
|
|
141
178
|
type Import = {
|
|
142
179
|
name: string | string[];
|
|
143
180
|
path: string;
|
|
@@ -210,6 +247,22 @@ declare class FileManager {
|
|
|
210
247
|
read(...params: Parameters<typeof read>): Promise<string>;
|
|
211
248
|
}
|
|
212
249
|
|
|
250
|
+
declare class PluginError extends Error {
|
|
251
|
+
pluginManager: PluginManager;
|
|
252
|
+
cause: Error;
|
|
253
|
+
constructor(message: string, options: {
|
|
254
|
+
cause: Error;
|
|
255
|
+
pluginManager: PluginManager;
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
260
|
+
private emitter;
|
|
261
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
262
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
263
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
264
|
+
}
|
|
265
|
+
|
|
213
266
|
/**
|
|
214
267
|
* Get the type of the first argument in a function.
|
|
215
268
|
* @example Arg0<(a: string, b: number) => void> -> string
|
|
@@ -220,10 +273,9 @@ type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
220
273
|
strategy: Strategy;
|
|
221
274
|
hookName: H;
|
|
222
275
|
plugin: KubbPlugin;
|
|
223
|
-
|
|
276
|
+
parameters?: unknown[] | undefined;
|
|
224
277
|
output?: unknown;
|
|
225
278
|
};
|
|
226
|
-
type OnExecute<H extends PluginLifecycleHooks = PluginLifecycleHooks> = (this: PluginManager, executer: Executer<H> | undefined, pluginManager: PluginManager) => void;
|
|
227
279
|
type ParseResult<H extends PluginLifecycleHooks> = PluginLifecycle[H];
|
|
228
280
|
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
229
281
|
result: Result;
|
|
@@ -235,20 +287,24 @@ type Options$1 = {
|
|
|
235
287
|
debug?: boolean;
|
|
236
288
|
task: QueueTask<ResolvedFile>;
|
|
237
289
|
logger: Logger;
|
|
238
|
-
|
|
290
|
+
};
|
|
291
|
+
type Events = {
|
|
292
|
+
execute: [executer: Executer];
|
|
293
|
+
executed: [executer: Executer];
|
|
294
|
+
error: [pluginError: PluginError];
|
|
239
295
|
};
|
|
240
296
|
declare class PluginManager {
|
|
241
297
|
plugins: KubbPlugin[];
|
|
242
298
|
readonly fileManager: FileManager;
|
|
243
|
-
private readonly onExecute?;
|
|
244
299
|
private readonly core;
|
|
245
300
|
queue: Queue;
|
|
246
301
|
executed: Executer[];
|
|
247
302
|
logger: Logger;
|
|
303
|
+
eventEmitter: EventEmitter<Events>;
|
|
248
304
|
constructor(config: KubbConfig, options: Options$1);
|
|
249
305
|
resolvePath: (params: ResolvePathParams) => OptionalPath;
|
|
250
306
|
resolveName: (params: ResolveNameParams) => string;
|
|
251
|
-
|
|
307
|
+
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
252
308
|
/**
|
|
253
309
|
*
|
|
254
310
|
* Run only hook for a specific plugin name
|
|
@@ -330,15 +386,6 @@ declare class ValidationPluginError extends Error {
|
|
|
330
386
|
}
|
|
331
387
|
declare function validatePlugins(plugins: KubbPlugin[], dependedPluginNames: string | string[]): true;
|
|
332
388
|
|
|
333
|
-
declare class PluginError extends Error {
|
|
334
|
-
pluginManager: PluginManager;
|
|
335
|
-
cause: Error;
|
|
336
|
-
constructor(message: string, options: {
|
|
337
|
-
cause: Error;
|
|
338
|
-
pluginManager: PluginManager;
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
|
|
342
389
|
declare class ParallelPluginError extends Error {
|
|
343
390
|
errors: PluginError[];
|
|
344
391
|
pluginManager: PluginManager;
|
|
@@ -347,7 +394,7 @@ declare class ParallelPluginError extends Error {
|
|
|
347
394
|
errors: PluginError[];
|
|
348
395
|
pluginManager: PluginManager;
|
|
349
396
|
});
|
|
350
|
-
findError<T extends Error = Error>(searchError: T): T | undefined;
|
|
397
|
+
findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
|
|
351
398
|
}
|
|
352
399
|
|
|
353
400
|
interface Register {
|
|
@@ -592,7 +639,6 @@ type PluginContext<TOptions = Record<string, unknown>> = {
|
|
|
592
639
|
addFile: (...file: File[]) => Promise<File[]>;
|
|
593
640
|
resolvePath: (params: ResolvePathParams<TOptions>) => OptionalPath;
|
|
594
641
|
resolveName: (params: ResolveNameParams) => string;
|
|
595
|
-
load: (id: string) => Promise<SafeParseResult<'load'>>;
|
|
596
642
|
logger: Logger;
|
|
597
643
|
};
|
|
598
644
|
type TransformResult = string | null;
|
|
@@ -635,7 +681,6 @@ type Options = {
|
|
|
635
681
|
fileManager: FileManager;
|
|
636
682
|
resolvePath: PluginContext['resolvePath'];
|
|
637
683
|
resolveName: PluginContext['resolveName'];
|
|
638
|
-
load: PluginContext['load'];
|
|
639
684
|
logger: PluginContext['logger'];
|
|
640
685
|
};
|
|
641
686
|
type CorePluginOptions = PluginFactoryOptions<'core', Options, false, PluginContext>;
|
|
@@ -659,4 +704,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
|
|
|
659
704
|
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
660
705
|
}
|
|
661
706
|
|
|
662
|
-
export { Argument0, BuildOutput, CLIOptions, Cache, CorePluginOptions, Executer, Extension, File, FileManager, FileName, Generator, KubbConfig, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogLevels, LogType, Logger,
|
|
707
|
+
export { Argument0, BuildOutput, CLIOptions, Cache, CorePluginOptions, Executer, Extension, File, FileManager, FileName, Generator, KubbConfig, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogLevels, LogType, Logger, OptionalPath, ParallelPluginError, ParseResult, Path, PathMode, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Queue, QueueTask, Register, ResolveNameParams, ResolvePathParams, ResolvedFile, SafeParseResult, SchemaGenerator, Source, Status, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, URLPath, UUID, ValidationPluginError, Warning, build, canLogHierarchy, clean, combineFiles, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, extensions, getEncodedText, getFileSource, getLocation, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, importModule, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, pluginName as name, nameSorter, normalizeDirectory, objectToParameters, pluginName, randomColour, randomPicoColour, read, renderTemplate, throttle, timeout, transformReservedWord, uniqueId, validatePlugins, write, writeIndexes };
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import pc3 from 'picocolors';
|
|
|
12
12
|
export { default as pc } from 'picocolors';
|
|
13
13
|
import seedrandom from 'seedrandom';
|
|
14
14
|
import { createImportDeclaration, print, createExportDeclaration } from '@kubb/ts-codegen';
|
|
15
|
+
import { EventEmitter as EventEmitter$1 } from 'node:events';
|
|
15
16
|
|
|
16
17
|
createRequire(import.meta.url);
|
|
17
18
|
|
|
@@ -97,19 +98,6 @@ function getPathMode(path) {
|
|
|
97
98
|
async function read(path) {
|
|
98
99
|
return fs.readFile(path, { encoding: "utf8" });
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
// src/utils/isURL.ts
|
|
102
|
-
function isURL(data) {
|
|
103
|
-
try {
|
|
104
|
-
const url = new URL(data);
|
|
105
|
-
if (url?.href) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
} catch (error) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
101
|
function objectToParameters(data, options = {}) {
|
|
114
102
|
const { typed } = options;
|
|
115
103
|
return data.reduce((acc, [key, value]) => {
|
|
@@ -399,7 +387,7 @@ var reservedWords = [
|
|
|
399
387
|
"valueOf"
|
|
400
388
|
];
|
|
401
389
|
function transformReservedWord(word) {
|
|
402
|
-
if (word && reservedWords.includes(word)) {
|
|
390
|
+
if (word && reservedWords.includes(word) || word?.match(/^\d/)) {
|
|
403
391
|
return `_${word}`;
|
|
404
392
|
}
|
|
405
393
|
return word;
|
|
@@ -555,6 +543,79 @@ function randomPicoColour(text, colors = defaultColours) {
|
|
|
555
543
|
}
|
|
556
544
|
return formatter(text);
|
|
557
545
|
}
|
|
546
|
+
var URLPath = class {
|
|
547
|
+
path;
|
|
548
|
+
constructor(path) {
|
|
549
|
+
this.path = path;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
553
|
+
* @example /pet/{petId} => /pet/:petId
|
|
554
|
+
*/
|
|
555
|
+
get URL() {
|
|
556
|
+
return this.toURLPath();
|
|
557
|
+
}
|
|
558
|
+
get isUrl() {
|
|
559
|
+
return URLPath.isURL(this.path);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
563
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
564
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
565
|
+
* @example /account/userID => `/account/${userId}`
|
|
566
|
+
*/
|
|
567
|
+
get template() {
|
|
568
|
+
return this.toTemplateString();
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
572
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
573
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
574
|
+
* @example /account/userID => `/account/${userId}`
|
|
575
|
+
*/
|
|
576
|
+
toTemplateString() {
|
|
577
|
+
return URLPath.toTemplateString(this.path);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
581
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
582
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
583
|
+
* @example /account/userID => `/account/${userId}`
|
|
584
|
+
*/
|
|
585
|
+
static toTemplateString(path) {
|
|
586
|
+
const regex = /{(\w|-)*}/g;
|
|
587
|
+
const found = path.match(regex);
|
|
588
|
+
let newPath = path.replaceAll("{", "${");
|
|
589
|
+
if (found) {
|
|
590
|
+
newPath = found.reduce((prev, curr) => {
|
|
591
|
+
const replacement = `\${${camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge })}}`;
|
|
592
|
+
return prev.replace(curr, replacement);
|
|
593
|
+
}, path);
|
|
594
|
+
}
|
|
595
|
+
return `\`${newPath}\``;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
599
|
+
* @example /pet/{petId} => /pet/:petId
|
|
600
|
+
*/
|
|
601
|
+
toURLPath() {
|
|
602
|
+
return URLPath.toURLPath(this.path);
|
|
603
|
+
}
|
|
604
|
+
static toURLPath(path) {
|
|
605
|
+
return path.replaceAll("{", ":").replaceAll("}", "");
|
|
606
|
+
}
|
|
607
|
+
static isURL(path) {
|
|
608
|
+
try {
|
|
609
|
+
const url = new URL(path);
|
|
610
|
+
if (url?.href) {
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
} catch (error) {
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
};
|
|
558
619
|
function writeIndexes(root, options = {}) {
|
|
559
620
|
const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
|
|
560
621
|
if (!tree) {
|
|
@@ -825,7 +886,7 @@ function createPlugin(factory) {
|
|
|
825
886
|
}
|
|
826
887
|
var pluginName = "core";
|
|
827
888
|
var definePlugin = createPlugin((options) => {
|
|
828
|
-
const { fileManager, resolvePath, resolveName,
|
|
889
|
+
const { fileManager, resolvePath, resolveName, logger } = options;
|
|
829
890
|
return {
|
|
830
891
|
name: pluginName,
|
|
831
892
|
options,
|
|
@@ -869,7 +930,6 @@ var definePlugin = createPlugin((options) => {
|
|
|
869
930
|
const name = resolveName(params);
|
|
870
931
|
return transformReservedWord(name);
|
|
871
932
|
},
|
|
872
|
-
load,
|
|
873
933
|
cache: createPluginCache()
|
|
874
934
|
};
|
|
875
935
|
},
|
|
@@ -894,6 +954,9 @@ var ParallelPluginError = class extends Error {
|
|
|
894
954
|
this.pluginManager = options.pluginManager;
|
|
895
955
|
}
|
|
896
956
|
findError(searchError) {
|
|
957
|
+
if (!searchError) {
|
|
958
|
+
return void 0;
|
|
959
|
+
}
|
|
897
960
|
return this.errors.find((error) => {
|
|
898
961
|
if (error.cause) {
|
|
899
962
|
if (error.cause.name == searchError.name) {
|
|
@@ -917,6 +980,30 @@ var PluginError = class extends Error {
|
|
|
917
980
|
this.pluginManager = options.pluginManager;
|
|
918
981
|
}
|
|
919
982
|
};
|
|
983
|
+
var EventEmitter = class {
|
|
984
|
+
emitter = new EventEmitter$1();
|
|
985
|
+
emit(eventName, ...eventArg) {
|
|
986
|
+
this.emitter.emit(eventName, ...eventArg);
|
|
987
|
+
}
|
|
988
|
+
on(eventName, handler) {
|
|
989
|
+
this.emitter.on(eventName, handler);
|
|
990
|
+
}
|
|
991
|
+
off(eventName, handler) {
|
|
992
|
+
this.emitter.off(eventName, handler);
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
|
|
996
|
+
// src/managers/pluginManager/pluginParser.ts
|
|
997
|
+
function pluginParser(plugin, context) {
|
|
998
|
+
if (plugin.api && typeof plugin.api === "function") {
|
|
999
|
+
const api = plugin.api.call(context);
|
|
1000
|
+
return {
|
|
1001
|
+
...plugin,
|
|
1002
|
+
api
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
return null;
|
|
1006
|
+
}
|
|
920
1007
|
|
|
921
1008
|
// src/managers/pluginManager/PluginManager.ts
|
|
922
1009
|
var hookNames = {
|
|
@@ -930,26 +1017,15 @@ var hookNames = {
|
|
|
930
1017
|
buildEnd: 1
|
|
931
1018
|
};
|
|
932
1019
|
var hooks = Object.keys(hookNames);
|
|
933
|
-
var convertKubbUserPluginToKubbPlugin = (plugin, context) => {
|
|
934
|
-
if (plugin.api && typeof plugin.api === "function") {
|
|
935
|
-
const api = plugin.api.call(context);
|
|
936
|
-
return {
|
|
937
|
-
...plugin,
|
|
938
|
-
api
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
return null;
|
|
942
|
-
};
|
|
943
1020
|
var PluginManager = class {
|
|
944
1021
|
plugins;
|
|
945
1022
|
fileManager;
|
|
946
|
-
onExecute;
|
|
947
1023
|
core;
|
|
948
1024
|
queue;
|
|
949
1025
|
executed = [];
|
|
950
1026
|
logger;
|
|
1027
|
+
eventEmitter = new EventEmitter();
|
|
951
1028
|
constructor(config, options) {
|
|
952
|
-
this.onExecute = options.onExecute?.bind(this);
|
|
953
1029
|
this.logger = options.logger;
|
|
954
1030
|
this.queue = new Queue(100, options.debug);
|
|
955
1031
|
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
@@ -957,14 +1033,12 @@ var PluginManager = class {
|
|
|
957
1033
|
config,
|
|
958
1034
|
logger: this.logger,
|
|
959
1035
|
fileManager: this.fileManager,
|
|
960
|
-
load: this.load,
|
|
961
1036
|
resolvePath: this.resolvePath,
|
|
962
1037
|
resolveName: this.resolveName
|
|
963
1038
|
});
|
|
964
|
-
|
|
965
|
-
this.core = convertedCore;
|
|
1039
|
+
this.core = pluginParser(core, core.api.call(null));
|
|
966
1040
|
this.plugins = [this.core, ...config.plugins || []].reduce((prev, plugin) => {
|
|
967
|
-
const convertedApi =
|
|
1041
|
+
const convertedApi = pluginParser(plugin, this.core?.api);
|
|
968
1042
|
if (convertedApi) {
|
|
969
1043
|
return [...prev, convertedApi];
|
|
970
1044
|
}
|
|
@@ -997,12 +1071,9 @@ var PluginManager = class {
|
|
|
997
1071
|
parameters: [params.name]
|
|
998
1072
|
}).result;
|
|
999
1073
|
};
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
parameters: [id]
|
|
1004
|
-
});
|
|
1005
|
-
};
|
|
1074
|
+
on(eventName, handler) {
|
|
1075
|
+
this.eventEmitter.on(eventName, handler);
|
|
1076
|
+
}
|
|
1006
1077
|
/**
|
|
1007
1078
|
*
|
|
1008
1079
|
* Run only hook for a specific plugin name
|
|
@@ -1175,8 +1246,8 @@ var PluginManager = class {
|
|
|
1175
1246
|
return pluginByPluginName;
|
|
1176
1247
|
}
|
|
1177
1248
|
addExecutedToCallStack(executer) {
|
|
1178
|
-
this.onExecute?.call(this, executer, this);
|
|
1179
1249
|
if (executer) {
|
|
1250
|
+
this.eventEmitter.emit("execute", executer);
|
|
1180
1251
|
this.executed.push(executer);
|
|
1181
1252
|
}
|
|
1182
1253
|
}
|
|
@@ -1198,6 +1269,7 @@ var PluginManager = class {
|
|
|
1198
1269
|
if (!hook) {
|
|
1199
1270
|
return null;
|
|
1200
1271
|
}
|
|
1272
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1201
1273
|
const task = Promise.resolve().then(() => {
|
|
1202
1274
|
if (typeof hook === "function") {
|
|
1203
1275
|
const possiblePromiseResult = hook.apply(this.core.api, parameters);
|
|
@@ -1215,7 +1287,7 @@ var PluginManager = class {
|
|
|
1215
1287
|
return null;
|
|
1216
1288
|
}).finally(() => {
|
|
1217
1289
|
this.addExecutedToCallStack({
|
|
1218
|
-
|
|
1290
|
+
parameters,
|
|
1219
1291
|
output,
|
|
1220
1292
|
strategy,
|
|
1221
1293
|
hookName,
|
|
@@ -1242,6 +1314,7 @@ var PluginManager = class {
|
|
|
1242
1314
|
if (!hook) {
|
|
1243
1315
|
return null;
|
|
1244
1316
|
}
|
|
1317
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1245
1318
|
try {
|
|
1246
1319
|
if (typeof hook === "function") {
|
|
1247
1320
|
const fn = hook.apply(this.core.api, parameters);
|
|
@@ -1255,7 +1328,7 @@ var PluginManager = class {
|
|
|
1255
1328
|
return null;
|
|
1256
1329
|
} finally {
|
|
1257
1330
|
this.addExecutedToCallStack({
|
|
1258
|
-
|
|
1331
|
+
parameters,
|
|
1259
1332
|
output,
|
|
1260
1333
|
strategy,
|
|
1261
1334
|
hookName,
|
|
@@ -1266,7 +1339,9 @@ var PluginManager = class {
|
|
|
1266
1339
|
catcher(e, plugin, hookName) {
|
|
1267
1340
|
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
1268
1341
|
`;
|
|
1269
|
-
|
|
1342
|
+
const pluginError = new PluginError(text, { cause: e, pluginManager: this });
|
|
1343
|
+
this.eventEmitter.emit("error", pluginError);
|
|
1344
|
+
throw pluginError;
|
|
1270
1345
|
}
|
|
1271
1346
|
};
|
|
1272
1347
|
function noReturn() {
|
|
@@ -1305,7 +1380,7 @@ async function transformReducer(_previousCode, result, _plugin) {
|
|
|
1305
1380
|
async function build(options) {
|
|
1306
1381
|
const { config, debug, logger = createLogger() } = options;
|
|
1307
1382
|
try {
|
|
1308
|
-
if (!isURL(config.input.path)) {
|
|
1383
|
+
if (!URLPath.isURL(config.input.path)) {
|
|
1309
1384
|
await read(config.input.path);
|
|
1310
1385
|
}
|
|
1311
1386
|
} catch (e) {
|
|
@@ -1346,32 +1421,29 @@ async function build(options) {
|
|
|
1346
1421
|
}
|
|
1347
1422
|
}
|
|
1348
1423
|
};
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
}
|
|
1353
|
-
const { hookName, plugin, output, input } = executer;
|
|
1424
|
+
const pluginManager = new PluginManager(config, { debug, logger, task: queueTask });
|
|
1425
|
+
const { plugins, fileManager } = pluginManager;
|
|
1426
|
+
pluginManager.on("execute", (executer) => {
|
|
1427
|
+
const { hookName, plugin, output, parameters } = executer;
|
|
1354
1428
|
const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
|
|
1355
|
-
if (config.logLevel === LogLevel.info && logger?.spinner &&
|
|
1429
|
+
if (config.logLevel === LogLevel.info && logger?.spinner && parameters) {
|
|
1356
1430
|
if (debug) {
|
|
1357
1431
|
logger.info(messsage);
|
|
1358
1432
|
} else {
|
|
1359
1433
|
logger.spinner.suffixText = messsage;
|
|
1360
1434
|
}
|
|
1361
1435
|
}
|
|
1362
|
-
if (config.logLevel === LogLevel.stacktrace && logger?.spinner &&
|
|
1436
|
+
if (config.logLevel === LogLevel.stacktrace && logger?.spinner && parameters) {
|
|
1363
1437
|
logger.info(messsage);
|
|
1364
1438
|
const logs = [
|
|
1365
|
-
|
|
1366
|
-
JSON.stringify(
|
|
1439
|
+
parameters && `${pc3.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
1440
|
+
JSON.stringify(parameters, void 0, 2),
|
|
1367
1441
|
output && `${pc3.bgWhite("Output")} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
1368
1442
|
output
|
|
1369
1443
|
].filter(Boolean);
|
|
1370
1444
|
console.log(logs.join("\n"));
|
|
1371
1445
|
}
|
|
1372
|
-
};
|
|
1373
|
-
const pluginManager = new PluginManager(config, { debug, logger, task: queueTask, onExecute });
|
|
1374
|
-
const { plugins, fileManager } = pluginManager;
|
|
1446
|
+
});
|
|
1375
1447
|
await pluginManager.hookParallel({
|
|
1376
1448
|
hookName: "validate",
|
|
1377
1449
|
parameters: [plugins]
|
|
@@ -1413,6 +1485,6 @@ var SchemaGenerator = class extends Generator {
|
|
|
1413
1485
|
// src/index.ts
|
|
1414
1486
|
var src_default = build;
|
|
1415
1487
|
|
|
1416
|
-
export { FileManager, Generator, LogLevel, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, ValidationPluginError, Warning, build, canLogHierarchy, clean, combineFiles, createJSDocBlockText, createLogger, createPlugin, createPluginCache, src_default as default, defaultColours, defineConfig, extensions, getEncodedText, getFileSource, getLocation, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, importModule, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult,
|
|
1488
|
+
export { FileManager, Generator, LogLevel, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, URLPath, ValidationPluginError, Warning, build, canLogHierarchy, clean, combineFiles, createJSDocBlockText, createLogger, createPlugin, createPluginCache, src_default as default, defaultColours, defineConfig, extensions, getEncodedText, getFileSource, getLocation, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, importModule, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, pluginName as name, nameSorter, normalizeDirectory, objectToParameters, pluginName, randomColour, randomPicoColour, read, renderTemplate, throttle, timeout, transformReservedWord, uniqueId, validatePlugins, write, writeIndexes };
|
|
1417
1489
|
//# sourceMappingURL=out.js.map
|
|
1418
1490
|
//# sourceMappingURL=index.js.map
|