@moostjs/event-cli 0.6.8 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +19 -43
- package/dist/index.mjs +7 -9
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const moost = __toESM(require("moost"));
|
|
25
|
-
const __wooksjs_event_cli = __toESM(require("@wooksjs/event-cli"));
|
|
26
|
-
const __wooksjs_event_core = __toESM(require("@wooksjs/event-core"));
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let moost = require("moost");
|
|
3
|
+
let _wooksjs_event_cli = require("@wooksjs/event-cli");
|
|
4
|
+
let _wooksjs_event_core = require("@wooksjs/event-core");
|
|
27
5
|
|
|
28
6
|
//#region packages/event-cli/src/meta-types.ts
|
|
29
7
|
function getCliMate() {
|
|
@@ -81,8 +59,7 @@ function getCliMate() {
|
|
|
81
59
|
//#endregion
|
|
82
60
|
//#region packages/event-cli/src/utils.ts
|
|
83
61
|
function formatParams(keys) {
|
|
84
|
-
|
|
85
|
-
return names.map((n) => n.length === 1 ? `-${n}` : `--${n}`);
|
|
62
|
+
return [keys].flat().map((n) => n.length === 1 ? `-${n}` : `--${n}`);
|
|
86
63
|
}
|
|
87
64
|
|
|
88
65
|
//#endregion
|
|
@@ -107,7 +84,7 @@ function formatParams(keys) {
|
|
|
107
84
|
* @returns
|
|
108
85
|
*/ function CliOption(...keys) {
|
|
109
86
|
const mate = getCliMate();
|
|
110
|
-
return mate.apply(mate.decorate("cliOptionsKeys", keys, false), (0, moost.Resolve)(() => (0,
|
|
87
|
+
return mate.apply(mate.decorate("cliOptionsKeys", keys, false), (0, moost.Resolve)(() => (0, _wooksjs_event_cli.useCliOption)(keys[0]), formatParams(keys).join(", ")));
|
|
111
88
|
}
|
|
112
89
|
/**
|
|
113
90
|
* ## Define Global CLI Option
|
|
@@ -116,8 +93,7 @@ function formatParams(keys) {
|
|
|
116
93
|
* @param option keys and description of CLI option
|
|
117
94
|
* @returns
|
|
118
95
|
*/ function CliGlobalOption(option) {
|
|
119
|
-
|
|
120
|
-
return mate.decorate("cliOptions", option, true);
|
|
96
|
+
return getCliMate().decorate("cliOptions", option, true);
|
|
121
97
|
}
|
|
122
98
|
|
|
123
99
|
//#endregion
|
|
@@ -165,7 +141,7 @@ const CONTEXT_TYPE = "CLI";
|
|
|
165
141
|
* ```
|
|
166
142
|
*/ var MoostCli = class {
|
|
167
143
|
async onNotFound() {
|
|
168
|
-
const pathParams = (0,
|
|
144
|
+
const pathParams = (0, _wooksjs_event_core.current)().get(_wooksjs_event_cli.cliKind.keys.pathParams) || [];
|
|
169
145
|
const response = await (0, moost.defineMoostEventHandler)({
|
|
170
146
|
loggerTitle: LOGGER_TITLE,
|
|
171
147
|
getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
|
|
@@ -219,8 +195,8 @@ const CONTEXT_TYPE = "CLI";
|
|
|
219
195
|
].forEach((o) => cliOptions.set(o.keys[0], o));
|
|
220
196
|
const aliases = [];
|
|
221
197
|
if (meta?.cliAliases) for (const alias of meta.cliAliases) {
|
|
222
|
-
const targetPath
|
|
223
|
-
aliases.push(targetPath
|
|
198
|
+
const targetPath = makePath(alias);
|
|
199
|
+
aliases.push(targetPath);
|
|
224
200
|
}
|
|
225
201
|
const cliOptionsArray = Array.from(cliOptions.values());
|
|
226
202
|
cliOptionsArray.forEach((o) => {
|
|
@@ -238,9 +214,9 @@ const CONTEXT_TYPE = "CLI";
|
|
|
238
214
|
aliases,
|
|
239
215
|
examples: meta?.cliExamples || [],
|
|
240
216
|
handler: fn,
|
|
241
|
-
onRegister: (path
|
|
242
|
-
opts.register(handler, path
|
|
243
|
-
if (this.opts?.debug) opts.logHandler(`[36m(${aliasTypes[aliasType]})[32m${path
|
|
217
|
+
onRegister: (path, aliasType, route) => {
|
|
218
|
+
opts.register(handler, path, route?.getArgs() || routerBinding.getArgs());
|
|
219
|
+
if (this.opts?.debug) opts.logHandler(`[36m(${aliasTypes[aliasType]})[32m${path}`);
|
|
244
220
|
}
|
|
245
221
|
});
|
|
246
222
|
opts.register(handler, targetPath, routerBinding.getArgs());
|
|
@@ -256,12 +232,12 @@ const CONTEXT_TYPE = "CLI";
|
|
|
256
232
|
this.name = "cli";
|
|
257
233
|
this.optionTypes = {};
|
|
258
234
|
const cliAppOpts = opts?.wooksCli;
|
|
259
|
-
if (cliAppOpts && cliAppOpts instanceof
|
|
260
|
-
else if (cliAppOpts) this.cliApp = (0,
|
|
235
|
+
if (cliAppOpts && cliAppOpts instanceof _wooksjs_event_cli.WooksCli) this.cliApp = cliAppOpts;
|
|
236
|
+
else if (cliAppOpts) this.cliApp = (0, _wooksjs_event_cli.createCliApp)({
|
|
261
237
|
...cliAppOpts,
|
|
262
238
|
onNotFound: this.onNotFound.bind(this)
|
|
263
239
|
});
|
|
264
|
-
else this.cliApp = (0,
|
|
240
|
+
else this.cliApp = (0, _wooksjs_event_cli.createCliApp)({ onNotFound: this.onNotFound.bind(this) });
|
|
265
241
|
if (!opts?.debug) (0, moost.setInfactLoggingOptions)({
|
|
266
242
|
newInstance: false,
|
|
267
243
|
error: false,
|
|
@@ -291,14 +267,14 @@ const aliasTypes = [
|
|
|
291
267
|
* @returns TInterceptorDef
|
|
292
268
|
*/ const cliHelpInterceptor = (opts) => (0, moost.defineBeforeInterceptor)((reply) => {
|
|
293
269
|
try {
|
|
294
|
-
if ((0,
|
|
270
|
+
if ((0, _wooksjs_event_cli.useAutoHelp)(opts?.helpOptions, opts?.colors)) {
|
|
295
271
|
reply("");
|
|
296
272
|
return;
|
|
297
273
|
}
|
|
298
274
|
} catch (error) {}
|
|
299
275
|
if (opts?.lookupLevel) {
|
|
300
276
|
const { getMethod } = (0, moost.useControllerContext)();
|
|
301
|
-
if (!getMethod()) (0,
|
|
277
|
+
if (!getMethod()) (0, _wooksjs_event_cli.useCommandLookupHelp)(opts.lookupLevel);
|
|
302
278
|
}
|
|
303
279
|
}, moost.TInterceptorPriority.BEFORE_ALL);
|
|
304
280
|
/**
|
|
@@ -462,7 +438,7 @@ exports.cliHelpInterceptor = cliHelpInterceptor;
|
|
|
462
438
|
Object.defineProperty(exports, 'cliKind', {
|
|
463
439
|
enumerable: true,
|
|
464
440
|
get: function () {
|
|
465
|
-
return
|
|
441
|
+
return _wooksjs_event_cli.cliKind;
|
|
466
442
|
}
|
|
467
443
|
});
|
|
468
444
|
Object.defineProperty(exports, 'defineAfterInterceptor', {
|
package/dist/index.mjs
CHANGED
|
@@ -58,8 +58,7 @@ function getCliMate() {
|
|
|
58
58
|
//#endregion
|
|
59
59
|
//#region packages/event-cli/src/utils.ts
|
|
60
60
|
function formatParams(keys) {
|
|
61
|
-
|
|
62
|
-
return names.map((n) => n.length === 1 ? `-${n}` : `--${n}`);
|
|
61
|
+
return [keys].flat().map((n) => n.length === 1 ? `-${n}` : `--${n}`);
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
//#endregion
|
|
@@ -93,8 +92,7 @@ function formatParams(keys) {
|
|
|
93
92
|
* @param option keys and description of CLI option
|
|
94
93
|
* @returns
|
|
95
94
|
*/ function CliGlobalOption(option) {
|
|
96
|
-
|
|
97
|
-
return mate.decorate("cliOptions", option, true);
|
|
95
|
+
return getCliMate().decorate("cliOptions", option, true);
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
//#endregion
|
|
@@ -196,8 +194,8 @@ const CONTEXT_TYPE = "CLI";
|
|
|
196
194
|
].forEach((o) => cliOptions.set(o.keys[0], o));
|
|
197
195
|
const aliases = [];
|
|
198
196
|
if (meta?.cliAliases) for (const alias of meta.cliAliases) {
|
|
199
|
-
const targetPath
|
|
200
|
-
aliases.push(targetPath
|
|
197
|
+
const targetPath = makePath(alias);
|
|
198
|
+
aliases.push(targetPath);
|
|
201
199
|
}
|
|
202
200
|
const cliOptionsArray = Array.from(cliOptions.values());
|
|
203
201
|
cliOptionsArray.forEach((o) => {
|
|
@@ -215,9 +213,9 @@ const CONTEXT_TYPE = "CLI";
|
|
|
215
213
|
aliases,
|
|
216
214
|
examples: meta?.cliExamples || [],
|
|
217
215
|
handler: fn,
|
|
218
|
-
onRegister: (path
|
|
219
|
-
opts.register(handler, path
|
|
220
|
-
if (this.opts?.debug) opts.logHandler(`[36m(${aliasTypes[aliasType]})[32m${path
|
|
216
|
+
onRegister: (path, aliasType, route) => {
|
|
217
|
+
opts.register(handler, path, route?.getArgs() || routerBinding.getArgs());
|
|
218
|
+
if (this.opts?.debug) opts.logHandler(`[36m(${aliasTypes[aliasType]})[32m${path}`);
|
|
221
219
|
}
|
|
222
220
|
});
|
|
223
221
|
opts.register(handler, targetPath, routerBinding.getArgs());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "@moostjs/event-cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"composables",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@wooksjs/event-cli": "^0.7.
|
|
41
|
+
"@wooksjs/event-cli": "^0.7.12"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"vitest": "3.2.4"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@wooksjs/event-core": "^0.7.
|
|
48
|
-
"wooks": "^0.7.
|
|
49
|
-
"moost": "^0.6.
|
|
47
|
+
"@wooksjs/event-core": "^0.7.12",
|
|
48
|
+
"wooks": "^0.7.12",
|
|
49
|
+
"moost": "^0.6.10"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"pub": "pnpm publish --access public",
|