@kubb/core 1.15.0-canary.20231027T200912 → 2.0.0-canary.20231027T203719
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 +1163 -1025
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +255 -313
- package/dist/index.d.ts +255 -313
- package/dist/index.js +1105 -958
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1260 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +235 -0
- package/dist/utils.d.ts +235 -0
- package/dist/utils.js +1207 -0
- package/dist/utils.js.map +1 -0
- package/globals.d.ts +33 -16
- package/package.json +14 -9
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,1260 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs2 = require('fs-extra');
|
|
4
|
+
var changeCase = require('change-case');
|
|
5
|
+
var naturalOrderby = require('natural-orderby');
|
|
6
|
+
var pc2 = require('picocolors');
|
|
7
|
+
var crypto = require('crypto');
|
|
8
|
+
var perf_hooks = require('perf_hooks');
|
|
9
|
+
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
|
+
|
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
+
|
|
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
|
+
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
|
+
|
|
47
|
+
var __accessCheck = (obj, member, msg) => {
|
|
48
|
+
if (!member.has(obj))
|
|
49
|
+
throw TypeError("Cannot " + msg);
|
|
50
|
+
};
|
|
51
|
+
var __privateGet = (obj, member, getter) => {
|
|
52
|
+
__accessCheck(obj, member, "read from private field");
|
|
53
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
54
|
+
};
|
|
55
|
+
var __privateAdd = (obj, member, value) => {
|
|
56
|
+
if (member.has(obj))
|
|
57
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
58
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
59
|
+
};
|
|
60
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
61
|
+
__accessCheck(obj, member, "write to private field");
|
|
62
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
63
|
+
return value;
|
|
64
|
+
};
|
|
65
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
66
|
+
set _(value) {
|
|
67
|
+
__privateSet(obj, member, value, setter);
|
|
68
|
+
},
|
|
69
|
+
get _() {
|
|
70
|
+
return __privateGet(obj, member, getter);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
var __privateMethod = (obj, member, method) => {
|
|
74
|
+
__accessCheck(obj, member, "access private method");
|
|
75
|
+
return method;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/utils/cache.ts
|
|
79
|
+
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
80
|
+
return {
|
|
81
|
+
set(id, value) {
|
|
82
|
+
Store[id] = [0, value];
|
|
83
|
+
},
|
|
84
|
+
get(id) {
|
|
85
|
+
const item = Store[id];
|
|
86
|
+
if (!item) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
item[0] = 0;
|
|
90
|
+
return item[1];
|
|
91
|
+
},
|
|
92
|
+
has(id) {
|
|
93
|
+
const item = Store[id];
|
|
94
|
+
if (!item) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
item[0] = 0;
|
|
98
|
+
return true;
|
|
99
|
+
},
|
|
100
|
+
delete(id) {
|
|
101
|
+
return delete Store[id];
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async function clean(path2) {
|
|
106
|
+
return fs2.remove(path2);
|
|
107
|
+
}
|
|
108
|
+
var FunctionParams = class {
|
|
109
|
+
constructor(type) {
|
|
110
|
+
this.items = [];
|
|
111
|
+
this.type = type;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
add(item) {
|
|
115
|
+
if (!item) {
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
if (Array.isArray(item)) {
|
|
119
|
+
item.filter(Boolean).forEach((it) => this.items.push(it));
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
this.items.push(item);
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
toString() {
|
|
126
|
+
const sortedData = naturalOrderby.orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
|
|
127
|
+
return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
|
|
128
|
+
if (!name) {
|
|
129
|
+
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
130
|
+
return acc;
|
|
131
|
+
}
|
|
132
|
+
const parameterName = name.startsWith("{") ? name : changeCase.camelCase(name, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
133
|
+
if (type) {
|
|
134
|
+
if (required) {
|
|
135
|
+
acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
136
|
+
} else {
|
|
137
|
+
acc.push(`${parameterName}?: ${type}`);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
acc.push(`${parameterName}`);
|
|
141
|
+
}
|
|
142
|
+
return acc;
|
|
143
|
+
}, []).join(", ");
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
var LogLevel = {
|
|
147
|
+
silent: "silent",
|
|
148
|
+
info: "info",
|
|
149
|
+
debug: "debug"
|
|
150
|
+
};
|
|
151
|
+
function createLogger({ logLevel, name, spinner }) {
|
|
152
|
+
const logs = [];
|
|
153
|
+
const log = (message) => {
|
|
154
|
+
if (message && spinner) {
|
|
155
|
+
spinner.text = message;
|
|
156
|
+
logs.push(message);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const error = (message) => {
|
|
160
|
+
if (message) {
|
|
161
|
+
throw new Error(message || "Something went wrong");
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const warn = (message) => {
|
|
165
|
+
if (message && spinner) {
|
|
166
|
+
spinner.warn(pc2__default.default.yellow(message));
|
|
167
|
+
logs.push(message);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const info = (message) => {
|
|
171
|
+
if (message && spinner) {
|
|
172
|
+
spinner.info(message);
|
|
173
|
+
logs.push(message);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const logger = {
|
|
177
|
+
name,
|
|
178
|
+
logLevel,
|
|
179
|
+
log,
|
|
180
|
+
error,
|
|
181
|
+
warn,
|
|
182
|
+
info,
|
|
183
|
+
spinner,
|
|
184
|
+
logs
|
|
185
|
+
};
|
|
186
|
+
return logger;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/utils/promise.ts
|
|
190
|
+
function isPromise(result) {
|
|
191
|
+
return !!result && typeof result?.then === "function";
|
|
192
|
+
}
|
|
193
|
+
function isPromiseFulfilledResult(result) {
|
|
194
|
+
return result.status === "fulfilled";
|
|
195
|
+
}
|
|
196
|
+
function isPromiseRejectedResult(result) {
|
|
197
|
+
return result.status === "rejected";
|
|
198
|
+
}
|
|
199
|
+
var _emitter;
|
|
200
|
+
var EventEmitter = class {
|
|
201
|
+
constructor() {
|
|
202
|
+
__privateAdd(this, _emitter, new events.EventEmitter());
|
|
203
|
+
__privateGet(this, _emitter).setMaxListeners(100);
|
|
204
|
+
}
|
|
205
|
+
emit(eventName, ...eventArg) {
|
|
206
|
+
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
207
|
+
}
|
|
208
|
+
on(eventName, handler) {
|
|
209
|
+
__privateGet(this, _emitter).on(eventName, handler);
|
|
210
|
+
}
|
|
211
|
+
off(eventName, handler) {
|
|
212
|
+
__privateGet(this, _emitter).off(eventName, handler);
|
|
213
|
+
}
|
|
214
|
+
removeAll() {
|
|
215
|
+
__privateGet(this, _emitter).removeAllListeners();
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
_emitter = new WeakMap();
|
|
219
|
+
|
|
220
|
+
// src/utils/Queue.ts
|
|
221
|
+
var _queue, _workerCount, _maxParallel, _debug, _work, work_fn;
|
|
222
|
+
var Queue = class {
|
|
223
|
+
constructor(maxParallel, debug = false) {
|
|
224
|
+
__privateAdd(this, _work);
|
|
225
|
+
__privateAdd(this, _queue, []);
|
|
226
|
+
this.eventEmitter = new EventEmitter();
|
|
227
|
+
__privateAdd(this, _workerCount, 0);
|
|
228
|
+
__privateAdd(this, _maxParallel, void 0);
|
|
229
|
+
__privateAdd(this, _debug, false);
|
|
230
|
+
__privateSet(this, _maxParallel, maxParallel);
|
|
231
|
+
__privateSet(this, _debug, debug);
|
|
232
|
+
}
|
|
233
|
+
run(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
|
|
234
|
+
return new Promise((resolve2, reject) => {
|
|
235
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
236
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
237
|
+
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
238
|
+
reject("Aborted");
|
|
239
|
+
});
|
|
240
|
+
__privateGet(this, _queue).push(item);
|
|
241
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
runSync(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
|
|
245
|
+
new Promise((resolve2, reject) => {
|
|
246
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
247
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
248
|
+
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
249
|
+
});
|
|
250
|
+
__privateGet(this, _queue).push(item);
|
|
251
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
get hasJobs() {
|
|
255
|
+
return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue).length > 0;
|
|
256
|
+
}
|
|
257
|
+
get count() {
|
|
258
|
+
return __privateGet(this, _workerCount);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
_queue = new WeakMap();
|
|
262
|
+
_workerCount = new WeakMap();
|
|
263
|
+
_maxParallel = new WeakMap();
|
|
264
|
+
_debug = new WeakMap();
|
|
265
|
+
_work = new WeakSet();
|
|
266
|
+
work_fn = function() {
|
|
267
|
+
if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
__privateWrapper(this, _workerCount)._++;
|
|
271
|
+
let entry;
|
|
272
|
+
while (entry = __privateGet(this, _queue).shift()) {
|
|
273
|
+
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
274
|
+
if (__privateGet(this, _debug)) {
|
|
275
|
+
perf_hooks.performance.mark(name + "_start");
|
|
276
|
+
}
|
|
277
|
+
job().then((result) => {
|
|
278
|
+
this.eventEmitter.emit("jobDone", result);
|
|
279
|
+
resolve2(result);
|
|
280
|
+
if (__privateGet(this, _debug)) {
|
|
281
|
+
perf_hooks.performance.mark(name + "_stop");
|
|
282
|
+
perf_hooks.performance.measure(description, name + "_start", name + "_stop");
|
|
283
|
+
}
|
|
284
|
+
}).catch((err) => {
|
|
285
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
286
|
+
reject(err);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
__privateWrapper(this, _workerCount)._--;
|
|
290
|
+
};
|
|
291
|
+
var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
292
|
+
function randomColour(text, colours = defaultColours) {
|
|
293
|
+
if (!text) {
|
|
294
|
+
return "white";
|
|
295
|
+
}
|
|
296
|
+
const random = seedrandom__default.default(text);
|
|
297
|
+
const colour = colours.at(Math.floor(random() * colours.length)) || "white";
|
|
298
|
+
return colour;
|
|
299
|
+
}
|
|
300
|
+
function randomPicoColour(text, colors = defaultColours) {
|
|
301
|
+
const colours = pc2__default.default.createColors(true);
|
|
302
|
+
if (!text) {
|
|
303
|
+
return colours.white(text);
|
|
304
|
+
}
|
|
305
|
+
const colour = randomColour(text, colors);
|
|
306
|
+
const isDark = colour.includes("dark");
|
|
307
|
+
const key = colour.replace("dark", "").toLowerCase();
|
|
308
|
+
const formatter = colours[key];
|
|
309
|
+
if (isDark) {
|
|
310
|
+
return pc2__default.default.bold(formatter(text));
|
|
311
|
+
}
|
|
312
|
+
if (typeof formatter !== "function") {
|
|
313
|
+
throw new Error("Formatter for picoColor is not of type function/Formatter");
|
|
314
|
+
}
|
|
315
|
+
return formatter(text);
|
|
316
|
+
}
|
|
317
|
+
function slash(path2, platform = "linux") {
|
|
318
|
+
const isWindowsPath = /^\\\\\?\\/.test(path2);
|
|
319
|
+
if (["linux", "mac"].includes(platform) && !isWindowsPath) {
|
|
320
|
+
return path2.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
321
|
+
}
|
|
322
|
+
return path2.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
323
|
+
}
|
|
324
|
+
function getRelativePath(rootDir, filePath, platform = "linux") {
|
|
325
|
+
if (!rootDir || !filePath) {
|
|
326
|
+
throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
327
|
+
}
|
|
328
|
+
const relativePath = path.relative(rootDir, filePath);
|
|
329
|
+
const slashedPath = slash(relativePath, platform);
|
|
330
|
+
if (slashedPath.startsWith("../")) {
|
|
331
|
+
return slashedPath.replace(path.basename(slashedPath), path.basename(slashedPath, path.extname(filePath)));
|
|
332
|
+
}
|
|
333
|
+
return `./${slashedPath.replace(path.basename(slashedPath), path.basename(slashedPath, path.extname(filePath)))}`;
|
|
334
|
+
}
|
|
335
|
+
var reader = jsRuntime.switcher(
|
|
336
|
+
{
|
|
337
|
+
node: async (path2) => {
|
|
338
|
+
return fs2__default.default.readFile(path2, { encoding: "utf8" });
|
|
339
|
+
},
|
|
340
|
+
bun: async (path2) => {
|
|
341
|
+
const file = Bun.file(path2);
|
|
342
|
+
return file.text();
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
"node"
|
|
346
|
+
);
|
|
347
|
+
var syncReader = jsRuntime.switcher(
|
|
348
|
+
{
|
|
349
|
+
node: (path2) => {
|
|
350
|
+
return fs2__default.default.readFileSync(path2, { encoding: "utf8" });
|
|
351
|
+
},
|
|
352
|
+
bun: () => {
|
|
353
|
+
throw new Error("Bun cannot read sync");
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
"node"
|
|
357
|
+
);
|
|
358
|
+
async function read(path2) {
|
|
359
|
+
return reader(path2);
|
|
360
|
+
}
|
|
361
|
+
function readSync(path2) {
|
|
362
|
+
return syncReader(path2);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/utils/renderTemplate.ts
|
|
366
|
+
function renderTemplate(template, data = void 0) {
|
|
367
|
+
if (!data || !Object.keys(data).length) {
|
|
368
|
+
return template.replace(/{{(.*?)}}/g, "");
|
|
369
|
+
}
|
|
370
|
+
const matches = template.match(/{{(.*?)}}/g);
|
|
371
|
+
return matches?.reduce((prev, curr) => {
|
|
372
|
+
const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
|
|
373
|
+
if (index === void 0) {
|
|
374
|
+
return prev;
|
|
375
|
+
}
|
|
376
|
+
const value = data[index];
|
|
377
|
+
if (value === void 0) {
|
|
378
|
+
return prev;
|
|
379
|
+
}
|
|
380
|
+
return prev.replace(curr, () => {
|
|
381
|
+
if (typeof value === "boolean") {
|
|
382
|
+
return `${value.toString()}` || "false";
|
|
383
|
+
}
|
|
384
|
+
return value || "";
|
|
385
|
+
}).trim();
|
|
386
|
+
}, template) || "";
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// src/utils/throttle.ts
|
|
390
|
+
var throttle = (fn, delay) => {
|
|
391
|
+
let wait = false;
|
|
392
|
+
let timeout2;
|
|
393
|
+
let cancelled = false;
|
|
394
|
+
return [
|
|
395
|
+
(...args) => {
|
|
396
|
+
if (cancelled) {
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
if (wait) {
|
|
400
|
+
return void 0;
|
|
401
|
+
}
|
|
402
|
+
const val = fn(...args);
|
|
403
|
+
wait = true;
|
|
404
|
+
timeout2 = setTimeout(() => {
|
|
405
|
+
wait = false;
|
|
406
|
+
}, delay);
|
|
407
|
+
return val;
|
|
408
|
+
},
|
|
409
|
+
() => {
|
|
410
|
+
cancelled = true;
|
|
411
|
+
clearTimeout(timeout2);
|
|
412
|
+
}
|
|
413
|
+
];
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// src/utils/timeout.ts
|
|
417
|
+
async function timeout(ms) {
|
|
418
|
+
return new Promise((resolve2) => {
|
|
419
|
+
setTimeout(() => {
|
|
420
|
+
resolve2(true);
|
|
421
|
+
}, ms);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/utils/transformers/combineCodes.ts
|
|
426
|
+
function combineCodes(codes) {
|
|
427
|
+
return codes.join("\n");
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/utils/transformers/createJSDocBlockText.ts
|
|
431
|
+
function createJSDocBlockText({ comments }) {
|
|
432
|
+
const filteredComments = comments.filter(Boolean);
|
|
433
|
+
if (!filteredComments.length) {
|
|
434
|
+
return "";
|
|
435
|
+
}
|
|
436
|
+
return `/**
|
|
437
|
+
* ${filteredComments.join("\n * ")}
|
|
438
|
+
*/`;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/utils/transformers/escape.ts
|
|
442
|
+
function escape(text) {
|
|
443
|
+
return text ? text.replaceAll("`", "\\`") : "";
|
|
444
|
+
}
|
|
445
|
+
function jsStringEscape(input) {
|
|
446
|
+
return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
|
|
447
|
+
switch (character) {
|
|
448
|
+
case '"':
|
|
449
|
+
case "'":
|
|
450
|
+
case "\\":
|
|
451
|
+
return "\\" + character;
|
|
452
|
+
case "\n":
|
|
453
|
+
return "\\n";
|
|
454
|
+
case "\r":
|
|
455
|
+
return "\\r";
|
|
456
|
+
case "\u2028":
|
|
457
|
+
return "\\u2028";
|
|
458
|
+
case "\u2029":
|
|
459
|
+
return "\\u2029";
|
|
460
|
+
default:
|
|
461
|
+
return "";
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/utils/transformers/indent.ts
|
|
467
|
+
function createIndent(size) {
|
|
468
|
+
return Array.from({ length: size + 1 }).join(" ");
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/utils/transformers/nameSorter.ts
|
|
472
|
+
function nameSorter(a, b) {
|
|
473
|
+
if (a.name < b.name) {
|
|
474
|
+
return -1;
|
|
475
|
+
}
|
|
476
|
+
if (a.name > b.name) {
|
|
477
|
+
return 1;
|
|
478
|
+
}
|
|
479
|
+
return 0;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/utils/transformers/searchAndReplace.ts
|
|
483
|
+
function searchAndReplace(options) {
|
|
484
|
+
const { text, replaceBy, prefix = "", key } = options;
|
|
485
|
+
const searchValues = options.searchValues?.(prefix, key) || [
|
|
486
|
+
`${prefix}["${key}"]`,
|
|
487
|
+
`${prefix}['${key}']`,
|
|
488
|
+
`${prefix}[\`${key}\`]`,
|
|
489
|
+
`${prefix}"${key}"`,
|
|
490
|
+
`${prefix}'${key}'`,
|
|
491
|
+
`${prefix}\`${key}\``,
|
|
492
|
+
new RegExp(`${prefix}${key}`, "g")
|
|
493
|
+
];
|
|
494
|
+
return searchValues.reduce((prev, searchValue) => {
|
|
495
|
+
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
496
|
+
}, text);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// src/utils/transformers/transformReservedWord.ts
|
|
500
|
+
var reservedWords = [
|
|
501
|
+
"abstract",
|
|
502
|
+
"arguments",
|
|
503
|
+
"boolean",
|
|
504
|
+
"break",
|
|
505
|
+
"byte",
|
|
506
|
+
"case",
|
|
507
|
+
"catch",
|
|
508
|
+
"char",
|
|
509
|
+
"class",
|
|
510
|
+
"const",
|
|
511
|
+
"continue",
|
|
512
|
+
"debugger",
|
|
513
|
+
"default",
|
|
514
|
+
"delete",
|
|
515
|
+
"do",
|
|
516
|
+
"double",
|
|
517
|
+
"else",
|
|
518
|
+
"enum",
|
|
519
|
+
"eval",
|
|
520
|
+
"export",
|
|
521
|
+
"extends",
|
|
522
|
+
"false",
|
|
523
|
+
"final",
|
|
524
|
+
"finally",
|
|
525
|
+
"float",
|
|
526
|
+
"for",
|
|
527
|
+
"function",
|
|
528
|
+
"goto",
|
|
529
|
+
"if",
|
|
530
|
+
"implements",
|
|
531
|
+
"import",
|
|
532
|
+
"in",
|
|
533
|
+
"instanceof",
|
|
534
|
+
"int",
|
|
535
|
+
"interface",
|
|
536
|
+
"let",
|
|
537
|
+
"long",
|
|
538
|
+
"native",
|
|
539
|
+
"new",
|
|
540
|
+
"null",
|
|
541
|
+
"package",
|
|
542
|
+
"private",
|
|
543
|
+
"protected",
|
|
544
|
+
"public",
|
|
545
|
+
"return",
|
|
546
|
+
"short",
|
|
547
|
+
"static",
|
|
548
|
+
"super",
|
|
549
|
+
"switch",
|
|
550
|
+
"synchronized",
|
|
551
|
+
"this",
|
|
552
|
+
"throw",
|
|
553
|
+
"throws",
|
|
554
|
+
"transient",
|
|
555
|
+
"true",
|
|
556
|
+
"try",
|
|
557
|
+
"typeof",
|
|
558
|
+
"var",
|
|
559
|
+
"void",
|
|
560
|
+
"volatile",
|
|
561
|
+
"while",
|
|
562
|
+
"with",
|
|
563
|
+
"yield",
|
|
564
|
+
"Array",
|
|
565
|
+
"Date",
|
|
566
|
+
"eval",
|
|
567
|
+
"function",
|
|
568
|
+
"hasOwnProperty",
|
|
569
|
+
"Infinity",
|
|
570
|
+
"isFinite",
|
|
571
|
+
"isNaN",
|
|
572
|
+
"isPrototypeOf",
|
|
573
|
+
"length",
|
|
574
|
+
"Math",
|
|
575
|
+
"name",
|
|
576
|
+
"NaN",
|
|
577
|
+
"Number",
|
|
578
|
+
"Object",
|
|
579
|
+
"prototype",
|
|
580
|
+
"String",
|
|
581
|
+
"toString",
|
|
582
|
+
"undefined",
|
|
583
|
+
"valueOf"
|
|
584
|
+
];
|
|
585
|
+
function transformReservedWord(word) {
|
|
586
|
+
if (word && reservedWords.includes(word) || word?.match(/^\d/)) {
|
|
587
|
+
return `_${word}`;
|
|
588
|
+
}
|
|
589
|
+
return word;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// src/utils/transformers/index.ts
|
|
593
|
+
var transformers = {
|
|
594
|
+
combineCodes,
|
|
595
|
+
escape,
|
|
596
|
+
jsStringEscape,
|
|
597
|
+
createIndent,
|
|
598
|
+
transformReservedWord,
|
|
599
|
+
nameSorter,
|
|
600
|
+
searchAndReplace,
|
|
601
|
+
JSDoc: {
|
|
602
|
+
createJSDocBlockText
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
async function saveCreateDirectory(path2) {
|
|
606
|
+
const passedPath = path.dirname(path.resolve(path2));
|
|
607
|
+
await fs2__default.default.mkdir(passedPath, { recursive: true });
|
|
608
|
+
}
|
|
609
|
+
var writer = jsRuntime.switcher(
|
|
610
|
+
{
|
|
611
|
+
node: async (path2, data) => {
|
|
612
|
+
try {
|
|
613
|
+
await fs2__default.default.stat(path.resolve(path2));
|
|
614
|
+
const oldContent = await fs2__default.default.readFile(path.resolve(path2), { encoding: "utf-8" });
|
|
615
|
+
if (oldContent?.toString() === data?.toString()) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
} catch (_err) {
|
|
619
|
+
}
|
|
620
|
+
await saveCreateDirectory(path2);
|
|
621
|
+
await fs2__default.default.writeFile(path.resolve(path2), data, { encoding: "utf-8" });
|
|
622
|
+
const savedData = await fs2__default.default.readFile(path.resolve(path2), { encoding: "utf-8" });
|
|
623
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
624
|
+
throw new Error(`Sanity check failed for ${path2}
|
|
625
|
+
|
|
626
|
+
Data[${data.length}]:
|
|
627
|
+
${data}
|
|
628
|
+
|
|
629
|
+
Saved[${savedData.length}]:
|
|
630
|
+
${savedData}
|
|
631
|
+
`);
|
|
632
|
+
}
|
|
633
|
+
return savedData;
|
|
634
|
+
},
|
|
635
|
+
bun: async (path2, data) => {
|
|
636
|
+
try {
|
|
637
|
+
await saveCreateDirectory(path2);
|
|
638
|
+
await Bun.write(path.resolve(path2), data);
|
|
639
|
+
const file = Bun.file(path.resolve(path2));
|
|
640
|
+
const savedData = await file.text();
|
|
641
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
642
|
+
throw new Error(`Sanity check failed for ${path2}
|
|
643
|
+
|
|
644
|
+
Data[${data.length}]:
|
|
645
|
+
${data}
|
|
646
|
+
|
|
647
|
+
Saved[${savedData.length}]:
|
|
648
|
+
${savedData}
|
|
649
|
+
`);
|
|
650
|
+
}
|
|
651
|
+
return savedData;
|
|
652
|
+
} catch (e) {
|
|
653
|
+
console.log(e, path.resolve(path2));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
"node"
|
|
658
|
+
);
|
|
659
|
+
async function write(data, path2) {
|
|
660
|
+
if (data.trim() === "") {
|
|
661
|
+
return void 0;
|
|
662
|
+
}
|
|
663
|
+
return writer(path2, data.trim());
|
|
664
|
+
}
|
|
665
|
+
var _options;
|
|
666
|
+
var BarrelManager = class {
|
|
667
|
+
constructor(options = {}) {
|
|
668
|
+
__privateAdd(this, _options, {});
|
|
669
|
+
__privateSet(this, _options, options);
|
|
670
|
+
return this;
|
|
671
|
+
}
|
|
672
|
+
getIndexes(root, extName) {
|
|
673
|
+
const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
|
|
674
|
+
const extMapper = {
|
|
675
|
+
".ts": {
|
|
676
|
+
extensions: /\.ts/,
|
|
677
|
+
exclude: [/schemas/, /json/]
|
|
678
|
+
},
|
|
679
|
+
".json": {
|
|
680
|
+
extensions: /\.json/,
|
|
681
|
+
exclude: []
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
|
|
685
|
+
if (!tree) {
|
|
686
|
+
return null;
|
|
687
|
+
}
|
|
688
|
+
const fileReducer = (files2, currentTree) => {
|
|
689
|
+
if (!currentTree.children) {
|
|
690
|
+
return [];
|
|
691
|
+
}
|
|
692
|
+
if (currentTree.children?.length > 1) {
|
|
693
|
+
const indexPath = path__default.default.resolve(currentTree.data.path, "index.ts");
|
|
694
|
+
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
695
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
696
|
+
if (importPath.includes("index") && indexPath.includes("index")) {
|
|
697
|
+
return void 0;
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
701
|
+
isTypeOnly
|
|
702
|
+
};
|
|
703
|
+
}).filter(Boolean);
|
|
704
|
+
files2.push({
|
|
705
|
+
path: indexPath,
|
|
706
|
+
baseName: "index.ts",
|
|
707
|
+
source: "",
|
|
708
|
+
exports: output ? exports?.filter((item) => {
|
|
709
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
710
|
+
}) : exports
|
|
711
|
+
});
|
|
712
|
+
} else {
|
|
713
|
+
currentTree.children?.forEach((child) => {
|
|
714
|
+
const indexPath = path__default.default.resolve(currentTree.data.path, "index.ts");
|
|
715
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
716
|
+
const exports = [
|
|
717
|
+
{
|
|
718
|
+
path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
719
|
+
isTypeOnly
|
|
720
|
+
}
|
|
721
|
+
];
|
|
722
|
+
files2.push({
|
|
723
|
+
path: indexPath,
|
|
724
|
+
baseName: "index.ts",
|
|
725
|
+
source: "",
|
|
726
|
+
exports: output ? exports?.filter((item) => {
|
|
727
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
728
|
+
}) : exports
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
currentTree.children.forEach((childItem) => {
|
|
733
|
+
fileReducer(files2, childItem);
|
|
734
|
+
});
|
|
735
|
+
return files2;
|
|
736
|
+
};
|
|
737
|
+
const files = fileReducer([], tree).reverse();
|
|
738
|
+
const filteredFiles = filter ? files.filter(filter) : files;
|
|
739
|
+
return map ? filteredFiles.map(map) : filteredFiles;
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
_options = new WeakMap();
|
|
743
|
+
|
|
744
|
+
// src/FileManager.ts
|
|
745
|
+
var _cache, _task, _isWriting, _timeout, _queue2, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
746
|
+
var _FileManager = class _FileManager {
|
|
747
|
+
constructor(options) {
|
|
748
|
+
__privateAdd(this, _validate);
|
|
749
|
+
__privateAdd(this, _add);
|
|
750
|
+
__privateAdd(this, _addOrAppend);
|
|
751
|
+
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
752
|
+
__privateAdd(this, _task, void 0);
|
|
753
|
+
__privateAdd(this, _isWriting, false);
|
|
754
|
+
/**
|
|
755
|
+
* Timeout between writes
|
|
756
|
+
*/
|
|
757
|
+
__privateAdd(this, _timeout, 0);
|
|
758
|
+
__privateAdd(this, _queue2, void 0);
|
|
759
|
+
if (options) {
|
|
760
|
+
__privateSet(this, _task, options.task);
|
|
761
|
+
__privateSet(this, _queue2, options.queue);
|
|
762
|
+
__privateSet(this, _timeout, options.timeout || 0);
|
|
763
|
+
}
|
|
764
|
+
return this;
|
|
765
|
+
}
|
|
766
|
+
get files() {
|
|
767
|
+
const files = [];
|
|
768
|
+
__privateGet(this, _cache).forEach((item) => {
|
|
769
|
+
files.push(...item.flat(1));
|
|
770
|
+
});
|
|
771
|
+
return files;
|
|
772
|
+
}
|
|
773
|
+
get isExecuting() {
|
|
774
|
+
return __privateGet(this, _queue2)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
|
|
775
|
+
}
|
|
776
|
+
async add(...files) {
|
|
777
|
+
const promises = files.map((file) => {
|
|
778
|
+
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
779
|
+
if (file.override) {
|
|
780
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
781
|
+
}
|
|
782
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
783
|
+
});
|
|
784
|
+
const resolvedFiles = await Promise.all(promises);
|
|
785
|
+
if (files.length > 1) {
|
|
786
|
+
return resolvedFiles;
|
|
787
|
+
}
|
|
788
|
+
return resolvedFiles[0];
|
|
789
|
+
}
|
|
790
|
+
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
791
|
+
const barrelManager = new BarrelManager(options);
|
|
792
|
+
const files = barrelManager.getIndexes(root, extName);
|
|
793
|
+
if (!files) {
|
|
794
|
+
return void 0;
|
|
795
|
+
}
|
|
796
|
+
return await Promise.all(
|
|
797
|
+
files.map((file) => {
|
|
798
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
799
|
+
...file,
|
|
800
|
+
meta: meta ? meta : file.meta
|
|
801
|
+
});
|
|
802
|
+
})
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
getCacheByUUID(UUID) {
|
|
806
|
+
let cache;
|
|
807
|
+
__privateGet(this, _cache).forEach((files) => {
|
|
808
|
+
cache = files.find((item) => item.id === UUID);
|
|
809
|
+
});
|
|
810
|
+
return cache;
|
|
811
|
+
}
|
|
812
|
+
get(path2) {
|
|
813
|
+
return __privateGet(this, _cache).get(path2);
|
|
814
|
+
}
|
|
815
|
+
remove(path2) {
|
|
816
|
+
const cacheItem = this.get(path2);
|
|
817
|
+
if (!cacheItem) {
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
__privateGet(this, _cache).delete(path2);
|
|
821
|
+
}
|
|
822
|
+
async write(...params) {
|
|
823
|
+
if (!__privateGet(this, _isWriting)) {
|
|
824
|
+
__privateSet(this, _isWriting, true);
|
|
825
|
+
const text = await write(...params);
|
|
826
|
+
__privateSet(this, _isWriting, false);
|
|
827
|
+
return text;
|
|
828
|
+
}
|
|
829
|
+
await timeout(__privateGet(this, _timeout));
|
|
830
|
+
return this.write(...params);
|
|
831
|
+
}
|
|
832
|
+
async read(...params) {
|
|
833
|
+
return read(...params);
|
|
834
|
+
}
|
|
835
|
+
// statics
|
|
836
|
+
static getSource(file) {
|
|
837
|
+
if (!_FileManager.isExtensionAllowed(file.baseName)) {
|
|
838
|
+
return file.source;
|
|
839
|
+
}
|
|
840
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
841
|
+
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
842
|
+
const importNodes = imports.map((item) => factory__namespace.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
843
|
+
const exportNodes = exports.map(
|
|
844
|
+
(item) => factory__namespace.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
|
|
845
|
+
);
|
|
846
|
+
return [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
847
|
+
}
|
|
848
|
+
static combineFiles(files) {
|
|
849
|
+
return files.filter(Boolean).reduce((acc, file) => {
|
|
850
|
+
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
851
|
+
if (prevIndex === -1) {
|
|
852
|
+
return [...acc, file];
|
|
853
|
+
}
|
|
854
|
+
const prev = acc[prevIndex];
|
|
855
|
+
if (prev && file.override) {
|
|
856
|
+
acc[prevIndex] = {
|
|
857
|
+
imports: [],
|
|
858
|
+
exports: [],
|
|
859
|
+
...file
|
|
860
|
+
};
|
|
861
|
+
return acc;
|
|
862
|
+
}
|
|
863
|
+
if (prev) {
|
|
864
|
+
acc[prevIndex] = {
|
|
865
|
+
...file,
|
|
866
|
+
source: prev.source && file.source ? `${prev.source}
|
|
867
|
+
${file.source}` : "",
|
|
868
|
+
imports: [...prev.imports || [], ...file.imports || []],
|
|
869
|
+
exports: [...prev.exports || [], ...file.exports || []],
|
|
870
|
+
env: { ...prev.env || {}, ...file.env || {} }
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
return acc;
|
|
874
|
+
}, []);
|
|
875
|
+
}
|
|
876
|
+
static getMode(path2) {
|
|
877
|
+
if (!path2) {
|
|
878
|
+
return "directory";
|
|
879
|
+
}
|
|
880
|
+
return path.extname(path2) ? "file" : "directory";
|
|
881
|
+
}
|
|
882
|
+
static get extensions() {
|
|
883
|
+
return [".js", ".ts", ".tsx"];
|
|
884
|
+
}
|
|
885
|
+
static isExtensionAllowed(baseName) {
|
|
886
|
+
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
_cache = new WeakMap();
|
|
890
|
+
_task = new WeakMap();
|
|
891
|
+
_isWriting = new WeakMap();
|
|
892
|
+
_timeout = new WeakMap();
|
|
893
|
+
_queue2 = new WeakMap();
|
|
894
|
+
_validate = new WeakSet();
|
|
895
|
+
validate_fn = function(file) {
|
|
896
|
+
if (!file.validate) {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
900
|
+
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
_add = new WeakSet();
|
|
904
|
+
add_fn = async function(file) {
|
|
905
|
+
const controller = new AbortController();
|
|
906
|
+
const resolvedFile = { id: crypto__default.default.randomUUID(), ...file };
|
|
907
|
+
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
908
|
+
if (__privateGet(this, _queue2)) {
|
|
909
|
+
await __privateGet(this, _queue2).run(
|
|
910
|
+
async () => {
|
|
911
|
+
var _a;
|
|
912
|
+
return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
|
|
913
|
+
},
|
|
914
|
+
{ controller }
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
return resolvedFile;
|
|
918
|
+
};
|
|
919
|
+
_addOrAppend = new WeakSet();
|
|
920
|
+
addOrAppend_fn = async function(file) {
|
|
921
|
+
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
922
|
+
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
923
|
+
if (previousCache) {
|
|
924
|
+
__privateGet(this, _cache).delete(previousCache.path);
|
|
925
|
+
return __privateMethod(this, _add, add_fn).call(this, {
|
|
926
|
+
...file,
|
|
927
|
+
source: previousCache.source && file.source ? `${previousCache.source}
|
|
928
|
+
${file.source}` : "",
|
|
929
|
+
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
930
|
+
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
931
|
+
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
935
|
+
};
|
|
936
|
+
var FileManager = _FileManager;
|
|
937
|
+
function combineExports(exports) {
|
|
938
|
+
const combinedExports = naturalOrderby.orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
939
|
+
const name = curr.name;
|
|
940
|
+
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
941
|
+
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
942
|
+
if (prevByPathAndIsTypeOnly) {
|
|
943
|
+
return prev;
|
|
944
|
+
}
|
|
945
|
+
const uniquePrev = prev.findLast(
|
|
946
|
+
(imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
947
|
+
);
|
|
948
|
+
if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
|
|
949
|
+
return prev;
|
|
950
|
+
}
|
|
951
|
+
if (!prevByPath) {
|
|
952
|
+
return [
|
|
953
|
+
...prev,
|
|
954
|
+
{
|
|
955
|
+
...curr,
|
|
956
|
+
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
957
|
+
}
|
|
958
|
+
];
|
|
959
|
+
}
|
|
960
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
961
|
+
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
|
|
962
|
+
return prev;
|
|
963
|
+
}
|
|
964
|
+
return [...prev, curr];
|
|
965
|
+
}, []);
|
|
966
|
+
return naturalOrderby.orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
967
|
+
}
|
|
968
|
+
function combineImports(imports, exports, source) {
|
|
969
|
+
const combinedImports = naturalOrderby.orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
970
|
+
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
971
|
+
const hasImportInSource = (importName) => {
|
|
972
|
+
if (!source) {
|
|
973
|
+
return true;
|
|
974
|
+
}
|
|
975
|
+
const checker = (name2) => name2 && !!source.includes(name2);
|
|
976
|
+
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
977
|
+
};
|
|
978
|
+
if (Array.isArray(name)) {
|
|
979
|
+
name = name.filter((item) => hasImportInSource(item));
|
|
980
|
+
}
|
|
981
|
+
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
982
|
+
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
983
|
+
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
984
|
+
if (prevByPathNameAndIsTypeOnly) {
|
|
985
|
+
return prev;
|
|
986
|
+
}
|
|
987
|
+
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
988
|
+
return prev;
|
|
989
|
+
}
|
|
990
|
+
if (!prevByPath) {
|
|
991
|
+
return [
|
|
992
|
+
...prev,
|
|
993
|
+
{
|
|
994
|
+
...curr,
|
|
995
|
+
name
|
|
996
|
+
}
|
|
997
|
+
];
|
|
998
|
+
}
|
|
999
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
1000
|
+
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
|
|
1001
|
+
return prev;
|
|
1002
|
+
}
|
|
1003
|
+
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
1004
|
+
return prev;
|
|
1005
|
+
}
|
|
1006
|
+
return [...prev, curr];
|
|
1007
|
+
}, []);
|
|
1008
|
+
return naturalOrderby.orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
1009
|
+
}
|
|
1010
|
+
function getEnvSource(source, env) {
|
|
1011
|
+
if (!env) {
|
|
1012
|
+
return source;
|
|
1013
|
+
}
|
|
1014
|
+
const keys = Object.keys(env);
|
|
1015
|
+
if (!keys.length) {
|
|
1016
|
+
return source;
|
|
1017
|
+
}
|
|
1018
|
+
return keys.reduce((prev, key) => {
|
|
1019
|
+
const environmentValue = env[key];
|
|
1020
|
+
const replaceBy = environmentValue ? `'${environmentValue.replaceAll('"', "")?.replaceAll("'", "")}'` : "undefined";
|
|
1021
|
+
if (key.toUpperCase() !== key) {
|
|
1022
|
+
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
1023
|
+
}
|
|
1024
|
+
if (typeof replaceBy === "string") {
|
|
1025
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
1026
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
1027
|
+
`, "ig"), ""), replaceBy, key });
|
|
1028
|
+
}
|
|
1029
|
+
return prev;
|
|
1030
|
+
}, source);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// src/utils/TreeNode.ts
|
|
1034
|
+
var TreeNode = class _TreeNode {
|
|
1035
|
+
constructor(data, parent) {
|
|
1036
|
+
this.children = [];
|
|
1037
|
+
this.data = data;
|
|
1038
|
+
this.parent = parent;
|
|
1039
|
+
return this;
|
|
1040
|
+
}
|
|
1041
|
+
addChild(data) {
|
|
1042
|
+
const child = new _TreeNode(data, this);
|
|
1043
|
+
if (!this.children) {
|
|
1044
|
+
this.children = [];
|
|
1045
|
+
}
|
|
1046
|
+
this.children.push(child);
|
|
1047
|
+
return child;
|
|
1048
|
+
}
|
|
1049
|
+
find(data) {
|
|
1050
|
+
if (!data) {
|
|
1051
|
+
return null;
|
|
1052
|
+
}
|
|
1053
|
+
if (data === this.data) {
|
|
1054
|
+
return this;
|
|
1055
|
+
}
|
|
1056
|
+
if (this.children?.length) {
|
|
1057
|
+
for (let i = 0, { length } = this.children, target = null; i < length; i++) {
|
|
1058
|
+
target = this.children[i].find(data);
|
|
1059
|
+
if (target) {
|
|
1060
|
+
return target;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return null;
|
|
1065
|
+
}
|
|
1066
|
+
get leaves() {
|
|
1067
|
+
if (!this.children || this.children.length === 0) {
|
|
1068
|
+
return [this];
|
|
1069
|
+
}
|
|
1070
|
+
const leaves = [];
|
|
1071
|
+
if (this.children) {
|
|
1072
|
+
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
1073
|
+
leaves.push.apply(leaves, this.children[i].leaves);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return leaves;
|
|
1077
|
+
}
|
|
1078
|
+
get root() {
|
|
1079
|
+
if (!this.parent) {
|
|
1080
|
+
return this;
|
|
1081
|
+
}
|
|
1082
|
+
return this.parent.root;
|
|
1083
|
+
}
|
|
1084
|
+
forEach(callback) {
|
|
1085
|
+
if (typeof callback !== "function") {
|
|
1086
|
+
throw new TypeError("forEach() callback must be a function");
|
|
1087
|
+
}
|
|
1088
|
+
callback(this);
|
|
1089
|
+
if (this.children) {
|
|
1090
|
+
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
1091
|
+
this.children[i].forEach(callback);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return this;
|
|
1095
|
+
}
|
|
1096
|
+
static build(path2, options = {}) {
|
|
1097
|
+
try {
|
|
1098
|
+
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
1099
|
+
const filteredTree = dirTree__default.default(path2, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
|
|
1100
|
+
if (!filteredTree) {
|
|
1101
|
+
return null;
|
|
1102
|
+
}
|
|
1103
|
+
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
|
|
1104
|
+
const recurse = (node, item) => {
|
|
1105
|
+
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
|
|
1106
|
+
if (item.children?.length) {
|
|
1107
|
+
item.children?.forEach((child) => {
|
|
1108
|
+
recurse(subNode, child);
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
filteredTree.children?.forEach((child) => recurse(treeNode, child));
|
|
1113
|
+
return treeNode;
|
|
1114
|
+
} catch (e) {
|
|
1115
|
+
throw new Error("Something went wrong with creating index files with the TreehNode class", { cause: e });
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
// src/utils/uniqueName.ts
|
|
1121
|
+
function getUniqueName(originalName, data) {
|
|
1122
|
+
let used = data[originalName] || 0;
|
|
1123
|
+
if (used) {
|
|
1124
|
+
data[originalName] = ++used;
|
|
1125
|
+
originalName += used;
|
|
1126
|
+
}
|
|
1127
|
+
data[originalName] = 1;
|
|
1128
|
+
return originalName;
|
|
1129
|
+
}
|
|
1130
|
+
function setUniqueName(originalName, data) {
|
|
1131
|
+
let used = data[originalName] || 0;
|
|
1132
|
+
if (used) {
|
|
1133
|
+
data[originalName] = ++used;
|
|
1134
|
+
return originalName;
|
|
1135
|
+
}
|
|
1136
|
+
data[originalName] = 1;
|
|
1137
|
+
return originalName;
|
|
1138
|
+
}
|
|
1139
|
+
var URLPath = class {
|
|
1140
|
+
constructor(path2) {
|
|
1141
|
+
this.path = path2;
|
|
1142
|
+
return this;
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
1146
|
+
* @example /pet/{petId} => /pet/:petId
|
|
1147
|
+
*/
|
|
1148
|
+
get URL() {
|
|
1149
|
+
return this.toURLPath();
|
|
1150
|
+
}
|
|
1151
|
+
get isURL() {
|
|
1152
|
+
try {
|
|
1153
|
+
const url = new URL(this.path);
|
|
1154
|
+
if (url?.href) {
|
|
1155
|
+
return true;
|
|
1156
|
+
}
|
|
1157
|
+
} catch (error) {
|
|
1158
|
+
return false;
|
|
1159
|
+
}
|
|
1160
|
+
return false;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
1164
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
1165
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
1166
|
+
* @example /account/userID => `/account/${userId}`
|
|
1167
|
+
*/
|
|
1168
|
+
get template() {
|
|
1169
|
+
return this.toTemplateString();
|
|
1170
|
+
}
|
|
1171
|
+
get object() {
|
|
1172
|
+
return this.toObject();
|
|
1173
|
+
}
|
|
1174
|
+
get params() {
|
|
1175
|
+
return this.getParams();
|
|
1176
|
+
}
|
|
1177
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
1178
|
+
const object = {
|
|
1179
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
1180
|
+
params: this.getParams()
|
|
1181
|
+
};
|
|
1182
|
+
if (stringify) {
|
|
1183
|
+
if (type !== "template") {
|
|
1184
|
+
throw new Error("Type should be `template` when using stringiyf");
|
|
1185
|
+
}
|
|
1186
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
1187
|
+
}
|
|
1188
|
+
return object;
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
1192
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
1193
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
1194
|
+
* @example /account/userID => `/account/${userId}`
|
|
1195
|
+
*/
|
|
1196
|
+
toTemplateString(replacer) {
|
|
1197
|
+
const regex = /{(\w|-)*}/g;
|
|
1198
|
+
const found = this.path.match(regex);
|
|
1199
|
+
let newPath = this.path.replaceAll("{", "${");
|
|
1200
|
+
if (found) {
|
|
1201
|
+
newPath = found.reduce((prev, curr) => {
|
|
1202
|
+
const pathParam = replacer ? replacer(changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
1203
|
+
const replacement = `\${${pathParam}}`;
|
|
1204
|
+
return prev.replace(curr, replacement);
|
|
1205
|
+
}, this.path);
|
|
1206
|
+
}
|
|
1207
|
+
return `\`${newPath}\``;
|
|
1208
|
+
}
|
|
1209
|
+
getParams(replacer) {
|
|
1210
|
+
const regex = /{(\w|-)*}/g;
|
|
1211
|
+
const found = this.path.match(regex);
|
|
1212
|
+
if (!found) {
|
|
1213
|
+
return void 0;
|
|
1214
|
+
}
|
|
1215
|
+
const params = {};
|
|
1216
|
+
found.forEach((item) => {
|
|
1217
|
+
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
1218
|
+
const pathParam = replacer ? replacer(changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
1219
|
+
params[pathParam] = pathParam;
|
|
1220
|
+
}, this.path);
|
|
1221
|
+
return params;
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
1225
|
+
* @example /pet/{petId} => /pet/:petId
|
|
1226
|
+
*/
|
|
1227
|
+
toURLPath() {
|
|
1228
|
+
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
|
|
1232
|
+
Object.defineProperty(exports, 'pc', {
|
|
1233
|
+
enumerable: true,
|
|
1234
|
+
get: function () { return pc2__default.default; }
|
|
1235
|
+
});
|
|
1236
|
+
exports.FunctionParams = FunctionParams;
|
|
1237
|
+
exports.LogLevel = LogLevel;
|
|
1238
|
+
exports.Queue = Queue;
|
|
1239
|
+
exports.TreeNode = TreeNode;
|
|
1240
|
+
exports.URLPath = URLPath;
|
|
1241
|
+
exports.clean = clean;
|
|
1242
|
+
exports.createLogger = createLogger;
|
|
1243
|
+
exports.createPluginCache = createPluginCache;
|
|
1244
|
+
exports.getRelativePath = getRelativePath;
|
|
1245
|
+
exports.getUniqueName = getUniqueName;
|
|
1246
|
+
exports.isPromise = isPromise;
|
|
1247
|
+
exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
|
|
1248
|
+
exports.isPromiseRejectedResult = isPromiseRejectedResult;
|
|
1249
|
+
exports.randomColour = randomColour;
|
|
1250
|
+
exports.randomPicoColour = randomPicoColour;
|
|
1251
|
+
exports.read = read;
|
|
1252
|
+
exports.readSync = readSync;
|
|
1253
|
+
exports.renderTemplate = renderTemplate;
|
|
1254
|
+
exports.setUniqueName = setUniqueName;
|
|
1255
|
+
exports.throttle = throttle;
|
|
1256
|
+
exports.timeout = timeout;
|
|
1257
|
+
exports.transformers = transformers;
|
|
1258
|
+
exports.write = write;
|
|
1259
|
+
//# sourceMappingURL=out.js.map
|
|
1260
|
+
//# sourceMappingURL=utils.cjs.map
|