unicommand 0.0.1 → 0.0.2
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 +221 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.js +278 -142
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
<a name="TOC"></a>
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<div>Unicommand</div>
|
|
5
|
+
<br />
|
|
6
|
+
<a href="#-overview">Overview</a> • <a href="#-motivation">Motivation</a> • <a href="#-features">Features</a> • <a href="#-quick-start">Quick Start</a> • <a href="#-usage">Usage</a> • <a href="#-development">Development</a> • <a href="#-license">License</a>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<div width="100%" align="center">
|
|
10
|
+
<img src=".github/image/divider.png" />
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## 🎺 Overview
|
|
14
|
+
|
|
15
|
+
Unicommand is a small TypeScript command framework for packages that expose CLIs and MCP servers from the same command definitions.
|
|
16
|
+
|
|
17
|
+
## ❓ Motivation
|
|
18
|
+
|
|
19
|
+
I keep building local tools that need the same boring pieces: command metadata, CLI help, completions, update commands, dev shims, MCP tools, package metadata, and generated README command docs.
|
|
20
|
+
|
|
21
|
+
Why? Repeating that per package makes command behavior drift. Unicommand centralizes the contract so apps only define commands.
|
|
22
|
+
|
|
23
|
+
## ⭐ Features
|
|
24
|
+
|
|
25
|
+
- One `defineCommand` contract for CLI and MCP metadata.
|
|
26
|
+
- Package-aware CLI runner using `package.json` bin, version, name, and description.
|
|
27
|
+
- Built-in `completion` and `update` commands.
|
|
28
|
+
- Local dev command shims with active dev-bin detection.
|
|
29
|
+
- README command docs generated from command definitions.
|
|
30
|
+
- MCP command server helpers for tools and resources.
|
|
31
|
+
|
|
32
|
+
## 🚀 Quick Start
|
|
33
|
+
|
|
34
|
+
1. Install the package:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
pnpm add unicommand
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
2. Define a command:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { createCommandAdapters, defineCommand, z } from 'unicommand';
|
|
44
|
+
|
|
45
|
+
const metadata = defineCommand({
|
|
46
|
+
name: 'hello',
|
|
47
|
+
description: 'Say hello',
|
|
48
|
+
arguments: [{ synopsis: '<name>', description: 'Name to greet' }],
|
|
49
|
+
outputSchema: z.string(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const helloCommand = createCommandAdapters({
|
|
53
|
+
metadata,
|
|
54
|
+
handler: ({ name }: { name: string }) => `Hello, ${name}`,
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
3. Create a CLI runner:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
#!/usr/bin/env node
|
|
62
|
+
import { createPackageCommandCliRunner } from 'unicommand';
|
|
63
|
+
|
|
64
|
+
const cli = createPackageCommandCliRunner({
|
|
65
|
+
importMetaUrl: import.meta.url,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (cli.isDirectRun()) {
|
|
69
|
+
process.exit(await cli.runCli());
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 🧰 Usage
|
|
74
|
+
|
|
75
|
+
<div align="center">
|
|
76
|
+
|
|
77
|
+
<details>
|
|
78
|
+
<summary>Show package API</summary>
|
|
79
|
+
<br />
|
|
80
|
+
|
|
81
|
+
<div align="left">
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import {
|
|
85
|
+
createCommandAdapters,
|
|
86
|
+
createPackageCommandCliRunner,
|
|
87
|
+
defineCommand,
|
|
88
|
+
generateReadmeCommandDocs,
|
|
89
|
+
installPackageDevCommands,
|
|
90
|
+
startPackageCommandMcpServer,
|
|
91
|
+
z,
|
|
92
|
+
} from 'unicommand';
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Common entry points:
|
|
96
|
+
|
|
97
|
+
- `defineCommand` describes a command once.
|
|
98
|
+
- `createCommandAdapters` exposes CLI and MCP adapters from one handler.
|
|
99
|
+
- `createPackageCommandCliRunner` builds a package-aware CLI.
|
|
100
|
+
- `startPackageCommandMcpServer` starts an MCP server from command exports.
|
|
101
|
+
- `installPackageDevCommands` installs local dev command shims.
|
|
102
|
+
- `generateReadmeCommandDocs` updates README command blocks.
|
|
103
|
+
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
</details>
|
|
107
|
+
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<div align="center">
|
|
111
|
+
|
|
112
|
+
<details>
|
|
113
|
+
<summary>Show README command docs</summary>
|
|
114
|
+
<br />
|
|
115
|
+
|
|
116
|
+
<div align="left">
|
|
117
|
+
|
|
118
|
+
Add markers to a README:
|
|
119
|
+
|
|
120
|
+
```md
|
|
121
|
+
<!-- <DYNFIELD:COMMANDS> -->
|
|
122
|
+
<!-- </DYNFIELD:COMMANDS> -->
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Then generate docs:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { join } from 'node:path';
|
|
129
|
+
import { generateReadmeCommandDocs } from 'unicommand';
|
|
130
|
+
|
|
131
|
+
await generateReadmeCommandDocs({
|
|
132
|
+
binName: 'my-cli',
|
|
133
|
+
commandsDir: join(process.cwd(), 'src', 'commands'),
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
</details>
|
|
140
|
+
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
<div align="center">
|
|
144
|
+
|
|
145
|
+
<details>
|
|
146
|
+
<summary>Show local dev shims</summary>
|
|
147
|
+
<br />
|
|
148
|
+
|
|
149
|
+
<div align="left">
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import { installPackageDevCommands } from 'unicommand';
|
|
153
|
+
|
|
154
|
+
installPackageDevCommands(import.meta.url, {
|
|
155
|
+
commandNames: ['my-clid'],
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
The generated shim runs `src/cli.ts`, sets the package program-name env var, and lets `update` detect dev mode.
|
|
160
|
+
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
</details>
|
|
164
|
+
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
## 🛠 Development
|
|
168
|
+
|
|
169
|
+
<div align="center">
|
|
170
|
+
|
|
171
|
+
<details>
|
|
172
|
+
<summary>Show local development setup</summary>
|
|
173
|
+
<br />
|
|
174
|
+
|
|
175
|
+
<div align="left">
|
|
176
|
+
|
|
177
|
+
Install dependencies:
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
pnpm install
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Run checks:
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
pnpm check:fix
|
|
187
|
+
pnpm typecheck
|
|
188
|
+
pnpm build
|
|
189
|
+
pnpm knip
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Create a changeset before publishing changes:
|
|
193
|
+
|
|
194
|
+
```sh
|
|
195
|
+
pnpm changeset
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
</details>
|
|
201
|
+
|
|
202
|
+
</div>
|
|
203
|
+
|
|
204
|
+
## 📜 License
|
|
205
|
+
|
|
206
|
+
[MIT](https://github.com/lucasvtiradentes/unicommand/blob/main/LICENSE)
|
|
207
|
+
|
|
208
|
+
<div width="100%" align="center">
|
|
209
|
+
<img src=".github/image/divider.png" />
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
<br />
|
|
213
|
+
|
|
214
|
+
<div align="center">
|
|
215
|
+
<div>
|
|
216
|
+
<a target="_blank" href="https://www.linkedin.com/in/lucasvtiradentes/"><img src="https://img.shields.io/badge/-linkedin-blue?logo=Linkedin&logoColor=white" alt="LinkedIn"></a>
|
|
217
|
+
<a target="_blank" href="mailto:lucasvtiradentes@gmail.com"><img src="https://img.shields.io/badge/gmail-red?logo=gmail&logoColor=white" alt="Gmail"></a>
|
|
218
|
+
<a target="_blank" href="https://x.com/lucasvtiradente"><img src="https://img.shields.io/badge/-X-black?logo=X&logoColor=white" alt="X"></a>
|
|
219
|
+
<a target="_blank" href="https://github.com/lucasvtiradentes"><img src="https://img.shields.io/badge/-github-gray?logo=Github" alt="Github"></a>
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
package/dist/index.d.ts
CHANGED
|
@@ -7,10 +7,6 @@ type CompletionConfig = {
|
|
|
7
7
|
};
|
|
8
8
|
declare const registerCompletionCommand: (program: Program, config?: CompletionConfig) => void;
|
|
9
9
|
|
|
10
|
-
declare const setProgramExamples: (program: Program, examples: string[]) => void;
|
|
11
|
-
declare const isGlobalHelpRequest: (args: readonly string[]) => boolean;
|
|
12
|
-
declare const printProgramHelp: (program: Program) => Promise<void>;
|
|
13
|
-
|
|
14
10
|
type JsonSchemaProperty = {
|
|
15
11
|
type: 'array' | 'boolean' | 'number' | 'string';
|
|
16
12
|
description?: string;
|
|
@@ -99,6 +95,17 @@ declare const commandDefinitionToInputSchema: (definition: CommandDefinition) =>
|
|
|
99
95
|
};
|
|
100
96
|
declare const commandOptionSynopsis: (option: CommandOptionDefinition) => string;
|
|
101
97
|
|
|
98
|
+
type ProgramHelpData = {
|
|
99
|
+
binName: string;
|
|
100
|
+
commands: readonly CommandDefinition[];
|
|
101
|
+
description: string;
|
|
102
|
+
examples: readonly string[];
|
|
103
|
+
version: string;
|
|
104
|
+
};
|
|
105
|
+
declare const setProgramHelpData: (program: Program, data: ProgramHelpData) => void;
|
|
106
|
+
declare const isGlobalHelpRequest: (args: readonly string[]) => boolean;
|
|
107
|
+
declare const printProgramHelp: (program: Program) => Promise<void>;
|
|
108
|
+
|
|
102
109
|
type CommandRegistrarContext$1<TContext> = {
|
|
103
110
|
binName: string;
|
|
104
111
|
getContext?: () => Promise<TContext> | TContext;
|
|
@@ -606,4 +613,4 @@ type DevCommandShimConfig = {
|
|
|
606
613
|
declare const installCommandShim: (binDir: string, config: DevCommandShimConfig) => void;
|
|
607
614
|
declare const getBinDir: (envName: string) => string;
|
|
608
615
|
|
|
609
|
-
export { type CliConfig, type CommandAdapterExport, type CommandAdaptersReturn, type CommandArgumentDefinition, type CommandCompletionDefinition, type CommandDefinition, type CommandExamplesDefinition, type CommandMcpMetadata, type CommandMcpResourceMetadata, type CommandMcpRoute, type CommandMcpRouteFactory, type CommandMcpToolMetadata, type CommandModule, type CommandOptionDefinition, type CommandRegistrar, type CommandRegistrarContext$1 as CommandRegistrarContext, type CommandResourceRoute, type CompletionConfig, type CreateCommandMcpRouterOptions, type CreateCommandMcpServerOptions, type CreateCommandProgramOptions, type CreateMcpServerOptions, type CreatePackageCommandMcpServerOptions, type CreateSingleToolMcpServerOptions, DEFAULT_COMMANDS_DIR, type DefineCommandDefinition, type DevCommandShimConfig, type GenerateReadmeCommandDocsOptions, type JsonRpcRequest, type JsonSchemaProperty, type McpResourceDefinition, type McpResourceTemplateDefinition, type McpResultEnvelope, type McpToolDefinition, PROGRAM_NAME_ENV_SUFFIX, type PackageBinEntry, type PackageCommandMetadata, type PackageJson, PackageManager, type RegisterCliCommandsFromDirectoryOptions, type RegisterParentCommandsFromDefinitionsOptions, type RegisterUpdateCommandOptions, type ResourceReadParams, type ShellCompletionSnippet, type ToolCallParams, assertToolName, commandActionInput, commandDefinitionToInputSchema, commandDefinitionToZodInputSchema, commandDefinitionsFromModules, commandExportsFromModules, commandInputString, commandInputValue, commandMcpRouteToResourceRoute, commandMcpRouteToTool, commandNameToMcpToolName, commandOptionSynopsis, commandResourceInput, commandResourceRouteToResource, commandResourceRouteToResourceTemplate, createCliRunner, createCommandAdapters, createCommandCliRunner, createCommandMcpRoute, createCommandMcpRouter, createCommandMcpServer, createCommandProgram, createMcpServer, createPackageCommandCliRunner, createSingleToolMcpServer, defineCommand, emptyMcpInputSchema, formatCommandDocs, generateReadmeCommandDocs, getBinDir, getPackageManagerFromPath, getProgramBin, getProgramConstructor, installCommandShim, installDevCommand, installPackageDevCommand, installPackageDevCommands, isCommandAdapterExport, isCommandMcpResourceMetadata, isCommandMcpToolMetadata, isDirectRun, isGlobalHelpRequest, isResourceTemplate, loadCommandMcpRoutes, loadCommandModules, loadCommandModulesFromFiles, mcpToolOutputSchema, normalizeCommandInputAliases, packageBinEntry, packageCommandMetadata, packageEnvPrefix, packageRoot, printProgramHelp, readPackageJson, registerCliCommandsFromDirectory, registerCommand, registerCompletionCommand, registerParentCommandsFromDefinitions, registerUpdateCommand, resourceResult,
|
|
616
|
+
export { type CliConfig, type CommandAdapterExport, type CommandAdaptersReturn, type CommandArgumentDefinition, type CommandCompletionDefinition, type CommandDefinition, type CommandExamplesDefinition, type CommandMcpMetadata, type CommandMcpResourceMetadata, type CommandMcpRoute, type CommandMcpRouteFactory, type CommandMcpToolMetadata, type CommandModule, type CommandOptionDefinition, type CommandRegistrar, type CommandRegistrarContext$1 as CommandRegistrarContext, type CommandResourceRoute, type CompletionConfig, type CreateCommandMcpRouterOptions, type CreateCommandMcpServerOptions, type CreateCommandProgramOptions, type CreateMcpServerOptions, type CreatePackageCommandMcpServerOptions, type CreateSingleToolMcpServerOptions, DEFAULT_COMMANDS_DIR, type DefineCommandDefinition, type DevCommandShimConfig, type GenerateReadmeCommandDocsOptions, type JsonRpcRequest, type JsonSchemaProperty, type McpResourceDefinition, type McpResourceTemplateDefinition, type McpResultEnvelope, type McpToolDefinition, PROGRAM_NAME_ENV_SUFFIX, type PackageBinEntry, type PackageCommandMetadata, type PackageJson, PackageManager, type RegisterCliCommandsFromDirectoryOptions, type RegisterParentCommandsFromDefinitionsOptions, type RegisterUpdateCommandOptions, type ResourceReadParams, type ShellCompletionSnippet, type ToolCallParams, assertToolName, commandActionInput, commandDefinitionToInputSchema, commandDefinitionToZodInputSchema, commandDefinitionsFromModules, commandExportsFromModules, commandInputString, commandInputValue, commandMcpRouteToResourceRoute, commandMcpRouteToTool, commandNameToMcpToolName, commandOptionSynopsis, commandResourceInput, commandResourceRouteToResource, commandResourceRouteToResourceTemplate, createCliRunner, createCommandAdapters, createCommandCliRunner, createCommandMcpRoute, createCommandMcpRouter, createCommandMcpServer, createCommandProgram, createMcpServer, createPackageCommandCliRunner, createSingleToolMcpServer, defineCommand, emptyMcpInputSchema, formatCommandDocs, generateReadmeCommandDocs, getBinDir, getPackageManagerFromPath, getProgramBin, getProgramConstructor, installCommandShim, installDevCommand, installPackageDevCommand, installPackageDevCommands, isCommandAdapterExport, isCommandMcpResourceMetadata, isCommandMcpToolMetadata, isDirectRun, isGlobalHelpRequest, isResourceTemplate, loadCommandMcpRoutes, loadCommandModules, loadCommandModulesFromFiles, mcpToolOutputSchema, normalizeCommandInputAliases, packageBinEntry, packageCommandMetadata, packageEnvPrefix, packageRoot, printProgramHelp, readPackageJson, registerCliCommandsFromDirectory, registerCommand, registerCompletionCommand, registerParentCommandsFromDefinitions, registerUpdateCommand, resourceResult, setProgramHelpData, shortPackageName, startCommandMcpServer, startPackageCommandMcpServer, throwUnknownTool, uninstallDevCommand, uninstallPackageDevCommand, uninstallPackageDevCommands };
|