@godscene/shared 1.7.11
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 +9 -0
- package/dist/es/baseDB.mjs +109 -0
- package/dist/es/cli/cli-args.mjs +95 -0
- package/dist/es/cli/cli-error.mjs +24 -0
- package/dist/es/cli/cli-runner.mjs +122 -0
- package/dist/es/cli/index.mjs +4 -0
- package/dist/es/common.mjs +37 -0
- package/dist/es/constants/example-code.mjs +227 -0
- package/dist/es/constants/index.mjs +124 -0
- package/dist/es/env/basic.mjs +6 -0
- package/dist/es/env/constants.mjs +110 -0
- package/dist/es/env/global-config-manager.mjs +94 -0
- package/dist/es/env/helper.mjs +43 -0
- package/dist/es/env/index.mjs +5 -0
- package/dist/es/env/init-debug.mjs +18 -0
- package/dist/es/env/model-config-manager.mjs +79 -0
- package/dist/es/env/parse-model-config.mjs +165 -0
- package/dist/es/env/types.mjs +232 -0
- package/dist/es/env/utils.mjs +18 -0
- package/dist/es/extractor/constants.mjs +2 -0
- package/dist/es/extractor/cs_postmessage.mjs +61 -0
- package/dist/es/extractor/customLocator.mjs +641 -0
- package/dist/es/extractor/debug.mjs +6 -0
- package/dist/es/extractor/dom-util.mjs +96 -0
- package/dist/es/extractor/index.mjs +5 -0
- package/dist/es/extractor/locator.mjs +250 -0
- package/dist/es/extractor/tree.mjs +78 -0
- package/dist/es/extractor/util.mjs +245 -0
- package/dist/es/extractor/web-extractor.mjs +393 -0
- package/dist/es/img/box-select.mjs +824 -0
- package/dist/es/img/canvas-fallback.mjs +238 -0
- package/dist/es/img/get-photon.mjs +45 -0
- package/dist/es/img/get-sharp.mjs +11 -0
- package/dist/es/img/index.mjs +4 -0
- package/dist/es/img/info.mjs +35 -0
- package/dist/es/img/transform.mjs +275 -0
- package/dist/es/index.mjs +2 -0
- package/dist/es/key-alias-utils.mjs +19 -0
- package/dist/es/logger.mjs +64 -0
- package/dist/es/mcp/base-server.mjs +282 -0
- package/dist/es/mcp/base-tools.mjs +159 -0
- package/dist/es/mcp/chrome-path.mjs +35 -0
- package/dist/es/mcp/cli-report-session.mjs +78 -0
- package/dist/es/mcp/error-formatter.mjs +19 -0
- package/dist/es/mcp/index.mjs +9 -0
- package/dist/es/mcp/init-arg-utils.mjs +38 -0
- package/dist/es/mcp/inject-report-html-plugin.mjs +53 -0
- package/dist/es/mcp/launcher-helper.mjs +52 -0
- package/dist/es/mcp/tool-generator.mjs +419 -0
- package/dist/es/mcp/types.mjs +3 -0
- package/dist/es/node/fs.mjs +44 -0
- package/dist/es/node/index.mjs +2 -0
- package/dist/es/node/port.mjs +24 -0
- package/dist/es/polyfills/async-hooks.mjs +2 -0
- package/dist/es/polyfills/index.mjs +1 -0
- package/dist/es/types/index.mjs +3 -0
- package/dist/es/us-keyboard-layout.mjs +1414 -0
- package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
- package/dist/es/utils.mjs +72 -0
- package/dist/es/zod-schema-utils.mjs +54 -0
- package/dist/lib/baseDB.js +149 -0
- package/dist/lib/cli/cli-args.js +138 -0
- package/dist/lib/cli/cli-error.js +61 -0
- package/dist/lib/cli/cli-runner.js +181 -0
- package/dist/lib/cli/index.js +53 -0
- package/dist/lib/common.js +93 -0
- package/dist/lib/constants/example-code.js +264 -0
- package/dist/lib/constants/index.js +221 -0
- package/dist/lib/env/basic.js +40 -0
- package/dist/lib/env/constants.js +153 -0
- package/dist/lib/env/global-config-manager.js +128 -0
- package/dist/lib/env/helper.js +80 -0
- package/dist/lib/env/index.js +90 -0
- package/dist/lib/env/init-debug.js +52 -0
- package/dist/lib/env/model-config-manager.js +113 -0
- package/dist/lib/env/parse-model-config.js +211 -0
- package/dist/lib/env/types.js +572 -0
- package/dist/lib/env/utils.js +61 -0
- package/dist/lib/extractor/constants.js +42 -0
- package/dist/lib/extractor/cs_postmessage.js +98 -0
- package/dist/lib/extractor/customLocator.js +693 -0
- package/dist/lib/extractor/debug.js +12 -0
- package/dist/lib/extractor/dom-util.js +157 -0
- package/dist/lib/extractor/index.js +87 -0
- package/dist/lib/extractor/locator.js +296 -0
- package/dist/lib/extractor/tree.js +124 -0
- package/dist/lib/extractor/util.js +336 -0
- package/dist/lib/extractor/web-extractor.js +442 -0
- package/dist/lib/img/box-select.js +875 -0
- package/dist/lib/img/canvas-fallback.js +305 -0
- package/dist/lib/img/get-photon.js +82 -0
- package/dist/lib/img/get-sharp.js +45 -0
- package/dist/lib/img/index.js +95 -0
- package/dist/lib/img/info.js +92 -0
- package/dist/lib/img/transform.js +364 -0
- package/dist/lib/index.js +36 -0
- package/dist/lib/key-alias-utils.js +62 -0
- package/dist/lib/logger.js +114 -0
- package/dist/lib/mcp/base-server.js +332 -0
- package/dist/lib/mcp/base-tools.js +193 -0
- package/dist/lib/mcp/chrome-path.js +72 -0
- package/dist/lib/mcp/cli-report-session.js +121 -0
- package/dist/lib/mcp/error-formatter.js +53 -0
- package/dist/lib/mcp/index.js +114 -0
- package/dist/lib/mcp/init-arg-utils.js +78 -0
- package/dist/lib/mcp/inject-report-html-plugin.js +98 -0
- package/dist/lib/mcp/launcher-helper.js +86 -0
- package/dist/lib/mcp/tool-generator.js +456 -0
- package/dist/lib/mcp/types.js +40 -0
- package/dist/lib/node/fs.js +97 -0
- package/dist/lib/node/index.js +65 -0
- package/dist/lib/node/port.js +61 -0
- package/dist/lib/polyfills/async-hooks.js +36 -0
- package/dist/lib/polyfills/index.js +58 -0
- package/dist/lib/types/index.js +37 -0
- package/dist/lib/us-keyboard-layout.js +1457 -0
- package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
- package/dist/lib/utils.js +148 -0
- package/dist/lib/zod-schema-utils.js +97 -0
- package/dist/types/baseDB.d.ts +25 -0
- package/dist/types/cli/cli-args.d.ts +8 -0
- package/dist/types/cli/cli-error.d.ts +5 -0
- package/dist/types/cli/cli-runner.d.ts +19 -0
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/common.d.ts +12 -0
- package/dist/types/constants/example-code.d.ts +2 -0
- package/dist/types/constants/index.d.ts +61 -0
- package/dist/types/env/basic.d.ts +6 -0
- package/dist/types/env/constants.d.ts +50 -0
- package/dist/types/env/global-config-manager.d.ts +32 -0
- package/dist/types/env/helper.d.ts +4 -0
- package/dist/types/env/index.d.ts +4 -0
- package/dist/types/env/init-debug.d.ts +1 -0
- package/dist/types/env/model-config-manager.d.ts +25 -0
- package/dist/types/env/parse-model-config.d.ts +31 -0
- package/dist/types/env/types.d.ts +339 -0
- package/dist/types/env/utils.d.ts +7 -0
- package/dist/types/extractor/constants.d.ts +1 -0
- package/dist/types/extractor/cs_postmessage.d.ts +2 -0
- package/dist/types/extractor/customLocator.d.ts +69 -0
- package/dist/types/extractor/debug.d.ts +1 -0
- package/dist/types/extractor/dom-util.d.ts +57 -0
- package/dist/types/extractor/index.d.ts +33 -0
- package/dist/types/extractor/locator.d.ts +9 -0
- package/dist/types/extractor/tree.d.ts +6 -0
- package/dist/types/extractor/util.d.ts +47 -0
- package/dist/types/extractor/web-extractor.d.ts +24 -0
- package/dist/types/img/box-select.d.ts +26 -0
- package/dist/types/img/canvas-fallback.d.ts +105 -0
- package/dist/types/img/get-photon.d.ts +19 -0
- package/dist/types/img/get-sharp.d.ts +3 -0
- package/dist/types/img/index.d.ts +3 -0
- package/dist/types/img/info.d.ts +34 -0
- package/dist/types/img/transform.d.ts +98 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/key-alias-utils.d.ts +9 -0
- package/dist/types/logger.d.ts +5 -0
- package/dist/types/mcp/base-server.d.ts +93 -0
- package/dist/types/mcp/base-tools.d.ts +148 -0
- package/dist/types/mcp/chrome-path.d.ts +2 -0
- package/dist/types/mcp/cli-report-session.d.ts +12 -0
- package/dist/types/mcp/error-formatter.d.ts +12 -0
- package/dist/types/mcp/index.d.ts +9 -0
- package/dist/types/mcp/init-arg-utils.d.ts +13 -0
- package/dist/types/mcp/inject-report-html-plugin.d.ts +18 -0
- package/dist/types/mcp/launcher-helper.d.ts +94 -0
- package/dist/types/mcp/tool-generator.d.ts +10 -0
- package/dist/types/mcp/types.d.ts +113 -0
- package/dist/types/node/fs.d.ts +15 -0
- package/dist/types/node/index.d.ts +2 -0
- package/dist/types/node/port.d.ts +8 -0
- package/dist/types/polyfills/async-hooks.d.ts +6 -0
- package/dist/types/polyfills/index.d.ts +4 -0
- package/dist/types/types/index.d.ts +36 -0
- package/dist/types/us-keyboard-layout.d.ts +32 -0
- package/dist/types/utils.d.ts +34 -0
- package/dist/types/zod-schema-utils.d.ts +23 -0
- package/package.json +125 -0
- package/src/baseDB.ts +158 -0
- package/src/cli/cli-args.ts +173 -0
- package/src/cli/cli-error.ts +24 -0
- package/src/cli/cli-runner.ts +230 -0
- package/src/cli/index.ts +4 -0
- package/src/common.ts +67 -0
- package/src/constants/example-code.ts +227 -0
- package/src/constants/index.ts +139 -0
- package/src/env/basic.ts +12 -0
- package/src/env/constants.ts +303 -0
- package/src/env/global-config-manager.ts +191 -0
- package/src/env/helper.ts +58 -0
- package/src/env/index.ts +4 -0
- package/src/env/init-debug.ts +34 -0
- package/src/env/model-config-manager.ts +149 -0
- package/src/env/parse-model-config.ts +357 -0
- package/src/env/types.ts +583 -0
- package/src/env/utils.ts +39 -0
- package/src/extractor/constants.ts +5 -0
- package/src/extractor/cs_postmessage.ts +136 -0
- package/src/extractor/customLocator.ts +1245 -0
- package/src/extractor/debug.ts +10 -0
- package/src/extractor/dom-util.ts +231 -0
- package/src/extractor/index.ts +50 -0
- package/src/extractor/locator.ts +469 -0
- package/src/extractor/tree.ts +179 -0
- package/src/extractor/util.ts +482 -0
- package/src/extractor/web-extractor.ts +617 -0
- package/src/img/box-select.ts +588 -0
- package/src/img/canvas-fallback.ts +393 -0
- package/src/img/get-photon.ts +108 -0
- package/src/img/get-sharp.ts +18 -0
- package/src/img/index.ts +27 -0
- package/src/img/info.ts +102 -0
- package/src/img/transform.ts +553 -0
- package/src/index.ts +1 -0
- package/src/key-alias-utils.ts +23 -0
- package/src/logger.ts +96 -0
- package/src/mcp/base-server.ts +500 -0
- package/src/mcp/base-tools.ts +391 -0
- package/src/mcp/chrome-path.ts +48 -0
- package/src/mcp/cli-report-session.ts +130 -0
- package/src/mcp/error-formatter.ts +52 -0
- package/src/mcp/index.ts +9 -0
- package/src/mcp/init-arg-utils.ts +105 -0
- package/src/mcp/inject-report-html-plugin.ts +119 -0
- package/src/mcp/launcher-helper.ts +200 -0
- package/src/mcp/tool-generator.ts +658 -0
- package/src/mcp/types.ts +131 -0
- package/src/node/fs.ts +84 -0
- package/src/node/index.ts +2 -0
- package/src/node/port.ts +37 -0
- package/src/polyfills/async-hooks.ts +6 -0
- package/src/polyfills/index.ts +4 -0
- package/src/types/index.ts +54 -0
- package/src/us-keyboard-layout.ts +723 -0
- package/src/utils.ts +149 -0
- package/src/zod-schema-utils.ts +133 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { sha256 } from "js-sha256";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
const ifInBrowser = "u" > typeof window;
|
|
4
|
+
const ifInWorker = "u" > typeof WorkerGlobalScope;
|
|
5
|
+
const ifInNode = "u" > typeof process && process.versions?.node;
|
|
6
|
+
function uuid() {
|
|
7
|
+
return v4();
|
|
8
|
+
}
|
|
9
|
+
const hashMap = {};
|
|
10
|
+
function generateHashId(rect, content = '') {
|
|
11
|
+
const combined = JSON.stringify({
|
|
12
|
+
content,
|
|
13
|
+
rect
|
|
14
|
+
});
|
|
15
|
+
let sliceLength = 5;
|
|
16
|
+
let slicedHash = '';
|
|
17
|
+
const hashHex = sha256.create().update(combined).hex();
|
|
18
|
+
const toLetters = (hex)=>hex.split('').map((char)=>{
|
|
19
|
+
const code = Number.parseInt(char, 16);
|
|
20
|
+
return String.fromCharCode(97 + code % 26);
|
|
21
|
+
}).join('');
|
|
22
|
+
const hashLetters = toLetters(hashHex);
|
|
23
|
+
while(sliceLength < hashLetters.length - 1){
|
|
24
|
+
slicedHash = hashLetters.slice(0, sliceLength);
|
|
25
|
+
if (hashMap[slicedHash] && hashMap[slicedHash] !== combined) {
|
|
26
|
+
sliceLength++;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
hashMap[slicedHash] = combined;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
return slicedHash;
|
|
33
|
+
}
|
|
34
|
+
function assert(condition, message) {
|
|
35
|
+
if (!condition) throw new Error(message || 'Assertion failed');
|
|
36
|
+
}
|
|
37
|
+
let isMcp = false;
|
|
38
|
+
function setIsMcp(value) {
|
|
39
|
+
isMcp = value;
|
|
40
|
+
}
|
|
41
|
+
function logMsg(...message) {
|
|
42
|
+
if (!isMcp) console.log(...message);
|
|
43
|
+
}
|
|
44
|
+
async function repeat(times, fn) {
|
|
45
|
+
for(let i = 0; i < times; i++)await fn(i);
|
|
46
|
+
}
|
|
47
|
+
const utils_REGEXP_LT = /</g;
|
|
48
|
+
const utils_REGEXP_GT = />/g;
|
|
49
|
+
const REGEXP_LT_ESCAPE = '__midscene_lt__';
|
|
50
|
+
const REGEXP_GT_ESCAPE = '__midscene_gt__';
|
|
51
|
+
const escapeScriptTag = (html)=>html.replace(utils_REGEXP_LT, REGEXP_LT_ESCAPE).replace(utils_REGEXP_GT, REGEXP_GT_ESCAPE);
|
|
52
|
+
const antiEscapeScriptTag = (html)=>{
|
|
53
|
+
const REGEXP_LT = new RegExp(REGEXP_LT_ESCAPE, 'g');
|
|
54
|
+
const REGEXP_GT = new RegExp(REGEXP_GT_ESCAPE, 'g');
|
|
55
|
+
return html.replace(REGEXP_LT, '<').replace(REGEXP_GT, '>');
|
|
56
|
+
};
|
|
57
|
+
function replaceIllegalPathCharsAndSpace(str) {
|
|
58
|
+
return str.replace(/[:*?"<>|# ]/g, '-');
|
|
59
|
+
}
|
|
60
|
+
function isPlainObject(value) {
|
|
61
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
62
|
+
}
|
|
63
|
+
function normalizeForComparison(str) {
|
|
64
|
+
return str.toLowerCase().replace(/[\s\-_]+/g, '');
|
|
65
|
+
}
|
|
66
|
+
function mergeAndNormalizeAppNameMapping(defaultMapping, userMapping) {
|
|
67
|
+
const result = {};
|
|
68
|
+
for (const [key, value] of Object.entries(defaultMapping))result[normalizeForComparison(key)] = value;
|
|
69
|
+
if (userMapping) for (const [key, value] of Object.entries(userMapping))result[normalizeForComparison(key)] = value;
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
export { antiEscapeScriptTag, assert, escapeScriptTag, generateHashId, ifInBrowser, ifInNode, ifInWorker, isPlainObject, logMsg, mergeAndNormalizeAppNameMapping, normalizeForComparison, repeat, replaceIllegalPathCharsAndSpace, setIsMcp, uuid };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function unwrapZodField(field) {
|
|
2
|
+
const f = field;
|
|
3
|
+
if (!f._def) return f;
|
|
4
|
+
const typeName = f._def.typeName;
|
|
5
|
+
if ('ZodOptional' === typeName || 'ZodNullable' === typeName || 'ZodDefault' === typeName) return unwrapZodField(f._def.innerType);
|
|
6
|
+
if ('ZodEffects' === typeName) {
|
|
7
|
+
if (f._def.schema) return unwrapZodField(f._def.schema);
|
|
8
|
+
}
|
|
9
|
+
return f;
|
|
10
|
+
}
|
|
11
|
+
function isMidsceneLocatorField(field) {
|
|
12
|
+
const actualField = unwrapZodField(field);
|
|
13
|
+
if (actualField._def?.typeName === 'ZodObject') {
|
|
14
|
+
const shape = actualField._def.shape?.();
|
|
15
|
+
if (shape) {
|
|
16
|
+
if ('midscene_location_field_flag' in shape) return true;
|
|
17
|
+
if ('prompt' in shape && shape.prompt) return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
function getZodTypeName(field, locatorTypeDescription) {
|
|
23
|
+
const actualField = unwrapZodField(field);
|
|
24
|
+
const fieldTypeName = actualField._def?.typeName;
|
|
25
|
+
if ('ZodString' === fieldTypeName) return 'string';
|
|
26
|
+
if ('ZodNumber' === fieldTypeName) return 'number';
|
|
27
|
+
if ('ZodBoolean' === fieldTypeName) return 'boolean';
|
|
28
|
+
if ('ZodArray' === fieldTypeName) return 'array';
|
|
29
|
+
if ('ZodObject' === fieldTypeName) {
|
|
30
|
+
if (isMidsceneLocatorField(actualField)) return locatorTypeDescription || 'object';
|
|
31
|
+
return 'object';
|
|
32
|
+
}
|
|
33
|
+
if ('ZodEnum' === fieldTypeName) {
|
|
34
|
+
const values = actualField._def?.values?.map((option)=>String(`'${option}'`)).join(', ') ?? 'enum';
|
|
35
|
+
return `enum(${values})`;
|
|
36
|
+
}
|
|
37
|
+
if ('ZodUnion' === fieldTypeName) {
|
|
38
|
+
const options = actualField._def?.options;
|
|
39
|
+
if (options && options.length > 0) {
|
|
40
|
+
const types = options.map((opt)=>getZodTypeName(opt, locatorTypeDescription));
|
|
41
|
+
return types.join(' | ');
|
|
42
|
+
}
|
|
43
|
+
return 'union';
|
|
44
|
+
}
|
|
45
|
+
return 'unknown';
|
|
46
|
+
}
|
|
47
|
+
function getZodDescription(field) {
|
|
48
|
+
if ("description" in field) return field.description || null;
|
|
49
|
+
const actualField = unwrapZodField(field);
|
|
50
|
+
if ("description" in actualField) return actualField.description || null;
|
|
51
|
+
if (isMidsceneLocatorField(actualField)) return 'Location information for the target element';
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
export { getZodDescription, getZodTypeName, isMidsceneLocatorField, unwrapZodField };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
IndexedDBManager: ()=>IndexedDBManager,
|
|
28
|
+
createCleanupFunction: ()=>createCleanupFunction,
|
|
29
|
+
withErrorHandling: ()=>withErrorHandling
|
|
30
|
+
});
|
|
31
|
+
function _define_property(obj, key, value) {
|
|
32
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
else obj[key] = value;
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
class IndexedDBManager {
|
|
42
|
+
initDB() {
|
|
43
|
+
return new Promise((resolve, reject)=>{
|
|
44
|
+
const request = indexedDB.open(this.dbName, this.version);
|
|
45
|
+
request.onerror = ()=>reject(request.error);
|
|
46
|
+
request.onsuccess = ()=>resolve(request.result);
|
|
47
|
+
request.onupgradeneeded = (event)=>{
|
|
48
|
+
const db = event.target.result;
|
|
49
|
+
this.storeConfigs.forEach(({ name, keyPath })=>{
|
|
50
|
+
if (!db.objectStoreNames.contains(name)) {
|
|
51
|
+
const store = db.createObjectStore(name, {
|
|
52
|
+
keyPath
|
|
53
|
+
});
|
|
54
|
+
store.createIndex('timestamp', 'timestamp', {
|
|
55
|
+
unique: false
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async withTransaction(storeNames, mode, operation) {
|
|
63
|
+
const db = await this.dbPromise;
|
|
64
|
+
const transaction = db.transaction(storeNames, mode);
|
|
65
|
+
const stores = Array.isArray(storeNames) ? storeNames.map((name)=>transaction.objectStore(name)) : transaction.objectStore(storeNames);
|
|
66
|
+
return operation(stores);
|
|
67
|
+
}
|
|
68
|
+
promisifyRequest(request) {
|
|
69
|
+
return new Promise((resolve, reject)=>{
|
|
70
|
+
request.onsuccess = ()=>resolve(request.result);
|
|
71
|
+
request.onerror = ()=>reject(request.error);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async put(storeName, data) {
|
|
75
|
+
await this.withTransaction(storeName, 'readwrite', async (store)=>{
|
|
76
|
+
await this.promisifyRequest(store.put(data));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async get(storeName, key) {
|
|
80
|
+
return this.withTransaction(storeName, 'readonly', async (store)=>this.promisifyRequest(store.get(key)));
|
|
81
|
+
}
|
|
82
|
+
async getAll(storeName, sortByTimestamp = true) {
|
|
83
|
+
return this.withTransaction(storeName, 'readonly', async (store)=>{
|
|
84
|
+
const objectStore = store;
|
|
85
|
+
const results = sortByTimestamp ? await this.promisifyRequest(objectStore.index('timestamp').getAll()) : await this.promisifyRequest(objectStore.getAll());
|
|
86
|
+
return sortByTimestamp ? results.sort((a, b)=>a.timestamp - b.timestamp) : results;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async clear(storeName) {
|
|
90
|
+
await this.withTransaction(storeName, 'readwrite', async (store)=>{
|
|
91
|
+
await this.promisifyRequest(store.clear());
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async delete(storeName, key) {
|
|
95
|
+
await this.withTransaction(storeName, 'readwrite', async (store)=>{
|
|
96
|
+
await this.promisifyRequest(store.delete(key));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async count(storeName) {
|
|
100
|
+
return this.withTransaction(storeName, 'readonly', async (store)=>this.promisifyRequest(store.count()));
|
|
101
|
+
}
|
|
102
|
+
getDBPromise() {
|
|
103
|
+
return this.dbPromise;
|
|
104
|
+
}
|
|
105
|
+
constructor(dbName, version, storeConfigs){
|
|
106
|
+
_define_property(this, "dbPromise", void 0);
|
|
107
|
+
_define_property(this, "dbName", void 0);
|
|
108
|
+
_define_property(this, "version", void 0);
|
|
109
|
+
_define_property(this, "storeConfigs", void 0);
|
|
110
|
+
this.dbName = dbName;
|
|
111
|
+
this.version = version;
|
|
112
|
+
this.storeConfigs = storeConfigs;
|
|
113
|
+
this.dbPromise = this.initDB();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const withErrorHandling = async (operation, errorMessage, defaultValue, onQuotaExceeded)=>{
|
|
117
|
+
try {
|
|
118
|
+
return await operation();
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error(errorMessage, e);
|
|
121
|
+
if (e instanceof Error && 'QuotaExceededError' === e.name && onQuotaExceeded) {
|
|
122
|
+
console.log('Storage quota exceeded, running cleanup...');
|
|
123
|
+
await onQuotaExceeded();
|
|
124
|
+
}
|
|
125
|
+
return defaultValue;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const createCleanupFunction = (dbManager, storeName, maxItems)=>async ()=>{
|
|
129
|
+
try {
|
|
130
|
+
const results = await dbManager.getAll(storeName);
|
|
131
|
+
if (results.length > maxItems) {
|
|
132
|
+
const toDelete = results.sort((a, b)=>a.timestamp - b.timestamp).slice(0, results.length - maxItems);
|
|
133
|
+
await Promise.all(toDelete.map((item)=>dbManager.delete(storeName, item.id)));
|
|
134
|
+
}
|
|
135
|
+
} catch (e) {
|
|
136
|
+
console.error(`Failed to cleanup ${storeName}:`, e);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
exports.IndexedDBManager = __webpack_exports__.IndexedDBManager;
|
|
140
|
+
exports.createCleanupFunction = __webpack_exports__.createCleanupFunction;
|
|
141
|
+
exports.withErrorHandling = __webpack_exports__.withErrorHandling;
|
|
142
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
143
|
+
"IndexedDBManager",
|
|
144
|
+
"createCleanupFunction",
|
|
145
|
+
"withErrorHandling"
|
|
146
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
147
|
+
Object.defineProperty(exports, '__esModule', {
|
|
148
|
+
value: true
|
|
149
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
parseCliArgs: ()=>parseCliArgs,
|
|
28
|
+
parseValue: ()=>parseValue,
|
|
29
|
+
formatCliValidationError: ()=>formatCliValidationError,
|
|
30
|
+
getCliOptionDisplay: ()=>getCliOptionDisplay
|
|
31
|
+
});
|
|
32
|
+
const external_zod_namespaceObject = require("zod");
|
|
33
|
+
const external_key_alias_utils_js_namespaceObject = require("../key-alias-utils.js");
|
|
34
|
+
function parseValue(raw) {
|
|
35
|
+
if (raw.startsWith('{') || raw.startsWith('[')) try {
|
|
36
|
+
return JSON.parse(raw);
|
|
37
|
+
} catch {}
|
|
38
|
+
if (/^-?\d+(\.\d+)?$/.test(raw)) return Number(raw);
|
|
39
|
+
return raw;
|
|
40
|
+
}
|
|
41
|
+
function walkCliArgs(args, setArgValue) {
|
|
42
|
+
for(let i = 0; i < args.length; i++){
|
|
43
|
+
const arg = args[i];
|
|
44
|
+
if (!arg.startsWith('--')) continue;
|
|
45
|
+
const body = arg.slice(2);
|
|
46
|
+
const eqIdx = body.indexOf('=');
|
|
47
|
+
if (eqIdx >= 0) setArgValue(body.slice(0, eqIdx), parseValue(body.slice(eqIdx + 1)));
|
|
48
|
+
else if (args[i + 1] && !args[i + 1].startsWith('--')) {
|
|
49
|
+
i++;
|
|
50
|
+
setArgValue(body, parseValue(args[i]));
|
|
51
|
+
} else setArgValue(body, true);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function parseCliArgs(args) {
|
|
55
|
+
const result = {};
|
|
56
|
+
walkCliArgs(args, (key, value)=>{
|
|
57
|
+
result[key] = value;
|
|
58
|
+
});
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
function formatCliOptionName(name) {
|
|
62
|
+
return `--${name}`;
|
|
63
|
+
}
|
|
64
|
+
function getCliOptionDisplay(key, cliOption) {
|
|
65
|
+
const label = formatCliOptionName(cliOption?.preferredName ?? key);
|
|
66
|
+
const aliases = [
|
|
67
|
+
...new Set(cliOption?.aliases ?? [])
|
|
68
|
+
].map((alias)=>formatCliOptionName(alias)).filter((alias)=>alias !== label);
|
|
69
|
+
return {
|
|
70
|
+
label,
|
|
71
|
+
aliases
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function getAcceptedCliOptionNames(key, cliOption) {
|
|
75
|
+
return [
|
|
76
|
+
...new Set(cliOption ? [
|
|
77
|
+
cliOption.preferredName ?? key,
|
|
78
|
+
...cliOption.aliases ?? []
|
|
79
|
+
] : [
|
|
80
|
+
key,
|
|
81
|
+
...(0, external_key_alias_utils_js_namespaceObject.getKeyAliases)(key)
|
|
82
|
+
])
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
function toOptionalCliSchemaField(field) {
|
|
86
|
+
if ('object' == typeof field && null !== field && 'function' == typeof field.optional) return field.optional();
|
|
87
|
+
const description = 'object' == typeof field && null !== field && "description" in field && 'string' == typeof field.description ? field.description : void 0;
|
|
88
|
+
return description ? external_zod_namespaceObject.z.any().describe(description) : external_zod_namespaceObject.z.any();
|
|
89
|
+
}
|
|
90
|
+
function buildCliArgSchema(def) {
|
|
91
|
+
return Object.fromEntries(Object.entries(def.schema).flatMap(([key, zodType])=>getAcceptedCliOptionNames(key, def.cli?.options?.[key]).map((cliKey)=>[
|
|
92
|
+
cliKey,
|
|
93
|
+
toOptionalCliSchemaField(zodType)
|
|
94
|
+
])));
|
|
95
|
+
}
|
|
96
|
+
function buildDisallowedCliSpellings(def) {
|
|
97
|
+
const disallowedSpellings = new Set();
|
|
98
|
+
for (const [key] of Object.entries(def.schema)){
|
|
99
|
+
const cliOption = def.cli?.options?.[key];
|
|
100
|
+
const acceptedNames = new Set(getAcceptedCliOptionNames(key, cliOption));
|
|
101
|
+
const knownSpellings = new Set([
|
|
102
|
+
key,
|
|
103
|
+
...(0, external_key_alias_utils_js_namespaceObject.getKeyAliases)(key),
|
|
104
|
+
...cliOption?.preferredName ? (0, external_key_alias_utils_js_namespaceObject.getKeyAliases)(cliOption.preferredName) : [],
|
|
105
|
+
...cliOption?.aliases ?? []
|
|
106
|
+
]);
|
|
107
|
+
for (const spelling of knownSpellings)if (!acceptedNames.has(spelling)) disallowedSpellings.add(spelling);
|
|
108
|
+
}
|
|
109
|
+
return disallowedSpellings;
|
|
110
|
+
}
|
|
111
|
+
function formatCliValidationError(scriptName, commandName, def, rawArgs) {
|
|
112
|
+
if (0 === Object.keys(def.schema).length) return;
|
|
113
|
+
const cliSchema = external_zod_namespaceObject.z.object(buildCliArgSchema(def)).strict();
|
|
114
|
+
const parsed = cliSchema.safeParse(rawArgs);
|
|
115
|
+
if (parsed.success) return;
|
|
116
|
+
const disallowedSpellings = buildDisallowedCliSpellings(def);
|
|
117
|
+
const unknownKeys = parsed.error.issues.flatMap((issue)=>'unrecognized_keys' === issue.code ? issue.keys : []);
|
|
118
|
+
if (unknownKeys.length > 0) return unknownKeys.map((key)=>{
|
|
119
|
+
if (disallowedSpellings.has(key)) return `Unsupported option "--${key}" for ${scriptName} ${commandName}.`;
|
|
120
|
+
return `Unknown option "--${key}" for ${scriptName} ${commandName}.`;
|
|
121
|
+
}).join('\n');
|
|
122
|
+
const [issue] = parsed.error.issues;
|
|
123
|
+
const optionName = 'string' == typeof issue?.path[0] ? `--${issue.path[0]}` : 'CLI arguments';
|
|
124
|
+
return `Invalid value for "${optionName}" in ${scriptName} ${commandName}: ${issue?.message ?? parsed.error.message}`;
|
|
125
|
+
}
|
|
126
|
+
exports.formatCliValidationError = __webpack_exports__.formatCliValidationError;
|
|
127
|
+
exports.getCliOptionDisplay = __webpack_exports__.getCliOptionDisplay;
|
|
128
|
+
exports.parseCliArgs = __webpack_exports__.parseCliArgs;
|
|
129
|
+
exports.parseValue = __webpack_exports__.parseValue;
|
|
130
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
131
|
+
"formatCliValidationError",
|
|
132
|
+
"getCliOptionDisplay",
|
|
133
|
+
"parseCliArgs",
|
|
134
|
+
"parseValue"
|
|
135
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
136
|
+
Object.defineProperty(exports, '__esModule', {
|
|
137
|
+
value: true
|
|
138
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
CLIError: ()=>CLIError,
|
|
28
|
+
reportCLIError: ()=>reportCLIError
|
|
29
|
+
});
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
32
|
+
value: value,
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true
|
|
36
|
+
});
|
|
37
|
+
else obj[key] = value;
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
40
|
+
class CLIError extends Error {
|
|
41
|
+
constructor(message, exitCode = 1){
|
|
42
|
+
super(message), _define_property(this, "exitCode", void 0), this.exitCode = exitCode;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function reportCLIError(error, log = console.error) {
|
|
46
|
+
if (error instanceof CLIError) {
|
|
47
|
+
log(error.message);
|
|
48
|
+
return error.exitCode;
|
|
49
|
+
}
|
|
50
|
+
log(error);
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
exports.CLIError = __webpack_exports__.CLIError;
|
|
54
|
+
exports.reportCLIError = __webpack_exports__.reportCLIError;
|
|
55
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
56
|
+
"CLIError",
|
|
57
|
+
"reportCLIError"
|
|
58
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
59
|
+
Object.defineProperty(exports, '__esModule', {
|
|
60
|
+
value: true
|
|
61
|
+
});
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
CLIError: ()=>external_cli_error_js_namespaceObject.CLIError,
|
|
37
|
+
parseCliArgs: ()=>external_cli_args_js_namespaceObject.parseCliArgs,
|
|
38
|
+
parseValue: ()=>external_cli_args_js_namespaceObject.parseValue,
|
|
39
|
+
runToolsCLI: ()=>runToolsCLI,
|
|
40
|
+
reportCLIError: ()=>external_cli_error_js_namespaceObject.reportCLIError,
|
|
41
|
+
removePrefix: ()=>removePrefix
|
|
42
|
+
});
|
|
43
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
44
|
+
const external_node_os_namespaceObject = require("node:os");
|
|
45
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
46
|
+
const external_dotenv_namespaceObject = require("dotenv");
|
|
47
|
+
var external_dotenv_default = /*#__PURE__*/ __webpack_require__.n(external_dotenv_namespaceObject);
|
|
48
|
+
const external_logger_js_namespaceObject = require("../logger.js");
|
|
49
|
+
const external_cli_args_js_namespaceObject = require("./cli-args.js");
|
|
50
|
+
const external_cli_error_js_namespaceObject = require("./cli-error.js");
|
|
51
|
+
const debug = (0, external_logger_js_namespaceObject.getDebug)('cli-runner');
|
|
52
|
+
function outputContentItem(item, isError) {
|
|
53
|
+
switch(item.type){
|
|
54
|
+
case 'text':
|
|
55
|
+
if (isError) console.error(item.text);
|
|
56
|
+
else console.log(item.text);
|
|
57
|
+
break;
|
|
58
|
+
case 'image':
|
|
59
|
+
{
|
|
60
|
+
const filename = `screenshot-${Date.now()}.png`;
|
|
61
|
+
const filepath = (0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), filename);
|
|
62
|
+
(0, external_node_fs_namespaceObject.writeFileSync)(filepath, Buffer.from(item.data, 'base64'));
|
|
63
|
+
console.log(`Screenshot saved: ${filepath}`);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
default:
|
|
67
|
+
console.log(`[${item.type} content not displayed in CLI]`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function outputResult(result) {
|
|
71
|
+
for (const item of result.content)outputContentItem(item, result.isError ?? false);
|
|
72
|
+
}
|
|
73
|
+
function removePrefix(name, prefix) {
|
|
74
|
+
if (prefix && name.startsWith(prefix)) return name.slice(prefix.length);
|
|
75
|
+
return name;
|
|
76
|
+
}
|
|
77
|
+
function printCommandHelp(scriptName, cmd) {
|
|
78
|
+
const { def } = cmd;
|
|
79
|
+
console.log(`\nUsage: ${scriptName} ${cmd.name} [options]\n`);
|
|
80
|
+
console.log(def.description);
|
|
81
|
+
const schemaEntries = Object.entries(def.schema);
|
|
82
|
+
if (schemaEntries.length > 0) {
|
|
83
|
+
const optionWidth = Math.max(22, ...schemaEntries.map(([key])=>(0, external_cli_args_js_namespaceObject.getCliOptionDisplay)(key, def.cli?.options?.[key]).label.length));
|
|
84
|
+
console.log('\nOptions:');
|
|
85
|
+
for (const [key, zodType] of schemaEntries){
|
|
86
|
+
const { label, aliases } = (0, external_cli_args_js_namespaceObject.getCliOptionDisplay)(key, def.cli?.options?.[key]);
|
|
87
|
+
const desc = zodType.description ?? '';
|
|
88
|
+
const aliasText = aliases.length > 0 ? ` (aliases: ${aliases.join(', ')})` : '';
|
|
89
|
+
console.log(` ${label.padEnd(optionWidth)} ${desc}${aliasText}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function printVersion(scriptName, version) {
|
|
94
|
+
console.log(`${scriptName} v${version}`);
|
|
95
|
+
}
|
|
96
|
+
function printHelp(scriptName, commands, version) {
|
|
97
|
+
if (version) {
|
|
98
|
+
printVersion(scriptName, version);
|
|
99
|
+
console.log('');
|
|
100
|
+
}
|
|
101
|
+
console.log(`\nUsage: ${scriptName} <command> [options]\n`);
|
|
102
|
+
console.log('Commands:');
|
|
103
|
+
for (const { name, def } of commands.filter((command)=>!command.hidden))console.log(` ${name.padEnd(30)} ${def.description}`);
|
|
104
|
+
console.log(` ${'version'.padEnd(30)} Show CLI version`);
|
|
105
|
+
console.log(`\nRun "${scriptName} <command> --help" for more info.`);
|
|
106
|
+
}
|
|
107
|
+
async function runToolsCLI(tools, scriptName, options) {
|
|
108
|
+
const rawArgs = options?.argv ?? process.argv.slice(2);
|
|
109
|
+
debug('CLI invoked: %s %s', scriptName, rawArgs.join(' '));
|
|
110
|
+
const envFile = (0, external_node_path_namespaceObject.join)(process.cwd(), '.env');
|
|
111
|
+
if ((0, external_node_fs_namespaceObject.existsSync)(envFile)) external_dotenv_default().config({
|
|
112
|
+
path: envFile
|
|
113
|
+
});
|
|
114
|
+
await tools.initTools();
|
|
115
|
+
const commands = tools.getToolDefinitions().map((def)=>({
|
|
116
|
+
name: removePrefix(def.name, options?.stripPrefix).toLowerCase(),
|
|
117
|
+
def
|
|
118
|
+
}));
|
|
119
|
+
if (options?.extraCommands?.length) commands.push(...options.extraCommands.flatMap((cmd)=>[
|
|
120
|
+
{
|
|
121
|
+
name: cmd.name.toLowerCase(),
|
|
122
|
+
def: cmd.def,
|
|
123
|
+
hidden: cmd.hidden
|
|
124
|
+
},
|
|
125
|
+
...(cmd.aliases ?? []).map((alias)=>({
|
|
126
|
+
name: alias.toLowerCase(),
|
|
127
|
+
def: cmd.def,
|
|
128
|
+
hidden: true
|
|
129
|
+
}))
|
|
130
|
+
]));
|
|
131
|
+
const cliVersion = options?.version;
|
|
132
|
+
const [commandName, ...restArgs] = rawArgs;
|
|
133
|
+
if (!commandName || '--help' === commandName || '-h' === commandName) {
|
|
134
|
+
debug('showing help (no command or --help flag)');
|
|
135
|
+
printHelp(scriptName, commands, cliVersion);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if ('--version' === commandName || '-v' === commandName || 'version' === commandName.toLowerCase()) {
|
|
139
|
+
if (!cliVersion) throw new external_cli_error_js_namespaceObject.CLIError('Failed to determine CLI version');
|
|
140
|
+
printVersion(scriptName, cliVersion);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const match = commands.find((c)=>c.name.toLowerCase() === commandName.toLowerCase());
|
|
144
|
+
if (!match) {
|
|
145
|
+
debug('unknown command: %s', commandName);
|
|
146
|
+
console.error(`Unknown command: ${commandName}`);
|
|
147
|
+
printHelp(scriptName, commands, cliVersion);
|
|
148
|
+
throw new external_cli_error_js_namespaceObject.CLIError(`Unknown command: ${commandName}`);
|
|
149
|
+
}
|
|
150
|
+
const parsedArgs = (0, external_cli_args_js_namespaceObject.parseCliArgs)(restArgs);
|
|
151
|
+
if (true === parsedArgs.help) {
|
|
152
|
+
debug('showing command help for: %s', match.name);
|
|
153
|
+
printCommandHelp(scriptName, match);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const cliValidationError = (0, external_cli_args_js_namespaceObject.formatCliValidationError)(scriptName, match.name, match.def, parsedArgs);
|
|
157
|
+
if (cliValidationError) throw new external_cli_error_js_namespaceObject.CLIError(cliValidationError);
|
|
158
|
+
debug('command: %s, args: %s', match.name, JSON.stringify(parsedArgs));
|
|
159
|
+
const result = await match.def.handler(parsedArgs);
|
|
160
|
+
debug('command %s completed, isError: %s', match.name, result.isError ?? false);
|
|
161
|
+
outputResult(result);
|
|
162
|
+
await tools.destroy();
|
|
163
|
+
if (result.isError) throw new external_cli_error_js_namespaceObject.CLIError('Command failed', 1);
|
|
164
|
+
}
|
|
165
|
+
exports.CLIError = __webpack_exports__.CLIError;
|
|
166
|
+
exports.parseCliArgs = __webpack_exports__.parseCliArgs;
|
|
167
|
+
exports.parseValue = __webpack_exports__.parseValue;
|
|
168
|
+
exports.removePrefix = __webpack_exports__.removePrefix;
|
|
169
|
+
exports.reportCLIError = __webpack_exports__.reportCLIError;
|
|
170
|
+
exports.runToolsCLI = __webpack_exports__.runToolsCLI;
|
|
171
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
172
|
+
"CLIError",
|
|
173
|
+
"parseCliArgs",
|
|
174
|
+
"parseValue",
|
|
175
|
+
"removePrefix",
|
|
176
|
+
"reportCLIError",
|
|
177
|
+
"runToolsCLI"
|
|
178
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
179
|
+
Object.defineProperty(exports, '__esModule', {
|
|
180
|
+
value: true
|
|
181
|
+
});
|