@ldlework/workmark 1.4.1 → 1.5.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/cli.js +15 -0
- package/dist/lib/jiti-options.d.ts +1 -1
- package/dist/lib/jiti-options.js +14 -11
- package/dist/lib/parse.js +12 -1
- package/package.json +1 -1
- package/src/cli.ts +32 -0
- package/src/lib/jiti-options.ts +14 -11
- package/src/lib/parse.ts +18 -1
package/dist/cli.js
CHANGED
|
@@ -69,6 +69,17 @@ function printCommandHelp(cmd) {
|
|
|
69
69
|
console.log(`${flag.padEnd(20)} ${desc}${parts.length ? " " + parts.join(", ") : ""}`);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
function toCommandMeta(cmd) {
|
|
73
|
+
return {
|
|
74
|
+
name: cmd.name,
|
|
75
|
+
label: cmd.label,
|
|
76
|
+
group: cmd.group,
|
|
77
|
+
description: cmd.description,
|
|
78
|
+
inputSchema: cmd.inputSchema,
|
|
79
|
+
positional: cmd.positional,
|
|
80
|
+
sourceFile: cmd.sourceFile ?? null,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
72
83
|
// ---------------------------------------------------------------------------
|
|
73
84
|
// Main
|
|
74
85
|
// ---------------------------------------------------------------------------
|
|
@@ -76,6 +87,10 @@ async function main() {
|
|
|
76
87
|
const [command, ...rest] = process.argv.slice(2);
|
|
77
88
|
const workspace = await loadWorkspace();
|
|
78
89
|
const commands = await loadCommands(workspace);
|
|
90
|
+
if (command === "--introspect") {
|
|
91
|
+
process.stdout.write(JSON.stringify(commands.map(toCommandMeta)) + "\n");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
79
94
|
if (!command || command === "--help" || command === "-h") {
|
|
80
95
|
printHelp(commands);
|
|
81
96
|
return;
|
|
@@ -2,6 +2,6 @@ import type { JitiOptions } from "jiti";
|
|
|
2
2
|
/**
|
|
3
3
|
* Build jiti options that let wm.ts / command files import from
|
|
4
4
|
* `@ldlework/workmark/*` and from workmark's own dependencies (zod, etc.)
|
|
5
|
-
* regardless of how the package is installed or
|
|
5
|
+
* regardless of how the package is installed, linked, or baked into a host.
|
|
6
6
|
*/
|
|
7
7
|
export declare function jitiOptions(opts?: Partial<JitiOptions>): JitiOptions;
|
package/dist/lib/jiti-options.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
import { dirname, join } from "node:path";
|
|
1
|
+
import { dirname, extname, join } from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
-
// Resolve
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
// Resolve sibling modules from this file's own location and extension, so the
|
|
4
|
+
// aliases work whether we're running from src/ (.ts) or a shipped/baked dist/
|
|
5
|
+
// (.js) — no dependency on src/ being present alongside the compiled output.
|
|
6
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const EXT = extname(fileURLToPath(import.meta.url));
|
|
8
|
+
const lib = (name) => join(HERE, `${name}${EXT}`);
|
|
6
9
|
/**
|
|
7
10
|
* Build jiti options that let wm.ts / command files import from
|
|
8
11
|
* `@ldlework/workmark/*` and from workmark's own dependencies (zod, etc.)
|
|
9
|
-
* regardless of how the package is installed or
|
|
12
|
+
* regardless of how the package is installed, linked, or baked into a host.
|
|
10
13
|
*/
|
|
11
14
|
export function jitiOptions(opts) {
|
|
12
15
|
return {
|
|
13
16
|
interopDefault: true,
|
|
14
17
|
moduleCache: false,
|
|
15
18
|
alias: {
|
|
16
|
-
"@ldlework/workmark/types":
|
|
17
|
-
"@ldlework/workmark/helpers":
|
|
18
|
-
"@ldlework/workmark/define":
|
|
19
|
-
"@ldlework/workmark/workspace":
|
|
20
|
-
"@ldlework/workmark/project":
|
|
21
|
-
"@ldlework/workmark":
|
|
19
|
+
"@ldlework/workmark/types": lib("types"),
|
|
20
|
+
"@ldlework/workmark/helpers": lib("helpers"),
|
|
21
|
+
"@ldlework/workmark/define": lib("define"),
|
|
22
|
+
"@ldlework/workmark/workspace": lib("workspace"),
|
|
23
|
+
"@ldlework/workmark/project": lib("project"),
|
|
24
|
+
"@ldlework/workmark": lib("load"),
|
|
22
25
|
},
|
|
23
26
|
nativeModules: ["zod", "@modelcontextprotocol/sdk"],
|
|
24
27
|
...opts,
|
package/dist/lib/parse.js
CHANGED
|
@@ -138,8 +138,19 @@ function coerce(raw, schema) {
|
|
|
138
138
|
}
|
|
139
139
|
return out;
|
|
140
140
|
}
|
|
141
|
+
// --- 4. apply defaults ---------------------------------------------------
|
|
142
|
+
function applyDefaults(out, schema) {
|
|
143
|
+
const props = schema.properties ?? {};
|
|
144
|
+
const result = { ...out };
|
|
145
|
+
for (const [key, prop] of Object.entries(props)) {
|
|
146
|
+
if (result[key] === undefined && prop && "default" in prop) {
|
|
147
|
+
result[key] = prop.default;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
141
152
|
// --- orchestrator --------------------------------------------------------
|
|
142
153
|
export function parseArgs(argv, positional, schema) {
|
|
143
154
|
const s = schema;
|
|
144
|
-
return coerce(dispatch(tokenize(argv), positional, s), s);
|
|
155
|
+
return applyDefaults(coerce(dispatch(tokenize(argv), positional, s), s), s);
|
|
145
156
|
}
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -79,6 +79,33 @@ function printCommandHelp(cmd: ResolvedCommand): void {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// Introspection — machine-readable command metadata (consumed by the VS Code
|
|
84
|
+
// extension, which spawns `wm --introspect` instead of importing the loader).
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
interface CommandMetaJson {
|
|
88
|
+
name: string;
|
|
89
|
+
label: string;
|
|
90
|
+
group: string;
|
|
91
|
+
description: string;
|
|
92
|
+
inputSchema: unknown;
|
|
93
|
+
positional: string[];
|
|
94
|
+
sourceFile: string | null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function toCommandMeta(cmd: ResolvedCommand): CommandMetaJson {
|
|
98
|
+
return {
|
|
99
|
+
name: cmd.name,
|
|
100
|
+
label: cmd.label,
|
|
101
|
+
group: cmd.group,
|
|
102
|
+
description: cmd.description,
|
|
103
|
+
inputSchema: cmd.inputSchema,
|
|
104
|
+
positional: cmd.positional,
|
|
105
|
+
sourceFile: cmd.sourceFile ?? null,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
82
109
|
// ---------------------------------------------------------------------------
|
|
83
110
|
// Main
|
|
84
111
|
// ---------------------------------------------------------------------------
|
|
@@ -89,6 +116,11 @@ async function main(): Promise<void> {
|
|
|
89
116
|
const workspace = await loadWorkspace();
|
|
90
117
|
const commands = await loadCommands(workspace);
|
|
91
118
|
|
|
119
|
+
if (command === "--introspect") {
|
|
120
|
+
process.stdout.write(JSON.stringify(commands.map(toCommandMeta)) + "\n");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
92
124
|
if (!command || command === "--help" || command === "-h") {
|
|
93
125
|
printHelp(commands);
|
|
94
126
|
return;
|
package/src/lib/jiti-options.ts
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import { dirname, join } from "node:path";
|
|
1
|
+
import { dirname, extname, join } from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import type { JitiOptions } from "jiti";
|
|
4
4
|
|
|
5
|
-
// Resolve
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
// Resolve sibling modules from this file's own location and extension, so the
|
|
6
|
+
// aliases work whether we're running from src/ (.ts) or a shipped/baked dist/
|
|
7
|
+
// (.js) — no dependency on src/ being present alongside the compiled output.
|
|
8
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const EXT = extname(fileURLToPath(import.meta.url));
|
|
10
|
+
const lib = (name: string) => join(HERE, `${name}${EXT}`);
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Build jiti options that let wm.ts / command files import from
|
|
11
14
|
* `@ldlework/workmark/*` and from workmark's own dependencies (zod, etc.)
|
|
12
|
-
* regardless of how the package is installed or
|
|
15
|
+
* regardless of how the package is installed, linked, or baked into a host.
|
|
13
16
|
*/
|
|
14
17
|
export function jitiOptions(opts?: Partial<JitiOptions>): JitiOptions {
|
|
15
18
|
return {
|
|
16
19
|
interopDefault: true,
|
|
17
20
|
moduleCache: false,
|
|
18
21
|
alias: {
|
|
19
|
-
"@ldlework/workmark/types":
|
|
20
|
-
"@ldlework/workmark/helpers":
|
|
21
|
-
"@ldlework/workmark/define":
|
|
22
|
-
"@ldlework/workmark/workspace":
|
|
23
|
-
"@ldlework/workmark/project":
|
|
24
|
-
"@ldlework/workmark":
|
|
22
|
+
"@ldlework/workmark/types": lib("types"),
|
|
23
|
+
"@ldlework/workmark/helpers": lib("helpers"),
|
|
24
|
+
"@ldlework/workmark/define": lib("define"),
|
|
25
|
+
"@ldlework/workmark/workspace": lib("workspace"),
|
|
26
|
+
"@ldlework/workmark/project": lib("project"),
|
|
27
|
+
"@ldlework/workmark": lib("load"),
|
|
25
28
|
},
|
|
26
29
|
nativeModules: ["zod", "@modelcontextprotocol/sdk"],
|
|
27
30
|
...opts,
|
package/src/lib/parse.ts
CHANGED
|
@@ -18,6 +18,7 @@ type SchemaProp = {
|
|
|
18
18
|
items?: { type?: string; enum?: unknown[] };
|
|
19
19
|
enum?: unknown[];
|
|
20
20
|
anyOf?: unknown[];
|
|
21
|
+
default?: unknown;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
type SchemaObject = {
|
|
@@ -180,6 +181,22 @@ function coerce(
|
|
|
180
181
|
return out;
|
|
181
182
|
}
|
|
182
183
|
|
|
184
|
+
// --- 4. apply defaults ---------------------------------------------------
|
|
185
|
+
|
|
186
|
+
function applyDefaults(
|
|
187
|
+
out: Record<string, unknown>,
|
|
188
|
+
schema: SchemaObject,
|
|
189
|
+
): Record<string, unknown> {
|
|
190
|
+
const props = schema.properties ?? {};
|
|
191
|
+
const result = { ...out };
|
|
192
|
+
for (const [key, prop] of Object.entries(props)) {
|
|
193
|
+
if (result[key] === undefined && prop && "default" in prop) {
|
|
194
|
+
result[key] = prop.default;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
|
|
183
200
|
// --- orchestrator --------------------------------------------------------
|
|
184
201
|
|
|
185
202
|
export function parseArgs(
|
|
@@ -188,5 +205,5 @@ export function parseArgs(
|
|
|
188
205
|
schema: Record<string, unknown>,
|
|
189
206
|
): Record<string, unknown> {
|
|
190
207
|
const s = schema as SchemaObject;
|
|
191
|
-
return coerce(dispatch(tokenize(argv), positional, s), s);
|
|
208
|
+
return applyDefaults(coerce(dispatch(tokenize(argv), positional, s), s), s);
|
|
192
209
|
}
|