@wooksjs/event-cli 0.7.10 → 0.7.12
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 +40 -38
- package/dist/index.mjs +7 -11
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6,12 +7,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
9
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
@@ -21,26 +26,27 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
26
|
}) : target, mod));
|
|
22
27
|
|
|
23
28
|
//#endregion
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
let _prostojs_cli_help = require("@prostojs/cli-help");
|
|
30
|
+
let _wooksjs_event_core = require("@wooksjs/event-core");
|
|
31
|
+
let minimist = require("minimist");
|
|
32
|
+
minimist = __toESM(minimist);
|
|
33
|
+
let wooks = require("wooks");
|
|
28
34
|
|
|
29
35
|
//#region packages/event-cli/src/cli-kind.ts
|
|
30
|
-
const cliKind = (0,
|
|
31
|
-
argv: (0,
|
|
32
|
-
pathParams: (0,
|
|
33
|
-
command: (0,
|
|
34
|
-
opts: (0,
|
|
35
|
-
cliHelp: (0,
|
|
36
|
+
const cliKind = (0, _wooksjs_event_core.defineEventKind)("CLI", {
|
|
37
|
+
argv: (0, _wooksjs_event_core.slot)(),
|
|
38
|
+
pathParams: (0, _wooksjs_event_core.slot)(),
|
|
39
|
+
command: (0, _wooksjs_event_core.slot)(),
|
|
40
|
+
opts: (0, _wooksjs_event_core.slot)(),
|
|
41
|
+
cliHelp: (0, _wooksjs_event_core.slot)()
|
|
36
42
|
});
|
|
37
|
-
const flagsKey = (0,
|
|
43
|
+
const flagsKey = (0, _wooksjs_event_core.key)("cli.flags");
|
|
38
44
|
|
|
39
45
|
//#endregion
|
|
40
46
|
//#region packages/event-cli/src/event-cli.ts
|
|
41
47
|
/** Creates a CLI event context and runs `fn` inside it. */
|
|
42
48
|
function createCliContext(options, seeds, fn) {
|
|
43
|
-
return (0,
|
|
49
|
+
return (0, _wooksjs_event_core.createEventContext)(options, cliKind, seeds, fn);
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
//#endregion
|
|
@@ -49,13 +55,12 @@ function createCliContext(options, seeds, fn) {
|
|
|
49
55
|
const cliShortcuts = { cli: "CLI" };
|
|
50
56
|
/** Wooks adapter for building CLI applications with command routing and help generation. */
|
|
51
57
|
var WooksCli = class extends wooks.WooksAdapterBase {
|
|
52
|
-
logger;
|
|
53
|
-
cliHelp;
|
|
54
58
|
constructor(opts, wooks$1) {
|
|
55
59
|
super(wooks$1, opts?.logger, opts?.router);
|
|
56
60
|
this.opts = opts;
|
|
61
|
+
this.alreadyComputedAliases = false;
|
|
57
62
|
this.logger = opts?.logger || this.getLogger(`[96m[wooks-cli]`);
|
|
58
|
-
this.cliHelp = opts?.cliHelp instanceof
|
|
63
|
+
this.cliHelp = opts?.cliHelp instanceof _prostojs_cli_help.CliHelpRenderer ? opts.cliHelp : new _prostojs_cli_help.CliHelpRenderer(opts?.cliHelp);
|
|
59
64
|
}
|
|
60
65
|
/**
|
|
61
66
|
* ### Register CLI Command
|
|
@@ -102,9 +107,9 @@ var WooksCli = class extends wooks.WooksAdapterBase {
|
|
|
102
107
|
if (options.onRegister) options.onRegister(targetPath, 0, routed);
|
|
103
108
|
for (const alias of options.aliases || []) {
|
|
104
109
|
const vars = routed.getArgs().map((k) => `:${k}`).join("/");
|
|
105
|
-
const targetPath
|
|
106
|
-
this.on("CLI", targetPath
|
|
107
|
-
if (options.onRegister) options.onRegister(targetPath
|
|
110
|
+
const targetPath = makePath(alias) + (vars ? `/${vars}` : "");
|
|
111
|
+
this.on("CLI", targetPath, handler);
|
|
112
|
+
if (options.onRegister) options.onRegister(targetPath, 1, routed);
|
|
108
113
|
}
|
|
109
114
|
const command = routed.getStaticPart().replace(/\//gu, " ").trim();
|
|
110
115
|
const args = { ...options.args };
|
|
@@ -123,7 +128,6 @@ var WooksCli = class extends wooks.WooksAdapterBase {
|
|
|
123
128
|
});
|
|
124
129
|
return routed;
|
|
125
130
|
}
|
|
126
|
-
alreadyComputedAliases = false;
|
|
127
131
|
computeAliases() {
|
|
128
132
|
if (!this.alreadyComputedAliases) {
|
|
129
133
|
this.alreadyComputedAliases = true;
|
|
@@ -159,7 +163,7 @@ var WooksCli = class extends wooks.WooksAdapterBase {
|
|
|
159
163
|
cliHelp: this.cliHelp,
|
|
160
164
|
command: path.replace(/\//gu, " ").trim()
|
|
161
165
|
}, async () => {
|
|
162
|
-
const ctx = (0,
|
|
166
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
163
167
|
ctx.set(flagsKey, parsedFlags);
|
|
164
168
|
this.computeAliases();
|
|
165
169
|
const { handlers: foundHandlers, firstStatic } = this.wooks.lookup("CLI", path);
|
|
@@ -223,8 +227,8 @@ var WooksCli = class extends wooks.WooksAdapterBase {
|
|
|
223
227
|
* app.run()
|
|
224
228
|
* ```
|
|
225
229
|
*/
|
|
226
|
-
function createCliApp(opts, wooks$
|
|
227
|
-
return new WooksCli(opts, wooks$
|
|
230
|
+
function createCliApp(opts, wooks$2) {
|
|
231
|
+
return new WooksCli(opts, wooks$2);
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
//#endregion
|
|
@@ -235,7 +239,7 @@ function createCliApp(opts, wooks$1) {
|
|
|
235
239
|
* @returns an object with CLI options
|
|
236
240
|
*/
|
|
237
241
|
function useCliOptions() {
|
|
238
|
-
const ctx = (0,
|
|
242
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
239
243
|
if (!ctx.has(flagsKey)) {
|
|
240
244
|
const argv = ctx.get(cliKind.keys.argv);
|
|
241
245
|
const opts = ctx.get(cliKind.keys.opts);
|
|
@@ -258,10 +262,9 @@ function useCliOptions() {
|
|
|
258
262
|
*/
|
|
259
263
|
function useCliOption(name) {
|
|
260
264
|
try {
|
|
261
|
-
const
|
|
262
|
-
const opt = options.find((o) => o.keys.includes(name));
|
|
265
|
+
const opt = (useCliHelp().getEntry().options || []).find((o) => o.keys.includes(name));
|
|
263
266
|
if (opt) {
|
|
264
|
-
for (const key
|
|
267
|
+
for (const key of opt.keys) if (useCliOptions()[key]) return useCliOptions()[key];
|
|
265
268
|
}
|
|
266
269
|
} catch {}
|
|
267
270
|
return useCliOptions()[name];
|
|
@@ -283,7 +286,7 @@ function useCliOption(name) {
|
|
|
283
286
|
* @returns
|
|
284
287
|
*/
|
|
285
288
|
function useCliHelp() {
|
|
286
|
-
const ctx = (0,
|
|
289
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
287
290
|
const getCliHelp = () => ctx.get(cliKind.keys.cliHelp);
|
|
288
291
|
const getEntry = () => getCliHelp().match(ctx.get(cliKind.keys.command)).main;
|
|
289
292
|
return {
|
|
@@ -358,8 +361,7 @@ function useAutoHelp(keys = ["help"], colors = true) {
|
|
|
358
361
|
* ...
|
|
359
362
|
*/
|
|
360
363
|
function useCommandLookupHelp(lookupDepth = 3) {
|
|
361
|
-
const
|
|
362
|
-
const parts = ctx.get(cliKind.keys.pathParams)?.flatMap((p) => `${p} `.split(":").map((s, i) => i ? `:${s}` : s)) || [];
|
|
364
|
+
const parts = (0, _wooksjs_event_core.current)().get(cliKind.keys.pathParams)?.flatMap((p) => `${p} `.split(":").map((s, i) => i ? `:${s}` : s)) || [];
|
|
363
365
|
const cliHelp = useCliHelp().getCliHelp();
|
|
364
366
|
const cmd = cliHelp.getCliName();
|
|
365
367
|
let data;
|
|
@@ -395,12 +397,12 @@ exports.useCommandLookupHelp = useCommandLookupHelp;
|
|
|
395
397
|
Object.defineProperty(exports, 'useLogger', {
|
|
396
398
|
enumerable: true,
|
|
397
399
|
get: function () {
|
|
398
|
-
return
|
|
400
|
+
return _wooksjs_event_core.useLogger;
|
|
399
401
|
}
|
|
400
402
|
});
|
|
401
403
|
Object.defineProperty(exports, 'useRouteParams', {
|
|
402
404
|
enumerable: true,
|
|
403
405
|
get: function () {
|
|
404
|
-
return
|
|
406
|
+
return _wooksjs_event_core.useRouteParams;
|
|
405
407
|
}
|
|
406
408
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -26,11 +26,10 @@ function createCliContext(options, seeds, fn) {
|
|
|
26
26
|
const cliShortcuts = { cli: "CLI" };
|
|
27
27
|
/** Wooks adapter for building CLI applications with command routing and help generation. */
|
|
28
28
|
var WooksCli = class extends WooksAdapterBase {
|
|
29
|
-
logger;
|
|
30
|
-
cliHelp;
|
|
31
29
|
constructor(opts, wooks) {
|
|
32
30
|
super(wooks, opts?.logger, opts?.router);
|
|
33
31
|
this.opts = opts;
|
|
32
|
+
this.alreadyComputedAliases = false;
|
|
34
33
|
this.logger = opts?.logger || this.getLogger(`[96m[wooks-cli]`);
|
|
35
34
|
this.cliHelp = opts?.cliHelp instanceof CliHelpRenderer ? opts.cliHelp : new CliHelpRenderer(opts?.cliHelp);
|
|
36
35
|
}
|
|
@@ -79,9 +78,9 @@ var WooksCli = class extends WooksAdapterBase {
|
|
|
79
78
|
if (options.onRegister) options.onRegister(targetPath, 0, routed);
|
|
80
79
|
for (const alias of options.aliases || []) {
|
|
81
80
|
const vars = routed.getArgs().map((k) => `:${k}`).join("/");
|
|
82
|
-
const targetPath
|
|
83
|
-
this.on("CLI", targetPath
|
|
84
|
-
if (options.onRegister) options.onRegister(targetPath
|
|
81
|
+
const targetPath = makePath(alias) + (vars ? `/${vars}` : "");
|
|
82
|
+
this.on("CLI", targetPath, handler);
|
|
83
|
+
if (options.onRegister) options.onRegister(targetPath, 1, routed);
|
|
85
84
|
}
|
|
86
85
|
const command = routed.getStaticPart().replace(/\//gu, " ").trim();
|
|
87
86
|
const args = { ...options.args };
|
|
@@ -100,7 +99,6 @@ var WooksCli = class extends WooksAdapterBase {
|
|
|
100
99
|
});
|
|
101
100
|
return routed;
|
|
102
101
|
}
|
|
103
|
-
alreadyComputedAliases = false;
|
|
104
102
|
computeAliases() {
|
|
105
103
|
if (!this.alreadyComputedAliases) {
|
|
106
104
|
this.alreadyComputedAliases = true;
|
|
@@ -235,10 +233,9 @@ function useCliOptions() {
|
|
|
235
233
|
*/
|
|
236
234
|
function useCliOption(name) {
|
|
237
235
|
try {
|
|
238
|
-
const
|
|
239
|
-
const opt = options.find((o) => o.keys.includes(name));
|
|
236
|
+
const opt = (useCliHelp().getEntry().options || []).find((o) => o.keys.includes(name));
|
|
240
237
|
if (opt) {
|
|
241
|
-
for (const key
|
|
238
|
+
for (const key of opt.keys) if (useCliOptions()[key]) return useCliOptions()[key];
|
|
242
239
|
}
|
|
243
240
|
} catch {}
|
|
244
241
|
return useCliOptions()[name];
|
|
@@ -335,8 +332,7 @@ function useAutoHelp(keys = ["help"], colors = true) {
|
|
|
335
332
|
* ...
|
|
336
333
|
*/
|
|
337
334
|
function useCommandLookupHelp(lookupDepth = 3) {
|
|
338
|
-
const
|
|
339
|
-
const parts = ctx.get(cliKind.keys.pathParams)?.flatMap((p) => `${p} `.split(":").map((s, i) => i ? `:${s}` : s)) || [];
|
|
335
|
+
const parts = current().get(cliKind.keys.pathParams)?.flatMap((p) => `${p} `.split(":").map((s, i) => i ? `:${s}` : s)) || [];
|
|
340
336
|
const cliHelp = useCliHelp().getCliHelp();
|
|
341
337
|
const cmd = cliHelp.getCliName();
|
|
342
338
|
let data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.12",
|
|
4
4
|
"description": "@wooksjs/event-cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -40,21 +40,21 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@prostojs/cli-help": "^0.0.
|
|
43
|
+
"@prostojs/cli-help": "^0.0.12",
|
|
44
44
|
"minimist": "^1.2.8"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/minimist": "^1.2.5",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vitest": "^3.2.4",
|
|
50
|
-
"@wooksjs/event-core": "^0.7.
|
|
51
|
-
"wooks": "^0.7.
|
|
50
|
+
"@wooksjs/event-core": "^0.7.12",
|
|
51
|
+
"wooks": "^0.7.12"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@prostojs/logger": "^0.4.3",
|
|
55
|
-
"@prostojs/router": "^0.3.
|
|
56
|
-
"@wooksjs/event-core": "^0.7.
|
|
57
|
-
"wooks": "^0.7.
|
|
55
|
+
"@prostojs/router": "^0.3.4",
|
|
56
|
+
"@wooksjs/event-core": "^0.7.12",
|
|
57
|
+
"wooks": "^0.7.12"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "rolldown -c ../../rolldown.config.mjs"
|