@cyberskill/shared 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/commitlint/index.js +8 -9
- package/dist/config/commitlint/index.js.map +1 -1
- package/dist/config/config.type.js +8 -5
- package/dist/config/config.type.js.map +1 -1
- package/dist/config/config.util.js +33 -42
- package/dist/config/config.util.js.map +1 -1
- package/dist/config/env/env.constant.js +6 -5
- package/dist/config/env/env.constant.js.map +1 -1
- package/dist/config/env/env.util.js +26 -27
- package/dist/config/env/env.util.js.map +1 -1
- package/dist/config/env/index.js +2 -7
- package/dist/config/eslint/index.js +23 -19
- package/dist/config/eslint/index.js.map +1 -1
- package/dist/config/graphql-codegen/graphql-codegen.util.js +30 -38
- package/dist/config/graphql-codegen/graphql-codegen.util.js.map +1 -1
- package/dist/config/graphql-codegen/index.js +2 -5
- package/dist/config/index.js +3 -7
- package/dist/config/lint-staged/index.js +8 -7
- package/dist/config/lint-staged/index.js.map +1 -1
- package/dist/config/storybook/index.js +2 -6
- package/dist/config/storybook/storybook.main.js +19 -18
- package/dist/config/storybook/storybook.main.js.map +1 -1
- package/dist/config/storybook/storybook.preview.js +31 -37
- package/dist/config/storybook/storybook.preview.js.map +1 -1
- package/dist/config/vitest/index.js +3 -7
- package/dist/config/vitest/vitest.e2e.js +14 -17
- package/dist/config/vitest/vitest.e2e.js.map +1 -1
- package/dist/config/vitest/vitest.unit.js +31 -32
- package/dist/config/vitest/vitest.unit.js.map +1 -1
- package/dist/constant/common.js +6 -5
- package/dist/constant/common.js.map +1 -1
- package/dist/constant/index.js +3 -7
- package/dist/constant/response-status.d.ts +186 -186
- package/dist/constant/response-status.js +254 -253
- package/dist/constant/response-status.js.map +1 -1
- package/dist/node/apollo-server/apollo-server.util.js +27 -29
- package/dist/node/apollo-server/apollo-server.util.js.map +1 -1
- package/dist/node/apollo-server/index.js +2 -7
- package/dist/node/cli/index.js +112 -113
- package/dist/node/cli/index.js.map +1 -1
- package/dist/node/command/command.type.js +8 -5
- package/dist/node/command/command.type.js.map +1 -1
- package/dist/node/command/command.util.js +136 -149
- package/dist/node/command/command.util.js.map +1 -1
- package/dist/node/command/index.js +3 -12
- package/dist/node/express/express.type.d.ts +11 -0
- package/dist/node/express/express.type.js +2 -0
- package/dist/node/express/express.util.js +74 -65
- package/dist/node/express/express.util.js.map +1 -1
- package/dist/node/express/index.js +3 -14
- package/dist/node/fs/fs.util.js +27 -51
- package/dist/node/fs/fs.util.js.map +1 -1
- package/dist/node/fs/index.js +2 -19
- package/dist/node/log/index.js +2 -8
- package/dist/node/log/log.type.js +8 -5
- package/dist/node/log/log.type.js.map +1 -1
- package/dist/node/log/log.util.js +51 -68
- package/dist/node/log/log.util.js.map +1 -1
- package/dist/node/mongo/index.js +8 -26
- package/dist/node/mongo/mongo.constant.js +6 -6
- package/dist/node/mongo/mongo.constant.js.map +1 -1
- package/dist/node/mongo/mongo.controller.mongoose.d.ts +6 -1
- package/dist/node/mongo/mongo.controller.mongoose.js +333 -467
- package/dist/node/mongo/mongo.controller.mongoose.js.map +1 -1
- package/dist/node/mongo/mongo.controller.native.js +153 -212
- package/dist/node/mongo/mongo.controller.native.js.map +1 -1
- package/dist/node/mongo/mongo.dynamic-populate.js +164 -192
- package/dist/node/mongo/mongo.dynamic-populate.js.map +1 -1
- package/dist/node/mongo/mongo.populate.js +229 -262
- package/dist/node/mongo/mongo.populate.js.map +1 -1
- package/dist/node/mongo/mongo.type.js +8 -17
- package/dist/node/mongo/mongo.type.js.map +1 -1
- package/dist/node/mongo/mongo.util.js +134 -293
- package/dist/node/mongo/mongo.util.js.map +1 -1
- package/dist/node/package/index.js +3 -11
- package/dist/node/package/package.type.js +8 -5
- package/dist/node/package/package.type.js.map +1 -1
- package/dist/node/package/package.util.js +216 -225
- package/dist/node/package/package.util.js.map +1 -1
- package/dist/node/path/index.js +3 -58
- package/dist/node/path/path.constant.js +211 -298
- package/dist/node/path/path.constant.js.map +1 -1
- package/dist/node/path/path.util.js +13 -16
- package/dist/node/path/path.util.js.map +1 -1
- package/dist/node/storage/index.js +3 -10
- package/dist/node/storage/storage.constant.js +6 -8
- package/dist/node/storage/storage.constant.js.map +1 -1
- package/dist/node/storage/storage.util.js +127 -178
- package/dist/node/storage/storage.util.js.map +1 -1
- package/dist/node/upload/index.js +4 -16
- package/dist/node/upload/upload.constant.js +58 -32
- package/dist/node/upload/upload.constant.js.map +1 -1
- package/dist/node/upload/upload.type.js +8 -5
- package/dist/node/upload/upload.type.js.map +1 -1
- package/dist/node/upload/upload.util.js +125 -137
- package/dist/node/upload/upload.util.js.map +1 -1
- package/dist/node/ws/index.js +2 -6
- package/dist/node/ws/ws.type.d.ts +7 -8
- package/dist/node/ws/ws.util.js +46 -44
- package/dist/node/ws/ws.util.js.map +1 -1
- package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5/node_modules/vitest/dist/config.js +8 -0
- package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5/node_modules/vitest/dist/config.js.map +1 -0
- package/dist/react/apollo-client/apollo-client.component.js +16 -18
- package/dist/react/apollo-client/apollo-client.component.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.constant.js +6 -5
- package/dist/react/apollo-client/apollo-client.constant.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.context.js +10 -13
- package/dist/react/apollo-client/apollo-client.context.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.module.scss.js +8 -7
- package/dist/react/apollo-client/apollo-client.module.scss.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.util.js +57 -75
- package/dist/react/apollo-client/apollo-client.util.js.map +1 -1
- package/dist/react/apollo-client/index.js +7 -30
- package/dist/react/apollo-client/links/index.js +2 -5
- package/dist/react/apollo-client/links/upload.js +63 -107
- package/dist/react/apollo-client/links/upload.js.map +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +14 -16
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js.map +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.js +8 -7
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.js.map +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js +14 -14
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js.map +1 -1
- package/dist/react/apollo-client-nextjs/index.js +3 -7
- package/dist/react/apollo-error/apollo-error.component.js +57 -69
- package/dist/react/apollo-error/apollo-error.component.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.context.js +7 -6
- package/dist/react/apollo-error/apollo-error.context.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.hook.js +10 -10
- package/dist/react/apollo-error/apollo-error.hook.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.module.scss.js +15 -11
- package/dist/react/apollo-error/apollo-error.module.scss.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.provider.js +31 -25
- package/dist/react/apollo-error/apollo-error.provider.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.util.js +14 -16
- package/dist/react/apollo-error/apollo-error.util.js.map +1 -1
- package/dist/react/apollo-error/index.js +5 -15
- package/dist/react/i18next/i18next.hook.js +7 -6
- package/dist/react/i18next/i18next.hook.js.map +1 -1
- package/dist/react/i18next/i18next.util.js +9 -8
- package/dist/react/i18next/i18next.util.js.map +1 -1
- package/dist/react/i18next/index.js +3 -7
- package/dist/react/loading/index.js +3 -9
- package/dist/react/loading/loading.component.js +47 -48
- package/dist/react/loading/loading.component.js.map +1 -1
- package/dist/react/loading/loading.context.js +7 -6
- package/dist/react/loading/loading.context.js.map +1 -1
- package/dist/react/loading/loading.hook.js +11 -11
- package/dist/react/loading/loading.hook.js.map +1 -1
- package/dist/react/loading/loading.module.scss.js +18 -15
- package/dist/react/loading/loading.module.scss.js.map +1 -1
- package/dist/react/loading/loading.provider.js +26 -18
- package/dist/react/loading/loading.provider.js.map +1 -1
- package/dist/react/log/index.js +2 -6
- package/dist/react/log/log.util.d.ts +8 -0
- package/dist/react/log/log.util.js +33 -29
- package/dist/react/log/log.util.js.map +1 -1
- package/dist/react/next-intl/index.js +6 -14
- package/dist/react/next-intl/next-intl.constant.js +16 -15
- package/dist/react/next-intl/next-intl.constant.js.map +1 -1
- package/dist/react/next-intl/next-intl.context.js +7 -6
- package/dist/react/next-intl/next-intl.context.js.map +1 -1
- package/dist/react/next-intl/next-intl.hoc.js +20 -23
- package/dist/react/next-intl/next-intl.hoc.js.map +1 -1
- package/dist/react/next-intl/next-intl.hook.js +13 -14
- package/dist/react/next-intl/next-intl.hook.js.map +1 -1
- package/dist/react/next-intl/next-intl.provider.js +28 -23
- package/dist/react/next-intl/next-intl.provider.js.map +1 -1
- package/dist/react/storage/index.js +3 -7
- package/dist/react/storage/storage.hook.js +61 -58
- package/dist/react/storage/storage.hook.js.map +1 -1
- package/dist/react/storage/storage.util.js +36 -68
- package/dist/react/storage/storage.util.js.map +1 -1
- package/dist/react/toast/index.js +2 -6
- package/dist/react/userback/index.js +2 -5
- package/dist/react/userback/userback.component.js +27 -27
- package/dist/react/userback/userback.component.js.map +1 -1
- package/dist/style.css +2 -1
- package/dist/typescript/common.type.js +8 -5
- package/dist/typescript/common.type.js.map +1 -1
- package/dist/typescript/index.js +2 -5
- package/dist/util/common/common.util.js +119 -48
- package/dist/util/common/common.util.js.map +1 -1
- package/dist/util/common/index.js +2 -9
- package/dist/util/index.js +6 -27
- package/dist/util/object/index.d.ts +3 -0
- package/dist/util/object/index.js +2 -10
- package/dist/util/object/object.util.js +94 -128
- package/dist/util/object/object.util.js.map +1 -1
- package/dist/util/serializer/index.js +2 -5
- package/dist/util/serializer/serializer.util.js +73 -78
- package/dist/util/serializer/serializer.util.js.map +1 -1
- package/dist/util/string/index.d.ts +3 -0
- package/dist/util/string/index.js +2 -10
- package/dist/util/string/string.util.js +59 -71
- package/dist/util/string/string.util.js.map +1 -1
- package/dist/util/validate/index.d.ts +3 -0
- package/dist/util/validate/index.js +2 -5
- package/dist/util/validate/validate.util.js +13 -39
- package/dist/util/validate/validate.util.js.map +1 -1
- package/package.json +29 -27
- package/dist/config/env/index.js.map +0 -1
- package/dist/config/graphql-codegen/index.js.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/config/storybook/index.js.map +0 -1
- package/dist/config/vitest/index.js.map +0 -1
- package/dist/constant/index.js.map +0 -1
- package/dist/node/apollo-server/index.js.map +0 -1
- package/dist/node/command/index.js.map +0 -1
- package/dist/node/express/index.js.map +0 -1
- package/dist/node/fs/index.js.map +0 -1
- package/dist/node/log/index.js.map +0 -1
- package/dist/node/mongo/index.js.map +0 -1
- package/dist/node/package/index.js.map +0 -1
- package/dist/node/path/index.js.map +0 -1
- package/dist/node/storage/index.js.map +0 -1
- package/dist/node/upload/index.js.map +0 -1
- package/dist/node/ws/index.js.map +0 -1
- package/dist/node_modules/.pnpm/vitest@4.0.18_@types_node@25.3.5_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/dist/config.js +0 -7
- package/dist/node_modules/.pnpm/vitest@4.0.18_@types_node@25.3.5_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/dist/config.js.map +0 -1
- package/dist/react/apollo-client/index.js.map +0 -1
- package/dist/react/apollo-client/links/index.js.map +0 -1
- package/dist/react/apollo-client-nextjs/index.js.map +0 -1
- package/dist/react/apollo-error/index.js.map +0 -1
- package/dist/react/i18next/index.js.map +0 -1
- package/dist/react/loading/index.js.map +0 -1
- package/dist/react/log/index.js.map +0 -1
- package/dist/react/next-intl/index.js.map +0 -1
- package/dist/react/storage/index.js.map +0 -1
- package/dist/react/toast/index.js.map +0 -1
- package/dist/react/userback/index.js.map +0 -1
- package/dist/typescript/index.js.map +0 -1
- package/dist/util/common/index.js.map +0 -1
- package/dist/util/index.js.map +0 -1
- package/dist/util/object/index.js.map +0 -1
- package/dist/util/serializer/index.js.map +0 -1
- package/dist/util/string/index.js.map +0 -1
- package/dist/util/validate/index.js.map +0 -1
|
@@ -1,161 +1,148 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { getEnv as e } from "../../config/env/env.util.js";
|
|
2
|
+
import { E_IssueType as t } from "../log/log.type.js";
|
|
3
|
+
import { catchError as n, log as r } from "../log/log.util.js";
|
|
4
|
+
import { getPackage as i } from "../package/package.util.js";
|
|
5
|
+
import { storage as a } from "../storage/storage.util.js";
|
|
6
|
+
import { CYBERSKILL_CLI as o, CYBERSKILL_CLI_PATH as s, CYBERSKILL_PACKAGE_NAME as c, PNPM_EXEC_CLI as l } from "../path/path.constant.js";
|
|
7
|
+
import u from "node:process";
|
|
8
|
+
import { exec as d, execFile as f } from "node:child_process";
|
|
9
|
+
import * as p from "node:util";
|
|
10
|
+
//#region src/node/command/command.util.ts
|
|
11
|
+
var m = p.promisify(d), h = p.promisify(f), g = /[|&;<>`$(){}[\]!#~*?]/, _ = /^\s*(\d+):(\d+)\s+(error|warning)\s+(.+)\s+(\S+)$/, v = /^(.+?)\((\d+),(\d+)\):\s+(error|warning)\s+TS\d+:\s+(\S.+)$/, y = /^✖\s+(.+)\s+\[([^\]]*)\]$/, b = /\s+/;
|
|
12
|
+
async function x() {
|
|
13
|
+
let e = await i();
|
|
14
|
+
return e.success ? e.result.name : Date.now().toString();
|
|
14
15
|
}
|
|
15
|
-
async function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
16
|
+
async function S(e) {
|
|
17
|
+
if (e.length === 0) return;
|
|
18
|
+
let t = await x();
|
|
19
|
+
try {
|
|
20
|
+
let n = [...await C(), ...e];
|
|
21
|
+
await a.set(t, n), setTimeout(async () => {
|
|
22
|
+
let e = await a.getLogLink(t);
|
|
23
|
+
e && r.info(`📂 Open the error list manually: ${e}`);
|
|
24
|
+
}, 0);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
n(e);
|
|
27
|
+
}
|
|
28
28
|
}
|
|
29
|
-
async function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
}
|
|
29
|
+
async function C() {
|
|
30
|
+
try {
|
|
31
|
+
let e = await x();
|
|
32
|
+
return await a.get(e) ?? [];
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return n(e, { returnValue: [] });
|
|
35
|
+
}
|
|
38
36
|
}
|
|
39
|
-
async function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
async function w() {
|
|
38
|
+
try {
|
|
39
|
+
let e = await x();
|
|
40
|
+
await a.remove(e);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
n(e);
|
|
43
|
+
}
|
|
46
44
|
}
|
|
47
|
-
async function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
rule: p?.[2]?.trim() ?? ""
|
|
73
|
-
}) : s.push(a.trim());
|
|
74
|
-
}
|
|
75
|
-
}), r.length && await L(r), s.length && (u.warn("Unmatched lines:"), s.forEach((a) => u.info(` ${a}`)));
|
|
45
|
+
async function T(e) {
|
|
46
|
+
let n = [], i = [], a = "", o = _, s = v, c = y;
|
|
47
|
+
e.split("\n").forEach((e) => {
|
|
48
|
+
if (e.startsWith("/")) a = e.trim();
|
|
49
|
+
else {
|
|
50
|
+
let r = o.exec(e) || [], l = s.exec(e) || [], u = c.exec(e) || [];
|
|
51
|
+
r.length && a ? n.push({
|
|
52
|
+
file: a,
|
|
53
|
+
position: `${r[1]}:${r[2]}`,
|
|
54
|
+
type: r[3] === t.Error ? t.Error : t.Warning,
|
|
55
|
+
message: r?.[4]?.trim() ?? "",
|
|
56
|
+
rule: r?.[5]?.trim() ?? ""
|
|
57
|
+
}) : l.length ? n.push({
|
|
58
|
+
file: l?.[1] ?? "",
|
|
59
|
+
position: `${l[2]}:${l[3]}`,
|
|
60
|
+
type: l[4] === t.Error ? t.Error : t.Warning,
|
|
61
|
+
message: l?.[5]?.trim() ?? ""
|
|
62
|
+
}) : u.length ? n.push({
|
|
63
|
+
file: "commitlint",
|
|
64
|
+
type: t.Error,
|
|
65
|
+
message: u?.[1]?.trim() ?? "",
|
|
66
|
+
rule: u?.[2]?.trim() ?? ""
|
|
67
|
+
}) : i.push(e.trim());
|
|
68
|
+
}
|
|
69
|
+
}), n.length && await S(n), i.length && (r.warn("Unmatched lines:"), i.forEach((e) => r.info(` ${e}`)));
|
|
76
70
|
}
|
|
77
|
-
async function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
71
|
+
async function E(e) {
|
|
72
|
+
try {
|
|
73
|
+
let n = JSON.parse(e), r = [];
|
|
74
|
+
n.forEach(({ filePath: e, messages: n }) => {
|
|
75
|
+
n.forEach(({ severity: n, line: i, column: a, ruleId: o, message: s }) => {
|
|
76
|
+
r.push({
|
|
77
|
+
type: n === 2 ? t.Error : t.Warning,
|
|
78
|
+
file: e,
|
|
79
|
+
position: `${i}:${a}`,
|
|
80
|
+
rule: o,
|
|
81
|
+
message: s
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}), r.length && await S(r);
|
|
85
|
+
} catch {
|
|
86
|
+
await T(e);
|
|
87
|
+
}
|
|
94
88
|
}
|
|
95
|
-
async function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
throw await Promise.all([i, n].map((c) => c && r(c))), !n && !i && u.error(`Command failed: ${a}`), e;
|
|
119
|
-
}
|
|
89
|
+
async function D(e, t = E, n = {}) {
|
|
90
|
+
let i = new AbortController();
|
|
91
|
+
u.on("SIGINT", () => {
|
|
92
|
+
r.warn("Process interrupted. Terminating..."), i.abort(), u.exit();
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
if (typeof e == "string") {
|
|
96
|
+
let r = {
|
|
97
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
98
|
+
signal: i.signal,
|
|
99
|
+
timeout: n.timeout
|
|
100
|
+
}, a;
|
|
101
|
+
if (g.test(e)) a = await m(e, r);
|
|
102
|
+
else {
|
|
103
|
+
let t = e.split(b).filter(Boolean);
|
|
104
|
+
a = await h(t[0], t.slice(1), r);
|
|
105
|
+
}
|
|
106
|
+
await Promise.all([a.stdout, a.stderr].map((e) => e && t(e)));
|
|
107
|
+
}
|
|
108
|
+
} catch (e) {
|
|
109
|
+
let { stdout: n, stderr: i, message: a } = e;
|
|
110
|
+
throw await Promise.all([n, i].map((e) => e && t(e))), !i && !n && r.error(`Command failed: ${a}`), e;
|
|
111
|
+
}
|
|
120
112
|
}
|
|
121
|
-
function
|
|
122
|
-
|
|
113
|
+
function O(e) {
|
|
114
|
+
return {
|
|
115
|
+
raw: !0,
|
|
116
|
+
cmd: e
|
|
117
|
+
};
|
|
123
118
|
}
|
|
124
|
-
function
|
|
125
|
-
|
|
119
|
+
function k(e, t) {
|
|
120
|
+
return t?.isCurrentProject ? `${l} tsx ${s} ${e}` : `${l} ${o} ${e}`;
|
|
126
121
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
122
|
+
function A(e, t) {
|
|
123
|
+
return typeof e == "function" ? k(e(t), t) : typeof e == "object" && e?.raw === !0 ? e.cmd : typeof e == "string" ? k(e, t) : e;
|
|
129
124
|
}
|
|
130
|
-
async function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
);
|
|
137
|
-
}
|
|
125
|
+
async function j(e) {
|
|
126
|
+
let t = await i({ name: c });
|
|
127
|
+
if (t.success) {
|
|
128
|
+
let n = { isCurrentProject: t.result.isCurrentProject }, r = typeof e == "function" ? e(n) : e;
|
|
129
|
+
return Object.fromEntries(Object.entries(r).map(([e, t]) => [e, A(t, n)]));
|
|
130
|
+
}
|
|
138
131
|
}
|
|
139
|
-
async function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
132
|
+
async function M(t, i, a = {}) {
|
|
133
|
+
let o;
|
|
134
|
+
try {
|
|
135
|
+
let n = Date.now();
|
|
136
|
+
r.start(`${t}`), e().DEBUG ? r.info(`→ ${i}`) : o = setInterval(() => {
|
|
137
|
+
let e = Math.floor((Date.now() - n) / 1e3);
|
|
138
|
+
e > 0 && u.stdout.write(`\r⏳ ${t}... ${e}s`);
|
|
139
|
+
}, 100), await D(i, E, a), o && (clearInterval(o), u.stdout.write("\r\x1B[K")), r.success(`${t} done.`);
|
|
140
|
+
} catch (e) {
|
|
141
|
+
if (o && (clearInterval(o), u.stdout.write("\r\x1B[K")), a.throwOnError) throw e;
|
|
142
|
+
n(e);
|
|
143
|
+
}
|
|
152
144
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
q as rawCommand,
|
|
158
|
-
z as resolveCommands,
|
|
159
|
-
Q as runCommand
|
|
160
|
-
};
|
|
161
|
-
//# sourceMappingURL=command.util.js.map
|
|
145
|
+
//#endregion
|
|
146
|
+
export { w as clearAllErrorLists, A as formatCommand, C as getStoredErrorLists, O as rawCommand, j as resolveCommands, M as runCommand };
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=command.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.util.js","sources":["../../../src/node/command/command.util.ts"],"sourcesContent":["import { exec, execFile } from 'node:child_process';\nimport process from 'node:process';\nimport * as util from 'node:util';\n\nimport { getEnv } from '#config/env/index.js';\n\nimport type { I_IssueEntry } from '../log/index.js';\nimport type { I_CommandContext, I_EslintError, T_Command, T_CommandMapInput } from './command.type.js';\n\nimport { catchError, E_IssueType, log } from '../log/index.js';\nimport { getPackage } from '../package/index.js';\nimport { CYBERSKILL_CLI, CYBERSKILL_CLI_PATH, CYBERSKILL_PACKAGE_NAME, PNPM_EXEC_CLI, TSX_CLI } from '../path/index.js';\nimport { storage } from '../storage/index.js';\n\nconst execPromise = util.promisify(exec);\nconst execFilePromise = util.promisify(execFile);\nconst SHELL_METACHARACTERS = /[|&;<>`$(){}[\\]!#~*?]/;\n// eslint-disable-next-line regexp/no-super-linear-backtracking, regexp/no-misleading-capturing-group\nconst RE_ESLINT_ERROR = /^\\s*(\\d+):(\\d+)\\s+(error|warning)\\s+(.+)\\s+(\\S+)$/;\nconst RE_TS_ERROR = /^(.+?)\\((\\d+),(\\d+)\\):\\s+(error|warning)\\s+TS\\d+:\\s+(\\S.+)$/;\n// eslint-disable-next-line regexp/no-super-linear-backtracking, regexp/no-misleading-capturing-group\nconst RE_COMMITLINT_ERROR = /^✖\\s+(.+)\\s+\\[([^\\]]*)\\]$/;\nconst RE_WHITESPACE = /\\s+/;\n\n/**\n * Retrieves the package name for the current project.\n * This function attempts to get the package name from the current project's package.json.\n * If the package information cannot be retrieved, it returns a timestamp as a fallback.\n *\n * @returns A promise that resolves to the package name or a timestamp string.\n */\nasync function getPackageName() {\n const pkg = await getPackage();\n\n if (!pkg.success) {\n return Date.now().toString();\n }\n\n return pkg.result.name;\n}\n\n/**\n * Saves a list of error entries to persistent storage.\n * This function stores error information with the package name as the key,\n * and provides a log link for manual inspection of the stored errors.\n *\n * @param errorList - An array of error entries to be stored.\n * @returns A promise that resolves when the storage operation is complete.\n */\nasync function saveErrorListToStorage(errorList: I_IssueEntry[]): Promise<void> {\n if (errorList.length === 0) {\n return;\n }\n\n const packageName = await getPackageName();\n\n try {\n const existingErrors = await getStoredErrorLists();\n const mergedErrors = [...existingErrors, ...errorList];\n\n await storage.set(packageName, mergedErrors);\n\n setTimeout(async () => {\n const logPath = await storage.getLogLink(packageName);\n\n if (logPath) {\n log.info(`📂 Open the error list manually: ${logPath}`);\n }\n }, 0);\n }\n catch (error) {\n catchError(error);\n }\n}\n\n/**\n * Retrieves all stored error lists from persistent storage.\n * This function fetches error entries that were previously saved using the package name as the key.\n *\n * @returns A promise that resolves to an array of error entries, or an empty array if none are found.\n */\nexport async function getStoredErrorLists(): Promise<I_IssueEntry[]> {\n try {\n const packageName = await getPackageName();\n const allErrors = await storage.get<I_IssueEntry[]>(packageName);\n\n return allErrors ?? [];\n }\n catch (error) {\n return catchError<I_IssueEntry[]>(error, {\n returnValue: [],\n });\n }\n}\n\n/**\n * Clears all stored error lists from persistent storage.\n * This function removes all error entries associated with the current package name.\n *\n * @returns A promise that resolves when the clearing operation is complete.\n */\nexport async function clearAllErrorLists(): Promise<void> {\n try {\n const packageName = await getPackageName();\n await storage.remove(packageName);\n }\n catch (error) {\n catchError(error);\n }\n}\n\n/**\n * Parses text-based error output and converts it to structured error entries.\n * This function processes command output that contains error information in text format,\n * extracting file paths, line numbers, error types, messages, and rule violations.\n * It handles multiple error formats including ESLint, TypeScript, and commitlint errors.\n *\n * @param output - The raw text output from a command execution containing error information.\n */\nasync function parseTextErrors(output: string): Promise<void> {\n const errorList: I_IssueEntry[] = [];\n const unmatchedLines: string[] = [];\n let lastFilePath = '';\n const eslintErrorDetailsRegex = RE_ESLINT_ERROR;\n const tsRegex = RE_TS_ERROR;\n const commitlintRegex = RE_COMMITLINT_ERROR;\n\n output.split('\\n').forEach((line) => {\n if (line.startsWith('/')) {\n lastFilePath = line.trim();\n }\n else {\n const eslintMatch = eslintErrorDetailsRegex.exec(line) || [];\n const tsMatch = tsRegex.exec(line) || [];\n const commitlintMatch = commitlintRegex.exec(line) || [];\n\n if (eslintMatch.length && lastFilePath) {\n errorList.push({\n file: lastFilePath,\n position: `${eslintMatch[1]}:${eslintMatch[2]}`,\n type: eslintMatch[3] === E_IssueType.Error ? E_IssueType.Error : E_IssueType.Warning,\n message: eslintMatch?.[4]?.trim() ?? '',\n rule: eslintMatch?.[5]?.trim() ?? '',\n });\n }\n else if (tsMatch.length) {\n errorList.push({\n file: tsMatch?.[1] ?? '',\n position: `${tsMatch[2]}:${tsMatch[3]}`,\n type: tsMatch[4] === E_IssueType.Error ? E_IssueType.Error : E_IssueType.Warning,\n message: tsMatch?.[5]?.trim() ?? '',\n });\n }\n else if (commitlintMatch.length) {\n errorList.push({\n file: 'commitlint',\n type: E_IssueType.Error,\n message: commitlintMatch?.[1]?.trim() ?? '',\n rule: commitlintMatch?.[2]?.trim() ?? '',\n });\n }\n else {\n unmatchedLines.push(line.trim());\n }\n }\n });\n\n if (errorList.length) {\n await saveErrorListToStorage(errorList);\n }\n\n if (unmatchedLines.length) {\n log.warn(`Unmatched lines:`);\n unmatchedLines.forEach(line => log.info(` ${line}`));\n }\n}\n\n/**\n * Parses command output that contains structured error information.\n * This function attempts to parse JSON-formatted error output (typically from ESLint)\n * and converts it to structured error entries. If JSON parsing fails, it falls back\n * to text-based parsing.\n *\n * @param output - The command output to parse, expected to be JSON-formatted error data.\n */\nasync function parseCommandOutput(output: string): Promise<void> {\n try {\n const results: I_EslintError[] = JSON.parse(output);\n const errorList: I_IssueEntry[] = [];\n\n results.forEach(({ filePath, messages }) => {\n messages.forEach(({ severity, line, column, ruleId, message }) => {\n errorList.push({\n type: severity === 2 ? E_IssueType.Error : E_IssueType.Warning,\n file: filePath,\n position: `${line}:${column}`,\n rule: ruleId,\n message,\n });\n });\n });\n\n if (errorList.length) {\n await saveErrorListToStorage(errorList);\n }\n }\n catch {\n await parseTextErrors(output);\n }\n}\n\n/**\n * Executes a command and processes its output for errors.\n * This function runs a command with proper signal handling for graceful termination,\n * processes both stdout and stderr for error information, and handles command failures.\n *\n * @param command - The command string to execute, or undefined if no command should be run.\n * @param parser - The function to use for parsing command output (defaults to parseCommandOutput).\n * @returns A promise that resolves when the command execution is complete.\n */\nasync function executeCommand(command: string | void, parser = parseCommandOutput, options: { timeout?: number } = {}): Promise<void> {\n const controller = new AbortController();\n\n process.on('SIGINT', () => {\n log.warn('Process interrupted. Terminating...');\n controller.abort();\n process.exit();\n });\n\n try {\n if (typeof command === 'string') {\n const execOptions = {\n maxBuffer: 10 * 1024 * 1024,\n signal: controller.signal,\n timeout: options.timeout,\n };\n\n let result: { stdout: string; stderr: string };\n\n if (SHELL_METACHARACTERS.test(command)) {\n result = await execPromise(command, execOptions);\n }\n else {\n const parts = command.split(RE_WHITESPACE).filter(Boolean);\n result = await execFilePromise(parts[0]!, parts.slice(1), execOptions);\n }\n\n await Promise.all([result.stdout, result.stderr].map(output => output && parser(output)));\n }\n }\n catch (error) {\n const { stdout, stderr, message } = error as {\n stdout?: string;\n stderr?: string;\n message: string;\n };\n\n await Promise.all([stdout, stderr].map(output => output && parser(output)));\n\n if (!stderr && !stdout) {\n log.error(`Command failed: ${message}`);\n }\n\n throw error;\n }\n}\n\n/**\n * Creates a raw command object that bypasses CLI formatting.\n * This function wraps a command string in an object that indicates it should be executed\n * as-is without any additional CLI formatting or path resolution.\n *\n * @param cmd - The raw command string to be executed directly.\n * @returns An object containing the raw command with a flag indicating it should not be formatted.\n */\nexport function rawCommand(cmd: string) {\n return { raw: true, cmd };\n}\n\n/**\n * Formats a command for CLI execution based on the current project context.\n * This function determines whether to use the current project's CLI path or the global CLI,\n * and formats the command accordingly with the appropriate executable paths.\n *\n * @param command - The command string to format.\n * @param context - Optional context information about the current project.\n * @returns The formatted command string ready for execution.\n */\nfunction formatCLI(command: string, context?: I_CommandContext) {\n if (context?.isCurrentProject) {\n return `${PNPM_EXEC_CLI} ${TSX_CLI} ${CYBERSKILL_CLI_PATH} ${command}`;\n }\n\n return `${PNPM_EXEC_CLI} ${CYBERSKILL_CLI} ${command}`;\n}\n\n/**\n * Formats a command based on its type and context.\n * This function handles different command types:\n * - Function commands: Executes the function with context and formats the result\n * - Raw commands: Returns the command as-is without formatting\n * - String commands: Formats them as CLI commands\n *\n * @param command - The command to format, which can be a string, function, or raw command object.\n * @param context - Optional context information for command execution.\n * @returns The formatted command string ready for execution.\n */\nexport function formatCommand(command: T_Command, context?: I_CommandContext) {\n if (typeof command === 'function') {\n return formatCLI(command(context), context);\n }\n\n if (typeof command === 'object' && command?.raw === true) {\n return command.cmd;\n }\n\n if (typeof command === 'string') {\n return formatCLI(command, context);\n }\n\n return command;\n}\n\n/**\n * Resolves a map of commands by formatting them based on the current project context.\n * This function takes a command map (either static or dynamic) and formats all commands\n * using the appropriate CLI paths based on whether the current project is the Cyberskill package.\n *\n * @param input - The command map to resolve, which can be static or a function that returns a map.\n * @returns A promise that resolves to an object with formatted command strings, or undefined if package info cannot be retrieved.\n */\nexport async function resolveCommands(input: T_CommandMapInput) {\n const packageData = await getPackage({ name: CYBERSKILL_PACKAGE_NAME });\n\n if (packageData.success) {\n const ctx: I_CommandContext = { isCurrentProject: packageData.result.isCurrentProject };\n const commands = typeof input === 'function' ? input(ctx) : input;\n\n return Object.fromEntries(\n Object.entries(commands).map(([key, cmd]) => [key, formatCommand(cmd, ctx)]),\n );\n }\n}\n\n/**\n * Executes a command with proper logging and error handling.\n * This function provides a standardized way to run commands with:\n * - Progress logging with start and success messages\n * - Debug logging of the actual command when DEBUG mode is enabled\n * - Error handling and reporting\n *\n * @param label - A human-readable label describing what the command does.\n * @param command - The command string to execute, or undefined if no command should be run.\n * @returns A promise that resolves when the command execution is complete.\n */\nexport async function runCommand(label: string, command: string | void, options: { timeout?: number; throwOnError?: boolean } = {}) {\n let timer: NodeJS.Timeout | undefined;\n\n try {\n const startTime = Date.now();\n log.start(`${label}`);\n\n if (getEnv().DEBUG) {\n log.info(`→ ${command}`);\n }\n else {\n timer = setInterval(() => {\n const elapsed = Math.floor((Date.now() - startTime) / 1000);\n\n if (elapsed > 0) {\n process.stdout.write(`\\r⏳ ${label}... ${elapsed}s`);\n }\n }, 100);\n }\n\n await executeCommand(command, parseCommandOutput, options);\n\n if (timer) {\n clearInterval(timer);\n process.stdout.write(`\\r\\x1B[K`);\n }\n\n log.success(`${label} done.`);\n }\n catch (error) {\n if (timer) {\n clearInterval(timer);\n process.stdout.write(`\\r\\x1B[K`);\n }\n\n if (options.throwOnError) {\n throw error;\n }\n catchError(error);\n }\n}\n"],"names":["exec","execFile","process","util","storage","getPackage","CYBERSKILL_PACKAGE_NAME","PNPM_EXEC_CLI","TSX_CLI","CYBERSKILL_CLI_PATH","CYBERSKILL_CLI","E_IssueType","log","catchError","getEnv","execPromise","execFilePromise","SHELL_METACHARACTERS","RE_ESLINT_ERROR","RE_TS_ERROR","RE_COMMITLINT_ERROR","RE_WHITESPACE","getPackageName","pkg","saveErrorListToStorage","errorList","packageName","mergedErrors","getStoredErrorLists","logPath","error","clearAllErrorLists","parseTextErrors","output","unmatchedLines","lastFilePath","eslintErrorDetailsRegex","tsRegex","commitlintRegex","line","eslintMatch","tsMatch","commitlintMatch","parseCommandOutput","results","filePath","messages","severity","column","ruleId","message","executeCommand","command","parser","options","controller","execOptions","result","parts","stdout","stderr","rawCommand","cmd","formatCLI","context","formatCommand","resolveCommands","input","packageData","ctx","commands","key","runCommand","label","timer","startTime","elapsed"],"mappings":"AAcA,SAAA,QAAAA,GAAA,YAAAC,SAAA;AAAA,OAAAC,OAAA;AAAA,YAAAC,OAAA;AAAA,SAAA,WAAAC,SAAA;AAAA,SAAA,cAAAC,SAAA;AAAA,SAAA,2BAAAC,GAAA,iBAAAC,GAAA,WAAAC,GAAA,uBAAAC,GAAA,kBAAAC,SAAA;AAAA,SAAA,eAAAC,SAAA;AAAA,SAAA,OAAAC,GAAA,cAAAC,SAAA;AAAA,SAAA,UAAAC,SAAA;AAAA,MAAMC,IAAcZ,EAAK,UAAUH,CAAI,GACjCgB,IAAkBb,EAAK,UAAUF,CAAQ,GACzCgB,IAAuB,yBAEvBC,IAAkB,qDAClBC,IAAc,+DAEdC,IAAsB,6BACtBC,IAAgB;AAStB,eAAeC,IAAiB;AAC5B,QAAMC,IAAM,MAAMlB,EAAA;AAElB,SAAKkB,EAAI,UAIFA,EAAI,OAAO,OAHP,KAAK,IAAA,EAAM,SAAA;AAI1B;AAUA,eAAeC,EAAuBC,GAA0C;AAC5E,MAAIA,EAAU,WAAW;AACrB;AAGJ,QAAMC,IAAc,MAAMJ,EAAA;AAE1B,MAAI;AAEA,UAAMK,IAAe,CAAC,GADC,MAAMC,EAAA,GACY,GAAGH,CAAS;AAErD,UAAMrB,EAAQ,IAAIsB,GAAaC,CAAY,GAE3C,WAAW,YAAY;AACnB,YAAME,IAAU,MAAMzB,EAAQ,WAAWsB,CAAW;AAEpD,MAAIG,KACAj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O,GAAG;AAAA,IAE1D,GAAG,GAAG,GAGV,MAAMzB,EAAeC,GAAST,GAAoBW,CAAO,GAErDoB,MACA,cAAcA,CAAK,GACnBxE,EAAQ,OAAO,MAAM,UAAU,IAGnCU,EAAI,QAAQ,GAAG6D,CAAK,QAAQ;AAAA,EAChC,SACO3C,GAAO;AAMV,QALI4C,MACA,cAAcA,CAAK,GACnBxE,EAAQ,OAAO,MAAM,UAAU,IAG/BoD,EAAQ;AACR,YAAMxB;AAEV,IAAAjB,EAAWiB,CAAK;AAAA,EACpB;AACJ;"}
|
|
1
|
+
{"version":3,"file":"command.util.js","names":[],"sources":["../../../src/node/command/command.util.ts"],"sourcesContent":["import { exec, execFile } from 'node:child_process';\nimport process from 'node:process';\nimport * as util from 'node:util';\n\nimport { getEnv } from '#config/env/index.js';\n\nimport type { I_IssueEntry } from '../log/index.js';\nimport type { I_CommandContext, I_EslintError, T_Command, T_CommandMapInput } from './command.type.js';\n\nimport { catchError, E_IssueType, log } from '../log/index.js';\nimport { getPackage } from '../package/index.js';\nimport { CYBERSKILL_CLI, CYBERSKILL_CLI_PATH, CYBERSKILL_PACKAGE_NAME, PNPM_EXEC_CLI, TSX_CLI } from '../path/index.js';\nimport { storage } from '../storage/index.js';\n\nconst execPromise = util.promisify(exec);\nconst execFilePromise = util.promisify(execFile);\nconst SHELL_METACHARACTERS = /[|&;<>`$(){}[\\]!#~*?]/;\n// eslint-disable-next-line regexp/no-super-linear-backtracking, regexp/no-misleading-capturing-group\nconst RE_ESLINT_ERROR = /^\\s*(\\d+):(\\d+)\\s+(error|warning)\\s+(.+)\\s+(\\S+)$/;\nconst RE_TS_ERROR = /^(.+?)\\((\\d+),(\\d+)\\):\\s+(error|warning)\\s+TS\\d+:\\s+(\\S.+)$/;\n// eslint-disable-next-line regexp/no-super-linear-backtracking, regexp/no-misleading-capturing-group\nconst RE_COMMITLINT_ERROR = /^✖\\s+(.+)\\s+\\[([^\\]]*)\\]$/;\nconst RE_WHITESPACE = /\\s+/;\n\n/**\n * Retrieves the package name for the current project.\n * This function attempts to get the package name from the current project's package.json.\n * If the package information cannot be retrieved, it returns a timestamp as a fallback.\n *\n * @returns A promise that resolves to the package name or a timestamp string.\n */\nasync function getPackageName() {\n const pkg = await getPackage();\n\n if (!pkg.success) {\n return Date.now().toString();\n }\n\n return pkg.result.name;\n}\n\n/**\n * Saves a list of error entries to persistent storage.\n * This function stores error information with the package name as the key,\n * and provides a log link for manual inspection of the stored errors.\n *\n * @param errorList - An array of error entries to be stored.\n * @returns A promise that resolves when the storage operation is complete.\n */\nasync function saveErrorListToStorage(errorList: I_IssueEntry[]): Promise<void> {\n if (errorList.length === 0) {\n return;\n }\n\n const packageName = await getPackageName();\n\n try {\n const existingErrors = await getStoredErrorLists();\n const mergedErrors = [...existingErrors, ...errorList];\n\n await storage.set(packageName, mergedErrors);\n\n setTimeout(async () => {\n const logPath = await storage.getLogLink(packageName);\n\n if (logPath) {\n log.info(`📂 Open the error list manually: ${logPath}`);\n }\n }, 0);\n }\n catch (error) {\n catchError(error);\n }\n}\n\n/**\n * Retrieves all stored error lists from persistent storage.\n * This function fetches error entries that were previously saved using the package name as the key.\n *\n * @returns A promise that resolves to an array of error entries, or an empty array if none are found.\n */\nexport async function getStoredErrorLists(): Promise<I_IssueEntry[]> {\n try {\n const packageName = await getPackageName();\n const allErrors = await storage.get<I_IssueEntry[]>(packageName);\n\n return allErrors ?? [];\n }\n catch (error) {\n return catchError<I_IssueEntry[]>(error, {\n returnValue: [],\n });\n }\n}\n\n/**\n * Clears all stored error lists from persistent storage.\n * This function removes all error entries associated with the current package name.\n *\n * @returns A promise that resolves when the clearing operation is complete.\n */\nexport async function clearAllErrorLists(): Promise<void> {\n try {\n const packageName = await getPackageName();\n await storage.remove(packageName);\n }\n catch (error) {\n catchError(error);\n }\n}\n\n/**\n * Parses text-based error output and converts it to structured error entries.\n * This function processes command output that contains error information in text format,\n * extracting file paths, line numbers, error types, messages, and rule violations.\n * It handles multiple error formats including ESLint, TypeScript, and commitlint errors.\n *\n * @param output - The raw text output from a command execution containing error information.\n */\nasync function parseTextErrors(output: string): Promise<void> {\n const errorList: I_IssueEntry[] = [];\n const unmatchedLines: string[] = [];\n let lastFilePath = '';\n const eslintErrorDetailsRegex = RE_ESLINT_ERROR;\n const tsRegex = RE_TS_ERROR;\n const commitlintRegex = RE_COMMITLINT_ERROR;\n\n output.split('\\n').forEach((line) => {\n if (line.startsWith('/')) {\n lastFilePath = line.trim();\n }\n else {\n const eslintMatch = eslintErrorDetailsRegex.exec(line) || [];\n const tsMatch = tsRegex.exec(line) || [];\n const commitlintMatch = commitlintRegex.exec(line) || [];\n\n if (eslintMatch.length && lastFilePath) {\n errorList.push({\n file: lastFilePath,\n position: `${eslintMatch[1]}:${eslintMatch[2]}`,\n type: eslintMatch[3] === E_IssueType.Error ? E_IssueType.Error : E_IssueType.Warning,\n message: eslintMatch?.[4]?.trim() ?? '',\n rule: eslintMatch?.[5]?.trim() ?? '',\n });\n }\n else if (tsMatch.length) {\n errorList.push({\n file: tsMatch?.[1] ?? '',\n position: `${tsMatch[2]}:${tsMatch[3]}`,\n type: tsMatch[4] === E_IssueType.Error ? E_IssueType.Error : E_IssueType.Warning,\n message: tsMatch?.[5]?.trim() ?? '',\n });\n }\n else if (commitlintMatch.length) {\n errorList.push({\n file: 'commitlint',\n type: E_IssueType.Error,\n message: commitlintMatch?.[1]?.trim() ?? '',\n rule: commitlintMatch?.[2]?.trim() ?? '',\n });\n }\n else {\n unmatchedLines.push(line.trim());\n }\n }\n });\n\n if (errorList.length) {\n await saveErrorListToStorage(errorList);\n }\n\n if (unmatchedLines.length) {\n log.warn(`Unmatched lines:`);\n unmatchedLines.forEach(line => log.info(` ${line}`));\n }\n}\n\n/**\n * Parses command output that contains structured error information.\n * This function attempts to parse JSON-formatted error output (typically from ESLint)\n * and converts it to structured error entries. If JSON parsing fails, it falls back\n * to text-based parsing.\n *\n * @param output - The command output to parse, expected to be JSON-formatted error data.\n */\nasync function parseCommandOutput(output: string): Promise<void> {\n try {\n const results: I_EslintError[] = JSON.parse(output);\n const errorList: I_IssueEntry[] = [];\n\n results.forEach(({ filePath, messages }) => {\n messages.forEach(({ severity, line, column, ruleId, message }) => {\n errorList.push({\n type: severity === 2 ? E_IssueType.Error : E_IssueType.Warning,\n file: filePath,\n position: `${line}:${column}`,\n rule: ruleId,\n message,\n });\n });\n });\n\n if (errorList.length) {\n await saveErrorListToStorage(errorList);\n }\n }\n catch {\n await parseTextErrors(output);\n }\n}\n\n/**\n * Executes a command and processes its output for errors.\n * This function runs a command with proper signal handling for graceful termination,\n * processes both stdout and stderr for error information, and handles command failures.\n *\n * @param command - The command string to execute, or undefined if no command should be run.\n * @param parser - The function to use for parsing command output (defaults to parseCommandOutput).\n * @returns A promise that resolves when the command execution is complete.\n */\nasync function executeCommand(command: string | void, parser = parseCommandOutput, options: { timeout?: number } = {}): Promise<void> {\n const controller = new AbortController();\n\n process.on('SIGINT', () => {\n log.warn('Process interrupted. Terminating...');\n controller.abort();\n process.exit();\n });\n\n try {\n if (typeof command === 'string') {\n const execOptions = {\n maxBuffer: 10 * 1024 * 1024,\n signal: controller.signal,\n timeout: options.timeout,\n };\n\n let result: { stdout: string; stderr: string };\n\n if (SHELL_METACHARACTERS.test(command)) {\n result = await execPromise(command, execOptions);\n }\n else {\n const parts = command.split(RE_WHITESPACE).filter(Boolean);\n result = await execFilePromise(parts[0]!, parts.slice(1), execOptions);\n }\n\n await Promise.all([result.stdout, result.stderr].map(output => output && parser(output)));\n }\n }\n catch (error) {\n const { stdout, stderr, message } = error as {\n stdout?: string;\n stderr?: string;\n message: string;\n };\n\n await Promise.all([stdout, stderr].map(output => output && parser(output)));\n\n if (!stderr && !stdout) {\n log.error(`Command failed: ${message}`);\n }\n\n throw error;\n }\n}\n\n/**\n * Creates a raw command object that bypasses CLI formatting.\n * This function wraps a command string in an object that indicates it should be executed\n * as-is without any additional CLI formatting or path resolution.\n *\n * @param cmd - The raw command string to be executed directly.\n * @returns An object containing the raw command with a flag indicating it should not be formatted.\n */\nexport function rawCommand(cmd: string) {\n return { raw: true, cmd };\n}\n\n/**\n * Formats a command for CLI execution based on the current project context.\n * This function determines whether to use the current project's CLI path or the global CLI,\n * and formats the command accordingly with the appropriate executable paths.\n *\n * @param command - The command string to format.\n * @param context - Optional context information about the current project.\n * @returns The formatted command string ready for execution.\n */\nfunction formatCLI(command: string, context?: I_CommandContext) {\n if (context?.isCurrentProject) {\n return `${PNPM_EXEC_CLI} ${TSX_CLI} ${CYBERSKILL_CLI_PATH} ${command}`;\n }\n\n return `${PNPM_EXEC_CLI} ${CYBERSKILL_CLI} ${command}`;\n}\n\n/**\n * Formats a command based on its type and context.\n * This function handles different command types:\n * - Function commands: Executes the function with context and formats the result\n * - Raw commands: Returns the command as-is without formatting\n * - String commands: Formats them as CLI commands\n *\n * @param command - The command to format, which can be a string, function, or raw command object.\n * @param context - Optional context information for command execution.\n * @returns The formatted command string ready for execution.\n */\nexport function formatCommand(command: T_Command, context?: I_CommandContext) {\n if (typeof command === 'function') {\n return formatCLI(command(context), context);\n }\n\n if (typeof command === 'object' && command?.raw === true) {\n return command.cmd;\n }\n\n if (typeof command === 'string') {\n return formatCLI(command, context);\n }\n\n return command;\n}\n\n/**\n * Resolves a map of commands by formatting them based on the current project context.\n * This function takes a command map (either static or dynamic) and formats all commands\n * using the appropriate CLI paths based on whether the current project is the Cyberskill package.\n *\n * @param input - The command map to resolve, which can be static or a function that returns a map.\n * @returns A promise that resolves to an object with formatted command strings, or undefined if package info cannot be retrieved.\n */\nexport async function resolveCommands(input: T_CommandMapInput) {\n const packageData = await getPackage({ name: CYBERSKILL_PACKAGE_NAME });\n\n if (packageData.success) {\n const ctx: I_CommandContext = { isCurrentProject: packageData.result.isCurrentProject };\n const commands = typeof input === 'function' ? input(ctx) : input;\n\n return Object.fromEntries(\n Object.entries(commands).map(([key, cmd]) => [key, formatCommand(cmd, ctx)]),\n );\n }\n}\n\n/**\n * Executes a command with proper logging and error handling.\n * This function provides a standardized way to run commands with:\n * - Progress logging with start and success messages\n * - Debug logging of the actual command when DEBUG mode is enabled\n * - Error handling and reporting\n *\n * @param label - A human-readable label describing what the command does.\n * @param command - The command string to execute, or undefined if no command should be run.\n * @returns A promise that resolves when the command execution is complete.\n */\nexport async function runCommand(label: string, command: string | void, options: { timeout?: number; throwOnError?: boolean } = {}) {\n let timer: NodeJS.Timeout | undefined;\n\n try {\n const startTime = Date.now();\n log.start(`${label}`);\n\n if (getEnv().DEBUG) {\n log.info(`→ ${command}`);\n }\n else {\n timer = setInterval(() => {\n const elapsed = Math.floor((Date.now() - startTime) / 1000);\n\n if (elapsed > 0) {\n process.stdout.write(`\\r⏳ ${label}... ${elapsed}s`);\n }\n }, 100);\n }\n\n await executeCommand(command, parseCommandOutput, options);\n\n if (timer) {\n clearInterval(timer);\n process.stdout.write(`\\r\\x1B[K`);\n }\n\n log.success(`${label} done.`);\n }\n catch (error) {\n if (timer) {\n clearInterval(timer);\n process.stdout.write(`\\r\\x1B[K`);\n }\n\n if (options.throwOnError) {\n throw error;\n }\n catchError(error);\n }\n}\n"],"mappings":";;;;;;;;;;AAcA,IAAM,IAAc,EAAK,UAAU,EAAK,EAClC,IAAkB,EAAK,UAAU,EAAS,EAC1C,IAAuB,yBAEvB,IAAkB,qDAClB,IAAc,+DAEd,IAAsB,6BACtB,IAAgB;AAStB,eAAe,IAAiB;CAC5B,IAAM,IAAM,MAAM,GAAY;AAM9B,QAJK,EAAI,UAIF,EAAI,OAAO,OAHP,KAAK,KAAK,CAAC,UAAU;;AAcpC,eAAe,EAAuB,GAA0C;AAC5E,KAAI,EAAU,WAAW,EACrB;CAGJ,IAAM,IAAc,MAAM,GAAgB;AAE1C,KAAI;EAEA,IAAM,IAAe,CAAC,GADC,MAAM,GAAqB,EACT,GAAG,EAAU;AAItD,EAFA,MAAM,EAAQ,IAAI,GAAa,EAAa,EAE5C,WAAW,YAAY;GACnB,IAAM,IAAU,MAAM,EAAQ,WAAW,EAAY;AA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GAAQ,CAAC,QACT,EAAI,KAAK,KAAK,IAAU,GAGxB,IAAQ,kBAAkB;GACtB,IAAM,IAAU,KAAK,OAAO,KAAK,KAAK,GAAG,KAAa,IAAK;AAE3D,GAAI,IAAU,KACV,EAAQ,OAAO,MAAM,OAAO,EAAM,MAAM,EAAQ,GAAG;KAExD,IAAI,EAGX,MAAM,EAAe,GAAS,GAAoB,EAAQ,EAEtD,MACA,cAAc,EAAM,EACpB,EAAQ,OAAO,MAAM,WAAW,GAGpC,EAAI,QAAQ,GAAG,EAAM,QAAQ;UAE1B,GAAO;AAMV,MALI,MACA,cAAc,EAAM,EACpB,EAAQ,OAAO,MAAM,WAAW,GAGhC,EAAQ,aACR,OAAM;AAEV,IAAW,EAAM"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import { E_CommandType as
|
|
2
|
-
import { clearAllErrorLists as
|
|
3
|
-
export {
|
|
4
|
-
m as E_CommandType,
|
|
5
|
-
e as clearAllErrorLists,
|
|
6
|
-
t as formatCommand,
|
|
7
|
-
d as getStoredErrorLists,
|
|
8
|
-
n as rawCommand,
|
|
9
|
-
s as resolveCommands,
|
|
10
|
-
C as runCommand
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { E_CommandType as e } from "./command.type.js";
|
|
2
|
+
import { clearAllErrorLists as t, formatCommand as n, getStoredErrorLists as r, rawCommand as i, resolveCommands as a, runCommand as o } from "./command.util.js";
|
|
3
|
+
export { e as E_CommandType, t as clearAllErrorLists, n as formatCommand, r as getStoredErrorLists, i as rawCommand, a as resolveCommands, o as runCommand };
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { ExceptionFilter, Type, ValidationPipe } from '@nestjs/common';
|
|
2
2
|
import { CorsOptions as CorsOptionsNestJS } from '@nestjs/common/interfaces/external/cors-options.interface.js';
|
|
3
3
|
import { CorsOptions, CorsOptionsDelegate, CorsRequest } from 'cors';
|
|
4
|
+
import { Store } from 'express-rate-limit';
|
|
4
5
|
export type { NextFunction, Request, Response } from 'express';
|
|
5
6
|
export { Router } from 'express';
|
|
7
|
+
export interface I_RateLimitOptions {
|
|
8
|
+
windowMs?: number;
|
|
9
|
+
limit?: number;
|
|
10
|
+
store?: Store;
|
|
11
|
+
skip?: (req: import('express').Request) => boolean | Promise<boolean>;
|
|
12
|
+
}
|
|
6
13
|
export interface I_ExpressOptions {
|
|
7
14
|
isDev?: boolean;
|
|
8
15
|
static?: string | string[];
|
|
9
16
|
maxFileSize?: number;
|
|
10
17
|
maxFiles?: number;
|
|
11
18
|
jsonLimit?: string;
|
|
19
|
+
trustProxy?: boolean | number | string | string[];
|
|
20
|
+
rateLimit?: false | I_RateLimitOptions;
|
|
12
21
|
}
|
|
13
22
|
export interface I_NestOptions {
|
|
14
23
|
module: Type<object>;
|
|
@@ -17,6 +26,8 @@ export interface I_NestOptions {
|
|
|
17
26
|
filters?: ExceptionFilter[];
|
|
18
27
|
pipes?: ValidationPipe[];
|
|
19
28
|
jsonLimit?: string;
|
|
29
|
+
trustProxy?: boolean | number | string | string[];
|
|
30
|
+
rateLimit?: false | I_RateLimitOptions;
|
|
20
31
|
}
|
|
21
32
|
export type T_CorsType = 'node' | 'nest';
|
|
22
33
|
interface I_BaseCorsOptions {
|
|
@@ -1,72 +1,81 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import i from "
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import e from "node:process";
|
|
2
|
+
import t from "express";
|
|
3
|
+
import { NestFactory as n } from "@nestjs/core";
|
|
4
|
+
import r from "body-parser";
|
|
5
|
+
import i from "compression";
|
|
6
|
+
import a from "cookie-parser";
|
|
7
|
+
import o from "cors";
|
|
8
|
+
import s from "express-rate-limit";
|
|
9
|
+
import c from "express-session";
|
|
10
|
+
import { express as l } from "express-useragent";
|
|
11
|
+
import u from "graphql-upload/graphqlUploadExpress.mjs";
|
|
12
|
+
import d from "helmet";
|
|
13
|
+
//#region src/node/express/express.util.ts
|
|
14
|
+
function f({ isDev: e, whiteList: t, ...n }) {
|
|
15
|
+
return {
|
|
16
|
+
origin: (n, r) => {
|
|
17
|
+
e || !n || t?.includes(n ?? "") ? r(null, !0) : r(/* @__PURE__ */ Error("Not allowed by CORS"), !1);
|
|
18
|
+
},
|
|
19
|
+
credentials: !0,
|
|
20
|
+
...n
|
|
21
|
+
};
|
|
20
22
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
+
function p(e) {
|
|
24
|
+
return o(f(e));
|
|
23
25
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
function m(t) {
|
|
27
|
+
if (!t.secret) throw Error("Session secret is required. Provide a strong secret string.");
|
|
28
|
+
let n = {
|
|
29
|
+
resave: !1,
|
|
30
|
+
saveUninitialized: !1,
|
|
31
|
+
cookie: {
|
|
32
|
+
httpOnly: !0,
|
|
33
|
+
sameSite: "lax",
|
|
34
|
+
secure: e.env.NODE_ENV === "production"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return c({
|
|
38
|
+
...n,
|
|
39
|
+
...t,
|
|
40
|
+
cookie: {
|
|
41
|
+
...n.cookie,
|
|
42
|
+
...t.cookie
|
|
43
|
+
}
|
|
44
|
+
});
|
|
39
45
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
function h(e, n = !1, r = "1mb", o = !1, c = {}) {
|
|
47
|
+
o !== !1 && e.set("trust proxy", o), e.use(d({
|
|
48
|
+
crossOriginEmbedderPolicy: n ? !1 : void 0,
|
|
49
|
+
contentSecurityPolicy: n ? !1 : void 0
|
|
50
|
+
})), c !== !1 && e.use(s({
|
|
51
|
+
windowMs: c.windowMs ?? 900 * 1e3,
|
|
52
|
+
limit: c.limit ?? 1e3,
|
|
53
|
+
standardHeaders: !0,
|
|
54
|
+
legacyHeaders: !1,
|
|
55
|
+
...c.store !== void 0 && { store: c.store },
|
|
56
|
+
...c.skip !== void 0 && { skip: c.skip }
|
|
57
|
+
})), e.use(a()), e.use(t.json({ limit: r })), e.use(t.urlencoded({
|
|
58
|
+
extended: !0,
|
|
59
|
+
limit: r
|
|
60
|
+
})), e.use(i()), e.use(l());
|
|
47
61
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
function g(e, n) {
|
|
63
|
+
n && (Array.isArray(n) ? n : [n]).forEach((n) => {
|
|
64
|
+
e.use(`/${n}`, t.static(n));
|
|
65
|
+
});
|
|
52
66
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
function _(e) {
|
|
68
|
+
let n = t();
|
|
69
|
+
return h(n, e?.isDev, e?.jsonLimit, e?.trustProxy, e?.rateLimit), g(n, e?.static), n.use(u({
|
|
70
|
+
maxFileSize: e?.maxFileSize ?? 1e7,
|
|
71
|
+
maxFiles: e?.maxFiles ?? 10
|
|
72
|
+
})), n;
|
|
59
73
|
}
|
|
60
|
-
async function
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
async function v(e) {
|
|
75
|
+
let t = await n.create(e.module);
|
|
76
|
+
return h(t.getHttpAdapter().getInstance(), e.isDev, e.jsonLimit, e.trustProxy, e.rateLimit), g(t.getHttpAdapter().getInstance(), e.static), e.filters && t.useGlobalFilters(...e.filters), e.pipes && t.useGlobalPipes(...e.pipes), t;
|
|
63
77
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
C as createNest,
|
|
69
|
-
P as createSession,
|
|
70
|
-
G as express
|
|
71
|
-
};
|
|
72
|
-
//# sourceMappingURL=express.util.js.map
|
|
78
|
+
//#endregion
|
|
79
|
+
export { r as bodyParser, p as createCors, f as createCorsOptions, _ as createExpress, v as createNest, m as createSession, t as express };
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=express.util.js.map
|