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