@kubb/core 2.0.0-alpha.3 → 2.0.0-alpha.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 +62 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -38
- package/dist/index.d.ts +18 -38
- package/dist/index.js +62 -72
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +12 -7
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +12 -7
- package/dist/utils.js.map +1 -1
- package/package.json +8 -7
- package/src/BarrelManager.ts +123 -0
- package/src/FileManager.ts +482 -0
- package/src/Generator.ts +34 -0
- package/src/PackageManager.ts +163 -0
- package/src/PluginManager.ts +640 -0
- package/src/PromiseManager.ts +48 -0
- package/src/SchemaGenerator.ts +8 -0
- package/src/build.ts +198 -0
- package/src/config.ts +21 -0
- package/src/errors.ts +12 -0
- package/src/index.ts +28 -0
- package/src/plugin.ts +80 -0
- package/src/types.ts +370 -0
- package/src/utils/EventEmitter.ts +24 -0
- package/src/utils/FunctionParams.ts +85 -0
- package/src/utils/Queue.ts +110 -0
- package/src/utils/TreeNode.ts +122 -0
- package/src/utils/URLPath.ts +128 -0
- package/src/utils/cache.ts +35 -0
- package/src/utils/clean.ts +5 -0
- package/src/utils/executeStrategies.ts +71 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/logger.ts +76 -0
- package/src/utils/promise.ts +13 -0
- package/src/utils/randomColour.ts +39 -0
- package/src/utils/read.ts +68 -0
- package/src/utils/renderTemplate.ts +31 -0
- package/src/utils/throttle.ts +30 -0
- package/src/utils/timeout.ts +7 -0
- package/src/utils/transformers/combineCodes.ts +3 -0
- package/src/utils/transformers/createJSDocBlockText.ts +15 -0
- package/src/utils/transformers/escape.ts +31 -0
- package/src/utils/transformers/indent.ts +3 -0
- package/src/utils/transformers/index.ts +20 -0
- package/src/utils/transformers/nameSorter.ts +9 -0
- package/src/utils/transformers/searchAndReplace.ts +25 -0
- package/src/utils/transformers/transformReservedWord.ts +97 -0
- package/src/utils/uniqueName.ts +20 -0
- package/src/utils/write.ts +63 -0
package/dist/index.d.cts
CHANGED
|
@@ -148,42 +148,6 @@ declare class FileManager {
|
|
|
148
148
|
declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
|
|
149
149
|
declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
|
|
150
150
|
|
|
151
|
-
declare class PluginError extends Error {
|
|
152
|
-
pluginManager: PluginManager;
|
|
153
|
-
cause: Error;
|
|
154
|
-
constructor(message: string, options: {
|
|
155
|
-
cause: Error;
|
|
156
|
-
pluginManager: PluginManager;
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
declare class ParallelPluginError extends Error {
|
|
160
|
-
errors: PluginError[];
|
|
161
|
-
pluginManager: PluginManager;
|
|
162
|
-
constructor(message: string, options: {
|
|
163
|
-
cause?: Error;
|
|
164
|
-
errors: PluginError[];
|
|
165
|
-
pluginManager: PluginManager;
|
|
166
|
-
});
|
|
167
|
-
findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
|
|
168
|
-
}
|
|
169
|
-
declare class SummaryError extends Error {
|
|
170
|
-
summary: string[];
|
|
171
|
-
constructor(message: string, options: {
|
|
172
|
-
cause: Error;
|
|
173
|
-
summary?: string[];
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
178
|
-
*/
|
|
179
|
-
declare class Warning extends Error {
|
|
180
|
-
constructor(message?: string, options?: {
|
|
181
|
-
cause: Error;
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
declare class ValidationPluginError extends Error {
|
|
185
|
-
}
|
|
186
|
-
|
|
187
151
|
declare const LogLevel: {
|
|
188
152
|
readonly silent: "silent";
|
|
189
153
|
readonly info: "info";
|
|
@@ -237,7 +201,7 @@ type Options$1 = {
|
|
|
237
201
|
type Events = {
|
|
238
202
|
execute: [executer: Executer];
|
|
239
203
|
executed: [executer: Executer];
|
|
240
|
-
error: [
|
|
204
|
+
error: [error: Error];
|
|
241
205
|
};
|
|
242
206
|
declare class PluginManager {
|
|
243
207
|
#private;
|
|
@@ -422,6 +386,10 @@ type CLIOptions = {
|
|
|
422
386
|
type BuildOutput = {
|
|
423
387
|
files: FileManager['files'];
|
|
424
388
|
pluginManager: PluginManager;
|
|
389
|
+
/**
|
|
390
|
+
* Only for safeBuild
|
|
391
|
+
*/
|
|
392
|
+
error?: Error;
|
|
425
393
|
};
|
|
426
394
|
type KubbPluginKind = 'schema' | 'controller';
|
|
427
395
|
type KubbUnionPlugins = PluginUnion;
|
|
@@ -622,6 +590,7 @@ type BuildOptions = {
|
|
|
622
590
|
logger?: Logger;
|
|
623
591
|
};
|
|
624
592
|
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
593
|
+
declare function safeBuild(options: BuildOptions): Promise<BuildOutput>;
|
|
625
594
|
|
|
626
595
|
/**
|
|
627
596
|
* Type helper to make it easier to use kubb.config.js
|
|
@@ -633,6 +602,17 @@ declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<Ku
|
|
|
633
602
|
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
|
|
634
603
|
declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
|
|
635
604
|
|
|
605
|
+
/**
|
|
606
|
+
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
607
|
+
*/
|
|
608
|
+
declare class Warning extends Error {
|
|
609
|
+
constructor(message?: string, options?: {
|
|
610
|
+
cause: Error;
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
declare class ValidationPluginError extends Error {
|
|
614
|
+
}
|
|
615
|
+
|
|
636
616
|
/**
|
|
637
617
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
638
618
|
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
@@ -707,4 +687,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
707
687
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
708
688
|
type Plugin = keyof Plugins;
|
|
709
689
|
|
|
710
|
-
export { AppMeta, BuildOutput, CLIOptions, FileManager, Generator, GetPluginFactoryOptions, GreaterThan, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, ObjValueTuple, OptionsOfPlugin, OptionsPlugins, PackageManager,
|
|
690
|
+
export { AppMeta, BuildOutput, CLIOptions, FileManager, Generator, GetPluginFactoryOptions, GreaterThan, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, ObjValueTuple, OptionsOfPlugin, OptionsPlugins, PackageManager, Plugin, PluginCache, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginUnion, Plugins, PossiblePromise, Prettify, PromiseManager, ResolveNameParams, ResolvePathParams, SchemaGenerator, TransformResult, TupleToUnion, ValidationPluginError, Warning, _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
package/dist/index.d.ts
CHANGED
|
@@ -148,42 +148,6 @@ declare class FileManager {
|
|
|
148
148
|
declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
|
|
149
149
|
declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
|
|
150
150
|
|
|
151
|
-
declare class PluginError extends Error {
|
|
152
|
-
pluginManager: PluginManager;
|
|
153
|
-
cause: Error;
|
|
154
|
-
constructor(message: string, options: {
|
|
155
|
-
cause: Error;
|
|
156
|
-
pluginManager: PluginManager;
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
declare class ParallelPluginError extends Error {
|
|
160
|
-
errors: PluginError[];
|
|
161
|
-
pluginManager: PluginManager;
|
|
162
|
-
constructor(message: string, options: {
|
|
163
|
-
cause?: Error;
|
|
164
|
-
errors: PluginError[];
|
|
165
|
-
pluginManager: PluginManager;
|
|
166
|
-
});
|
|
167
|
-
findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
|
|
168
|
-
}
|
|
169
|
-
declare class SummaryError extends Error {
|
|
170
|
-
summary: string[];
|
|
171
|
-
constructor(message: string, options: {
|
|
172
|
-
cause: Error;
|
|
173
|
-
summary?: string[];
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
178
|
-
*/
|
|
179
|
-
declare class Warning extends Error {
|
|
180
|
-
constructor(message?: string, options?: {
|
|
181
|
-
cause: Error;
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
declare class ValidationPluginError extends Error {
|
|
185
|
-
}
|
|
186
|
-
|
|
187
151
|
declare const LogLevel: {
|
|
188
152
|
readonly silent: "silent";
|
|
189
153
|
readonly info: "info";
|
|
@@ -237,7 +201,7 @@ type Options$1 = {
|
|
|
237
201
|
type Events = {
|
|
238
202
|
execute: [executer: Executer];
|
|
239
203
|
executed: [executer: Executer];
|
|
240
|
-
error: [
|
|
204
|
+
error: [error: Error];
|
|
241
205
|
};
|
|
242
206
|
declare class PluginManager {
|
|
243
207
|
#private;
|
|
@@ -422,6 +386,10 @@ type CLIOptions = {
|
|
|
422
386
|
type BuildOutput = {
|
|
423
387
|
files: FileManager['files'];
|
|
424
388
|
pluginManager: PluginManager;
|
|
389
|
+
/**
|
|
390
|
+
* Only for safeBuild
|
|
391
|
+
*/
|
|
392
|
+
error?: Error;
|
|
425
393
|
};
|
|
426
394
|
type KubbPluginKind = 'schema' | 'controller';
|
|
427
395
|
type KubbUnionPlugins = PluginUnion;
|
|
@@ -622,6 +590,7 @@ type BuildOptions = {
|
|
|
622
590
|
logger?: Logger;
|
|
623
591
|
};
|
|
624
592
|
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
593
|
+
declare function safeBuild(options: BuildOptions): Promise<BuildOutput>;
|
|
625
594
|
|
|
626
595
|
/**
|
|
627
596
|
* Type helper to make it easier to use kubb.config.js
|
|
@@ -633,6 +602,17 @@ declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<Ku
|
|
|
633
602
|
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
|
|
634
603
|
declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
|
|
635
604
|
|
|
605
|
+
/**
|
|
606
|
+
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
607
|
+
*/
|
|
608
|
+
declare class Warning extends Error {
|
|
609
|
+
constructor(message?: string, options?: {
|
|
610
|
+
cause: Error;
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
declare class ValidationPluginError extends Error {
|
|
614
|
+
}
|
|
615
|
+
|
|
636
616
|
/**
|
|
637
617
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
638
618
|
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
@@ -707,4 +687,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
707
687
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
708
688
|
type Plugin = keyof Plugins;
|
|
709
689
|
|
|
710
|
-
export { AppMeta, BuildOutput, CLIOptions, FileManager, Generator, GetPluginFactoryOptions, GreaterThan, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, ObjValueTuple, OptionsOfPlugin, OptionsPlugins, PackageManager,
|
|
690
|
+
export { AppMeta, BuildOutput, CLIOptions, FileManager, Generator, GetPluginFactoryOptions, GreaterThan, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, ObjValueTuple, OptionsOfPlugin, OptionsPlugins, PackageManager, Plugin, PluginCache, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginUnion, Plugins, PossiblePromise, Prettify, PromiseManager, ResolveNameParams, ResolvePathParams, SchemaGenerator, TransformResult, TupleToUnion, ValidationPluginError, Warning, _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
package/dist/index.js
CHANGED
|
@@ -270,14 +270,19 @@ function combineCodes(codes) {
|
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
// src/utils/transformers/createJSDocBlockText.ts
|
|
273
|
-
function createJSDocBlockText({ comments }) {
|
|
273
|
+
function createJSDocBlockText({ comments, newLine }) {
|
|
274
274
|
const filteredComments = comments.filter(Boolean);
|
|
275
275
|
if (!filteredComments.length) {
|
|
276
276
|
return "";
|
|
277
277
|
}
|
|
278
|
-
|
|
278
|
+
const source = `/**
|
|
279
279
|
* ${filteredComments.join("\n * ")}
|
|
280
280
|
*/`;
|
|
281
|
+
if (newLine) {
|
|
282
|
+
return `${source}
|
|
283
|
+
`;
|
|
284
|
+
}
|
|
285
|
+
return source;
|
|
281
286
|
}
|
|
282
287
|
|
|
283
288
|
// src/utils/transformers/escape.ts
|
|
@@ -621,12 +626,12 @@ var BarrelManager = class {
|
|
|
621
626
|
if (currentTree.children?.length > 1) {
|
|
622
627
|
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
623
628
|
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
624
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
625
|
-
if (importPath.includes("index") &&
|
|
629
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
630
|
+
if (importPath.includes("index") && file.data.type === "file") {
|
|
626
631
|
return void 0;
|
|
627
632
|
}
|
|
628
633
|
return {
|
|
629
|
-
path: includeExt ?
|
|
634
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
630
635
|
isTypeOnly
|
|
631
636
|
};
|
|
632
637
|
}).filter(Boolean);
|
|
@@ -641,10 +646,10 @@ var BarrelManager = class {
|
|
|
641
646
|
} else {
|
|
642
647
|
currentTree.children?.forEach((child) => {
|
|
643
648
|
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
644
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
649
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
645
650
|
const exports = [
|
|
646
651
|
{
|
|
647
|
-
path: includeExt ?
|
|
652
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
648
653
|
isTypeOnly
|
|
649
654
|
}
|
|
650
655
|
];
|
|
@@ -1064,44 +1069,6 @@ function setUniqueName(originalName, data) {
|
|
|
1064
1069
|
}
|
|
1065
1070
|
|
|
1066
1071
|
// src/errors.ts
|
|
1067
|
-
var PluginError = class extends Error {
|
|
1068
|
-
constructor(message, options) {
|
|
1069
|
-
super(message, { cause: options.cause });
|
|
1070
|
-
this.name = "PluginError";
|
|
1071
|
-
this.cause = options.cause;
|
|
1072
|
-
this.pluginManager = options.pluginManager;
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
var ParallelPluginError = class extends Error {
|
|
1076
|
-
constructor(message, options) {
|
|
1077
|
-
super(message, { cause: options.cause });
|
|
1078
|
-
this.errors = [];
|
|
1079
|
-
this.name = "ParallelPluginError";
|
|
1080
|
-
this.errors = options.errors;
|
|
1081
|
-
this.pluginManager = options.pluginManager;
|
|
1082
|
-
}
|
|
1083
|
-
findError(searchError) {
|
|
1084
|
-
if (!searchError) {
|
|
1085
|
-
return void 0;
|
|
1086
|
-
}
|
|
1087
|
-
return this.errors.find((error) => {
|
|
1088
|
-
if (error.cause) {
|
|
1089
|
-
if (error.cause.name == searchError.name) {
|
|
1090
|
-
return true;
|
|
1091
|
-
}
|
|
1092
|
-
return !!this.findError(error.cause);
|
|
1093
|
-
}
|
|
1094
|
-
return error.name === searchError.name;
|
|
1095
|
-
})?.cause;
|
|
1096
|
-
}
|
|
1097
|
-
};
|
|
1098
|
-
var SummaryError = class extends Error {
|
|
1099
|
-
constructor(message, options) {
|
|
1100
|
-
super(message, { cause: options.cause });
|
|
1101
|
-
this.name = "SummaryError";
|
|
1102
|
-
this.summary = options.summary || [];
|
|
1103
|
-
}
|
|
1104
|
-
};
|
|
1105
1072
|
var Warning = class extends Error {
|
|
1106
1073
|
constructor(message, options) {
|
|
1107
1074
|
super(message, { cause: options?.cause });
|
|
@@ -1446,15 +1413,12 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1446
1413
|
}
|
|
1447
1414
|
}
|
|
1448
1415
|
const results = await Promise.allSettled(parallelPromises);
|
|
1449
|
-
|
|
1450
|
-
if (isPromiseRejectedResult(result)
|
|
1451
|
-
|
|
1416
|
+
results.forEach((result, index) => {
|
|
1417
|
+
if (isPromiseRejectedResult(result)) {
|
|
1418
|
+
const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
|
|
1419
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, result.reason, plugin, hookName);
|
|
1452
1420
|
}
|
|
1453
|
-
|
|
1454
|
-
}).filter(Boolean);
|
|
1455
|
-
if (errors.length) {
|
|
1456
|
-
throw new ParallelPluginError("Error", { errors, pluginManager: this });
|
|
1457
|
-
}
|
|
1421
|
+
});
|
|
1458
1422
|
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
1459
1423
|
}
|
|
1460
1424
|
/**
|
|
@@ -1588,11 +1552,6 @@ execute_fn = function({
|
|
|
1588
1552
|
return hook;
|
|
1589
1553
|
}).then((result) => {
|
|
1590
1554
|
output = result;
|
|
1591
|
-
return result;
|
|
1592
|
-
}).catch((e) => {
|
|
1593
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1594
|
-
return null;
|
|
1595
|
-
}).finally(() => {
|
|
1596
1555
|
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1597
1556
|
parameters,
|
|
1598
1557
|
output,
|
|
@@ -1600,6 +1559,10 @@ execute_fn = function({
|
|
|
1600
1559
|
hookName,
|
|
1601
1560
|
plugin
|
|
1602
1561
|
});
|
|
1562
|
+
return result;
|
|
1563
|
+
}).catch((e) => {
|
|
1564
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1565
|
+
return null;
|
|
1603
1566
|
});
|
|
1604
1567
|
return task;
|
|
1605
1568
|
};
|
|
@@ -1623,11 +1586,6 @@ executeSync_fn = function({
|
|
|
1623
1586
|
return fn;
|
|
1624
1587
|
}
|
|
1625
1588
|
output = hook;
|
|
1626
|
-
return hook;
|
|
1627
|
-
} catch (e) {
|
|
1628
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1629
|
-
return null;
|
|
1630
|
-
} finally {
|
|
1631
1589
|
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1632
1590
|
parameters,
|
|
1633
1591
|
output,
|
|
@@ -1635,15 +1593,18 @@ executeSync_fn = function({
|
|
|
1635
1593
|
hookName,
|
|
1636
1594
|
plugin
|
|
1637
1595
|
});
|
|
1596
|
+
return hook;
|
|
1597
|
+
} catch (e) {
|
|
1598
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1599
|
+
return null;
|
|
1638
1600
|
}
|
|
1639
1601
|
};
|
|
1640
1602
|
_catcher = new WeakSet();
|
|
1641
1603
|
catcher_fn = function(e, plugin, hookName) {
|
|
1642
|
-
const text = `${e.message} (plugin: ${plugin
|
|
1604
|
+
const text = `${e.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})
|
|
1643
1605
|
`;
|
|
1644
|
-
|
|
1645
|
-
this.eventEmitter.emit("error",
|
|
1646
|
-
throw pluginError;
|
|
1606
|
+
this.logger.error(text);
|
|
1607
|
+
this.eventEmitter.emit("error", e);
|
|
1647
1608
|
};
|
|
1648
1609
|
_parse = new WeakSet();
|
|
1649
1610
|
parse_fn = function(plugin, pluginManager, context) {
|
|
@@ -1676,7 +1637,7 @@ parse_fn = function(plugin, pluginManager, context) {
|
|
|
1676
1637
|
async function transformReducer(_previousCode, result, _plugin) {
|
|
1677
1638
|
return result;
|
|
1678
1639
|
}
|
|
1679
|
-
async function
|
|
1640
|
+
async function setup(options) {
|
|
1680
1641
|
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1681
1642
|
try {
|
|
1682
1643
|
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
@@ -1730,7 +1691,6 @@ async function build(options) {
|
|
|
1730
1691
|
}
|
|
1731
1692
|
};
|
|
1732
1693
|
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1733
|
-
const { plugins, fileManager } = pluginManager;
|
|
1734
1694
|
pluginManager.on("execute", (executer) => {
|
|
1735
1695
|
const { hookName, parameters, plugin } = executer;
|
|
1736
1696
|
if (hookName === "writeFile" && logger.spinner) {
|
|
@@ -1768,13 +1728,18 @@ ${code}`);
|
|
|
1768
1728
|
console.log(logs.join("\n"));
|
|
1769
1729
|
}
|
|
1770
1730
|
});
|
|
1731
|
+
return pluginManager;
|
|
1732
|
+
}
|
|
1733
|
+
async function build(options) {
|
|
1734
|
+
const pluginManager = await setup(options);
|
|
1735
|
+
const { fileManager, logger } = pluginManager;
|
|
1771
1736
|
await pluginManager.hookParallel({
|
|
1772
1737
|
hookName: "validate",
|
|
1773
|
-
parameters: [plugins]
|
|
1738
|
+
parameters: [pluginManager.plugins]
|
|
1774
1739
|
});
|
|
1775
1740
|
await pluginManager.hookParallel({
|
|
1776
1741
|
hookName: "buildStart",
|
|
1777
|
-
parameters: [config]
|
|
1742
|
+
parameters: [options.config]
|
|
1778
1743
|
});
|
|
1779
1744
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1780
1745
|
if (!fileManager.isExecuting && logger.spinner) {
|
|
@@ -1783,6 +1748,28 @@ ${code}`);
|
|
|
1783
1748
|
}
|
|
1784
1749
|
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1785
1750
|
}
|
|
1751
|
+
async function safeBuild(options) {
|
|
1752
|
+
const pluginManager = await setup(options);
|
|
1753
|
+
const { fileManager, logger } = pluginManager;
|
|
1754
|
+
try {
|
|
1755
|
+
await pluginManager.hookParallel({
|
|
1756
|
+
hookName: "validate",
|
|
1757
|
+
parameters: [pluginManager.plugins]
|
|
1758
|
+
});
|
|
1759
|
+
await pluginManager.hookParallel({
|
|
1760
|
+
hookName: "buildStart",
|
|
1761
|
+
parameters: [options.config]
|
|
1762
|
+
});
|
|
1763
|
+
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1764
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1765
|
+
logger.spinner.suffixText = "";
|
|
1766
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1767
|
+
}
|
|
1768
|
+
} catch (e) {
|
|
1769
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager, error: e };
|
|
1770
|
+
}
|
|
1771
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1772
|
+
}
|
|
1786
1773
|
|
|
1787
1774
|
// src/Generator.ts
|
|
1788
1775
|
var _options3, _context;
|
|
@@ -1899,6 +1886,9 @@ var _PackageManager = class _PackageManager {
|
|
|
1899
1886
|
if (!packageVersion) {
|
|
1900
1887
|
return false;
|
|
1901
1888
|
}
|
|
1889
|
+
if (packageVersion === version) {
|
|
1890
|
+
return true;
|
|
1891
|
+
}
|
|
1902
1892
|
const semVer = coerce(packageVersion);
|
|
1903
1893
|
if (!semVer) {
|
|
1904
1894
|
throw new Error(`${packageVersion} is not valid`);
|
|
@@ -1930,6 +1920,6 @@ var SchemaGenerator = class extends Generator {
|
|
|
1930
1920
|
// src/index.ts
|
|
1931
1921
|
var src_default = build;
|
|
1932
1922
|
|
|
1933
|
-
export { FileManager, Generator, KubbFile, PackageManager,
|
|
1923
|
+
export { FileManager, Generator, KubbFile, PackageManager, PluginManager, PromiseManager, SchemaGenerator, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
|
1934
1924
|
//# sourceMappingURL=out.js.map
|
|
1935
1925
|
//# sourceMappingURL=index.js.map
|