@maroonedsoftware/johnny5 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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/index.d.ts +146 -0
- package/dist/index.js +506 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/docker/index.d.ts +27 -0
- package/dist/integrations/docker/index.js +102 -0
- package/dist/integrations/docker/index.js.map +1 -0
- package/dist/integrations/filesystem/index.d.ts +31 -0
- package/dist/integrations/filesystem/index.js +73 -0
- package/dist/integrations/filesystem/index.js.map +1 -0
- package/dist/integrations/postgres/index.d.ts +24 -0
- package/dist/integrations/postgres/index.js +60 -0
- package/dist/integrations/postgres/index.js.map +1 -0
- package/dist/integrations/redis/index.d.ts +28 -0
- package/dist/integrations/redis/index.js +64 -0
- package/dist/integrations/redis/index.js.map +1 -0
- package/dist/integrations/serverkit/index.d.ts +50 -0
- package/dist/integrations/serverkit/index.js +74 -0
- package/dist/integrations/serverkit/index.js.map +1 -0
- package/dist/integrations/versions/index.d.ts +26 -0
- package/dist/integrations/versions/index.js +56 -0
- package/dist/integrations/versions/index.js.map +1 -0
- package/dist/types-CH7ccr3j.d.ts +119 -0
- package/package.json +113 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Marooned Software
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @maroonedsoftware/johnny5
|
|
2
|
+
|
|
3
|
+
A CLI framework for ServerKit-based applications. Provides:
|
|
4
|
+
|
|
5
|
+
- **`createCliApp`** — single-call factory that wires a `commander` program from a list of `CommandModule` definitions.
|
|
6
|
+
- **Doctor runner** — built-in `doctor` subcommand backed by a list of `Check` objects, with optional `--fix` auto-remediation.
|
|
7
|
+
- **Plugin discovery** — workspace packages can register additional commands by declaring `"johnny5": { "commands": "./path.js" }` in their `package.json`; collisions with core commands throw at startup.
|
|
8
|
+
- **ServerKit integration** (subpath `/serverkit`) — `bootstrapForCli` runs each `ServerKitModule.setup()` (but not `start()`) and gives commands a scoped InjectKit container via `requireContainer`.
|
|
9
|
+
- **Opt-in check libraries** under subpath exports — `/postgres`, `/redis`, `/docker`, `/versions`, `/filesystem`. Each is a tiny module so non-Postgres (or non-Redis, etc.) consumers don't pull the underlying drivers.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @maroonedsoftware/johnny5
|
|
15
|
+
# plus whichever optional peers your CLI needs:
|
|
16
|
+
pnpm add pg ioredis kysely
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
#!/usr/bin/env node
|
|
23
|
+
import { createCliApp, defineCommand } from '@maroonedsoftware/johnny5';
|
|
24
|
+
import { nodeVersion } from '@maroonedsoftware/johnny5/versions';
|
|
25
|
+
import { postgresReachable } from '@maroonedsoftware/johnny5/postgres';
|
|
26
|
+
|
|
27
|
+
const hello = defineCommand({
|
|
28
|
+
description: 'say hello',
|
|
29
|
+
options: [{ flags: '--name <name>', description: 'who to greet' }],
|
|
30
|
+
run: async (opts, ctx) => {
|
|
31
|
+
ctx.logger.success(`hi, ${opts['name'] ?? 'world'}`);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const app = await createCliApp({
|
|
36
|
+
name: 'my-cli',
|
|
37
|
+
description: 'example CLI',
|
|
38
|
+
version: '0.0.1',
|
|
39
|
+
commands: [{ path: ['hello'], module: hello }],
|
|
40
|
+
checks: [nodeVersion({ min: 22 }), postgresReachable()],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
process.exit(await app.run(process.argv));
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`my-cli doctor` auto-registers because `checks` is non-empty. `my-cli hello --name alice` invokes the registered command. Add `modules: [...]` to enable the ServerKit integration and use `requireContainer` for commands that need DI-resolved services.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { AppConfig } from '@maroonedsoftware/appconfig';
|
|
2
|
+
import { C as CliContext, D as DiscoveredCommand, a as CommandRegistration, b as Check, c as CliLogger, d as CommandModule } from './types-CH7ccr3j.js';
|
|
3
|
+
export { A as ArgSpec, e as CheckResult, f as CliPaths, g as CreateLoggerOptions, O as OptionSpec, h as OptionType, P as PluginManifest, S as Shell, i as ShellOptions, j as createDefaultLogger, k as createShell } from './types-CH7ccr3j.js';
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
import * as clack from '@clack/prompts';
|
|
6
|
+
import 'execa';
|
|
7
|
+
|
|
8
|
+
/** Options accepted by `loadWorkspacePlugins`. */
|
|
9
|
+
interface WorkspacePluginOptions {
|
|
10
|
+
repoRoot: string;
|
|
11
|
+
/**
|
|
12
|
+
* Workspace-relative directories whose immediate children are scanned for
|
|
13
|
+
* `package.json` files. Defaults to `['apps', 'packages']`.
|
|
14
|
+
*/
|
|
15
|
+
roots?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Package names to skip — typically the consumer's own CLI package whose
|
|
18
|
+
* commands are loaded directly, not via plugin discovery.
|
|
19
|
+
*/
|
|
20
|
+
excludePackages?: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Scan every workspace package in the configured roots for a `"johnny5"` field
|
|
24
|
+
* in `package.json`. When present, the referenced file is dynamically imported
|
|
25
|
+
* and expected to default-export a `PluginManifest`. Failures to load a single
|
|
26
|
+
* plugin log a warning through `ctx.logger.warn` but don't abort the CLI.
|
|
27
|
+
*/
|
|
28
|
+
declare const loadWorkspacePlugins: (ctx: CliContext, options: WorkspacePluginOptions) => Promise<DiscoveredCommand[]>;
|
|
29
|
+
|
|
30
|
+
interface ServerKitModuleLike<ConfigT> {
|
|
31
|
+
name?: string;
|
|
32
|
+
setup?: (registry: unknown, config: ConfigT) => Promise<void>;
|
|
33
|
+
start?: (container: unknown) => Promise<void>;
|
|
34
|
+
shutdown?: (container: unknown) => Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/** Options accepted by `createCliApp`. */
|
|
37
|
+
interface CliAppOptions<ConfigT extends AppConfig = AppConfig> {
|
|
38
|
+
name: string;
|
|
39
|
+
description: string;
|
|
40
|
+
version: string;
|
|
41
|
+
commands: CommandRegistration[];
|
|
42
|
+
checks?: Check[];
|
|
43
|
+
config?: ConfigT | (() => Promise<ConfigT>);
|
|
44
|
+
logger?: CliLogger;
|
|
45
|
+
modules?: ServerKitModuleLike<ConfigT>[];
|
|
46
|
+
plugins?: {
|
|
47
|
+
workspace?: Omit<WorkspacePluginOptions, 'repoRoot'> & {
|
|
48
|
+
repoRoot?: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
doctorCommandPath?: string[] | null;
|
|
52
|
+
}
|
|
53
|
+
/** The runnable CLI returned by `createCliApp`. */
|
|
54
|
+
interface CliApp {
|
|
55
|
+
/** Parse `argv` (defaults to `process.argv`) and resolve with a process exit code. */
|
|
56
|
+
run: (argv?: string[]) => Promise<number>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Identity helper that exists purely to give TypeScript a place to infer the
|
|
60
|
+
* `Opts` generic from the literal passed in. Equivalent to writing the type
|
|
61
|
+
* annotation manually.
|
|
62
|
+
*/
|
|
63
|
+
declare const defineCommand: <Opts = Record<string, unknown>>(mod: CommandModule<Opts>) => CommandModule<Opts>;
|
|
64
|
+
/**
|
|
65
|
+
* Build a CLI from a list of `CommandModule` registrations. Auto-registers a
|
|
66
|
+
* `doctor` subcommand when `checks` is non-empty, discovers workspace plugins
|
|
67
|
+
* when `plugins.workspace` is configured, and wires up the ServerKit
|
|
68
|
+
* integration when `modules` is supplied.
|
|
69
|
+
*/
|
|
70
|
+
declare const createCliApp: <ConfigT extends AppConfig = AppConfig>(options: CliAppOptions<ConfigT>) => Promise<CliApp>;
|
|
71
|
+
|
|
72
|
+
/** Options accepted by `buildContext`. */
|
|
73
|
+
interface BuildContextOptions {
|
|
74
|
+
config?: AppConfig;
|
|
75
|
+
logger?: CliLogger;
|
|
76
|
+
verbose?: boolean;
|
|
77
|
+
repoRoot?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Paths to .env files (absolute, or relative to the resolved repoRoot) to
|
|
80
|
+
* load into process.env before building AppConfig. Missing files are
|
|
81
|
+
* silently skipped. Existing process.env values are not overridden.
|
|
82
|
+
* Defaults to ['.env', 'apps/api/.env'].
|
|
83
|
+
*/
|
|
84
|
+
envFiles?: string[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Build an AppConfig with only the dotenv provider attached. Callers are
|
|
88
|
+
* expected to have loaded .env files into `process.env` beforehand — see
|
|
89
|
+
* `buildContext` for the default loading sequence.
|
|
90
|
+
*/
|
|
91
|
+
declare const buildDefaultAppConfig: () => Promise<AppConfig>;
|
|
92
|
+
/**
|
|
93
|
+
* Build the `CliContext` handed to every command, check, and plugin hook. Loads
|
|
94
|
+
* `.env` files into `process.env`, resolves the workspace `repoRoot`, and wires
|
|
95
|
+
* up shell, logger, and config.
|
|
96
|
+
*/
|
|
97
|
+
declare const buildContext: (options?: BuildContextOptions) => Promise<CliContext>;
|
|
98
|
+
|
|
99
|
+
/** Options passed to `runChecks`. */
|
|
100
|
+
interface DoctorOptions {
|
|
101
|
+
/** When true, failing checks with an `autoFix` hook get a chance to remediate. */
|
|
102
|
+
fix?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Run a list of doctor checks sequentially, rendering progress to stdout. Returns
|
|
106
|
+
* a process exit code: `0` when every check passes (including via `autoFix` when
|
|
107
|
+
* `--fix` is supplied), `1` when at least one check fails.
|
|
108
|
+
*/
|
|
109
|
+
declare const runChecks: (ctx: CliContext, checks: Check[], options: DoctorOptions) => Promise<number>;
|
|
110
|
+
/**
|
|
111
|
+
* Build the `CommandModule` for the built-in `doctor` subcommand from a set of
|
|
112
|
+
* checks. `createCliApp` auto-registers this when `checks` is non-empty.
|
|
113
|
+
*/
|
|
114
|
+
declare const buildDoctorCommand: (checks: Check[]) => CommandModule<{
|
|
115
|
+
fix?: boolean;
|
|
116
|
+
}>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Attach every discovered command to a commander `Program`, building intermediate
|
|
120
|
+
* group nodes as needed. Core registrations are processed before plugin ones, so
|
|
121
|
+
* a plugin that tries to claim a path already held by core throws with a
|
|
122
|
+
* descriptive error.
|
|
123
|
+
*/
|
|
124
|
+
declare const registerCommands: (program: Command, discovered: DiscoveredCommand[], ctx: CliContext) => void;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Best-effort guess at whether the CLI is talking to a human. Returns false in
|
|
128
|
+
* CI (`CI=true` / `CI=1`), when `JOHNNY5_NON_INTERACTIVE=1`, or when either of
|
|
129
|
+
* stdout/stdin isn't a TTY.
|
|
130
|
+
*/
|
|
131
|
+
declare const isInteractive: () => boolean;
|
|
132
|
+
|
|
133
|
+
/** Re-export of the `@clack/prompts` namespace under a stable name. */
|
|
134
|
+
declare const prompts: typeof clack;
|
|
135
|
+
/** Thrown by `unwrap` when the user cancels a clack prompt (e.g. Ctrl+C). */
|
|
136
|
+
declare class PromptCancelledError extends Error {
|
|
137
|
+
constructor();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Unwrap a clack prompt result, throwing `PromptCancelledError` when the user
|
|
141
|
+
* cancelled. Lets command handlers use try/catch instead of branching on
|
|
142
|
+
* `isCancel` at every prompt.
|
|
143
|
+
*/
|
|
144
|
+
declare const unwrap: <T>(value: T | symbol) => T;
|
|
145
|
+
|
|
146
|
+
export { type BuildContextOptions, Check, type CliApp, type CliAppOptions, CliContext, CliLogger, CommandModule, CommandRegistration, DiscoveredCommand, type DoctorOptions, PromptCancelledError, type WorkspacePluginOptions, buildContext, buildDefaultAppConfig, buildDoctorCommand, createCliApp, defineCommand, isInteractive, loadWorkspacePlugins, prompts, registerCommands, runChecks, unwrap };
|