@kubb/core 2.0.0-beta.10 → 2.0.0-beta.12
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/Queue-2-6pMcCx.d.cts +32 -0
- package/dist/Queue-2-6pMcCx.d.ts +32 -0
- package/dist/fs.cjs +2383 -0
- package/dist/fs.cjs.map +1 -0
- package/dist/fs.d.cts +5 -0
- package/dist/fs.d.ts +5 -0
- package/dist/fs.js +2380 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.cjs +3336 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -69
- package/dist/index.d.ts +18 -69
- package/dist/index.js +3655 -226
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +148 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +31 -0
- package/dist/logger.d.ts +31 -0
- package/dist/logger.js +140 -0
- package/dist/logger.js.map +1 -0
- package/dist/transformers.cjs +79 -9
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.js +82 -8
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +86 -766
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +3 -595
- package/dist/utils.d.ts +3 -595
- package/dist/utils.js +87 -727
- package/dist/utils.js.map +1 -1
- package/dist/write-46ytbnu9.d.cts +7 -0
- package/dist/write-46ytbnu9.d.ts +7 -0
- package/package.json +21 -11
- package/src/FileManager.ts +34 -62
- package/src/PluginManager.ts +20 -15
- package/src/build.ts +11 -12
- package/src/fs/index.ts +3 -0
- package/src/index.ts +4 -4
- package/src/{utils/logger.ts → logger.ts} +38 -3
- package/src/plugin.ts +1 -1
- package/src/transformers/casing.ts +3 -3
- package/src/types.ts +1 -1
- package/src/utils/index.ts +10 -18
- package/src/utils/randomColour.ts +0 -39
- package/src/utils/throttle.ts +0 -30
- /package/src/{utils → fs}/clean.ts +0 -0
- /package/src/{utils → fs}/read.ts +0 -0
- /package/src/{utils → fs}/write.ts +0 -0
package/dist/utils.cjs
CHANGED
|
@@ -1,48 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fs2 = require('fs-extra');
|
|
4
3
|
var naturalOrderby = require('natural-orderby');
|
|
5
|
-
var changeCase = require('change-case');
|
|
6
|
-
var pc2 = require('picocolors');
|
|
7
4
|
var crypto = require('crypto');
|
|
8
5
|
var perf_hooks = require('perf_hooks');
|
|
9
6
|
var events = require('events');
|
|
10
|
-
var seedrandom = require('seedrandom');
|
|
11
|
-
var path = require('path');
|
|
12
|
-
var jsRuntime = require('js-runtime');
|
|
13
|
-
var dirTree = require('directory-tree');
|
|
14
|
-
var parser = require('@kubb/parser');
|
|
15
|
-
var factory = require('@kubb/parser/factory');
|
|
16
|
-
var isEqual = require('lodash.isequal');
|
|
17
7
|
|
|
18
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
9
|
|
|
20
|
-
function _interopNamespace(e) {
|
|
21
|
-
if (e && e.__esModule) return e;
|
|
22
|
-
var n = Object.create(null);
|
|
23
|
-
if (e) {
|
|
24
|
-
Object.keys(e).forEach(function (k) {
|
|
25
|
-
if (k !== 'default') {
|
|
26
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () { return e[k]; }
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
n.default = e;
|
|
35
|
-
return Object.freeze(n);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
39
|
-
var pc2__default = /*#__PURE__*/_interopDefault(pc2);
|
|
40
10
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
41
|
-
var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
|
|
42
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
43
|
-
var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
|
|
44
|
-
var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
|
|
45
|
-
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
46
11
|
|
|
47
12
|
var __accessCheck = (obj, member, msg) => {
|
|
48
13
|
if (!member.has(obj))
|
|
@@ -75,41 +40,84 @@ var __privateMethod = (obj, member, method) => {
|
|
|
75
40
|
return method;
|
|
76
41
|
};
|
|
77
42
|
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
43
|
+
// ../../node_modules/.pnpm/change-case@5.2.0/node_modules/change-case/dist/index.js
|
|
44
|
+
var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
|
|
45
|
+
var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
|
|
46
|
+
var SPLIT_NUMBER_LOWER_RE = /(\d)(\p{Ll})/gu;
|
|
47
|
+
var SPLIT_LETTER_NUMBER_RE = /(\p{L})(\d)/gu;
|
|
48
|
+
var DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;
|
|
49
|
+
var SPLIT_REPLACE_VALUE = "$1\0$2";
|
|
50
|
+
var DEFAULT_PREFIX_CHARACTERS = "";
|
|
51
|
+
function split(input, options) {
|
|
52
|
+
let result = input.trim();
|
|
53
|
+
result = result.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE).replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
|
|
54
|
+
if (options?.separateNumbers) {
|
|
55
|
+
result = result.replace(SPLIT_NUMBER_LOWER_RE, SPLIT_REPLACE_VALUE).replace(SPLIT_LETTER_NUMBER_RE, SPLIT_REPLACE_VALUE);
|
|
56
|
+
}
|
|
57
|
+
result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
|
|
58
|
+
let start = 0;
|
|
59
|
+
let end = result.length;
|
|
60
|
+
while (result.charAt(start) === "\0")
|
|
61
|
+
start++;
|
|
62
|
+
if (start === end)
|
|
63
|
+
return [];
|
|
64
|
+
while (result.charAt(end - 1) === "\0")
|
|
65
|
+
end--;
|
|
66
|
+
return result.slice(start, end).split(/\0/g);
|
|
67
|
+
}
|
|
68
|
+
function camelCase(input, options) {
|
|
69
|
+
const prefix = getPrefix(input, options?.prefixCharacters);
|
|
70
|
+
const lower = lowerFactory(options?.locale);
|
|
71
|
+
const upper = upperFactory(options?.locale);
|
|
72
|
+
const transform = options?.mergeAmbiguousCharacters ? capitalCaseTransformFactory(lower, upper) : pascalCaseTransformFactory(lower, upper);
|
|
73
|
+
return prefix + split(input, options).map((word, index) => {
|
|
74
|
+
if (index === 0)
|
|
75
|
+
return lower(word);
|
|
76
|
+
return transform(word, index);
|
|
77
|
+
}).join(options?.delimiter ?? "");
|
|
78
|
+
}
|
|
79
|
+
function pascalCase(input, options) {
|
|
80
|
+
const prefix = getPrefix(input, options?.prefixCharacters);
|
|
81
|
+
const lower = lowerFactory(options?.locale);
|
|
82
|
+
const upper = upperFactory(options?.locale);
|
|
83
|
+
const transform = options?.mergeAmbiguousCharacters ? capitalCaseTransformFactory(lower, upper) : pascalCaseTransformFactory(lower, upper);
|
|
84
|
+
return prefix + split(input, options).map(transform).join(options?.delimiter ?? "");
|
|
85
|
+
}
|
|
86
|
+
function lowerFactory(locale) {
|
|
87
|
+
return locale === false ? (input) => input.toLowerCase() : (input) => input.toLocaleLowerCase(locale);
|
|
88
|
+
}
|
|
89
|
+
function upperFactory(locale) {
|
|
90
|
+
return locale === false ? (input) => input.toUpperCase() : (input) => input.toLocaleUpperCase(locale);
|
|
91
|
+
}
|
|
92
|
+
function capitalCaseTransformFactory(lower, upper) {
|
|
93
|
+
return (word) => `${upper(word[0])}${lower(word.slice(1))}`;
|
|
94
|
+
}
|
|
95
|
+
function pascalCaseTransformFactory(lower, upper) {
|
|
96
|
+
return (word, index) => {
|
|
97
|
+
const char0 = word[0];
|
|
98
|
+
const initial = index > 0 && char0 >= "0" && char0 <= "9" ? "_" + char0 : upper(char0);
|
|
99
|
+
return initial + lower(word.slice(1));
|
|
103
100
|
};
|
|
104
101
|
}
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
function getPrefix(input, prefixCharacters = DEFAULT_PREFIX_CHARACTERS) {
|
|
103
|
+
let prefix = "";
|
|
104
|
+
for (let i = 0; i < input.length; i++) {
|
|
105
|
+
const char = input.charAt(i);
|
|
106
|
+
if (prefixCharacters.includes(char)) {
|
|
107
|
+
prefix += char;
|
|
108
|
+
} else {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return prefix;
|
|
107
113
|
}
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
|
|
115
|
+
// src/transformers/casing.ts
|
|
116
|
+
function camelCase2(text) {
|
|
117
|
+
return camelCase(text, { delimiter: "", mergeAmbiguousCharacters: true });
|
|
110
118
|
}
|
|
111
|
-
function
|
|
112
|
-
return
|
|
119
|
+
function pascalCase2(text) {
|
|
120
|
+
return pascalCase(text, { delimiter: "", mergeAmbiguousCharacters: true });
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
// src/transformers/combineCodes.ts
|
|
@@ -301,8 +309,8 @@ var transformers_default = {
|
|
|
301
309
|
JSDoc: {
|
|
302
310
|
createJSDocBlockText
|
|
303
311
|
},
|
|
304
|
-
camelCase,
|
|
305
|
-
pascalCase
|
|
312
|
+
camelCase: camelCase2,
|
|
313
|
+
pascalCase: pascalCase2
|
|
306
314
|
};
|
|
307
315
|
|
|
308
316
|
// src/utils/FunctionParams.ts
|
|
@@ -344,48 +352,6 @@ var FunctionParams = class {
|
|
|
344
352
|
}, []).join(", ");
|
|
345
353
|
}
|
|
346
354
|
};
|
|
347
|
-
var LogLevel = {
|
|
348
|
-
silent: "silent",
|
|
349
|
-
info: "info",
|
|
350
|
-
debug: "debug"
|
|
351
|
-
};
|
|
352
|
-
function createLogger({ logLevel, name, spinner }) {
|
|
353
|
-
const logs = [];
|
|
354
|
-
const log = (message) => {
|
|
355
|
-
if (message && spinner) {
|
|
356
|
-
spinner.text = message;
|
|
357
|
-
logs.push(message);
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
const error = (message) => {
|
|
361
|
-
if (message) {
|
|
362
|
-
throw new Error(message || "Something went wrong");
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
const warn = (message) => {
|
|
366
|
-
if (message && spinner) {
|
|
367
|
-
spinner.warn(pc2__default.default.yellow(message));
|
|
368
|
-
logs.push(message);
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
const info = (message) => {
|
|
372
|
-
if (message && spinner && logLevel !== LogLevel.silent) {
|
|
373
|
-
spinner.info(message);
|
|
374
|
-
logs.push(message);
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
const logger = {
|
|
378
|
-
name,
|
|
379
|
-
logLevel,
|
|
380
|
-
log,
|
|
381
|
-
error,
|
|
382
|
-
warn,
|
|
383
|
-
info,
|
|
384
|
-
spinner,
|
|
385
|
-
logs
|
|
386
|
-
};
|
|
387
|
-
return logger;
|
|
388
|
-
}
|
|
389
355
|
|
|
390
356
|
// src/utils/promise.ts
|
|
391
357
|
function isPromise(result) {
|
|
@@ -432,8 +398,8 @@ var Queue = class {
|
|
|
432
398
|
__privateSet(this, _debug, debug);
|
|
433
399
|
}
|
|
434
400
|
run(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
|
|
435
|
-
return new Promise((
|
|
436
|
-
const item = { reject, resolve
|
|
401
|
+
return new Promise((resolve, reject) => {
|
|
402
|
+
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
437
403
|
options.controller?.signal.addEventListener("abort", () => {
|
|
438
404
|
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
439
405
|
reject("Aborted");
|
|
@@ -443,8 +409,8 @@ var Queue = class {
|
|
|
443
409
|
});
|
|
444
410
|
}
|
|
445
411
|
runSync(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
|
|
446
|
-
new Promise((
|
|
447
|
-
const item = { reject, resolve
|
|
412
|
+
new Promise((resolve, reject) => {
|
|
413
|
+
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
448
414
|
options.controller?.signal.addEventListener("abort", () => {
|
|
449
415
|
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
450
416
|
});
|
|
@@ -471,13 +437,13 @@ work_fn = function() {
|
|
|
471
437
|
__privateWrapper(this, _workerCount)._++;
|
|
472
438
|
let entry;
|
|
473
439
|
while (entry = __privateGet(this, _queue).shift()) {
|
|
474
|
-
const { reject, resolve
|
|
440
|
+
const { reject, resolve, job, name, description } = entry;
|
|
475
441
|
if (__privateGet(this, _debug)) {
|
|
476
442
|
perf_hooks.performance.mark(name + "_start");
|
|
477
443
|
}
|
|
478
444
|
job().then((result) => {
|
|
479
445
|
this.eventEmitter.emit("jobDone", result);
|
|
480
|
-
|
|
446
|
+
resolve(result);
|
|
481
447
|
if (__privateGet(this, _debug)) {
|
|
482
448
|
perf_hooks.performance.mark(name + "_stop");
|
|
483
449
|
perf_hooks.performance.measure(description, name + "_start", name + "_stop");
|
|
@@ -489,79 +455,6 @@ work_fn = function() {
|
|
|
489
455
|
}
|
|
490
456
|
__privateWrapper(this, _workerCount)._--;
|
|
491
457
|
};
|
|
492
|
-
var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
493
|
-
function randomColour(text, colours = defaultColours) {
|
|
494
|
-
if (!text) {
|
|
495
|
-
return "white";
|
|
496
|
-
}
|
|
497
|
-
const random = seedrandom__default.default(text);
|
|
498
|
-
const colour = colours.at(Math.floor(random() * colours.length)) || "white";
|
|
499
|
-
return colour;
|
|
500
|
-
}
|
|
501
|
-
function randomPicoColour(text, colors = defaultColours) {
|
|
502
|
-
const colours = pc2__default.default.createColors(true);
|
|
503
|
-
if (!text) {
|
|
504
|
-
return colours.white(text);
|
|
505
|
-
}
|
|
506
|
-
const colour = randomColour(text, colors);
|
|
507
|
-
const isDark = colour.includes("dark");
|
|
508
|
-
const key = colour.replace("dark", "").toLowerCase();
|
|
509
|
-
const formatter = colours[key];
|
|
510
|
-
if (isDark) {
|
|
511
|
-
return pc2__default.default.bold(formatter(text));
|
|
512
|
-
}
|
|
513
|
-
if (typeof formatter !== "function") {
|
|
514
|
-
throw new Error("Formatter for picoColor is not of type function/Formatter");
|
|
515
|
-
}
|
|
516
|
-
return formatter(text);
|
|
517
|
-
}
|
|
518
|
-
function slash(path2, platform = "linux") {
|
|
519
|
-
const isWindowsPath = /^\\\\\?\\/.test(path2);
|
|
520
|
-
if (["linux", "mac"].includes(platform) && !isWindowsPath) {
|
|
521
|
-
return path2.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
522
|
-
}
|
|
523
|
-
return path2.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
524
|
-
}
|
|
525
|
-
function getRelativePath(rootDir, filePath, platform = "linux") {
|
|
526
|
-
if (!rootDir || !filePath) {
|
|
527
|
-
throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
528
|
-
}
|
|
529
|
-
const relativePath = path.relative(rootDir, filePath);
|
|
530
|
-
const slashedPath = slash(relativePath, platform);
|
|
531
|
-
if (slashedPath.startsWith("../")) {
|
|
532
|
-
return slashedPath.replace(path.basename(slashedPath), path.basename(slashedPath, path.extname(filePath)));
|
|
533
|
-
}
|
|
534
|
-
return `./${slashedPath.replace(path.basename(slashedPath), path.basename(slashedPath, path.extname(filePath)))}`;
|
|
535
|
-
}
|
|
536
|
-
var reader = jsRuntime.switcher(
|
|
537
|
-
{
|
|
538
|
-
node: async (path2) => {
|
|
539
|
-
return fs2__default.default.readFile(path2, { encoding: "utf8" });
|
|
540
|
-
},
|
|
541
|
-
bun: async (path2) => {
|
|
542
|
-
const file = Bun.file(path2);
|
|
543
|
-
return file.text();
|
|
544
|
-
}
|
|
545
|
-
},
|
|
546
|
-
"node"
|
|
547
|
-
);
|
|
548
|
-
var syncReader = jsRuntime.switcher(
|
|
549
|
-
{
|
|
550
|
-
node: (path2) => {
|
|
551
|
-
return fs2__default.default.readFileSync(path2, { encoding: "utf8" });
|
|
552
|
-
},
|
|
553
|
-
bun: () => {
|
|
554
|
-
throw new Error("Bun cannot read sync");
|
|
555
|
-
}
|
|
556
|
-
},
|
|
557
|
-
"node"
|
|
558
|
-
);
|
|
559
|
-
async function read(path2) {
|
|
560
|
-
return reader(path2);
|
|
561
|
-
}
|
|
562
|
-
function readSync(path2) {
|
|
563
|
-
return syncReader(path2);
|
|
564
|
-
}
|
|
565
458
|
|
|
566
459
|
// src/utils/renderTemplate.ts
|
|
567
460
|
function renderTemplate(template, data = void 0) {
|
|
@@ -587,571 +480,14 @@ function renderTemplate(template, data = void 0) {
|
|
|
587
480
|
}, template) || "";
|
|
588
481
|
}
|
|
589
482
|
|
|
590
|
-
// src/utils/throttle.ts
|
|
591
|
-
var throttle = (fn, delay) => {
|
|
592
|
-
let wait = false;
|
|
593
|
-
let timeout2;
|
|
594
|
-
let cancelled = false;
|
|
595
|
-
return [
|
|
596
|
-
(...args) => {
|
|
597
|
-
if (cancelled) {
|
|
598
|
-
return void 0;
|
|
599
|
-
}
|
|
600
|
-
if (wait) {
|
|
601
|
-
return void 0;
|
|
602
|
-
}
|
|
603
|
-
const val = fn(...args);
|
|
604
|
-
wait = true;
|
|
605
|
-
timeout2 = setTimeout(() => {
|
|
606
|
-
wait = false;
|
|
607
|
-
}, delay);
|
|
608
|
-
return val;
|
|
609
|
-
},
|
|
610
|
-
() => {
|
|
611
|
-
cancelled = true;
|
|
612
|
-
clearTimeout(timeout2);
|
|
613
|
-
}
|
|
614
|
-
];
|
|
615
|
-
};
|
|
616
|
-
|
|
617
483
|
// src/utils/timeout.ts
|
|
618
484
|
async function timeout(ms) {
|
|
619
|
-
return new Promise((
|
|
485
|
+
return new Promise((resolve) => {
|
|
620
486
|
setTimeout(() => {
|
|
621
|
-
|
|
487
|
+
resolve(true);
|
|
622
488
|
}, ms);
|
|
623
489
|
});
|
|
624
490
|
}
|
|
625
|
-
async function saveCreateDirectory(path2) {
|
|
626
|
-
const passedPath = path.dirname(path.resolve(path2));
|
|
627
|
-
await fs2__default.default.mkdir(passedPath, { recursive: true });
|
|
628
|
-
}
|
|
629
|
-
var writer = jsRuntime.switcher(
|
|
630
|
-
{
|
|
631
|
-
node: async (path2, data) => {
|
|
632
|
-
try {
|
|
633
|
-
await fs2__default.default.stat(path.resolve(path2));
|
|
634
|
-
const oldContent = await fs2__default.default.readFile(path.resolve(path2), { encoding: "utf-8" });
|
|
635
|
-
if (oldContent?.toString() === data?.toString()) {
|
|
636
|
-
return;
|
|
637
|
-
}
|
|
638
|
-
} catch (_err) {
|
|
639
|
-
}
|
|
640
|
-
await saveCreateDirectory(path2);
|
|
641
|
-
await fs2__default.default.writeFile(path.resolve(path2), data, { encoding: "utf-8" });
|
|
642
|
-
const savedData = await fs2__default.default.readFile(path.resolve(path2), { encoding: "utf-8" });
|
|
643
|
-
if (savedData?.toString() !== data?.toString()) {
|
|
644
|
-
throw new Error(`Sanity check failed for ${path2}
|
|
645
|
-
|
|
646
|
-
Data[${data.length}]:
|
|
647
|
-
${data}
|
|
648
|
-
|
|
649
|
-
Saved[${savedData.length}]:
|
|
650
|
-
${savedData}
|
|
651
|
-
`);
|
|
652
|
-
}
|
|
653
|
-
return savedData;
|
|
654
|
-
},
|
|
655
|
-
bun: async (path2, data) => {
|
|
656
|
-
try {
|
|
657
|
-
await saveCreateDirectory(path2);
|
|
658
|
-
await Bun.write(path.resolve(path2), data);
|
|
659
|
-
const file = Bun.file(path.resolve(path2));
|
|
660
|
-
const savedData = await file.text();
|
|
661
|
-
if (savedData?.toString() !== data?.toString()) {
|
|
662
|
-
throw new Error(`Sanity check failed for ${path2}
|
|
663
|
-
|
|
664
|
-
Data[${data.length}]:
|
|
665
|
-
${data}
|
|
666
|
-
|
|
667
|
-
Saved[${savedData.length}]:
|
|
668
|
-
${savedData}
|
|
669
|
-
`);
|
|
670
|
-
}
|
|
671
|
-
return savedData;
|
|
672
|
-
} catch (e) {
|
|
673
|
-
console.log(e, path.resolve(path2));
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
},
|
|
677
|
-
"node"
|
|
678
|
-
);
|
|
679
|
-
async function write(data, path2) {
|
|
680
|
-
if (data.trim() === "") {
|
|
681
|
-
return void 0;
|
|
682
|
-
}
|
|
683
|
-
return writer(path2, data.trim());
|
|
684
|
-
}
|
|
685
|
-
var _options;
|
|
686
|
-
var BarrelManager = class {
|
|
687
|
-
constructor(options = {}) {
|
|
688
|
-
__privateAdd(this, _options, void 0);
|
|
689
|
-
__privateSet(this, _options, options);
|
|
690
|
-
return this;
|
|
691
|
-
}
|
|
692
|
-
getIndexes(pathToBuild) {
|
|
693
|
-
const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
|
|
694
|
-
const tree = TreeNode.build(pathToBuild, treeNode);
|
|
695
|
-
if (!tree) {
|
|
696
|
-
return null;
|
|
697
|
-
}
|
|
698
|
-
const fileReducer = (files, treeNode2) => {
|
|
699
|
-
if (!treeNode2.children) {
|
|
700
|
-
return [];
|
|
701
|
-
}
|
|
702
|
-
if (treeNode2.children.length > 1) {
|
|
703
|
-
const indexPath = path__default.default.resolve(treeNode2.data.path, "index.ts");
|
|
704
|
-
const exports = treeNode2.children.filter(Boolean).map((file) => {
|
|
705
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${transformers_default.trimExtName(file.data.name)}`;
|
|
706
|
-
if (importPath.endsWith("index") && file.data.type === "file") {
|
|
707
|
-
return void 0;
|
|
708
|
-
}
|
|
709
|
-
return {
|
|
710
|
-
path: extName ? `${importPath}${extName}` : importPath,
|
|
711
|
-
isTypeOnly
|
|
712
|
-
};
|
|
713
|
-
}).filter(Boolean);
|
|
714
|
-
files.push({
|
|
715
|
-
path: indexPath,
|
|
716
|
-
baseName: "index.ts",
|
|
717
|
-
source: "",
|
|
718
|
-
exports,
|
|
719
|
-
meta: {
|
|
720
|
-
treeNode: treeNode2
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
} else if (treeNode2.children.length === 1) {
|
|
724
|
-
const [treeNodeChild] = treeNode2.children;
|
|
725
|
-
const indexPath = path__default.default.resolve(treeNode2.data.path, "index.ts");
|
|
726
|
-
const importPath = treeNodeChild.data.type === "directory" ? `./${treeNodeChild.data.name}/index` : `./${transformers_default.trimExtName(treeNodeChild.data.name)}`;
|
|
727
|
-
const exports = [
|
|
728
|
-
{
|
|
729
|
-
path: extName ? `${importPath}${extName}` : importPath,
|
|
730
|
-
isTypeOnly
|
|
731
|
-
}
|
|
732
|
-
];
|
|
733
|
-
files.push({
|
|
734
|
-
path: indexPath,
|
|
735
|
-
baseName: "index.ts",
|
|
736
|
-
source: "",
|
|
737
|
-
exports,
|
|
738
|
-
meta: {
|
|
739
|
-
treeNode: treeNode2
|
|
740
|
-
}
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
treeNode2.children.forEach((childItem) => {
|
|
744
|
-
fileReducer(files, childItem);
|
|
745
|
-
});
|
|
746
|
-
return files;
|
|
747
|
-
};
|
|
748
|
-
return fileReducer([], tree).reverse();
|
|
749
|
-
}
|
|
750
|
-
};
|
|
751
|
-
_options = new WeakMap();
|
|
752
|
-
var _cache, _task, _isWriting, _timeout, _queue2, _validate, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
753
|
-
var _FileManager = class _FileManager {
|
|
754
|
-
constructor(options) {
|
|
755
|
-
__privateAdd(this, _validate);
|
|
756
|
-
__privateAdd(this, _add);
|
|
757
|
-
__privateAdd(this, _addOrAppend);
|
|
758
|
-
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
759
|
-
__privateAdd(this, _task, void 0);
|
|
760
|
-
__privateAdd(this, _isWriting, false);
|
|
761
|
-
/**
|
|
762
|
-
* Timeout between writes
|
|
763
|
-
*/
|
|
764
|
-
__privateAdd(this, _timeout, 0);
|
|
765
|
-
__privateAdd(this, _queue2, void 0);
|
|
766
|
-
if (options) {
|
|
767
|
-
__privateSet(this, _task, options.task);
|
|
768
|
-
__privateSet(this, _queue2, options.queue);
|
|
769
|
-
__privateSet(this, _timeout, options.timeout || 0);
|
|
770
|
-
}
|
|
771
|
-
return this;
|
|
772
|
-
}
|
|
773
|
-
get files() {
|
|
774
|
-
const files = [];
|
|
775
|
-
__privateGet(this, _cache).forEach((item) => {
|
|
776
|
-
files.push(...item.flat(1));
|
|
777
|
-
});
|
|
778
|
-
return files;
|
|
779
|
-
}
|
|
780
|
-
get isExecuting() {
|
|
781
|
-
return __privateGet(this, _queue2)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
|
|
782
|
-
}
|
|
783
|
-
async add(...files) {
|
|
784
|
-
const promises = files.map((file) => {
|
|
785
|
-
if (file.override) {
|
|
786
|
-
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
787
|
-
}
|
|
788
|
-
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
789
|
-
});
|
|
790
|
-
const resolvedFiles = await Promise.all(promises);
|
|
791
|
-
if (files.length > 1) {
|
|
792
|
-
return resolvedFiles;
|
|
793
|
-
}
|
|
794
|
-
return resolvedFiles[0];
|
|
795
|
-
}
|
|
796
|
-
async addIndexes({ root, output, meta, options = {} }) {
|
|
797
|
-
const { exportType = "barrel" } = output;
|
|
798
|
-
if (!exportType) {
|
|
799
|
-
return void 0;
|
|
800
|
-
}
|
|
801
|
-
const exportPath = output.path.startsWith("./") ? output.path : `./${output.path}`;
|
|
802
|
-
const barrelManager = new BarrelManager({ extName: output.extName, ...options });
|
|
803
|
-
const files = barrelManager.getIndexes(path.resolve(root, output.path));
|
|
804
|
-
if (!files) {
|
|
805
|
-
return void 0;
|
|
806
|
-
}
|
|
807
|
-
const rootFile = {
|
|
808
|
-
path: path.resolve(root, "index.ts"),
|
|
809
|
-
baseName: "index.ts",
|
|
810
|
-
source: "",
|
|
811
|
-
exports: [
|
|
812
|
-
output.exportAs ? {
|
|
813
|
-
name: output.exportAs,
|
|
814
|
-
asAlias: true,
|
|
815
|
-
path: exportPath,
|
|
816
|
-
isTypeOnly: options.isTypeOnly
|
|
817
|
-
} : {
|
|
818
|
-
path: exportPath,
|
|
819
|
-
isTypeOnly: options.isTypeOnly
|
|
820
|
-
}
|
|
821
|
-
]
|
|
822
|
-
};
|
|
823
|
-
await __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
824
|
-
...rootFile,
|
|
825
|
-
meta: meta ? meta : rootFile.meta
|
|
826
|
-
});
|
|
827
|
-
return await Promise.all(
|
|
828
|
-
files.map((file) => {
|
|
829
|
-
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
830
|
-
...file,
|
|
831
|
-
meta: meta ? meta : file.meta
|
|
832
|
-
});
|
|
833
|
-
})
|
|
834
|
-
);
|
|
835
|
-
}
|
|
836
|
-
getCacheByUUID(UUID) {
|
|
837
|
-
let cache;
|
|
838
|
-
__privateGet(this, _cache).forEach((files) => {
|
|
839
|
-
cache = files.find((item) => item.id === UUID);
|
|
840
|
-
});
|
|
841
|
-
return cache;
|
|
842
|
-
}
|
|
843
|
-
get(path2) {
|
|
844
|
-
return __privateGet(this, _cache).get(path2);
|
|
845
|
-
}
|
|
846
|
-
remove(path2) {
|
|
847
|
-
const cacheItem = this.get(path2);
|
|
848
|
-
if (!cacheItem) {
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
851
|
-
__privateGet(this, _cache).delete(path2);
|
|
852
|
-
}
|
|
853
|
-
async write(...params) {
|
|
854
|
-
if (!__privateGet(this, _isWriting)) {
|
|
855
|
-
__privateSet(this, _isWriting, true);
|
|
856
|
-
const text = await write(...params);
|
|
857
|
-
__privateSet(this, _isWriting, false);
|
|
858
|
-
return text;
|
|
859
|
-
}
|
|
860
|
-
await timeout(__privateGet(this, _timeout));
|
|
861
|
-
return this.write(...params);
|
|
862
|
-
}
|
|
863
|
-
async read(...params) {
|
|
864
|
-
return read(...params);
|
|
865
|
-
}
|
|
866
|
-
// statics
|
|
867
|
-
static getSource(file) {
|
|
868
|
-
if (!_FileManager.isExtensionAllowed(file.baseName)) {
|
|
869
|
-
return file.source;
|
|
870
|
-
}
|
|
871
|
-
const exports = file.exports ? combineExports(file.exports) : [];
|
|
872
|
-
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
873
|
-
const importNodes = imports.filter((item) => {
|
|
874
|
-
return item.path !== transformers_default.trimExtName(file.path);
|
|
875
|
-
}).map((item) => {
|
|
876
|
-
return factory__namespace.createImportDeclaration({
|
|
877
|
-
name: item.name,
|
|
878
|
-
path: item.root ? getRelativePath(item.root, item.path) : item.path,
|
|
879
|
-
isTypeOnly: item.isTypeOnly
|
|
880
|
-
});
|
|
881
|
-
});
|
|
882
|
-
const exportNodes = exports.map(
|
|
883
|
-
(item) => factory__namespace.createExportDeclaration({
|
|
884
|
-
name: item.name,
|
|
885
|
-
path: item.path,
|
|
886
|
-
isTypeOnly: item.isTypeOnly,
|
|
887
|
-
asAlias: item.asAlias
|
|
888
|
-
})
|
|
889
|
-
);
|
|
890
|
-
return [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
891
|
-
}
|
|
892
|
-
static combineFiles(files) {
|
|
893
|
-
return files.filter(Boolean).reduce((acc, file) => {
|
|
894
|
-
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
895
|
-
if (prevIndex === -1) {
|
|
896
|
-
return [...acc, file];
|
|
897
|
-
}
|
|
898
|
-
const prev = acc[prevIndex];
|
|
899
|
-
if (prev && file.override) {
|
|
900
|
-
acc[prevIndex] = {
|
|
901
|
-
imports: [],
|
|
902
|
-
exports: [],
|
|
903
|
-
...file
|
|
904
|
-
};
|
|
905
|
-
return acc;
|
|
906
|
-
}
|
|
907
|
-
if (prev) {
|
|
908
|
-
acc[prevIndex] = {
|
|
909
|
-
...file,
|
|
910
|
-
source: prev.source && file.source ? `${prev.source}
|
|
911
|
-
${file.source}` : "",
|
|
912
|
-
imports: [...prev.imports || [], ...file.imports || []],
|
|
913
|
-
exports: [...prev.exports || [], ...file.exports || []],
|
|
914
|
-
env: { ...prev.env || {}, ...file.env || {} }
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
return acc;
|
|
918
|
-
}, []);
|
|
919
|
-
}
|
|
920
|
-
static getMode(path2) {
|
|
921
|
-
if (!path2) {
|
|
922
|
-
return "directory";
|
|
923
|
-
}
|
|
924
|
-
return path.extname(path2) ? "file" : "directory";
|
|
925
|
-
}
|
|
926
|
-
static get extensions() {
|
|
927
|
-
return [".js", ".ts", ".tsx"];
|
|
928
|
-
}
|
|
929
|
-
static isExtensionAllowed(baseName) {
|
|
930
|
-
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
_cache = new WeakMap();
|
|
934
|
-
_task = new WeakMap();
|
|
935
|
-
_isWriting = new WeakMap();
|
|
936
|
-
_timeout = new WeakMap();
|
|
937
|
-
_queue2 = new WeakMap();
|
|
938
|
-
_validate = new WeakSet();
|
|
939
|
-
_add = new WeakSet();
|
|
940
|
-
add_fn = async function(file) {
|
|
941
|
-
const controller = new AbortController();
|
|
942
|
-
const resolvedFile = { id: crypto__default.default.randomUUID(), name: transformers_default.trimExtName(file.baseName), ...file };
|
|
943
|
-
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
944
|
-
if (__privateGet(this, _queue2)) {
|
|
945
|
-
await __privateGet(this, _queue2).run(
|
|
946
|
-
async () => {
|
|
947
|
-
var _a;
|
|
948
|
-
return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
|
|
949
|
-
},
|
|
950
|
-
{ controller }
|
|
951
|
-
);
|
|
952
|
-
}
|
|
953
|
-
return resolvedFile;
|
|
954
|
-
};
|
|
955
|
-
_addOrAppend = new WeakSet();
|
|
956
|
-
addOrAppend_fn = async function(file) {
|
|
957
|
-
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
958
|
-
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
959
|
-
if (previousCache) {
|
|
960
|
-
__privateGet(this, _cache).delete(previousCache.path);
|
|
961
|
-
return __privateMethod(this, _add, add_fn).call(this, {
|
|
962
|
-
...file,
|
|
963
|
-
source: previousCache.source && file.source ? `${previousCache.source}
|
|
964
|
-
${file.source}` : "",
|
|
965
|
-
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
966
|
-
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
967
|
-
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
971
|
-
};
|
|
972
|
-
var FileManager = _FileManager;
|
|
973
|
-
function combineExports(exports) {
|
|
974
|
-
const combinedExports = naturalOrderby.orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
975
|
-
const name = curr.name;
|
|
976
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
977
|
-
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
978
|
-
if (prevByPathAndIsTypeOnly) {
|
|
979
|
-
return prev;
|
|
980
|
-
}
|
|
981
|
-
const uniquePrev = prev.findLast(
|
|
982
|
-
(imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
983
|
-
);
|
|
984
|
-
if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
|
|
985
|
-
return prev;
|
|
986
|
-
}
|
|
987
|
-
if (!prevByPath) {
|
|
988
|
-
return [
|
|
989
|
-
...prev,
|
|
990
|
-
{
|
|
991
|
-
...curr,
|
|
992
|
-
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
993
|
-
}
|
|
994
|
-
];
|
|
995
|
-
}
|
|
996
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
997
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
|
|
998
|
-
return prev;
|
|
999
|
-
}
|
|
1000
|
-
return [...prev, curr];
|
|
1001
|
-
}, []);
|
|
1002
|
-
return naturalOrderby.orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
1003
|
-
}
|
|
1004
|
-
function combineImports(imports, exports, source) {
|
|
1005
|
-
const combinedImports = naturalOrderby.orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
1006
|
-
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
1007
|
-
const hasImportInSource = (importName) => {
|
|
1008
|
-
if (!source) {
|
|
1009
|
-
return true;
|
|
1010
|
-
}
|
|
1011
|
-
const checker = (name2) => name2 && !!source.includes(name2);
|
|
1012
|
-
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
1013
|
-
};
|
|
1014
|
-
if (Array.isArray(name)) {
|
|
1015
|
-
name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
1016
|
-
}
|
|
1017
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
1018
|
-
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
1019
|
-
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
1020
|
-
if (prevByPathNameAndIsTypeOnly) {
|
|
1021
|
-
return prev;
|
|
1022
|
-
}
|
|
1023
|
-
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
1024
|
-
return prev;
|
|
1025
|
-
}
|
|
1026
|
-
if (!prevByPath) {
|
|
1027
|
-
return [
|
|
1028
|
-
...prev,
|
|
1029
|
-
{
|
|
1030
|
-
...curr,
|
|
1031
|
-
name
|
|
1032
|
-
}
|
|
1033
|
-
];
|
|
1034
|
-
}
|
|
1035
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
1036
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
|
|
1037
|
-
return prev;
|
|
1038
|
-
}
|
|
1039
|
-
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
1040
|
-
return prev;
|
|
1041
|
-
}
|
|
1042
|
-
return [...prev, curr];
|
|
1043
|
-
}, []);
|
|
1044
|
-
return naturalOrderby.orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
1045
|
-
}
|
|
1046
|
-
function getEnvSource(source, env) {
|
|
1047
|
-
if (!env) {
|
|
1048
|
-
return source;
|
|
1049
|
-
}
|
|
1050
|
-
const keys = Object.keys(env);
|
|
1051
|
-
if (!keys.length) {
|
|
1052
|
-
return source;
|
|
1053
|
-
}
|
|
1054
|
-
return keys.reduce((prev, key) => {
|
|
1055
|
-
const environmentValue = env[key];
|
|
1056
|
-
const replaceBy = environmentValue ? `'${environmentValue.replaceAll('"', "")?.replaceAll("'", "")}'` : "undefined";
|
|
1057
|
-
if (key.toUpperCase() !== key) {
|
|
1058
|
-
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
1059
|
-
}
|
|
1060
|
-
if (typeof replaceBy === "string") {
|
|
1061
|
-
prev = transformers_default.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
1062
|
-
prev = transformers_default.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
1063
|
-
`, "ig"), ""), replaceBy, key });
|
|
1064
|
-
}
|
|
1065
|
-
return prev;
|
|
1066
|
-
}, source);
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
// src/utils/TreeNode.ts
|
|
1070
|
-
var TreeNode = class _TreeNode {
|
|
1071
|
-
constructor(data, parent) {
|
|
1072
|
-
this.children = [];
|
|
1073
|
-
this.data = data;
|
|
1074
|
-
this.parent = parent;
|
|
1075
|
-
return this;
|
|
1076
|
-
}
|
|
1077
|
-
addChild(data) {
|
|
1078
|
-
const child = new _TreeNode(data, this);
|
|
1079
|
-
if (!this.children) {
|
|
1080
|
-
this.children = [];
|
|
1081
|
-
}
|
|
1082
|
-
this.children.push(child);
|
|
1083
|
-
return child;
|
|
1084
|
-
}
|
|
1085
|
-
find(data) {
|
|
1086
|
-
if (!data) {
|
|
1087
|
-
return null;
|
|
1088
|
-
}
|
|
1089
|
-
if (data === this.data) {
|
|
1090
|
-
return this;
|
|
1091
|
-
}
|
|
1092
|
-
if (this.children?.length) {
|
|
1093
|
-
for (let i = 0, { length } = this.children, target = null; i < length; i++) {
|
|
1094
|
-
target = this.children[i].find(data);
|
|
1095
|
-
if (target) {
|
|
1096
|
-
return target;
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
return null;
|
|
1101
|
-
}
|
|
1102
|
-
get leaves() {
|
|
1103
|
-
if (!this.children || this.children.length === 0) {
|
|
1104
|
-
return [this];
|
|
1105
|
-
}
|
|
1106
|
-
const leaves = [];
|
|
1107
|
-
if (this.children) {
|
|
1108
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
1109
|
-
leaves.push.apply(leaves, this.children[i].leaves);
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
return leaves;
|
|
1113
|
-
}
|
|
1114
|
-
get root() {
|
|
1115
|
-
if (!this.parent) {
|
|
1116
|
-
return this;
|
|
1117
|
-
}
|
|
1118
|
-
return this.parent.root;
|
|
1119
|
-
}
|
|
1120
|
-
forEach(callback) {
|
|
1121
|
-
if (typeof callback !== "function") {
|
|
1122
|
-
throw new TypeError("forEach() callback must be a function");
|
|
1123
|
-
}
|
|
1124
|
-
callback(this);
|
|
1125
|
-
if (this.children) {
|
|
1126
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
1127
|
-
this.children[i].forEach(callback);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
return this;
|
|
1131
|
-
}
|
|
1132
|
-
static build(path2, options = {}) {
|
|
1133
|
-
try {
|
|
1134
|
-
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
1135
|
-
const filteredTree = dirTree__default.default(path2, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
|
|
1136
|
-
if (!filteredTree) {
|
|
1137
|
-
return null;
|
|
1138
|
-
}
|
|
1139
|
-
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
|
|
1140
|
-
const recurse = (node, item) => {
|
|
1141
|
-
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
|
|
1142
|
-
if (item.children?.length) {
|
|
1143
|
-
item.children?.forEach((child) => {
|
|
1144
|
-
recurse(subNode, child);
|
|
1145
|
-
});
|
|
1146
|
-
}
|
|
1147
|
-
};
|
|
1148
|
-
filteredTree.children?.forEach((child) => recurse(treeNode, child));
|
|
1149
|
-
return treeNode;
|
|
1150
|
-
} catch (e) {
|
|
1151
|
-
throw new Error("Something went wrong with creating index files with the TreehNode class", { cause: e });
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
};
|
|
1155
491
|
|
|
1156
492
|
// src/utils/uniqueName.ts
|
|
1157
493
|
function getUniqueName(originalName, data) {
|
|
@@ -1175,8 +511,8 @@ function setUniqueName(originalName, data) {
|
|
|
1175
511
|
|
|
1176
512
|
// src/utils/URLPath.ts
|
|
1177
513
|
var URLPath = class {
|
|
1178
|
-
constructor(
|
|
1179
|
-
this.path =
|
|
514
|
+
constructor(path) {
|
|
515
|
+
this.path = path;
|
|
1180
516
|
return this;
|
|
1181
517
|
}
|
|
1182
518
|
/**
|
|
@@ -1270,31 +606,15 @@ var URLPath = class {
|
|
|
1270
606
|
}
|
|
1271
607
|
};
|
|
1272
608
|
|
|
1273
|
-
Object.defineProperty(exports, 'pc', {
|
|
1274
|
-
enumerable: true,
|
|
1275
|
-
get: function () { return pc2__default.default; }
|
|
1276
|
-
});
|
|
1277
609
|
exports.FunctionParams = FunctionParams;
|
|
1278
|
-
exports.LogLevel = LogLevel;
|
|
1279
610
|
exports.Queue = Queue;
|
|
1280
|
-
exports.TreeNode = TreeNode;
|
|
1281
611
|
exports.URLPath = URLPath;
|
|
1282
|
-
exports.clean = clean;
|
|
1283
|
-
exports.createLogger = createLogger;
|
|
1284
|
-
exports.createPluginCache = createPluginCache;
|
|
1285
|
-
exports.getRelativePath = getRelativePath;
|
|
1286
612
|
exports.getUniqueName = getUniqueName;
|
|
1287
613
|
exports.isPromise = isPromise;
|
|
1288
614
|
exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
|
|
1289
615
|
exports.isPromiseRejectedResult = isPromiseRejectedResult;
|
|
1290
|
-
exports.randomColour = randomColour;
|
|
1291
|
-
exports.randomPicoColour = randomPicoColour;
|
|
1292
|
-
exports.read = read;
|
|
1293
|
-
exports.readSync = readSync;
|
|
1294
616
|
exports.renderTemplate = renderTemplate;
|
|
1295
617
|
exports.setUniqueName = setUniqueName;
|
|
1296
|
-
exports.throttle = throttle;
|
|
1297
618
|
exports.timeout = timeout;
|
|
1298
|
-
exports.write = write;
|
|
1299
619
|
//# sourceMappingURL=out.js.map
|
|
1300
620
|
//# sourceMappingURL=utils.cjs.map
|