@kubb/core 1.2.1 → 1.2.3
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 +80 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +54 -18
- package/dist/index.js +78 -12
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/schema.json +95 -0
- package/schemas/config.json +0 -70
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,7 @@ var rimraf = require('rimraf');
|
|
|
11
11
|
var dirTree = require('directory-tree');
|
|
12
12
|
var mod = require('module');
|
|
13
13
|
var url = require('url');
|
|
14
|
-
var
|
|
14
|
+
var pc3 = require('picocolors');
|
|
15
15
|
var seedrandom = require('seedrandom');
|
|
16
16
|
var tsCodegen = require('@kubb/ts-codegen');
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
|
22
22
|
var pathParser2__default = /*#__PURE__*/_interopDefault(pathParser2);
|
|
23
23
|
var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
|
|
24
24
|
var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
25
|
-
var
|
|
25
|
+
var pc3__default = /*#__PURE__*/_interopDefault(pc3);
|
|
26
26
|
var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
|
|
27
27
|
|
|
28
28
|
// src/managers/fileManager/FileManager.ts
|
|
@@ -56,7 +56,7 @@ async function write(data, path) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// src/utils/cache.ts
|
|
59
|
-
function createPluginCache(Store) {
|
|
59
|
+
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
60
60
|
return {
|
|
61
61
|
set(id, value) {
|
|
62
62
|
Store[id] = [0, value];
|
|
@@ -518,7 +518,7 @@ function createLogger(spinner) {
|
|
|
518
518
|
};
|
|
519
519
|
const warn = (message) => {
|
|
520
520
|
if (message && spinner) {
|
|
521
|
-
spinner.warn(
|
|
521
|
+
spinner.warn(pc3__default.default.yellow(message));
|
|
522
522
|
}
|
|
523
523
|
};
|
|
524
524
|
const info = (message) => {
|
|
@@ -551,7 +551,7 @@ function randomColour(text, colours = defaultColours) {
|
|
|
551
551
|
return colour;
|
|
552
552
|
}
|
|
553
553
|
function randomPicoColour(text, colors = defaultColours) {
|
|
554
|
-
const colours =
|
|
554
|
+
const colours = pc3__default.default.createColors(true);
|
|
555
555
|
if (!text) {
|
|
556
556
|
return colours.white(text);
|
|
557
557
|
}
|
|
@@ -560,13 +560,72 @@ function randomPicoColour(text, colors = defaultColours) {
|
|
|
560
560
|
const key = colour.replace("dark", "").toLowerCase();
|
|
561
561
|
const formatter = colours[key];
|
|
562
562
|
if (isDark) {
|
|
563
|
-
return
|
|
563
|
+
return pc3__default.default.bold(formatter(text));
|
|
564
564
|
}
|
|
565
565
|
if (typeof formatter !== "function") {
|
|
566
566
|
throw new Error("Formatter for picoColor is not of type function/Formatter");
|
|
567
567
|
}
|
|
568
568
|
return formatter(text);
|
|
569
569
|
}
|
|
570
|
+
var URLPath = class {
|
|
571
|
+
path;
|
|
572
|
+
constructor(path) {
|
|
573
|
+
this.path = path;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
577
|
+
* @example /pet/{petId} => /pet/:petId
|
|
578
|
+
*/
|
|
579
|
+
get URL() {
|
|
580
|
+
return this.toURLPath();
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
584
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
585
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
586
|
+
* @example /account/userID => `/account/${userId}`
|
|
587
|
+
*/
|
|
588
|
+
get template() {
|
|
589
|
+
return this.toTemplateString();
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
593
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
594
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
595
|
+
* @example /account/userID => `/account/${userId}`
|
|
596
|
+
*/
|
|
597
|
+
toTemplateString() {
|
|
598
|
+
return URLPath.toTemplateString(this.path);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
602
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
603
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
604
|
+
* @example /account/userID => `/account/${userId}`
|
|
605
|
+
*/
|
|
606
|
+
static toTemplateString(path) {
|
|
607
|
+
const regex = /{(\w|-)*}/g;
|
|
608
|
+
const found = path.match(regex);
|
|
609
|
+
let newPath = path.replaceAll("{", "${");
|
|
610
|
+
if (found) {
|
|
611
|
+
newPath = found.reduce((prev, curr) => {
|
|
612
|
+
const replacement = `\${${changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })}}`;
|
|
613
|
+
return prev.replace(curr, replacement);
|
|
614
|
+
}, path);
|
|
615
|
+
}
|
|
616
|
+
return `\`${newPath}\``;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
620
|
+
* @example /pet/{petId} => /pet/:petId
|
|
621
|
+
*/
|
|
622
|
+
toURLPath() {
|
|
623
|
+
return URLPath.toURLPath(this.path);
|
|
624
|
+
}
|
|
625
|
+
static toURLPath(path) {
|
|
626
|
+
return path.replaceAll("{", ":").replaceAll("}", "");
|
|
627
|
+
}
|
|
628
|
+
};
|
|
570
629
|
function writeIndexes(root, options = {}) {
|
|
571
630
|
const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
|
|
572
631
|
if (!tree) {
|
|
@@ -882,7 +941,7 @@ var definePlugin = createPlugin((options) => {
|
|
|
882
941
|
return transformReservedWord(name);
|
|
883
942
|
},
|
|
884
943
|
load,
|
|
885
|
-
cache: createPluginCache(
|
|
944
|
+
cache: createPluginCache()
|
|
886
945
|
};
|
|
887
946
|
},
|
|
888
947
|
resolvePath(fileName) {
|
|
@@ -1002,7 +1061,7 @@ var PluginManager = class {
|
|
|
1002
1061
|
pluginName: params.pluginName,
|
|
1003
1062
|
hookName: "resolveName",
|
|
1004
1063
|
parameters: [params.name]
|
|
1005
|
-
});
|
|
1064
|
+
}) || params.name;
|
|
1006
1065
|
}
|
|
1007
1066
|
return this.hookFirstSync({
|
|
1008
1067
|
hookName: "resolveName",
|
|
@@ -1321,7 +1380,12 @@ async function build(options) {
|
|
|
1321
1380
|
await read(config.input.path);
|
|
1322
1381
|
}
|
|
1323
1382
|
} catch (e) {
|
|
1324
|
-
throw new Error(
|
|
1383
|
+
throw new Error(
|
|
1384
|
+
"Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config " + pc3__default.default.dim(config.input.path),
|
|
1385
|
+
{
|
|
1386
|
+
cause: e
|
|
1387
|
+
}
|
|
1388
|
+
);
|
|
1325
1389
|
}
|
|
1326
1390
|
if (config.output.clean) {
|
|
1327
1391
|
await clean(config.output.path);
|
|
@@ -1369,9 +1433,9 @@ async function build(options) {
|
|
|
1369
1433
|
if (config.logLevel === LogLevel.stacktrace && logger?.spinner && input) {
|
|
1370
1434
|
logger.info(messsage);
|
|
1371
1435
|
const logs = [
|
|
1372
|
-
input && `${
|
|
1436
|
+
input && `${pc3__default.default.bgWhite(`Input`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
1373
1437
|
JSON.stringify(input, void 0, 2),
|
|
1374
|
-
output && `${
|
|
1438
|
+
output && `${pc3__default.default.bgWhite("Output")} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
1375
1439
|
output
|
|
1376
1440
|
].filter(Boolean);
|
|
1377
1441
|
console.log(logs.join("\n"));
|
|
@@ -1392,7 +1456,9 @@ async function build(options) {
|
|
|
1392
1456
|
}
|
|
1393
1457
|
|
|
1394
1458
|
// src/config.ts
|
|
1395
|
-
|
|
1459
|
+
function defineConfig(options) {
|
|
1460
|
+
return options;
|
|
1461
|
+
}
|
|
1396
1462
|
|
|
1397
1463
|
// src/generators/Generator.ts
|
|
1398
1464
|
var Generator = class {
|
|
@@ -1420,7 +1486,7 @@ var src_default = build;
|
|
|
1420
1486
|
|
|
1421
1487
|
Object.defineProperty(exports, 'pc', {
|
|
1422
1488
|
enumerable: true,
|
|
1423
|
-
get: function () { return
|
|
1489
|
+
get: function () { return pc3__default.default; }
|
|
1424
1490
|
});
|
|
1425
1491
|
exports.FileManager = FileManager;
|
|
1426
1492
|
exports.Generator = Generator;
|
|
@@ -1432,6 +1498,7 @@ exports.Queue = Queue;
|
|
|
1432
1498
|
exports.SchemaGenerator = SchemaGenerator;
|
|
1433
1499
|
exports.SummaryError = SummaryError;
|
|
1434
1500
|
exports.TreeNode = TreeNode;
|
|
1501
|
+
exports.URLPath = URLPath;
|
|
1435
1502
|
exports.ValidationPluginError = ValidationPluginError;
|
|
1436
1503
|
exports.Warning = Warning;
|
|
1437
1504
|
exports.build = build;
|