@catbee/utils 0.0.8-next.0 → 0.0.8-rc.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 -2
- package/build/esm/config.d.ts +122 -0
- package/build/esm/config.js +133 -0
- package/build/esm/config.js.map +1 -0
- package/build/esm/index.d.ts +27 -0
- package/build/esm/index.js +50 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/servers/server.builder.d.ts +508 -0
- package/build/esm/servers/server.builder.js +702 -0
- package/build/esm/servers/server.builder.js.map +1 -0
- package/build/esm/servers/server.d.ts +256 -0
- package/build/esm/servers/server.js +1248 -0
- package/build/esm/servers/server.js.map +1 -0
- package/build/esm/types/api-response.d.ts +152 -0
- package/build/esm/types/api-response.js +34 -0
- package/build/esm/types/api-response.js.map +1 -0
- package/build/esm/types/index.d.ts +125 -0
- package/build/esm/types/index.js +25 -0
- package/build/esm/types/index.js.map +1 -0
- package/build/esm/types/server.d.ts +268 -0
- package/build/esm/types/server.js +25 -0
- package/build/esm/types/server.js.map +1 -0
- package/build/esm/utils/array.utils.d.ts +168 -0
- package/build/esm/utils/array.utils.js +382 -0
- package/build/esm/utils/array.utils.js.map +1 -0
- package/build/esm/utils/async.utils.d.ts +265 -0
- package/build/esm/utils/async.utils.js +896 -0
- package/build/esm/utils/async.utils.js.map +1 -0
- package/build/esm/utils/cache.utils.d.ts +153 -0
- package/build/esm/utils/cache.utils.js +499 -0
- package/build/esm/utils/cache.utils.js.map +1 -0
- package/build/esm/utils/context-store.utils.d.ts +189 -0
- package/build/esm/utils/context-store.utils.js +307 -0
- package/build/esm/utils/context-store.utils.js.map +1 -0
- package/build/esm/utils/crypto.utils.d.ts +160 -0
- package/build/esm/utils/crypto.utils.js +375 -0
- package/build/esm/utils/crypto.utils.js.map +1 -0
- package/build/esm/utils/date.utils.d.ts +159 -0
- package/build/esm/utils/date.utils.js +389 -0
- package/build/esm/utils/date.utils.js.map +1 -0
- package/build/esm/utils/decorators.utils.d.ts +508 -0
- package/build/esm/utils/decorators.utils.js +1057 -0
- package/build/esm/utils/decorators.utils.js.map +1 -0
- package/build/esm/utils/dir.utils.d.ts +196 -0
- package/build/esm/utils/dir.utils.js +998 -0
- package/build/esm/utils/dir.utils.js.map +1 -0
- package/build/esm/utils/env.utils.d.ts +377 -0
- package/build/esm/utils/env.utils.js +873 -0
- package/build/esm/utils/env.utils.js.map +1 -0
- package/build/esm/utils/exception.utils.d.ts +230 -0
- package/build/esm/utils/exception.utils.js +559 -0
- package/build/esm/utils/exception.utils.js.map +1 -0
- package/build/esm/utils/fs.utils.d.ts +164 -0
- package/build/esm/utils/fs.utils.js +580 -0
- package/build/esm/utils/fs.utils.js.map +1 -0
- package/build/esm/utils/http-status-codes.d.ts +266 -0
- package/build/esm/utils/http-status-codes.js +295 -0
- package/build/esm/utils/http-status-codes.js.map +1 -0
- package/build/esm/utils/id.utils.d.ts +36 -0
- package/build/esm/utils/id.utils.js +87 -0
- package/build/esm/utils/id.utils.js.map +1 -0
- package/build/esm/utils/logger.utils.d.ts +160 -0
- package/build/esm/utils/logger.utils.js +341 -0
- package/build/esm/utils/logger.utils.js.map +1 -0
- package/build/esm/utils/middleware.utils.d.ts +100 -0
- package/build/esm/utils/middleware.utils.js +325 -0
- package/build/esm/utils/middleware.utils.js.map +1 -0
- package/build/esm/utils/obj.utils.d.ts +124 -0
- package/build/esm/utils/obj.utils.js +519 -0
- package/build/esm/utils/obj.utils.js.map +1 -0
- package/build/esm/utils/performance.utils.d.ts +136 -0
- package/build/esm/utils/performance.utils.js +376 -0
- package/build/esm/utils/performance.utils.js.map +1 -0
- package/build/esm/utils/request.utils.d.ts +86 -0
- package/build/esm/utils/request.utils.js +223 -0
- package/build/esm/utils/request.utils.js.map +1 -0
- package/build/esm/utils/response.utils.d.ts +163 -0
- package/build/esm/utils/response.utils.js +284 -0
- package/build/esm/utils/response.utils.js.map +1 -0
- package/build/esm/utils/stream.utils.d.ts +88 -0
- package/build/esm/utils/stream.utils.js +284 -0
- package/build/esm/utils/stream.utils.js.map +1 -0
- package/build/esm/utils/string.utils.d.ts +93 -0
- package/build/esm/utils/string.utils.js +169 -0
- package/build/esm/utils/string.utils.js.map +1 -0
- package/build/esm/utils/type.utils.d.ts +90 -0
- package/build/esm/utils/type.utils.js +190 -0
- package/build/esm/utils/type.utils.js.map +1 -0
- package/build/esm/utils/url.utils.d.ts +141 -0
- package/build/esm/utils/url.utils.js +381 -0
- package/build/esm/utils/url.utils.js.map +1 -0
- package/build/esm/utils/validate.utils.d.ts +177 -0
- package/build/esm/utils/validate.utils.js +336 -0
- package/build/esm/utils/validate.utils.js.map +1 -0
- package/build/esnext/config.d.ts +122 -0
- package/build/esnext/config.js +133 -0
- package/build/esnext/config.js.map +1 -0
- package/build/esnext/index.d.ts +27 -0
- package/build/esnext/index.js +50 -0
- package/build/esnext/index.js.map +1 -0
- package/build/esnext/servers/server.builder.d.ts +508 -0
- package/build/esnext/servers/server.builder.js +657 -0
- package/build/esnext/servers/server.builder.js.map +1 -0
- package/build/esnext/servers/server.d.ts +256 -0
- package/build/esnext/servers/server.js +955 -0
- package/build/esnext/servers/server.js.map +1 -0
- package/build/esnext/types/api-response.d.ts +152 -0
- package/build/esnext/types/api-response.js +34 -0
- package/build/esnext/types/api-response.js.map +1 -0
- package/build/esnext/types/index.d.ts +125 -0
- package/build/esnext/types/index.js +25 -0
- package/build/esnext/types/index.js.map +1 -0
- package/build/esnext/types/server.d.ts +268 -0
- package/build/esnext/types/server.js +25 -0
- package/build/esnext/types/server.js.map +1 -0
- package/build/esnext/utils/array.utils.d.ts +168 -0
- package/build/esnext/utils/array.utils.js +345 -0
- package/build/esnext/utils/array.utils.js.map +1 -0
- package/build/esnext/utils/async.utils.d.ts +265 -0
- package/build/esnext/utils/async.utils.js +620 -0
- package/build/esnext/utils/async.utils.js.map +1 -0
- package/build/esnext/utils/cache.utils.d.ts +153 -0
- package/build/esnext/utils/cache.utils.js +293 -0
- package/build/esnext/utils/cache.utils.js.map +1 -0
- package/build/esnext/utils/context-store.utils.d.ts +189 -0
- package/build/esnext/utils/context-store.utils.js +289 -0
- package/build/esnext/utils/context-store.utils.js.map +1 -0
- package/build/esnext/utils/crypto.utils.d.ts +160 -0
- package/build/esnext/utils/crypto.utils.js +276 -0
- package/build/esnext/utils/crypto.utils.js.map +1 -0
- package/build/esnext/utils/date.utils.d.ts +159 -0
- package/build/esnext/utils/date.utils.js +384 -0
- package/build/esnext/utils/date.utils.js.map +1 -0
- package/build/esnext/utils/decorators.utils.d.ts +508 -0
- package/build/esnext/utils/decorators.utils.js +877 -0
- package/build/esnext/utils/decorators.utils.js.map +1 -0
- package/build/esnext/utils/dir.utils.d.ts +196 -0
- package/build/esnext/utils/dir.utils.js +477 -0
- package/build/esnext/utils/dir.utils.js.map +1 -0
- package/build/esnext/utils/env.utils.d.ts +377 -0
- package/build/esnext/utils/env.utils.js +785 -0
- package/build/esnext/utils/env.utils.js.map +1 -0
- package/build/esnext/utils/exception.utils.d.ts +230 -0
- package/build/esnext/utils/exception.utils.js +381 -0
- package/build/esnext/utils/exception.utils.js.map +1 -0
- package/build/esnext/utils/fs.utils.d.ts +164 -0
- package/build/esnext/utils/fs.utils.js +349 -0
- package/build/esnext/utils/fs.utils.js.map +1 -0
- package/build/esnext/utils/http-status-codes.d.ts +266 -0
- package/build/esnext/utils/http-status-codes.js +295 -0
- package/build/esnext/utils/http-status-codes.js.map +1 -0
- package/build/esnext/utils/id.utils.d.ts +36 -0
- package/build/esnext/utils/id.utils.js +84 -0
- package/build/esnext/utils/id.utils.js.map +1 -0
- package/build/esnext/utils/logger.utils.d.ts +160 -0
- package/build/esnext/utils/logger.utils.js +300 -0
- package/build/esnext/utils/logger.utils.js.map +1 -0
- package/build/esnext/utils/middleware.utils.d.ts +100 -0
- package/build/esnext/utils/middleware.utils.js +236 -0
- package/build/esnext/utils/middleware.utils.js.map +1 -0
- package/build/esnext/utils/obj.utils.d.ts +124 -0
- package/build/esnext/utils/obj.utils.js +413 -0
- package/build/esnext/utils/obj.utils.js.map +1 -0
- package/build/esnext/utils/performance.utils.d.ts +136 -0
- package/build/esnext/utils/performance.utils.js +271 -0
- package/build/esnext/utils/performance.utils.js.map +1 -0
- package/build/esnext/utils/request.utils.d.ts +86 -0
- package/build/esnext/utils/request.utils.js +186 -0
- package/build/esnext/utils/request.utils.js.map +1 -0
- package/build/esnext/utils/response.utils.d.ts +163 -0
- package/build/esnext/utils/response.utils.js +247 -0
- package/build/esnext/utils/response.utils.js.map +1 -0
- package/build/esnext/utils/stream.utils.d.ts +88 -0
- package/build/esnext/utils/stream.utils.js +210 -0
- package/build/esnext/utils/stream.utils.js.map +1 -0
- package/build/esnext/utils/string.utils.d.ts +93 -0
- package/build/esnext/utils/string.utils.js +165 -0
- package/build/esnext/utils/string.utils.js.map +1 -0
- package/build/esnext/utils/type.utils.d.ts +90 -0
- package/build/esnext/utils/type.utils.js +187 -0
- package/build/esnext/utils/type.utils.js.map +1 -0
- package/build/esnext/utils/url.utils.d.ts +141 -0
- package/build/esnext/utils/url.utils.js +304 -0
- package/build/esnext/utils/url.utils.js.map +1 -0
- package/build/esnext/utils/validate.utils.d.ts +177 -0
- package/build/esnext/utils/validate.utils.js +320 -0
- package/build/esnext/utils/validate.utils.js.map +1 -0
- package/build/src/config.d.ts +122 -0
- package/build/src/config.js +138 -0
- package/build/src/config.js.map +1 -0
- package/build/src/index.d.ts +27 -0
- package/build/src/index.js +69 -0
- package/build/src/index.js.map +1 -0
- package/build/src/servers/server.builder.d.ts +508 -0
- package/build/src/servers/server.builder.js +661 -0
- package/build/src/servers/server.builder.js.map +1 -0
- package/build/src/servers/server.d.ts +256 -0
- package/build/src/servers/server.js +962 -0
- package/build/src/servers/server.js.map +1 -0
- package/build/src/types/api-response.d.ts +152 -0
- package/build/src/types/api-response.js +37 -0
- package/build/src/types/api-response.js.map +1 -0
- package/build/src/types/index.d.ts +125 -0
- package/build/src/types/index.js +26 -0
- package/build/src/types/index.js.map +1 -0
- package/build/src/types/server.d.ts +268 -0
- package/build/src/types/server.js +26 -0
- package/build/src/types/server.js.map +1 -0
- package/build/src/utils/array.utils.d.ts +168 -0
- package/build/src/utils/array.utils.js +364 -0
- package/build/src/utils/array.utils.js.map +1 -0
- package/build/src/utils/async.utils.d.ts +265 -0
- package/build/src/utils/async.utils.js +641 -0
- package/build/src/utils/async.utils.js.map +1 -0
- package/build/src/utils/cache.utils.d.ts +153 -0
- package/build/src/utils/cache.utils.js +297 -0
- package/build/src/utils/cache.utils.js.map +1 -0
- package/build/src/utils/context-store.utils.d.ts +189 -0
- package/build/src/utils/context-store.utils.js +296 -0
- package/build/src/utils/context-store.utils.js.map +1 -0
- package/build/src/utils/crypto.utils.d.ts +160 -0
- package/build/src/utils/crypto.utils.js +293 -0
- package/build/src/utils/crypto.utils.js.map +1 -0
- package/build/src/utils/date.utils.d.ts +159 -0
- package/build/src/utils/date.utils.js +396 -0
- package/build/src/utils/date.utils.js.map +1 -0
- package/build/src/utils/decorators.utils.d.ts +508 -0
- package/build/src/utils/decorators.utils.js +896 -0
- package/build/src/utils/decorators.utils.js.map +1 -0
- package/build/src/utils/dir.utils.d.ts +196 -0
- package/build/src/utils/dir.utils.js +501 -0
- package/build/src/utils/dir.utils.js.map +1 -0
- package/build/src/utils/env.utils.d.ts +377 -0
- package/build/src/utils/env.utils.js +789 -0
- package/build/src/utils/env.utils.js.map +1 -0
- package/build/src/utils/exception.utils.d.ts +230 -0
- package/build/src/utils/exception.utils.js +407 -0
- package/build/src/utils/exception.utils.js.map +1 -0
- package/build/src/utils/fs.utils.d.ts +164 -0
- package/build/src/utils/fs.utils.js +372 -0
- package/build/src/utils/fs.utils.js.map +1 -0
- package/build/src/utils/http-status-codes.d.ts +266 -0
- package/build/src/utils/http-status-codes.js +298 -0
- package/build/src/utils/http-status-codes.js.map +1 -0
- package/build/src/utils/id.utils.d.ts +36 -0
- package/build/src/utils/id.utils.js +91 -0
- package/build/src/utils/id.utils.js.map +1 -0
- package/build/src/utils/logger.utils.d.ts +160 -0
- package/build/src/utils/logger.utils.js +346 -0
- package/build/src/utils/logger.utils.js.map +1 -0
- package/build/src/utils/middleware.utils.d.ts +100 -0
- package/build/src/utils/middleware.utils.js +244 -0
- package/build/src/utils/middleware.utils.js.map +1 -0
- package/build/src/utils/obj.utils.d.ts +124 -0
- package/build/src/utils/obj.utils.js +429 -0
- package/build/src/utils/obj.utils.js.map +1 -0
- package/build/src/utils/performance.utils.d.ts +136 -0
- package/build/src/utils/performance.utils.js +278 -0
- package/build/src/utils/performance.utils.js.map +1 -0
- package/build/src/utils/request.utils.d.ts +86 -0
- package/build/src/utils/request.utils.js +195 -0
- package/build/src/utils/request.utils.js.map +1 -0
- package/build/src/utils/response.utils.d.ts +163 -0
- package/build/src/utils/response.utils.js +260 -0
- package/build/src/utils/response.utils.js.map +1 -0
- package/build/src/utils/stream.utils.d.ts +88 -0
- package/build/src/utils/stream.utils.js +218 -0
- package/build/src/utils/stream.utils.js.map +1 -0
- package/build/src/utils/string.utils.d.ts +93 -0
- package/build/src/utils/string.utils.js +179 -0
- package/build/src/utils/string.utils.js.map +1 -0
- package/build/src/utils/type.utils.d.ts +90 -0
- package/build/src/utils/type.utils.js +196 -0
- package/build/src/utils/type.utils.js.map +1 -0
- package/build/src/utils/url.utils.d.ts +141 -0
- package/build/src/utils/url.utils.js +317 -0
- package/build/src/utils/url.utils.js.map +1 -0
- package/build/src/utils/validate.utils.d.ts +177 -0
- package/build/src/utils/validate.utils.js +345 -0
- package/build/src/utils/validate.utils.js.map +1 -0
- package/package.json +66 -12
- package/build/index.cjs +0 -6888
- package/build/index.d.ts +0 -5242
- package/build/index.mjs +0 -6615
|
@@ -0,0 +1,998 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
var __assign = (this && this.__assign) || function () {
|
|
25
|
+
__assign = Object.assign || function(t) {
|
|
26
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
27
|
+
s = arguments[i];
|
|
28
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
29
|
+
t[p] = s[p];
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
};
|
|
33
|
+
return __assign.apply(this, arguments);
|
|
34
|
+
};
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
45
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
46
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
47
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
48
|
+
function step(op) {
|
|
49
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
50
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
51
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
52
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
53
|
+
switch (op[0]) {
|
|
54
|
+
case 0: case 1: t = op; break;
|
|
55
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
56
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
57
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
58
|
+
default:
|
|
59
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
60
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
61
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
62
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
63
|
+
if (t[2]) _.ops.pop();
|
|
64
|
+
_.trys.pop(); continue;
|
|
65
|
+
}
|
|
66
|
+
op = body.call(thisArg, _);
|
|
67
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
68
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var __values = (this && this.__values) || function(o) {
|
|
72
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
73
|
+
if (m) return m.call(o);
|
|
74
|
+
if (o && typeof o.length === "number") return {
|
|
75
|
+
next: function () {
|
|
76
|
+
if (o && i >= o.length) o = void 0;
|
|
77
|
+
return { value: o && o[i++], done: !o };
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
81
|
+
};
|
|
82
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
83
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
84
|
+
if (!m) return o;
|
|
85
|
+
var i = m.call(o), r, ar = [], e;
|
|
86
|
+
try {
|
|
87
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
88
|
+
}
|
|
89
|
+
catch (error) { e = { error: error }; }
|
|
90
|
+
finally {
|
|
91
|
+
try {
|
|
92
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
93
|
+
}
|
|
94
|
+
finally { if (e) throw e.error; }
|
|
95
|
+
}
|
|
96
|
+
return ar;
|
|
97
|
+
};
|
|
98
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
99
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
100
|
+
if (ar || !(i in from)) {
|
|
101
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
102
|
+
ar[i] = from[i];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
106
|
+
};
|
|
107
|
+
import os from 'os';
|
|
108
|
+
import fs from 'fs';
|
|
109
|
+
import fsp from 'fs/promises';
|
|
110
|
+
import path from 'path';
|
|
111
|
+
import { glob } from 'glob';
|
|
112
|
+
import { randomBytes } from 'crypto';
|
|
113
|
+
/**
|
|
114
|
+
* Ensures that a directory exists, creating parent directories if needed (like `mkdir -p`).
|
|
115
|
+
*
|
|
116
|
+
* @param {string} dirPath - The directory path to ensure.
|
|
117
|
+
* @returns {Promise<void>} Resolves when the directory exists.
|
|
118
|
+
* @throws {Error} If directory cannot be created.
|
|
119
|
+
*/
|
|
120
|
+
export function ensureDir(dirPath) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
switch (_a.label) {
|
|
124
|
+
case 0: return [4 /*yield*/, fsp.mkdir(dirPath, { recursive: true })];
|
|
125
|
+
case 1:
|
|
126
|
+
_a.sent();
|
|
127
|
+
return [2 /*return*/];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Recursively lists all files in a directory.
|
|
134
|
+
*
|
|
135
|
+
* @param {string} dirPath - The base directory.
|
|
136
|
+
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
|
|
137
|
+
* @returns {Promise<string[]>} Array of absolute file paths.
|
|
138
|
+
* @throws {Error} If the directory cannot be read.
|
|
139
|
+
*/
|
|
140
|
+
export function listFiles(dirPath_1) {
|
|
141
|
+
return __awaiter(this, arguments, void 0, function (dirPath, recursive) {
|
|
142
|
+
var entries, files, entries_1, entries_1_1, entry, fullPath, nestedFiles, e_1_1;
|
|
143
|
+
var e_1, _a;
|
|
144
|
+
if (recursive === void 0) { recursive = false; }
|
|
145
|
+
return __generator(this, function (_b) {
|
|
146
|
+
switch (_b.label) {
|
|
147
|
+
case 0: return [4 /*yield*/, fsp.readdir(dirPath, { withFileTypes: true })];
|
|
148
|
+
case 1:
|
|
149
|
+
entries = _b.sent();
|
|
150
|
+
files = [];
|
|
151
|
+
_b.label = 2;
|
|
152
|
+
case 2:
|
|
153
|
+
_b.trys.push([2, 8, 9, 10]);
|
|
154
|
+
entries_1 = __values(entries), entries_1_1 = entries_1.next();
|
|
155
|
+
_b.label = 3;
|
|
156
|
+
case 3:
|
|
157
|
+
if (!!entries_1_1.done) return [3 /*break*/, 7];
|
|
158
|
+
entry = entries_1_1.value;
|
|
159
|
+
fullPath = path.join(dirPath, entry.name);
|
|
160
|
+
if (!entry.isFile()) return [3 /*break*/, 4];
|
|
161
|
+
files.push(fullPath);
|
|
162
|
+
return [3 /*break*/, 6];
|
|
163
|
+
case 4:
|
|
164
|
+
if (!(recursive && entry.isDirectory())) return [3 /*break*/, 6];
|
|
165
|
+
return [4 /*yield*/, listFiles(fullPath, true)];
|
|
166
|
+
case 5:
|
|
167
|
+
nestedFiles = _b.sent();
|
|
168
|
+
files.push.apply(files, __spreadArray([], __read(nestedFiles), false));
|
|
169
|
+
_b.label = 6;
|
|
170
|
+
case 6:
|
|
171
|
+
entries_1_1 = entries_1.next();
|
|
172
|
+
return [3 /*break*/, 3];
|
|
173
|
+
case 7: return [3 /*break*/, 10];
|
|
174
|
+
case 8:
|
|
175
|
+
e_1_1 = _b.sent();
|
|
176
|
+
e_1 = { error: e_1_1 };
|
|
177
|
+
return [3 /*break*/, 10];
|
|
178
|
+
case 9:
|
|
179
|
+
try {
|
|
180
|
+
if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) _a.call(entries_1);
|
|
181
|
+
}
|
|
182
|
+
finally { if (e_1) throw e_1.error; }
|
|
183
|
+
return [7 /*endfinally*/];
|
|
184
|
+
case 10: return [2 /*return*/, files];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Deletes a directory and all its contents recursively (like `rm -rf`).
|
|
191
|
+
*
|
|
192
|
+
* @param {string} dirPath - Directory to delete.
|
|
193
|
+
* @returns {Promise<void>} Resolves when deletion is complete.
|
|
194
|
+
* @throws {Error} If deletion fails.
|
|
195
|
+
*/
|
|
196
|
+
export function deleteDirRecursive(dirPath) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0: return [4 /*yield*/, fsp.rm(dirPath, { recursive: true, force: true })];
|
|
201
|
+
case 1:
|
|
202
|
+
_a.sent();
|
|
203
|
+
return [2 /*return*/];
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Checks whether a given path is a directory.
|
|
210
|
+
*
|
|
211
|
+
* @param {string} pathStr - Path to check.
|
|
212
|
+
* @returns {Promise<boolean>} True if the path is a directory, else false.
|
|
213
|
+
*/
|
|
214
|
+
export function isDirectory(pathStr) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
+
var stat, _a;
|
|
217
|
+
return __generator(this, function (_b) {
|
|
218
|
+
switch (_b.label) {
|
|
219
|
+
case 0:
|
|
220
|
+
_b.trys.push([0, 2, , 3]);
|
|
221
|
+
return [4 /*yield*/, fsp.stat(pathStr)];
|
|
222
|
+
case 1:
|
|
223
|
+
stat = _b.sent();
|
|
224
|
+
return [2 /*return*/, stat.isDirectory()];
|
|
225
|
+
case 2:
|
|
226
|
+
_a = _b.sent();
|
|
227
|
+
return [2 /*return*/, false];
|
|
228
|
+
case 3: return [2 /*return*/];
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Recursively copies a directory and all its contents to a destination.
|
|
235
|
+
*
|
|
236
|
+
* @param {string} src - Source directory path.
|
|
237
|
+
* @param {string} dest - Destination directory path.
|
|
238
|
+
* @returns {Promise<void>} Resolves when copy is complete.
|
|
239
|
+
* @throws {Error} If source does not exist or copy fails.
|
|
240
|
+
*/
|
|
241
|
+
export function copyDir(src, dest) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
+
var entries, entries_2, entries_2_1, entry, srcPath, destPath, e_2_1;
|
|
244
|
+
var e_2, _a;
|
|
245
|
+
return __generator(this, function (_b) {
|
|
246
|
+
switch (_b.label) {
|
|
247
|
+
case 0: return [4 /*yield*/, ensureDir(dest)];
|
|
248
|
+
case 1:
|
|
249
|
+
_b.sent();
|
|
250
|
+
return [4 /*yield*/, fsp.readdir(src, { withFileTypes: true })];
|
|
251
|
+
case 2:
|
|
252
|
+
entries = _b.sent();
|
|
253
|
+
_b.label = 3;
|
|
254
|
+
case 3:
|
|
255
|
+
_b.trys.push([3, 10, 11, 12]);
|
|
256
|
+
entries_2 = __values(entries), entries_2_1 = entries_2.next();
|
|
257
|
+
_b.label = 4;
|
|
258
|
+
case 4:
|
|
259
|
+
if (!!entries_2_1.done) return [3 /*break*/, 9];
|
|
260
|
+
entry = entries_2_1.value;
|
|
261
|
+
srcPath = path.join(src, entry.name);
|
|
262
|
+
destPath = path.join(dest, entry.name);
|
|
263
|
+
if (!entry.isDirectory()) return [3 /*break*/, 6];
|
|
264
|
+
return [4 /*yield*/, copyDir(srcPath, destPath)];
|
|
265
|
+
case 5:
|
|
266
|
+
_b.sent();
|
|
267
|
+
return [3 /*break*/, 8];
|
|
268
|
+
case 6: return [4 /*yield*/, fsp.copyFile(srcPath, destPath)];
|
|
269
|
+
case 7:
|
|
270
|
+
_b.sent();
|
|
271
|
+
_b.label = 8;
|
|
272
|
+
case 8:
|
|
273
|
+
entries_2_1 = entries_2.next();
|
|
274
|
+
return [3 /*break*/, 4];
|
|
275
|
+
case 9: return [3 /*break*/, 12];
|
|
276
|
+
case 10:
|
|
277
|
+
e_2_1 = _b.sent();
|
|
278
|
+
e_2 = { error: e_2_1 };
|
|
279
|
+
return [3 /*break*/, 12];
|
|
280
|
+
case 11:
|
|
281
|
+
try {
|
|
282
|
+
if (entries_2_1 && !entries_2_1.done && (_a = entries_2.return)) _a.call(entries_2);
|
|
283
|
+
}
|
|
284
|
+
finally { if (e_2) throw e_2.error; }
|
|
285
|
+
return [7 /*endfinally*/];
|
|
286
|
+
case 12: return [2 /*return*/];
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Moves a directory to a new location by copying and deleting the original.
|
|
293
|
+
*
|
|
294
|
+
* @param {string} src - Source directory path.
|
|
295
|
+
* @param {string} dest - Destination directory path.
|
|
296
|
+
* @returns {Promise<void>} Resolves when move is complete.
|
|
297
|
+
* @throws {Error} If copy or deletion fails.
|
|
298
|
+
*/
|
|
299
|
+
export function moveDir(src, dest) {
|
|
300
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
+
return __generator(this, function (_a) {
|
|
302
|
+
switch (_a.label) {
|
|
303
|
+
case 0: return [4 /*yield*/, copyDir(src, dest)];
|
|
304
|
+
case 1:
|
|
305
|
+
_a.sent();
|
|
306
|
+
return [4 /*yield*/, deleteDirRecursive(src)];
|
|
307
|
+
case 2:
|
|
308
|
+
_a.sent();
|
|
309
|
+
return [2 /*return*/];
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Empties a directory by deleting all files and subdirectories inside it.
|
|
316
|
+
*
|
|
317
|
+
* @param {string} dirPath - Path to the directory to empty.
|
|
318
|
+
* @returns {Promise<void>} Resolves when the directory has been emptied.
|
|
319
|
+
* @throws {Error} If files or subdirectories cannot be removed.
|
|
320
|
+
*/
|
|
321
|
+
export function emptyDir(dirPath) {
|
|
322
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
323
|
+
var entries, entries_3, entries_3_1, entry, entryPath, e_3_1;
|
|
324
|
+
var e_3, _a;
|
|
325
|
+
return __generator(this, function (_b) {
|
|
326
|
+
switch (_b.label) {
|
|
327
|
+
case 0: return [4 /*yield*/, fsp.readdir(dirPath, { withFileTypes: true })];
|
|
328
|
+
case 1:
|
|
329
|
+
entries = _b.sent();
|
|
330
|
+
_b.label = 2;
|
|
331
|
+
case 2:
|
|
332
|
+
_b.trys.push([2, 9, 10, 11]);
|
|
333
|
+
entries_3 = __values(entries), entries_3_1 = entries_3.next();
|
|
334
|
+
_b.label = 3;
|
|
335
|
+
case 3:
|
|
336
|
+
if (!!entries_3_1.done) return [3 /*break*/, 8];
|
|
337
|
+
entry = entries_3_1.value;
|
|
338
|
+
entryPath = path.join(dirPath, entry.name);
|
|
339
|
+
if (!entry.isDirectory()) return [3 /*break*/, 5];
|
|
340
|
+
return [4 /*yield*/, fsp.rm(entryPath, { recursive: true, force: true })];
|
|
341
|
+
case 4:
|
|
342
|
+
_b.sent();
|
|
343
|
+
return [3 /*break*/, 7];
|
|
344
|
+
case 5: return [4 /*yield*/, fsp.unlink(entryPath)];
|
|
345
|
+
case 6:
|
|
346
|
+
_b.sent();
|
|
347
|
+
_b.label = 7;
|
|
348
|
+
case 7:
|
|
349
|
+
entries_3_1 = entries_3.next();
|
|
350
|
+
return [3 /*break*/, 3];
|
|
351
|
+
case 8: return [3 /*break*/, 11];
|
|
352
|
+
case 9:
|
|
353
|
+
e_3_1 = _b.sent();
|
|
354
|
+
e_3 = { error: e_3_1 };
|
|
355
|
+
return [3 /*break*/, 11];
|
|
356
|
+
case 10:
|
|
357
|
+
try {
|
|
358
|
+
if (entries_3_1 && !entries_3_1.done && (_a = entries_3.return)) _a.call(entries_3);
|
|
359
|
+
}
|
|
360
|
+
finally { if (e_3) throw e_3.error; }
|
|
361
|
+
return [7 /*endfinally*/];
|
|
362
|
+
case 11: return [2 /*return*/];
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Calculates the total size (in bytes) of all files in a directory (recursive).
|
|
369
|
+
*
|
|
370
|
+
* @param {string} dirPath - Path to the directory.
|
|
371
|
+
* @returns {Promise<number>} Total size in bytes.
|
|
372
|
+
* @throws {Error} If any file stats cannot be read.
|
|
373
|
+
*/
|
|
374
|
+
export function getDirSize(dirPath) {
|
|
375
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
376
|
+
var total, entries, entries_4, entries_4_1, entry, entryPath, _a, stat, e_4_1;
|
|
377
|
+
var e_4, _b;
|
|
378
|
+
return __generator(this, function (_c) {
|
|
379
|
+
switch (_c.label) {
|
|
380
|
+
case 0:
|
|
381
|
+
total = 0;
|
|
382
|
+
return [4 /*yield*/, fsp.readdir(dirPath, { withFileTypes: true })];
|
|
383
|
+
case 1:
|
|
384
|
+
entries = _c.sent();
|
|
385
|
+
_c.label = 2;
|
|
386
|
+
case 2:
|
|
387
|
+
_c.trys.push([2, 9, 10, 11]);
|
|
388
|
+
entries_4 = __values(entries), entries_4_1 = entries_4.next();
|
|
389
|
+
_c.label = 3;
|
|
390
|
+
case 3:
|
|
391
|
+
if (!!entries_4_1.done) return [3 /*break*/, 8];
|
|
392
|
+
entry = entries_4_1.value;
|
|
393
|
+
entryPath = path.join(dirPath, entry.name);
|
|
394
|
+
if (!entry.isDirectory()) return [3 /*break*/, 5];
|
|
395
|
+
_a = total;
|
|
396
|
+
return [4 /*yield*/, getDirSize(entryPath)];
|
|
397
|
+
case 4:
|
|
398
|
+
total = _a + _c.sent();
|
|
399
|
+
return [3 /*break*/, 7];
|
|
400
|
+
case 5: return [4 /*yield*/, fsp.stat(entryPath)];
|
|
401
|
+
case 6:
|
|
402
|
+
stat = _c.sent();
|
|
403
|
+
total += stat.size;
|
|
404
|
+
_c.label = 7;
|
|
405
|
+
case 7:
|
|
406
|
+
entries_4_1 = entries_4.next();
|
|
407
|
+
return [3 /*break*/, 3];
|
|
408
|
+
case 8: return [3 /*break*/, 11];
|
|
409
|
+
case 9:
|
|
410
|
+
e_4_1 = _c.sent();
|
|
411
|
+
e_4 = { error: e_4_1 };
|
|
412
|
+
return [3 /*break*/, 11];
|
|
413
|
+
case 10:
|
|
414
|
+
try {
|
|
415
|
+
if (entries_4_1 && !entries_4_1.done && (_b = entries_4.return)) _b.call(entries_4);
|
|
416
|
+
}
|
|
417
|
+
finally { if (e_4) throw e_4.error; }
|
|
418
|
+
return [7 /*endfinally*/];
|
|
419
|
+
case 11: return [2 /*return*/, total];
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Watches a directory for file changes and calls a callback on each event.
|
|
426
|
+
*
|
|
427
|
+
* @param {string} dirPath - Directory path to watch.
|
|
428
|
+
* @param {(eventType: "rename" | "change", filename: string | null) => void} callback - Callback for each change event.
|
|
429
|
+
* @returns {() => void} A function to stop watching the directory.
|
|
430
|
+
*/
|
|
431
|
+
export function watchDir(dirPath, callback) {
|
|
432
|
+
var watcher = fs.watch(dirPath, function (eventType, filename) {
|
|
433
|
+
callback(eventType, filename);
|
|
434
|
+
});
|
|
435
|
+
return function () { return watcher.close(); };
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Finds files matching a glob pattern.
|
|
439
|
+
*
|
|
440
|
+
* @param {string} pattern - Glob pattern to match files.
|
|
441
|
+
* @param {object} [options] - Options for glob pattern matching.
|
|
442
|
+
* @param {string} [options.cwd] - Current working directory for relative patterns.
|
|
443
|
+
* @param {boolean} [options.dot=false] - Include dotfiles in matches.
|
|
444
|
+
* @param {boolean} [options.nodir=true] - Only match files, not directories.
|
|
445
|
+
* @returns {Promise<string[]>} Array of matched file paths.
|
|
446
|
+
* @throws {Error} If pattern matching fails.
|
|
447
|
+
*/
|
|
448
|
+
export function findFilesByPattern(pattern_1) {
|
|
449
|
+
return __awaiter(this, arguments, void 0, function (pattern, options) {
|
|
450
|
+
var defaultOptions;
|
|
451
|
+
if (options === void 0) { options = {}; }
|
|
452
|
+
return __generator(this, function (_a) {
|
|
453
|
+
defaultOptions = __assign({ nodir: true }, options);
|
|
454
|
+
return [2 /*return*/, glob(pattern, defaultOptions)];
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Gets all subdirectories in a directory.
|
|
460
|
+
*
|
|
461
|
+
* @param {string} dirPath - The directory to search in.
|
|
462
|
+
* @param {boolean} [recursive=false] - Whether to include subdirectories recursively.
|
|
463
|
+
* @returns {Promise<string[]>} Array of absolute subdirectory paths.
|
|
464
|
+
* @throws {Error} If directory cannot be read.
|
|
465
|
+
*/
|
|
466
|
+
export function getSubdirectories(dirPath_1) {
|
|
467
|
+
return __awaiter(this, arguments, void 0, function (dirPath, recursive) {
|
|
468
|
+
var entries, dirs, nestedDirs;
|
|
469
|
+
if (recursive === void 0) { recursive = false; }
|
|
470
|
+
return __generator(this, function (_a) {
|
|
471
|
+
switch (_a.label) {
|
|
472
|
+
case 0: return [4 /*yield*/, fsp.readdir(dirPath, { withFileTypes: true })];
|
|
473
|
+
case 1:
|
|
474
|
+
entries = _a.sent();
|
|
475
|
+
dirs = entries.filter(function (entry) { return entry.isDirectory(); }).map(function (entry) { return path.join(dirPath, entry.name); });
|
|
476
|
+
if (!(recursive && dirs.length > 0)) return [3 /*break*/, 3];
|
|
477
|
+
return [4 /*yield*/, Promise.all(dirs.map(function (dir) { return getSubdirectories(dir, true); }))];
|
|
478
|
+
case 2:
|
|
479
|
+
nestedDirs = _a.sent();
|
|
480
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], __read(dirs), false), __read(nestedDirs.flat()), false)];
|
|
481
|
+
case 3: return [2 /*return*/, dirs];
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Ensures a directory exists and is empty.
|
|
488
|
+
*
|
|
489
|
+
* @param {string} dirPath - Path to the directory.
|
|
490
|
+
* @returns {Promise<void>} Resolves when the directory exists and is empty.
|
|
491
|
+
* @throws {Error} If directory cannot be created or emptied.
|
|
492
|
+
*/
|
|
493
|
+
export function ensureEmptyDir(dirPath) {
|
|
494
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
495
|
+
var error_1;
|
|
496
|
+
return __generator(this, function (_a) {
|
|
497
|
+
switch (_a.label) {
|
|
498
|
+
case 0: return [4 /*yield*/, isDirectory(dirPath)];
|
|
499
|
+
case 1:
|
|
500
|
+
if (!_a.sent()) return [3 /*break*/, 3];
|
|
501
|
+
return [4 /*yield*/, emptyDir(dirPath)];
|
|
502
|
+
case 2:
|
|
503
|
+
_a.sent();
|
|
504
|
+
return [3 /*break*/, 8];
|
|
505
|
+
case 3:
|
|
506
|
+
_a.trys.push([3, 5, , 6]);
|
|
507
|
+
return [4 /*yield*/, fsp.unlink(dirPath)];
|
|
508
|
+
case 4:
|
|
509
|
+
_a.sent();
|
|
510
|
+
return [3 /*break*/, 6];
|
|
511
|
+
case 5:
|
|
512
|
+
error_1 = _a.sent();
|
|
513
|
+
// Ignore if file doesn't exist
|
|
514
|
+
if (error_1.code !== 'ENOENT') {
|
|
515
|
+
throw error_1;
|
|
516
|
+
}
|
|
517
|
+
return [3 /*break*/, 6];
|
|
518
|
+
case 6: return [4 /*yield*/, ensureDir(dirPath)];
|
|
519
|
+
case 7:
|
|
520
|
+
_a.sent();
|
|
521
|
+
_a.label = 8;
|
|
522
|
+
case 8: return [2 /*return*/];
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Creates a temporary directory with optional auto-cleanup.
|
|
529
|
+
*
|
|
530
|
+
* @param {object} [options] - Options for the temporary directory.
|
|
531
|
+
* @param {string} [options.prefix='tmp-'] - Prefix for the directory name.
|
|
532
|
+
* @param {string} [options.parentDir=os.tmpdir()] - Parent directory.
|
|
533
|
+
* @param {boolean} [options.cleanup=false] - Whether to register cleanup on process exit.
|
|
534
|
+
* @returns {Promise<{ path: string, cleanup: () => Promise<void> }>} Object with directory path and cleanup function.
|
|
535
|
+
* @throws {Error} If directory cannot be created.
|
|
536
|
+
*/
|
|
537
|
+
export function createTempDir() {
|
|
538
|
+
return __awaiter(this, arguments, void 0, function (options) {
|
|
539
|
+
var prefix, parentDir, dirName, tempDirPath, cleanup;
|
|
540
|
+
var _this = this;
|
|
541
|
+
if (options === void 0) { options = {}; }
|
|
542
|
+
return __generator(this, function (_a) {
|
|
543
|
+
switch (_a.label) {
|
|
544
|
+
case 0:
|
|
545
|
+
prefix = options.prefix || 'tmp-';
|
|
546
|
+
parentDir = options.parentDir || os.tmpdir();
|
|
547
|
+
dirName = "".concat(prefix).concat(randomBytes(6).toString('hex'));
|
|
548
|
+
tempDirPath = path.join(parentDir, dirName);
|
|
549
|
+
return [4 /*yield*/, ensureDir(tempDirPath)];
|
|
550
|
+
case 1:
|
|
551
|
+
_a.sent();
|
|
552
|
+
cleanup = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
553
|
+
var _a;
|
|
554
|
+
return __generator(this, function (_b) {
|
|
555
|
+
switch (_b.label) {
|
|
556
|
+
case 0:
|
|
557
|
+
_b.trys.push([0, 2, , 3]);
|
|
558
|
+
return [4 /*yield*/, deleteDirRecursive(tempDirPath)];
|
|
559
|
+
case 1:
|
|
560
|
+
_b.sent();
|
|
561
|
+
return [3 /*break*/, 3];
|
|
562
|
+
case 2:
|
|
563
|
+
_a = _b.sent();
|
|
564
|
+
return [3 /*break*/, 3];
|
|
565
|
+
case 3: return [2 /*return*/];
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
}); };
|
|
569
|
+
if (options.cleanup) {
|
|
570
|
+
process.once('exit', function () {
|
|
571
|
+
try {
|
|
572
|
+
fs.rmSync(tempDirPath, { recursive: true, force: true });
|
|
573
|
+
}
|
|
574
|
+
catch (_a) {
|
|
575
|
+
// Ignore cleanup errors on exit
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
// Handle signals for better cleanup
|
|
579
|
+
['SIGINT', 'SIGTERM', 'SIGUSR1', 'SIGUSR2'].forEach(function (signal) {
|
|
580
|
+
process.once(signal, function () {
|
|
581
|
+
cleanup().then(function () { return process.exit(); });
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
return [2 /*return*/, { path: tempDirPath, cleanup: cleanup }];
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Finds the newest file in a directory.
|
|
592
|
+
*
|
|
593
|
+
* @param {string} dirPath - Directory to search.
|
|
594
|
+
* @param {boolean} [recursive=false] - Whether to search subdirectories.
|
|
595
|
+
* @returns {Promise<string | null>} Path to the newest file or null if no files.
|
|
596
|
+
* @throws {Error} If directory cannot be read.
|
|
597
|
+
*/
|
|
598
|
+
export function findNewestFile(dirPath_1) {
|
|
599
|
+
return __awaiter(this, arguments, void 0, function (dirPath, recursive) {
|
|
600
|
+
var files, stats;
|
|
601
|
+
var _this = this;
|
|
602
|
+
if (recursive === void 0) { recursive = false; }
|
|
603
|
+
return __generator(this, function (_a) {
|
|
604
|
+
switch (_a.label) {
|
|
605
|
+
case 0: return [4 /*yield*/, listFiles(dirPath, recursive)];
|
|
606
|
+
case 1:
|
|
607
|
+
files = _a.sent();
|
|
608
|
+
if (files.length === 0)
|
|
609
|
+
return [2 /*return*/, null];
|
|
610
|
+
return [4 /*yield*/, Promise.all(files.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
611
|
+
var _a;
|
|
612
|
+
return __generator(this, function (_b) {
|
|
613
|
+
switch (_b.label) {
|
|
614
|
+
case 0:
|
|
615
|
+
_a = {
|
|
616
|
+
path: file
|
|
617
|
+
};
|
|
618
|
+
return [4 /*yield*/, fsp.stat(file)];
|
|
619
|
+
case 1: return [2 /*return*/, (_a.mtime = (_b.sent()).mtime,
|
|
620
|
+
_a)];
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}); }))];
|
|
624
|
+
case 2:
|
|
625
|
+
stats = _a.sent();
|
|
626
|
+
return [2 /*return*/, stats.sort(function (a, b) { return b.mtime.getTime() - a.mtime.getTime(); })[0].path];
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Finds the oldest file in a directory.
|
|
633
|
+
*
|
|
634
|
+
* @param {string} dirPath - Directory to search.
|
|
635
|
+
* @param {boolean} [recursive=false] - Whether to search subdirectories.
|
|
636
|
+
* @returns {Promise<string | null>} Path to the oldest file or null if no files.
|
|
637
|
+
* @throws {Error} If directory cannot be read.
|
|
638
|
+
*/
|
|
639
|
+
export function findOldestFile(dirPath_1) {
|
|
640
|
+
return __awaiter(this, arguments, void 0, function (dirPath, recursive) {
|
|
641
|
+
var files, stats;
|
|
642
|
+
var _this = this;
|
|
643
|
+
if (recursive === void 0) { recursive = false; }
|
|
644
|
+
return __generator(this, function (_a) {
|
|
645
|
+
switch (_a.label) {
|
|
646
|
+
case 0: return [4 /*yield*/, listFiles(dirPath, recursive)];
|
|
647
|
+
case 1:
|
|
648
|
+
files = _a.sent();
|
|
649
|
+
if (files.length === 0)
|
|
650
|
+
return [2 /*return*/, null];
|
|
651
|
+
return [4 /*yield*/, Promise.all(files.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
652
|
+
var _a;
|
|
653
|
+
return __generator(this, function (_b) {
|
|
654
|
+
switch (_b.label) {
|
|
655
|
+
case 0:
|
|
656
|
+
_a = {
|
|
657
|
+
path: file
|
|
658
|
+
};
|
|
659
|
+
return [4 /*yield*/, fsp.stat(file)];
|
|
660
|
+
case 1: return [2 /*return*/, (_a.mtime = (_b.sent()).mtime,
|
|
661
|
+
_a)];
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
}); }))];
|
|
665
|
+
case 2:
|
|
666
|
+
stats = _a.sent();
|
|
667
|
+
return [2 /*return*/, stats.sort(function (a, b) { return a.mtime.getTime() - b.mtime.getTime(); })[0].path];
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Finds files or directories in a directory matching a predicate function.
|
|
674
|
+
*
|
|
675
|
+
* @param {string} dirPath - Directory to search.
|
|
676
|
+
* @param {(path: string, stat: fs.Stats) => boolean | Promise<boolean>} predicate - Function to test each path.
|
|
677
|
+
* @param {boolean} [recursive=false] - Whether to search subdirectories.
|
|
678
|
+
* @returns {Promise<string[]>} Array of matching paths.
|
|
679
|
+
* @throws {Error} If directory cannot be read.
|
|
680
|
+
*/
|
|
681
|
+
export function findInDir(dirPath_1, predicate_1) {
|
|
682
|
+
return __awaiter(this, arguments, void 0, function (dirPath, predicate, recursive) {
|
|
683
|
+
var entries, results, entries_5, entries_5_1, entry, entryPath, stat, nestedResults, e_5_1;
|
|
684
|
+
var e_5, _a;
|
|
685
|
+
if (recursive === void 0) { recursive = false; }
|
|
686
|
+
return __generator(this, function (_b) {
|
|
687
|
+
switch (_b.label) {
|
|
688
|
+
case 0: return [4 /*yield*/, fsp.readdir(dirPath, { withFileTypes: true })];
|
|
689
|
+
case 1:
|
|
690
|
+
entries = _b.sent();
|
|
691
|
+
results = [];
|
|
692
|
+
_b.label = 2;
|
|
693
|
+
case 2:
|
|
694
|
+
_b.trys.push([2, 9, 10, 11]);
|
|
695
|
+
entries_5 = __values(entries), entries_5_1 = entries_5.next();
|
|
696
|
+
_b.label = 3;
|
|
697
|
+
case 3:
|
|
698
|
+
if (!!entries_5_1.done) return [3 /*break*/, 8];
|
|
699
|
+
entry = entries_5_1.value;
|
|
700
|
+
entryPath = path.join(dirPath, entry.name);
|
|
701
|
+
return [4 /*yield*/, fsp.stat(entryPath)];
|
|
702
|
+
case 4:
|
|
703
|
+
stat = _b.sent();
|
|
704
|
+
return [4 /*yield*/, predicate(entryPath, stat)];
|
|
705
|
+
case 5:
|
|
706
|
+
if (_b.sent()) {
|
|
707
|
+
results.push(entryPath);
|
|
708
|
+
}
|
|
709
|
+
if (!(recursive && entry.isDirectory())) return [3 /*break*/, 7];
|
|
710
|
+
return [4 /*yield*/, findInDir(entryPath, predicate, true)];
|
|
711
|
+
case 6:
|
|
712
|
+
nestedResults = _b.sent();
|
|
713
|
+
results.push.apply(results, __spreadArray([], __read(nestedResults), false));
|
|
714
|
+
_b.label = 7;
|
|
715
|
+
case 7:
|
|
716
|
+
entries_5_1 = entries_5.next();
|
|
717
|
+
return [3 /*break*/, 3];
|
|
718
|
+
case 8: return [3 /*break*/, 11];
|
|
719
|
+
case 9:
|
|
720
|
+
e_5_1 = _b.sent();
|
|
721
|
+
e_5 = { error: e_5_1 };
|
|
722
|
+
return [3 /*break*/, 11];
|
|
723
|
+
case 10:
|
|
724
|
+
try {
|
|
725
|
+
if (entries_5_1 && !entries_5_1.done && (_a = entries_5.return)) _a.call(entries_5);
|
|
726
|
+
}
|
|
727
|
+
finally { if (e_5) throw e_5.error; }
|
|
728
|
+
return [7 /*endfinally*/];
|
|
729
|
+
case 11: return [2 /*return*/, results];
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Watches a directory recursively for file changes.
|
|
736
|
+
*
|
|
737
|
+
* @param {string} dirPath - Base directory path to watch.
|
|
738
|
+
* @param {(eventType: "rename" | "change", filename: string) => void} callback - Callback for each change event.
|
|
739
|
+
* @param {boolean} [includeSubdirs=true] - Whether to watch subdirectories.
|
|
740
|
+
* @returns {Promise<() => void>} A function to stop watching the directory.
|
|
741
|
+
* @throws {Error} If directory cannot be watched.
|
|
742
|
+
*/
|
|
743
|
+
export function watchDirRecursive(dirPath_1, callback_1) {
|
|
744
|
+
return __awaiter(this, arguments, void 0, function (dirPath, callback, includeSubdirs) {
|
|
745
|
+
var normalizedBasePath, watchers, addWatcher, subdirs, subdirs_1, subdirs_1_1, subdir;
|
|
746
|
+
var e_6, _a;
|
|
747
|
+
var _this = this;
|
|
748
|
+
if (includeSubdirs === void 0) { includeSubdirs = true; }
|
|
749
|
+
return __generator(this, function (_b) {
|
|
750
|
+
switch (_b.label) {
|
|
751
|
+
case 0:
|
|
752
|
+
normalizedBasePath = path.normalize(dirPath);
|
|
753
|
+
watchers = [];
|
|
754
|
+
addWatcher = function (dir) {
|
|
755
|
+
try {
|
|
756
|
+
var watcher = fs.watch(dir, function (eventType, filename) {
|
|
757
|
+
if (!filename)
|
|
758
|
+
return;
|
|
759
|
+
var fullPath = path.join(dir, filename);
|
|
760
|
+
// Make the path relative to the base directory
|
|
761
|
+
var relativePath = path.relative(normalizedBasePath, fullPath);
|
|
762
|
+
callback(eventType, relativePath);
|
|
763
|
+
// If a new directory is created, we should watch it
|
|
764
|
+
if (eventType === 'rename' && includeSubdirs) {
|
|
765
|
+
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
766
|
+
var _a;
|
|
767
|
+
return __generator(this, function (_b) {
|
|
768
|
+
switch (_b.label) {
|
|
769
|
+
case 0:
|
|
770
|
+
_b.trys.push([0, 2, , 3]);
|
|
771
|
+
return [4 /*yield*/, isDirectory(fullPath)];
|
|
772
|
+
case 1:
|
|
773
|
+
if (_b.sent()) {
|
|
774
|
+
addWatcher(fullPath);
|
|
775
|
+
}
|
|
776
|
+
return [3 /*break*/, 3];
|
|
777
|
+
case 2:
|
|
778
|
+
_a = _b.sent();
|
|
779
|
+
return [3 /*break*/, 3];
|
|
780
|
+
case 3: return [2 /*return*/];
|
|
781
|
+
}
|
|
782
|
+
});
|
|
783
|
+
}); }, 100);
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
watchers.push(watcher);
|
|
787
|
+
}
|
|
788
|
+
catch (_a) {
|
|
789
|
+
// Silently ignore directories we can't watch
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
// Add watcher for the base directory
|
|
793
|
+
addWatcher(normalizedBasePath);
|
|
794
|
+
if (!includeSubdirs) return [3 /*break*/, 2];
|
|
795
|
+
return [4 /*yield*/, getSubdirectories(normalizedBasePath, true)];
|
|
796
|
+
case 1:
|
|
797
|
+
subdirs = _b.sent();
|
|
798
|
+
try {
|
|
799
|
+
for (subdirs_1 = __values(subdirs), subdirs_1_1 = subdirs_1.next(); !subdirs_1_1.done; subdirs_1_1 = subdirs_1.next()) {
|
|
800
|
+
subdir = subdirs_1_1.value;
|
|
801
|
+
addWatcher(subdir);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
805
|
+
finally {
|
|
806
|
+
try {
|
|
807
|
+
if (subdirs_1_1 && !subdirs_1_1.done && (_a = subdirs_1.return)) _a.call(subdirs_1);
|
|
808
|
+
}
|
|
809
|
+
finally { if (e_6) throw e_6.error; }
|
|
810
|
+
}
|
|
811
|
+
_b.label = 2;
|
|
812
|
+
case 2:
|
|
813
|
+
// Return a function to close all watchers
|
|
814
|
+
return [2 /*return*/, function () {
|
|
815
|
+
watchers.forEach(function (watcher) { return watcher.close(); });
|
|
816
|
+
}];
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Gets detailed directory statistics including file count, directory count, and size.
|
|
823
|
+
*
|
|
824
|
+
* @param {string} dirPath - Path to the directory.
|
|
825
|
+
* @returns {Promise<{ fileCount: number, dirCount: number, totalSize: number }>} Directory statistics.
|
|
826
|
+
* @throws {Error} If directory cannot be read.
|
|
827
|
+
*/
|
|
828
|
+
export function getDirStats(dirPath) {
|
|
829
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
830
|
+
function processDir(currentPath) {
|
|
831
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
832
|
+
var entries, entries_6, entries_6_1, entry, entryPath, stat, e_7_1;
|
|
833
|
+
var e_7, _a;
|
|
834
|
+
return __generator(this, function (_b) {
|
|
835
|
+
switch (_b.label) {
|
|
836
|
+
case 0: return [4 /*yield*/, fsp.readdir(currentPath, { withFileTypes: true })];
|
|
837
|
+
case 1:
|
|
838
|
+
entries = _b.sent();
|
|
839
|
+
_b.label = 2;
|
|
840
|
+
case 2:
|
|
841
|
+
_b.trys.push([2, 9, 10, 11]);
|
|
842
|
+
entries_6 = __values(entries), entries_6_1 = entries_6.next();
|
|
843
|
+
_b.label = 3;
|
|
844
|
+
case 3:
|
|
845
|
+
if (!!entries_6_1.done) return [3 /*break*/, 8];
|
|
846
|
+
entry = entries_6_1.value;
|
|
847
|
+
entryPath = path.join(currentPath, entry.name);
|
|
848
|
+
if (!entry.isDirectory()) return [3 /*break*/, 5];
|
|
849
|
+
dirCount++;
|
|
850
|
+
return [4 /*yield*/, processDir(entryPath)];
|
|
851
|
+
case 4:
|
|
852
|
+
_b.sent();
|
|
853
|
+
return [3 /*break*/, 7];
|
|
854
|
+
case 5:
|
|
855
|
+
if (!entry.isFile()) return [3 /*break*/, 7];
|
|
856
|
+
fileCount++;
|
|
857
|
+
return [4 /*yield*/, fsp.stat(entryPath)];
|
|
858
|
+
case 6:
|
|
859
|
+
stat = _b.sent();
|
|
860
|
+
totalSize += stat.size;
|
|
861
|
+
_b.label = 7;
|
|
862
|
+
case 7:
|
|
863
|
+
entries_6_1 = entries_6.next();
|
|
864
|
+
return [3 /*break*/, 3];
|
|
865
|
+
case 8: return [3 /*break*/, 11];
|
|
866
|
+
case 9:
|
|
867
|
+
e_7_1 = _b.sent();
|
|
868
|
+
e_7 = { error: e_7_1 };
|
|
869
|
+
return [3 /*break*/, 11];
|
|
870
|
+
case 10:
|
|
871
|
+
try {
|
|
872
|
+
if (entries_6_1 && !entries_6_1.done && (_a = entries_6.return)) _a.call(entries_6);
|
|
873
|
+
}
|
|
874
|
+
finally { if (e_7) throw e_7.error; }
|
|
875
|
+
return [7 /*endfinally*/];
|
|
876
|
+
case 11: return [2 /*return*/];
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
var fileCount, dirCount, totalSize;
|
|
882
|
+
return __generator(this, function (_a) {
|
|
883
|
+
switch (_a.label) {
|
|
884
|
+
case 0:
|
|
885
|
+
fileCount = 0;
|
|
886
|
+
dirCount = 0;
|
|
887
|
+
totalSize = 0;
|
|
888
|
+
return [4 /*yield*/, processDir(dirPath)];
|
|
889
|
+
case 1:
|
|
890
|
+
_a.sent();
|
|
891
|
+
return [2 /*return*/, { fileCount: fileCount, dirCount: dirCount, totalSize: totalSize }];
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Walks through a directory hierarchy, calling a visitor function for each entry.
|
|
898
|
+
*
|
|
899
|
+
* @param {string} dirPath - Starting directory path.
|
|
900
|
+
* @param {object} options - Options for walking the directory.
|
|
901
|
+
* @param {(entry: { path: string, name: string, isDirectory: boolean, stats: fs.Stats }) => boolean | void | Promise<boolean | void>} options.visitorFn -
|
|
902
|
+
* Function called for each file/directory. Return false to skip a directory.
|
|
903
|
+
* @param {'pre' | 'post'} [options.traversalOrder='pre'] - Whether to visit directories before or after their contents.
|
|
904
|
+
* @throws {Error} If directory cannot be read.
|
|
905
|
+
*/
|
|
906
|
+
export function walkDir(dirPath, options) {
|
|
907
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
908
|
+
var traversalOrder, entries, entries_7, entries_7_1, entry, entryPath, stats, entryInfo, shouldContinue, e_8_1, stats, entryInfo;
|
|
909
|
+
var e_8, _a;
|
|
910
|
+
return __generator(this, function (_b) {
|
|
911
|
+
switch (_b.label) {
|
|
912
|
+
case 0:
|
|
913
|
+
traversalOrder = options.traversalOrder || 'pre';
|
|
914
|
+
return [4 /*yield*/, fsp.readdir(dirPath, { withFileTypes: true })];
|
|
915
|
+
case 1:
|
|
916
|
+
entries = _b.sent();
|
|
917
|
+
_b.label = 2;
|
|
918
|
+
case 2:
|
|
919
|
+
_b.trys.push([2, 16, 17, 18]);
|
|
920
|
+
entries_7 = __values(entries), entries_7_1 = entries_7.next();
|
|
921
|
+
_b.label = 3;
|
|
922
|
+
case 3:
|
|
923
|
+
if (!!entries_7_1.done) return [3 /*break*/, 15];
|
|
924
|
+
entry = entries_7_1.value;
|
|
925
|
+
entryPath = path.join(dirPath, entry.name);
|
|
926
|
+
return [4 /*yield*/, fsp.stat(entryPath)];
|
|
927
|
+
case 4:
|
|
928
|
+
stats = _b.sent();
|
|
929
|
+
entryInfo = {
|
|
930
|
+
path: entryPath,
|
|
931
|
+
name: entry.name,
|
|
932
|
+
isDirectory: entry.isDirectory(),
|
|
933
|
+
stats: stats
|
|
934
|
+
};
|
|
935
|
+
if (!entry.isDirectory()) return [3 /*break*/, 12];
|
|
936
|
+
if (!(traversalOrder === 'pre')) return [3 /*break*/, 8];
|
|
937
|
+
return [4 /*yield*/, options.visitorFn(entryInfo)];
|
|
938
|
+
case 5:
|
|
939
|
+
shouldContinue = _b.sent();
|
|
940
|
+
if (!(shouldContinue !== false)) return [3 /*break*/, 7];
|
|
941
|
+
return [4 /*yield*/, walkDir(entryPath, options)];
|
|
942
|
+
case 6:
|
|
943
|
+
_b.sent();
|
|
944
|
+
_b.label = 7;
|
|
945
|
+
case 7: return [3 /*break*/, 11];
|
|
946
|
+
case 8:
|
|
947
|
+
// Post-order: visit directory after its contents
|
|
948
|
+
return [4 /*yield*/, walkDir(entryPath, options)];
|
|
949
|
+
case 9:
|
|
950
|
+
// Post-order: visit directory after its contents
|
|
951
|
+
_b.sent();
|
|
952
|
+
return [4 /*yield*/, options.visitorFn(entryInfo)];
|
|
953
|
+
case 10:
|
|
954
|
+
_b.sent();
|
|
955
|
+
_b.label = 11;
|
|
956
|
+
case 11: return [3 /*break*/, 14];
|
|
957
|
+
case 12:
|
|
958
|
+
// Files are always visited when encountered
|
|
959
|
+
return [4 /*yield*/, options.visitorFn(entryInfo)];
|
|
960
|
+
case 13:
|
|
961
|
+
// Files are always visited when encountered
|
|
962
|
+
_b.sent();
|
|
963
|
+
_b.label = 14;
|
|
964
|
+
case 14:
|
|
965
|
+
entries_7_1 = entries_7.next();
|
|
966
|
+
return [3 /*break*/, 3];
|
|
967
|
+
case 15: return [3 /*break*/, 18];
|
|
968
|
+
case 16:
|
|
969
|
+
e_8_1 = _b.sent();
|
|
970
|
+
e_8 = { error: e_8_1 };
|
|
971
|
+
return [3 /*break*/, 18];
|
|
972
|
+
case 17:
|
|
973
|
+
try {
|
|
974
|
+
if (entries_7_1 && !entries_7_1.done && (_a = entries_7.return)) _a.call(entries_7);
|
|
975
|
+
}
|
|
976
|
+
finally { if (e_8) throw e_8.error; }
|
|
977
|
+
return [7 /*endfinally*/];
|
|
978
|
+
case 18:
|
|
979
|
+
if (!(traversalOrder === 'post')) return [3 /*break*/, 21];
|
|
980
|
+
return [4 /*yield*/, fsp.stat(dirPath)];
|
|
981
|
+
case 19:
|
|
982
|
+
stats = _b.sent();
|
|
983
|
+
entryInfo = {
|
|
984
|
+
path: dirPath,
|
|
985
|
+
name: path.basename(dirPath),
|
|
986
|
+
isDirectory: true,
|
|
987
|
+
stats: stats
|
|
988
|
+
};
|
|
989
|
+
return [4 /*yield*/, options.visitorFn(entryInfo)];
|
|
990
|
+
case 20:
|
|
991
|
+
_b.sent();
|
|
992
|
+
_b.label = 21;
|
|
993
|
+
case 21: return [2 /*return*/];
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
//# sourceMappingURL=dir.utils.js.map
|