@vite-hub/cli 0.0.4 → 0.1.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/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # @vite-hub/cli
2
2
 
3
- `@vite-hub/cli` runs the development commands contributed by a ViteHub project's active Vite plugins. It loads the local Vite or Nuxt config, combines their command namespaces, and adds the built-in `provision` command.
3
+ [![npm version](https://comark-ui.onmax.me/badge.svg?source=npm-version&package=%40vite-hub%2Fcli&icon=npm)](https://npmx.dev/package/@vite-hub/cli)
4
+ [![npm downloads](https://comark-ui.onmax.me/badge.svg?source=npm-downloads&package=%40vite-hub%2Fcli&period=month&icon=npm)](https://npmx.dev/package/@vite-hub/cli)
5
+ [![license](https://comark-ui.onmax.me/badge.svg?label=license&value=Apache-2.0)](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
6
+ [![docs](https://comark-ui.onmax.me/badge.svg?label=docs&value=vitehub.dev)](https://vitehub.dev/docs)
7
+
8
+ `@vite-hub/cli` runs the development commands contributed by a ViteHub project's active Vite plugins. It loads the local Vite or Nuxt config, combines their command namespaces, and adds the built-in `inspect` and `provision` namespaces.
4
9
 
5
10
  ## Choose the package
6
11
 
@@ -36,15 +41,31 @@ Run help from the project root. The CLI loads the project config before it print
36
41
  pnpm vitehub --help
37
42
  ```
38
43
 
39
- Every project includes `provision`. Other namespaces appear when their Vite integrations are active.
44
+ Every project includes `inspect` and `provision`. Other namespaces appear when their Vite integrations are active.
45
+ Each CLI invocation resolves every active plugin's CLI contributor once. Commands and Provision Steps use that contribution for the invocation; the next invocation resolves it again.
46
+
47
+ The CLI owns the `inspect` namespace. Plugin command contributions with that name are ignored. Generated operations cannot use the built-in `inspect` or `provision` namespaces: registry creation rejects them. Set the operation's `cli.namespace` to another name.
40
48
 
41
49
  ```txt
42
50
  Usage: vitehub <namespace> <feature> [args...]
43
51
 
44
52
  Available namespaces:
53
+ inspect Inspect discovered Definitions and generated Provider Output.
45
54
  provision Idempotently create missing provider resources.
46
55
  ```
47
56
 
57
+ ## Inspect the project
58
+
59
+ `inspect definitions` lists the Definitions that each active package discovered. The Console reads the same package-owned summaries. `inspect provider-output` lists generated Provider Output files and shows which exist. It resolves Vite configuration for build with production mode and loads Nuxt with development disabled, so production-only contributors are included. Other commands use development configuration.
60
+
61
+ ```sh
62
+ pnpm vitehub inspect definitions --kind queue
63
+ pnpm vitehub inspect definitions --json
64
+ pnpm vitehub inspect provider-output --json
65
+ ```
66
+
67
+ Human output is the default. `--json` prints a stable object. Both forms redact secret-like keys, Worker `vars` values, and URLs with embedded credentials.
68
+
48
69
  Open namespace help to see the commands contributed by one integration. Open feature help for its current arguments and defaults.
49
70
 
50
71
  ```sh
@@ -72,13 +93,23 @@ const exitCode = await runViteHubCli({
72
93
  process.exitCode = exitCode;
73
94
  ```
74
95
 
96
+ Pass `runtimeNamespaces` for namespaces that never need the project config, such as `vitehub sandbox` inside a deployed container. Pass `runtimeFeatures` for single features that do not need it, such as `vitehub agent invocations`, which only talks to a server or a journal database. A matching runtime feature runs before the CLI loads the config. The other features of a namespace with the same name still load it.
97
+
75
98
  `runViteHubCli()` returns `0` for successful commands and help, or a non-zero code when a command reports failure. It rejects if config loading or a contributor throws. Pass custom `stdout`, `stderr`, `env`, or `spawn` implementations only when the host needs to capture output or control subprocesses.
76
99
 
100
+ The binary catches these failures, writes them to stderr, and exits with code
101
+ `1`. Nostics errors include the diagnostic code, message, fix, source locations,
102
+ and documentation link when present. Causes and stacks are omitted. Plain errors
103
+ print their message. Error output is bounded by Runtime's diagnostic limits.
104
+
77
105
  ## Limits and safety
78
106
 
79
- - Root and namespace help is human-readable text, not a structured output contract.
107
+ CLI-owned argument and execution defects use stable `CLI_R####` Nostics codes. Contributing packages keep their own diagnostic codes.
108
+
109
+ - Root and namespace help is human-readable text, not a structured output contract. Use `inspect ... --json` for machine-readable output.
80
110
  - Help loads and executes the local Vite or Nuxt config. A missing dependency or config error can stop help before it prints.
81
111
  - Command effects come from the package that contributes the command. Review command-specific help before applying Database migrations, Channel registration changes, or Provider provisioning.
82
112
  - `provision run` creates missing resources but does not delete or replace existing resources. Start with `--dry-run` and pass a provider explicitly.
113
+ - `provision status` shows recorded ids from `.vitehub/provision.json` and pending plan actions. It never applies actions. Add `--json` to `provision run` or `provision status` for one JSON document on stdout.
83
114
 
84
115
  Read the [CLI guide](https://vitehub.dev/docs/development/cli) for every public command, examples, and troubleshooting.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,49 @@
1
+ import "nostics";
2
+ import { ConfigEnv } from "vite";
3
+ //#region ../internal/dist/cli.d.ts
4
+ //#region src/cli.d.ts
5
+ interface ViteHubCliStreams$1 {
6
+ stderr: {
7
+ write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
8
+ };
9
+ stdout: {
10
+ write: (chunk: string | Uint8Array) => unknown;
11
+ };
12
+ }
13
+ interface ViteHubCliSpawnResult$1 {
14
+ exitCode: number | null;
15
+ signal?: NodeJS.Signals | null;
16
+ }
17
+ interface ViteHubCliSpawnOptions$1 {
18
+ cwd?: string;
19
+ env?: NodeJS.ProcessEnv;
20
+ stderr?: "inherit" | "pipe";
21
+ stdout?: "inherit" | "pipe";
22
+ }
23
+ type ViteHubCliSpawn$1 = (command: string, args: string[], options?: ViteHubCliSpawnOptions$1) => Promise<ViteHubCliSpawnResult$1>;
24
+ interface ViteHubCliContext extends ViteHubCliStreams$1 {
25
+ cwd: string;
26
+ env: NodeJS.ProcessEnv;
27
+ /** Replaces `fetch` for commands that call a running app, so tests need no server. */
28
+ fetch?: typeof fetch;
29
+ rootDir: string;
30
+ spawn: ViteHubCliSpawn$1;
31
+ }
32
+ interface ViteHubCliFeature {
33
+ description?: string;
34
+ name: string;
35
+ run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
36
+ usage?: string;
37
+ }
38
+ interface ViteHubCliCommandNamespace {
39
+ /** The feature that `vitehub <name>` runs when no feature is named. */
40
+ defaultFeature?: string;
41
+ description?: string;
42
+ features: ViteHubCliFeature[];
43
+ name: string;
44
+ }
45
+ type StdoutWriteCallback = (error?: Error | null) => void;
46
+ //#endregion
1
47
  //#region src/index.d.ts
2
48
  interface ViteHubCliSpawnResult {
3
49
  exitCode: number | null;
@@ -16,7 +62,7 @@ interface ViteHubCliStreams {
16
62
  }
17
63
  interface ViteHubCliStream {
18
64
  flush?: () => unknown;
19
- write: (chunk: string | Uint8Array) => unknown;
65
+ write: (chunk: string | Uint8Array, encoding?: BufferEncoding | ((error?: Error | null) => void), callback?: (error?: Error | null) => void) => unknown;
20
66
  }
21
67
  type ViteHubCliEntrypointStream = {
22
68
  flush: () => unknown;
@@ -30,12 +76,23 @@ interface ViteHubCliLoadedConfig {
30
76
  root: string;
31
77
  vitehubConfigResolved?: true;
32
78
  }
33
- interface RunViteHubCliOptions {
79
+ export interface RunViteHubCliOptions {
34
80
  args?: string[];
35
81
  cwd?: string;
36
82
  env?: NodeJS.ProcessEnv;
37
- loadConfig?: (rootDir: string) => Promise<ViteHubCliLoadedConfig>;
38
- loadNuxtViteConfig?: (rootDir: string) => Promise<{
83
+ /** Namespaces that run without loading the project config, for example inside a deployed container. */
84
+ runtimeNamespaces?: ViteHubCliCommandNamespace[];
85
+ /**
86
+ * Features that run without loading the project config, for example commands that only talk to a server.
87
+ * Other features of a project namespace with the same name still load the config.
88
+ */
89
+ runtimeFeatures?: ViteHubCliCommandNamespace[];
90
+ /** Optional guard for runtime features that have a project-level opt-out. */
91
+ runtimeFeatureGuard?: (namespace: string, feature: string, cwd: string) => boolean | Promise<boolean>;
92
+ /** Replaces `fetch` in commands that call a running app. */
93
+ fetch?: typeof fetch;
94
+ loadConfig?: (rootDir: string, command: ConfigEnv["command"]) => Promise<ViteHubCliLoadedConfig>;
95
+ loadNuxtViteConfig?: (rootDir: string, command: ConfigEnv["command"]) => Promise<{
39
96
  plugins: readonly unknown[];
40
97
  root?: string;
41
98
  } | undefined>;
@@ -43,11 +100,10 @@ interface RunViteHubCliOptions {
43
100
  stderr?: ViteHubCliStreams["stderr"];
44
101
  stdout?: ViteHubCliStreams["stdout"];
45
102
  }
46
- interface RunViteHubCliEntrypointOptions extends Omit<RunViteHubCliOptions, "stderr" | "stdout"> {
103
+ export interface RunViteHubCliEntrypointOptions extends Omit<RunViteHubCliOptions, "stderr" | "stdout"> {
47
104
  stderr?: ViteHubCliEntrypointStream;
48
105
  stdout?: ViteHubCliEntrypointStream;
49
106
  }
50
- declare function runViteHubCli(options?: RunViteHubCliOptions): Promise<number>;
51
- declare function runViteHubCliEntrypoint(options?: RunViteHubCliEntrypointOptions): void;
52
- //#endregion
53
- export { RunViteHubCliEntrypointOptions, RunViteHubCliOptions, runViteHubCli, runViteHubCliEntrypoint };
107
+ export declare function runViteHubCli(options?: RunViteHubCliOptions): Promise<number>;
108
+ export declare function runViteHubCliEntrypoint(options?: RunViteHubCliEntrypointOptions): void;
109
+ //#endregion