hexbus 0.1.0 → 0.1.1
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 +133 -10
- package/dist/index.d.mts +1216 -36
- package/dist/index.mjs +959 -277
- package/package.json +45 -46
package/README.md
CHANGED
|
@@ -1,17 +1,140 @@
|
|
|
1
1
|
# hexbus
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Opinionated CLI framework for Inth apps. `hexbus` gives Inth app CLIs a small, typed foundation for parsing flags, creating execution context, rendering help, reporting errors, logging progress, detecting projects, and showing update hints.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
7
|
+
- [Key Features](#key-features)
|
|
8
|
+
- [Prerequisites](#prerequisites)
|
|
9
|
+
- [Quick Start](#quick-start)
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Usage](#usage)
|
|
12
|
+
- [Global Flags](#global-flags)
|
|
13
|
+
- [Support](#support)
|
|
14
|
+
- [License](#license)
|
|
15
|
+
- [Core Exports](#core-exports)
|
|
16
|
+
- [Context Shape](#context-shape)
|
|
17
|
+
- [Update Checks](#update-checks)
|
|
18
|
+
|
|
19
|
+
## Key Features
|
|
20
|
+
|
|
21
|
+
- Typed `CliContext` creation with command metadata, parsed flags, project root, package manager detection, framework detection, file-system helpers, config loading, telemetry, and confirmation prompts.
|
|
22
|
+
- Shared argument parser and global flags for help, version, logging, color, config, confirmation, telemetry, and force behavior.
|
|
23
|
+
- Consistent logger, spinner, intro, help, and error rendering built on top of `@clack/prompts`.
|
|
24
|
+
- Configurable error catalog and best-effort telemetry hooks that Inth app CLIs can extend or disable.
|
|
25
|
+
- Project, framework, package manager, install source, and registry update helpers for better CLI guidance.
|
|
26
|
+
- Test helpers for creating lightweight contexts without standing up a full CLI invocation.
|
|
27
|
+
|
|
28
|
+
## Prerequisites
|
|
29
|
+
|
|
30
|
+
- Node.js 18.17.0 or later
|
|
31
|
+
- A TypeScript ESM project
|
|
32
|
+
- Bun, npm, pnpm, or yarn in the consuming project
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
Define command metadata, create a context from `process.argv`, then route to the selected command:
|
|
14
37
|
|
|
15
38
|
```ts
|
|
16
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
createCliContext,
|
|
41
|
+
showHelpMenu,
|
|
42
|
+
globalFlags,
|
|
43
|
+
type CliCommand,
|
|
44
|
+
} from "hexbus";
|
|
45
|
+
|
|
46
|
+
const commands: CliCommand[] = [
|
|
47
|
+
{
|
|
48
|
+
name: "init",
|
|
49
|
+
label: "Initialize",
|
|
50
|
+
hint: "Create project files",
|
|
51
|
+
description: "Initialize project files.",
|
|
52
|
+
async action(context) {
|
|
53
|
+
context.logger.info(`Project root: ${context.projectRoot}`);
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const context = await createCliContext({
|
|
59
|
+
rawArgs: process.argv.slice(2),
|
|
60
|
+
commands,
|
|
61
|
+
appName: "my-cli",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (context.flags.help) {
|
|
65
|
+
showHelpMenu(
|
|
66
|
+
context,
|
|
67
|
+
{ appName: "my-cli", version: "0.1.0" },
|
|
68
|
+
commands,
|
|
69
|
+
globalFlags
|
|
70
|
+
);
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const command =
|
|
75
|
+
commands.find((item) => item.name === context.commandName) ?? commands[0];
|
|
76
|
+
await command.action(context);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
bun add hexbus
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm install hexbus
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pnpm add hexbus
|
|
17
91
|
```
|
|
92
|
+
|
|
93
|
+
## Usage
|
|
94
|
+
|
|
95
|
+
1. Use `parseCliArgs` when you only need normalized command names, command args, and global flags.
|
|
96
|
+
2. Use `createCliContext` when command execution needs the full runtime context.
|
|
97
|
+
3. Use `CliError`, `extendErrorCatalog`, and `withErrorHandling` to keep app-specific failures consistent with shared CLI output.
|
|
98
|
+
4. Use `displayIntro`, `showHelpMenu`, `createSpinner`, and `createCliLogger` for consistent terminal UX.
|
|
99
|
+
5. Use `isVersionRequest`, `printVersionInfo`, and `startBackgroundUpdateCheck` for fast `-v` / `--version` handling and install-source-aware update hints.
|
|
100
|
+
|
|
101
|
+
## Global Flags
|
|
102
|
+
|
|
103
|
+
- `--help, -h`: Show the CLI help menu.
|
|
104
|
+
- `--version, -v`: Show the CLI version.
|
|
105
|
+
- `--logger <level>`: Set log level to `error`, `warn`, `info`, or `debug`.
|
|
106
|
+
- `--color / --no-color`: Force or disable color output.
|
|
107
|
+
- `--config <path>`: Specify a configuration file path.
|
|
108
|
+
- `-y, --yes`: Skip confirmation prompts.
|
|
109
|
+
- `--no-telemetry`: Disable telemetry data collection.
|
|
110
|
+
- `--telemetry-debug`: Log telemetry payloads through the debug channel.
|
|
111
|
+
- `--force`: Force an operation even if files exist.
|
|
112
|
+
|
|
113
|
+
## Support
|
|
114
|
+
|
|
115
|
+
- Open an issue in the Hexbus repository for bugs or API questions.
|
|
116
|
+
- See `examples/minimal-cli` for a runnable reference CLI.
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
[Apache-2.0](../../LICENSE)
|
|
121
|
+
|
|
122
|
+
## Core Exports
|
|
123
|
+
|
|
124
|
+
- Context: `createCliContext`, `createTestContext`, `CreateContextOptions`
|
|
125
|
+
- Parser: `parseCliArgs`, `parseSubcommand`, `hasFlag`, `getFlagValue`, `globalFlags`
|
|
126
|
+
- Terminal UX: `createCliLogger`, `createSpinner`, `withSpinner`, `displayIntro`, `showHelpMenu`
|
|
127
|
+
- Errors: `CliError`, `createErrorHandlers`, `extendErrorCatalog`, `withErrorHandling`
|
|
128
|
+
- Detection: `detectProjectRoot`, `detectPackageManager`, `detectFramework`, `getInstallCommand`, `getRunCommand`, `getExecCommand`
|
|
129
|
+
- Telemetry: `createTelemetry`, `createDisabledTelemetry`, `TelemetryEventName`
|
|
130
|
+
- Updates: `isVersionRequest`, `printVersionInfo`, `checkForUpdate`, `startBackgroundUpdateCheck`, `formatUpdateHint`
|
|
131
|
+
|
|
132
|
+
## Context Shape
|
|
133
|
+
|
|
134
|
+
`createCliContext` resolves the common services command actions usually need: logger, parsed flags, command args, project root, framework metadata, package manager commands, config helpers, file-system helpers, telemetry, confirmation prompts, and shared error handlers.
|
|
135
|
+
|
|
136
|
+
Inth app CLIs can extend the generic context type when they attach additional services before invoking command actions.
|
|
137
|
+
|
|
138
|
+
## Update Checks
|
|
139
|
+
|
|
140
|
+
`hexbus` supports fast version requests before full context creation. Use `isVersionRequest` and `printVersionInfo` for `-v` / `--version`, then call `startBackgroundUpdateCheck` during normal command execution to show cached update hints and refresh stale registry data in the background.
|