@rhythmjs/cli 0.0.3 → 0.0.5
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/rhythm-cli.d.ts +5 -4
- package/dist/rhythm-cli.js +11 -21
- package/package.json +2 -2
package/dist/rhythm-cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as RhythmCliContext } from "./context-DyXPT9sP.js";
|
|
2
|
-
import { Middleware } from "@rhythmjs/rhythm/types";
|
|
2
|
+
import { DeriveMiddleware, Middleware } from "@rhythmjs/rhythm/types";
|
|
3
3
|
//#region src/rhythm-cli.d.ts
|
|
4
4
|
export interface RhythmCliCommandContext {
|
|
5
5
|
readonly args: Readonly<Record<string, string>>;
|
|
@@ -10,9 +10,10 @@ export interface RhythmCliOptions {
|
|
|
10
10
|
export declare class RhythmCli<TContext extends RhythmCliContext = RhythmCliContext> {
|
|
11
11
|
#private;
|
|
12
12
|
constructor(options?: RhythmCliOptions);
|
|
13
|
-
use(
|
|
14
|
-
use
|
|
13
|
+
use<TExtra extends object>(fn: DeriveMiddleware<TContext, TExtra>): RhythmCli<TContext & TExtra>;
|
|
14
|
+
use(fn: Middleware<TContext>): this;
|
|
15
|
+
command<TExtra extends object>(path: string, middleware: DeriveMiddleware<TContext & RhythmCliCommandContext, TExtra>, ...handlers: Middleware<TContext & RhythmCliCommandContext & TExtra>[]): this;
|
|
15
16
|
command(path: string, ...handlers: Middleware<TContext & RhythmCliCommandContext>[]): this;
|
|
16
|
-
|
|
17
|
+
middleware(): Middleware<TContext>;
|
|
17
18
|
}
|
|
18
19
|
//#endregion
|
package/dist/rhythm-cli.js
CHANGED
|
@@ -15,29 +15,21 @@ function matchCommand(pattern, positionals) {
|
|
|
15
15
|
}
|
|
16
16
|
return params;
|
|
17
17
|
}
|
|
18
|
-
var RhythmCli = class
|
|
18
|
+
var RhythmCli = class {
|
|
19
19
|
#options;
|
|
20
20
|
#entries = [];
|
|
21
|
-
#composed = null;
|
|
22
21
|
constructor(options = {}) {
|
|
23
22
|
this.#options = options;
|
|
24
23
|
}
|
|
25
24
|
get #prefixSegments() {
|
|
26
25
|
return this.#options.prefix ? toSegments(this.#options.prefix) : [];
|
|
27
26
|
}
|
|
28
|
-
use(
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (typeof arg !== "function") throw new TypeError("middleware must be a function!");
|
|
35
|
-
this.#entries.push({
|
|
36
|
-
kind: "middleware",
|
|
37
|
-
fn: arg
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
this.#composed = null;
|
|
27
|
+
use(fn) {
|
|
28
|
+
if (typeof fn !== "function") throw new TypeError("middleware must be a function!");
|
|
29
|
+
this.#entries.push({
|
|
30
|
+
kind: "middleware",
|
|
31
|
+
fn
|
|
32
|
+
});
|
|
41
33
|
return this;
|
|
42
34
|
}
|
|
43
35
|
command(path, ...handlers) {
|
|
@@ -46,11 +38,9 @@ var RhythmCli = class RhythmCli {
|
|
|
46
38
|
segments: [...this.#prefixSegments, ...toSegments(path)],
|
|
47
39
|
handlers
|
|
48
40
|
});
|
|
49
|
-
this.#composed = null;
|
|
50
41
|
return this;
|
|
51
42
|
}
|
|
52
43
|
#compile() {
|
|
53
|
-
if (this.#composed) return this.#composed;
|
|
54
44
|
const dispatchFor = (compiled) => {
|
|
55
45
|
return async (ctx, next) => {
|
|
56
46
|
const { positionals } = parseArgv(ctx.argv);
|
|
@@ -87,12 +77,12 @@ var RhythmCli = class RhythmCli {
|
|
|
87
77
|
}
|
|
88
78
|
stack.push(dispatchFor(compiled));
|
|
89
79
|
}
|
|
90
|
-
|
|
91
|
-
return this.#composed;
|
|
80
|
+
return compose(stack);
|
|
92
81
|
}
|
|
93
|
-
|
|
82
|
+
middleware() {
|
|
83
|
+
const fn = this.#compile();
|
|
94
84
|
return async (ctx, next) => {
|
|
95
|
-
await
|
|
85
|
+
await fn(ctx, next);
|
|
96
86
|
};
|
|
97
87
|
}
|
|
98
88
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhythmjs/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Command-line argument parsing, prompts, and command routing for the Rhythm middleware kernel.",
|
|
5
5
|
"homepage": "https://rhythm.js.org/cli",
|
|
6
6
|
"license": "ISC",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@rhythmjs/rhythm": "0.0.
|
|
52
|
+
"@rhythmjs/rhythm": "0.0.5"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/bun": "^1.4.2",
|