padrone 1.5.0 → 1.7.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/CHANGELOG.md +44 -0
- package/README.md +15 -11
- package/dist/{args-D5PNDyNu.mjs → args-Cnq0nwSM.mjs} +91 -41
- package/dist/args-Cnq0nwSM.mjs.map +1 -0
- package/dist/codegen/index.mjs +4 -4
- package/dist/codegen/index.mjs.map +1 -1
- package/dist/commands-B_gufyR9.mjs +514 -0
- package/dist/commands-B_gufyR9.mjs.map +1 -0
- package/dist/{completion.mjs → completion-BEuflbDO.mjs} +12 -82
- package/dist/completion-BEuflbDO.mjs.map +1 -0
- package/dist/docs/index.d.mts +4 -4
- package/dist/docs/index.d.mts.map +1 -1
- package/dist/docs/index.mjs +10 -12
- package/dist/docs/index.mjs.map +1 -1
- package/dist/{errors-BiVrBgi6.mjs → errors-DA4KzK1M.mjs} +26 -3
- package/dist/errors-DA4KzK1M.mjs.map +1 -0
- package/dist/{formatter-DtHzbP22.d.mts → formatter-DrvhDMrq.d.mts} +3 -3
- package/dist/formatter-DrvhDMrq.d.mts.map +1 -0
- package/dist/{help-bbmu9-qd.mjs → help-BtxLgrF_.mjs} +190 -43
- package/dist/help-BtxLgrF_.mjs.map +1 -0
- package/dist/{types-Ch8Mk6Qb.d.mts → index-D6-7dz0l.d.mts} +634 -745
- package/dist/index-D6-7dz0l.d.mts.map +1 -0
- package/dist/index.d.mts +869 -36
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3884 -1699
- package/dist/index.mjs.map +1 -1
- package/dist/{mcp-mLWIdUIu.mjs → mcp-6-Jw4Bpq.mjs} +13 -15
- package/dist/mcp-6-Jw4Bpq.mjs.map +1 -0
- package/dist/{serve-B0u43DK7.mjs → serve-YVTPzBCl.mjs} +12 -14
- package/dist/serve-YVTPzBCl.mjs.map +1 -0
- package/dist/{stream-BcC146Ud.mjs → stream-DC4H8YTx.mjs} +24 -3
- package/dist/stream-DC4H8YTx.mjs.map +1 -0
- package/dist/test.d.mts +5 -8
- package/dist/test.d.mts.map +1 -1
- package/dist/test.mjs +2 -13
- package/dist/test.mjs.map +1 -1
- package/dist/{update-check-CFX1FV3v.mjs → update-check-CZ2VqjnV.mjs} +16 -17
- package/dist/update-check-CZ2VqjnV.mjs.map +1 -0
- package/dist/zod.d.mts +2 -2
- package/dist/zod.d.mts.map +1 -1
- package/dist/zod.mjs +2 -2
- package/dist/zod.mjs.map +1 -1
- package/package.json +15 -12
- package/src/cli/completions.ts +14 -11
- package/src/cli/docs.ts +13 -10
- package/src/cli/doctor.ts +22 -18
- package/src/cli/index.ts +28 -82
- package/src/cli/init.ts +10 -7
- package/src/cli/link.ts +20 -16
- package/src/cli/wrap.ts +14 -11
- package/src/codegen/schema-to-code.ts +2 -2
- package/src/{args.ts → core/args.ts} +32 -225
- package/src/core/commands.ts +373 -0
- package/src/core/create.ts +301 -0
- package/src/core/default-runtime.ts +239 -0
- package/src/{errors.ts → core/errors.ts} +22 -0
- package/src/core/exec.ts +259 -0
- package/src/core/interceptors.ts +302 -0
- package/src/{parse.ts → core/parse.ts} +36 -89
- package/src/core/program-methods.ts +301 -0
- package/src/core/results.ts +229 -0
- package/src/core/runtime.ts +246 -0
- package/src/core/validate.ts +247 -0
- package/src/docs/index.ts +12 -13
- package/src/extension/auto-output.ts +146 -0
- package/src/extension/color.ts +38 -0
- package/src/extension/completion.ts +49 -0
- package/src/extension/config.ts +262 -0
- package/src/extension/env.ts +101 -0
- package/src/extension/help.ts +192 -0
- package/src/extension/index.ts +44 -0
- package/src/extension/ink.ts +93 -0
- package/src/extension/interactive.ts +106 -0
- package/src/extension/logger.ts +262 -0
- package/src/extension/man.ts +51 -0
- package/src/extension/mcp.ts +52 -0
- package/src/extension/progress-renderer.ts +338 -0
- package/src/extension/progress.ts +299 -0
- package/src/extension/repl.ts +94 -0
- package/src/extension/serve.ts +48 -0
- package/src/extension/signal.ts +87 -0
- package/src/extension/stdin.ts +62 -0
- package/src/extension/suggestions.ts +114 -0
- package/src/extension/timing.ts +81 -0
- package/src/extension/tracing.ts +175 -0
- package/src/extension/update-check.ts +77 -0
- package/src/extension/utils.ts +51 -0
- package/src/extension/version.ts +63 -0
- package/src/{completion.ts → feature/completion.ts} +12 -12
- package/src/{interactive.ts → feature/interactive.ts} +4 -4
- package/src/{mcp.ts → feature/mcp.ts} +12 -15
- package/src/{repl-loop.ts → feature/repl-loop.ts} +10 -13
- package/src/{serve.ts → feature/serve.ts} +11 -15
- package/src/feature/test.ts +262 -0
- package/src/{update-check.ts → feature/update-check.ts} +16 -16
- package/src/{wrap.ts → feature/wrap.ts} +10 -8
- package/src/index.ts +115 -30
- package/src/{formatter.ts → output/formatter.ts} +124 -176
- package/src/{help.ts → output/help.ts} +22 -8
- package/src/output/output-indicator.ts +87 -0
- package/src/output/primitives.ts +335 -0
- package/src/output/styling.ts +221 -0
- package/src/{zod.d.ts → schema/zod.d.ts} +1 -1
- package/src/schema/zod.ts +50 -0
- package/src/test.ts +2 -276
- package/src/types/args-meta.ts +151 -0
- package/src/types/builder.ts +718 -0
- package/src/types/command.ts +157 -0
- package/src/types/index.ts +60 -0
- package/src/types/interceptor.ts +296 -0
- package/src/types/preferences.ts +83 -0
- package/src/types/result.ts +71 -0
- package/src/types/schema.ts +19 -0
- package/src/util/dotenv.ts +244 -0
- package/src/{shell-utils.ts → util/shell-utils.ts} +26 -9
- package/src/{stream.ts → util/stream.ts} +27 -1
- package/src/{type-helpers.ts → util/type-helpers.ts} +23 -16
- package/src/{type-utils.ts → util/type-utils.ts} +71 -33
- package/src/util/utils.ts +51 -0
- package/src/zod.ts +1 -50
- package/dist/args-D5PNDyNu.mjs.map +0 -1
- package/dist/chunk-CjcI7cDX.mjs +0 -15
- package/dist/command-utils-B1D-HqCd.mjs +0 -1117
- package/dist/command-utils-B1D-HqCd.mjs.map +0 -1
- package/dist/completion.d.mts +0 -64
- package/dist/completion.d.mts.map +0 -1
- package/dist/completion.mjs.map +0 -1
- package/dist/errors-BiVrBgi6.mjs.map +0 -1
- package/dist/formatter-DtHzbP22.d.mts.map +0 -1
- package/dist/help-bbmu9-qd.mjs.map +0 -1
- package/dist/mcp-mLWIdUIu.mjs.map +0 -1
- package/dist/serve-B0u43DK7.mjs.map +0 -1
- package/dist/stream-BcC146Ud.mjs.map +0 -1
- package/dist/types-Ch8Mk6Qb.d.mts.map +0 -1
- package/dist/update-check-CFX1FV3v.mjs.map +0 -1
- package/src/command-utils.ts +0 -882
- package/src/create.ts +0 -1829
- package/src/runtime.ts +0 -497
- package/src/types.ts +0 -1291
- package/src/utils.ts +0 -140
- /package/src/{colorizer.ts → output/colorizer.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# padrone
|
|
2
2
|
|
|
3
|
+
## 1.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`3eecb40`](https://github.com/KurtGokhan/padrone/commit/3eecb40ad4f678bf745b70fb1f791ceff4dfb541) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add format-aware output primitives (table, tree, list, key-value) to auto-output. Actions can use `ctx.context.output.table()`, `.tree()`, `.list()`, `.kv()` for styled output that adapts to the runtime format (ANSI, text, JSON, markdown, HTML). Declarative formatting via `padroneAutoOutput({ output: 'table' })` per-command. Extract shared Styler/Layout infrastructure from help formatter into reusable `styling.ts` module.
|
|
8
|
+
|
|
9
|
+
- [`0a27a69`](https://github.com/KurtGokhan/padrone/commit/0a27a6960622be5f053a9a49731de8d6adf65646) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add printf-style format specifiers (`%s`, `%d`, `%i`, `%f`, `%j`, `%o`, `%O`, `%%`) to the logger extension, following WHATWG Console Standard conventions.
|
|
10
|
+
|
|
11
|
+
## 1.6.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [`75066f9`](https://github.com/KurtGokhan/padrone/commit/75066f9e12c33a1f64c502e248fce4d4e455d0da) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Improve "Did you mean?" suggestions for typos in commands and options. Return multiple matches (up to 3), add prefix/substring matching for inputs longer than 3 characters, and include `--` prefix in option suggestions. Suggestions are now included in soft-mode validation errors too.
|
|
16
|
+
|
|
17
|
+
- [`93ab85c`](https://github.com/KurtGokhan/padrone/commit/93ab85c88441e9062b2402f7d97f3d337293f2e7) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add typed context support. Define context with `.context<T>()` or `.context(transform)`, provide it via `cli()`, `eval()`, `run()`, and access it in action handlers as `ctx.context` and in all plugin phase contexts. Subcommands inherit context from parents. `.mount()` accepts an optional `{ context }` transform. New `InferContext` type helper.
|
|
18
|
+
|
|
19
|
+
- [`3b7fed0`](https://github.com/KurtGokhan/padrone/commit/3b7fed06d15cc2acad04df7d919ce0f6c9b66207) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add typed context injection for interceptors. Interceptors can declare provided context via `.provides<T>()` and required context via `.requires<T>()` on `defineInterceptor()`. Action handlers see the full merged context type. `.intercept()` rejects interceptors whose required context is not satisfied at compile time.
|
|
20
|
+
|
|
21
|
+
- [`067b9f7`](https://github.com/KurtGokhan/padrone/commit/067b9f7d695a838f0c39204c563029f8a2527675) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add extension system with `.extend()` for build-time composition. Rename plugins to interceptors (`.use()` → `.intercept()`, `PadronePlugin` → `PadroneInterceptor`). Move built-in commands to composable extensions. Default builtins (help, version, repl, color, config, interactive) are applied automatically via `createPadrone()`. Advanced features (completion, man, mcp, serve, update-check) are opt-in extensions. Individual builtins can be disabled via `createPadrone('name', { builtins: { help: false } })`.
|
|
22
|
+
|
|
23
|
+
- [`4e7f88b`](https://github.com/KurtGokhan/padrone/commit/4e7f88bdc68b7c97f36e3546142b6ebf5f87f76e) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Respect terminal width in help output. Default and choices metadata now appear inline with descriptions when space allows, and long descriptions wrap aligned to the description column.
|
|
24
|
+
|
|
25
|
+
- [`aa0b568`](https://github.com/KurtGokhan/padrone/commit/aa0b568f35c2fcb97a78abf077561a914606de6f) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add support for Ink apps. The `ink` interceptor renders an Ink app as part of a command's execution, and waits for it to unmount before proceeding.
|
|
26
|
+
|
|
27
|
+
- [`91fd814`](https://github.com/KurtGokhan/padrone/commit/91fd8146c0fff0eb8c4e5f46191d1a6bf8203ecf) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add `padroneLogger()` and `padroneTiming()` extensions for structured logging and command execution timing.
|
|
28
|
+
|
|
29
|
+
- [`99c8cfa`](https://github.com/KurtGokhan/padrone/commit/99c8cfa298194d9632b9c784858c1695e7782acf) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add `program.info` for read-only access to program metadata (name, version, description, commands, etc.). Add XDG config directory support via `xdg` option on `padroneConfig()`.
|
|
30
|
+
|
|
31
|
+
- [`88c45af`](https://github.com/KurtGokhan/padrone/commit/88c45afeef123d4a3e5d5e4d359e080ddf60a154) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add elapsed time (`time: true`) and ETA (`eta: true`) to progress indicators. ETA is calculated from numeric progress updates and counts down between updates. Move progress messages into a `message` field (string or `{ validation, progress, success, error }` object) with runtime-level defaults via context.
|
|
32
|
+
|
|
33
|
+
- [`8691694`](https://github.com/KurtGokhan/padrone/commit/86916947b189109e6647684d30dc06992a3909b5) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Improve runtime agnosticism. Add `terminal` and `exit` fields to `PadroneRuntime`. Replace `Buffer` usage with `Uint8Array`/`TextEncoder`. Route scattered `process.*` reads through runtime abstraction. Replace all `require()` calls with dynamic `import()`. Use `runtime.onSignal` in serve/MCP instead of direct `process.on`.
|
|
34
|
+
|
|
35
|
+
- [`4343f78`](https://github.com/KurtGokhan/padrone/commit/4343f7857b6685c8e1774b4d933846cd786fe828) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add signal handling support for graceful shutdown. Actions and plugins receive an `AbortSignal` via `ctx.signal` that aborts on SIGINT/SIGTERM/SIGHUP. Command results include `signal` and `exitCode` fields when interrupted. Double Ctrl+C within 2 seconds force-quits. Export new `SignalError` class and `PadroneSignal` type.
|
|
36
|
+
|
|
37
|
+
- [`7464026`](https://github.com/KurtGokhan/padrone/commit/746402615e11262a0ff7257f41a4840c3a54143e) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Reject unknown options for commands without `.arguments()`. Previously, commands without a schema accepted all options silently. Now they infer an empty object and error on unknown options.
|
|
38
|
+
|
|
39
|
+
- [`be62401`](https://github.com/KurtGokhan/padrone/commit/be624016ee6e4852ab043b15b4d525431319a168) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add experimental `padroneTracing()` extension for OpenTelemetry tracing. Logger automatically bridges log calls to span events when tracing is active.
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- [`dbac7ec`](https://github.com/KurtGokhan/padrone/commit/dbac7ec56a9f0c320550eef2f6b188a3741d1d4e) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Add `runtime` to interceptor contexts. Interceptors can now access and override the runtime via `ctx.runtime` instead of calling `getCommandRuntime()`. Support `next()` overrides for passing modified context to downstream interceptors.
|
|
44
|
+
|
|
45
|
+
- [`0dfae77`](https://github.com/KurtGokhan/padrone/commit/0dfae774d264d4cab092b90bb779dd3da46abaef) Thanks [@KurtGokhan](https://github.com/KurtGokhan)! - Collect repeated non-array options into an array for the validator. Enables schemas like `z.union([z.string(), z.array(z.string())])` to receive all values when an option is passed multiple times.
|
|
46
|
+
|
|
3
47
|
## 1.5.0
|
|
4
48
|
|
|
5
49
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -101,13 +101,15 @@ program.help('greet', { format: 'json' }); // json, markdown, html, ansi
|
|
|
101
101
|
|
|
102
102
|
**Arguments** — positional args, variadic args, short flags (`-v`), long aliases (`--dry-run`), auto kebab-case aliases, negatable booleans (`--no-verbose`).
|
|
103
103
|
|
|
104
|
-
**Env & Config** — load from environment variables with `.
|
|
104
|
+
**Env & Config** — load from environment variables with `.extend(padroneEnv(schema))` and config files with `.extend(padroneConfig({ files, schema }))`. Precedence: CLI > stdin > env > config > defaults.
|
|
105
105
|
|
|
106
106
|
**Interactive prompts** — auto-prompt for missing fields. Booleans become confirm, enums become select, arrays become multi-select.
|
|
107
107
|
|
|
108
|
-
**Progress indicators** — auto-managed spinners with
|
|
108
|
+
**Progress indicators** — auto-managed spinners and progress bars with elapsed time and ETA. `.extend(padroneProgress({ message: 'Deploying...', bar: true, time: true, eta: true }))`.
|
|
109
109
|
|
|
110
|
-
**
|
|
110
|
+
**Extension-first architecture** — most built-in features (help, version, REPL, color, signal handling, auto-output, stdin, config, interactive, suggestions) are implemented as extensions composed via `.extend()`. Any built-in can be disabled or replaced.
|
|
111
|
+
|
|
112
|
+
**Interceptors** — middleware hooks for 6 phases (start, parse, validate, execute, error, shutdown). Onion model with `next()`. Extensions register interceptors under the hood. Create your own with `defineInterceptor()`.
|
|
111
113
|
|
|
112
114
|
**Composition** — mount programs as subcommands with `.mount()`, override commands with merge semantics.
|
|
113
115
|
|
|
@@ -122,13 +124,15 @@ program.help('greet', { format: 'json' }); // json, markdown, html, ansi
|
|
|
122
124
|
| `.arguments(schema, meta?)` | Define args with Zod schema, positional config, field metadata |
|
|
123
125
|
| `.action(handler)` | Set handler `(args, ctx, base?) => result` |
|
|
124
126
|
| `.command(name, builder)` | Add subcommand (name or `[name, ...aliases]`) |
|
|
125
|
-
| `.
|
|
127
|
+
| `.context(transform?)` | Define typed context or transform inherited context |
|
|
128
|
+
| `.mount(name, program, options?)` | Mount another program as subcommand tree |
|
|
126
129
|
| `.configure(config)` | Set title, description, version, etc. |
|
|
127
|
-
| `.
|
|
128
|
-
| `.
|
|
130
|
+
| `.extend(padroneEnv(schema))` | Map env vars to args (composable extension) |
|
|
131
|
+
| `.extend(padroneConfig({ files, schema }))` | Load args from config files (composable extension) |
|
|
129
132
|
| `.wrap(config)` | Wrap an external CLI tool *(experimental)* |
|
|
130
|
-
| `.
|
|
131
|
-
| `.
|
|
133
|
+
| `.extend(padroneProgress(config?))` | Auto-managed progress indicator (extension) |
|
|
134
|
+
| `.intercept(interceptor)` | Register middleware interceptor (use `defineInterceptor()`) |
|
|
135
|
+
| `.extend(extension)` | Apply a build-time extension (bundle of config, commands, interceptors) |
|
|
132
136
|
| `.runtime(runtime)` | Custom I/O (for non-terminal use) |
|
|
133
137
|
| `.updateCheck(config?)` | Background version check |
|
|
134
138
|
| `.async()` | Mark as async validation |
|
|
@@ -137,9 +141,9 @@ program.help('greet', { format: 'json' }); // json, markdown, html, ansi
|
|
|
137
141
|
|
|
138
142
|
| Method | What it does |
|
|
139
143
|
|--------|-------------|
|
|
140
|
-
| `.cli(prefs?)` | Entry point — parses `process.argv`, throws on errors |
|
|
141
|
-
| `.eval(input, prefs?)` | Parse + validate + execute string, returns errors softly |
|
|
142
|
-
| `.run(command, args)` | Run by name with typed args (no validation) |
|
|
144
|
+
| `.cli(prefs?)` | Entry point — parses `process.argv`, throws on errors. Pass `context` in prefs. |
|
|
145
|
+
| `.eval(input, prefs?)` | Parse + validate + execute string, returns errors softly. Pass `context` in prefs. |
|
|
146
|
+
| `.run(command, args, prefs?)` | Run by name with typed args (no validation). Pass `context` in prefs. |
|
|
143
147
|
| `.parse(input?)` | Parse without executing |
|
|
144
148
|
| `.api()` | Generate typed function API |
|
|
145
149
|
| `.repl(options?)` | Interactive REPL session |
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as asyncStreamRegistry } from "./stream-
|
|
2
|
-
//#region src/
|
|
1
|
+
import { n as asyncStreamRegistry } from "./stream-DC4H8YTx.mjs";
|
|
2
|
+
//#region src/util/shell-utils.ts
|
|
3
3
|
/**
|
|
4
4
|
* Convert a camelCase string to kebab-case.
|
|
5
5
|
* Returns null if the string has no uppercase letters (no conversion needed).
|
|
@@ -9,20 +9,85 @@ function camelToKebab(str) {
|
|
|
9
9
|
return str.replace(/[A-Z]/g, (ch) => `-${ch.toLowerCase()}`);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Detects the current shell from environment variables and process info.
|
|
13
|
+
* @returns The detected shell type, or undefined if unknown
|
|
13
14
|
*/
|
|
14
|
-
function
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
async function detectShell() {
|
|
16
|
+
if (typeof process === "undefined") return void 0;
|
|
17
|
+
const shellEnv = process.env.SHELL || "";
|
|
18
|
+
if (shellEnv.includes("zsh")) return "zsh";
|
|
19
|
+
if (shellEnv.includes("bash")) return "bash";
|
|
20
|
+
if (shellEnv.includes("fish")) return "fish";
|
|
21
|
+
if (process.env.PSModulePath || process.env.POWERSHELL_DISTRIBUTION_CHANNEL) return "powershell";
|
|
22
|
+
try {
|
|
23
|
+
const ppid = process.ppid;
|
|
24
|
+
if (ppid) {
|
|
25
|
+
const { execSync } = await import("node:child_process");
|
|
26
|
+
const processName = execSync(`ps -p ${ppid} -o comm=`, {
|
|
27
|
+
encoding: "utf-8",
|
|
28
|
+
stdio: [
|
|
29
|
+
"pipe",
|
|
30
|
+
"pipe",
|
|
31
|
+
"ignore"
|
|
32
|
+
]
|
|
33
|
+
}).trim();
|
|
34
|
+
if (processName.includes("zsh")) return "zsh";
|
|
35
|
+
if (processName.includes("bash")) return "bash";
|
|
36
|
+
if (processName.includes("fish")) return "fish";
|
|
37
|
+
}
|
|
38
|
+
} catch {}
|
|
39
|
+
}
|
|
40
|
+
async function getRcFile(shell, home) {
|
|
41
|
+
const { homedir } = await import("node:os");
|
|
42
|
+
const { join } = await import("node:path");
|
|
43
|
+
const h = home ?? homedir();
|
|
44
|
+
switch (shell) {
|
|
45
|
+
case "bash": return join(h, ".bashrc");
|
|
46
|
+
case "zsh": return join(h, ".zshrc");
|
|
47
|
+
case "fish": return join(h, ".config", "fish", "config.fish");
|
|
48
|
+
case "powershell": return (typeof process !== "undefined" ? process.env.PROFILE : void 0) || join(h, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1");
|
|
49
|
+
default: return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function escapeRegExp(str) {
|
|
53
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Writes a snippet to a shell config file using begin/end markers for idempotency.
|
|
57
|
+
* If a block with the same begin marker exists, it is replaced. Otherwise the snippet is appended.
|
|
58
|
+
*/
|
|
59
|
+
async function writeToRcFile(rcFile, snippet, beginMarker, endMarker) {
|
|
60
|
+
const { existsSync, mkdirSync, readFileSync, writeFileSync } = await import("node:fs");
|
|
61
|
+
const { dirname } = await import("node:path");
|
|
62
|
+
const existing = existsSync(rcFile) ? readFileSync(rcFile, "utf-8") : "";
|
|
63
|
+
if (existing.includes(beginMarker)) {
|
|
64
|
+
const pattern = new RegExp(`${escapeRegExp(beginMarker)}[\\s\\S]*?${escapeRegExp(endMarker)}`);
|
|
65
|
+
writeFileSync(rcFile, existing.replace(pattern, snippet));
|
|
66
|
+
return {
|
|
67
|
+
file: rcFile,
|
|
68
|
+
updated: true
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
mkdirSync(dirname(rcFile), { recursive: true });
|
|
72
|
+
writeFileSync(rcFile, `${existing}${existing.length > 0 && !existing.endsWith("\n") ? "\n" : ""}\n${snippet}\n`);
|
|
73
|
+
return {
|
|
74
|
+
file: rcFile,
|
|
75
|
+
updated: false
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/core/args.ts
|
|
80
|
+
/** Extract the JSON schema from a Standard Schema, returning it as a plain record. */
|
|
81
|
+
function getJsonSchema(schema) {
|
|
82
|
+
return schema["~standard"].jsonSchema.input({
|
|
83
|
+
target: "draft-2020-12",
|
|
84
|
+
libraryOptions: { unrepresentable: "any" }
|
|
85
|
+
});
|
|
86
|
+
}
|
|
22
87
|
function getFieldJsonSchema(schema, field) {
|
|
23
88
|
if (!schema) return void 0;
|
|
24
89
|
try {
|
|
25
|
-
const jsonSchema = schema
|
|
90
|
+
const jsonSchema = getJsonSchema(schema);
|
|
26
91
|
if (jsonSchema.type === "object" && jsonSchema.properties) return jsonSchema.properties[field];
|
|
27
92
|
} catch {}
|
|
28
93
|
}
|
|
@@ -46,10 +111,10 @@ function isAsyncStreamField(schema, field) {
|
|
|
46
111
|
*/
|
|
47
112
|
function parsePositionalConfig(positional) {
|
|
48
113
|
return positional.map((p) => {
|
|
49
|
-
const
|
|
114
|
+
const variadic = p.startsWith("...");
|
|
50
115
|
return {
|
|
51
|
-
name:
|
|
52
|
-
variadic
|
|
116
|
+
name: variadic ? p.slice(3) : p,
|
|
117
|
+
variadic
|
|
53
118
|
};
|
|
54
119
|
});
|
|
55
120
|
}
|
|
@@ -71,7 +136,7 @@ function extractSchemaMetadata(schema, meta, autoAlias) {
|
|
|
71
136
|
if (value.alias) addEntries(aliases, key, value.alias, (item) => item.length > 1);
|
|
72
137
|
}
|
|
73
138
|
try {
|
|
74
|
-
const jsonSchema = schema
|
|
139
|
+
const jsonSchema = getJsonSchema(schema);
|
|
75
140
|
if (jsonSchema.type === "object" && jsonSchema.properties) for (const [propertyName, propertySchema] of Object.entries(jsonSchema.properties)) {
|
|
76
141
|
if (!propertySchema) continue;
|
|
77
142
|
const propFlags = propertySchema.flags;
|
|
@@ -102,8 +167,8 @@ function preprocessMappings(data, mappings) {
|
|
|
102
167
|
return result;
|
|
103
168
|
}
|
|
104
169
|
/**
|
|
105
|
-
* Apply values
|
|
106
|
-
*
|
|
170
|
+
* Apply values to arguments using "set if not present" semantics.
|
|
171
|
+
* Existing values take precedence — only fills in undefined or missing keys.
|
|
107
172
|
*/
|
|
108
173
|
function applyValues(data, values) {
|
|
109
174
|
const result = { ...data };
|
|
@@ -113,17 +178,11 @@ function applyValues(data, values) {
|
|
|
113
178
|
}
|
|
114
179
|
return result;
|
|
115
180
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Combined preprocessing of arguments with all features.
|
|
118
|
-
* Precedence order (highest to lowest): CLI args > stdin > env vars > config file
|
|
119
|
-
*/
|
|
181
|
+
/** Applies flag and alias mappings to raw arguments. */
|
|
120
182
|
function preprocessArgs(data, ctx) {
|
|
121
183
|
let result = { ...data };
|
|
122
184
|
if (ctx.flags && Object.keys(ctx.flags).length > 0) result = preprocessMappings(result, ctx.flags);
|
|
123
185
|
if (ctx.aliases && Object.keys(ctx.aliases).length > 0) result = preprocessMappings(result, ctx.aliases);
|
|
124
|
-
if (ctx.stdinData) result = applyValues(result, ctx.stdinData);
|
|
125
|
-
if (ctx.envData) result = applyValues(result, ctx.envData);
|
|
126
|
-
if (ctx.configData) result = applyValues(result, ctx.configData);
|
|
127
186
|
return result;
|
|
128
187
|
}
|
|
129
188
|
/**
|
|
@@ -134,7 +193,7 @@ function preprocessArgs(data, ctx) {
|
|
|
134
193
|
function coerceArgs(data, schema) {
|
|
135
194
|
let properties;
|
|
136
195
|
try {
|
|
137
|
-
const jsonSchema = schema
|
|
196
|
+
const jsonSchema = getJsonSchema(schema);
|
|
138
197
|
if (jsonSchema.type !== "object" || !jsonSchema.properties) return data;
|
|
139
198
|
properties = jsonSchema.properties;
|
|
140
199
|
} catch {
|
|
@@ -179,18 +238,16 @@ function coerceArgs(data, schema) {
|
|
|
179
238
|
}
|
|
180
239
|
return result;
|
|
181
240
|
}
|
|
182
|
-
/** Keys consumed by the CLI framework that are not user-defined args. */
|
|
183
|
-
const frameworkReservedKeys = new Set(["config", "c"]);
|
|
184
241
|
/**
|
|
185
242
|
* Detect unknown keys in the args that don't match any schema property.
|
|
186
|
-
* Returns an array of { key
|
|
243
|
+
* Returns an array of { key } for each unknown key.
|
|
187
244
|
* Framework-reserved keys (--config, -c) are always allowed.
|
|
188
245
|
*/
|
|
189
|
-
function detectUnknownArgs(data, schema, flags, aliases
|
|
246
|
+
function detectUnknownArgs(data, schema, flags, aliases) {
|
|
190
247
|
let properties;
|
|
191
248
|
let isLoose = false;
|
|
192
249
|
try {
|
|
193
|
-
const jsonSchema = schema
|
|
250
|
+
const jsonSchema = getJsonSchema(schema);
|
|
194
251
|
if (jsonSchema.type !== "object" || !jsonSchema.properties) return [];
|
|
195
252
|
properties = jsonSchema.properties;
|
|
196
253
|
if (jsonSchema.additionalProperties !== void 0 && jsonSchema.additionalProperties !== false) isLoose = true;
|
|
@@ -205,18 +262,11 @@ function detectUnknownArgs(data, schema, flags, aliases, suggestFn) {
|
|
|
205
262
|
...Object.keys(aliases),
|
|
206
263
|
...Object.values(aliases)
|
|
207
264
|
]);
|
|
208
|
-
const propertyNames = Object.keys(properties);
|
|
209
265
|
const unknowns = [];
|
|
210
|
-
for (const key of Object.keys(data)) if (!knownKeys.has(key)
|
|
211
|
-
const suggestion = suggestFn(key, propertyNames);
|
|
212
|
-
unknowns.push({
|
|
213
|
-
key,
|
|
214
|
-
suggestion
|
|
215
|
-
});
|
|
216
|
-
}
|
|
266
|
+
for (const key of Object.keys(data)) if (!knownKeys.has(key)) unknowns.push({ key });
|
|
217
267
|
return unknowns;
|
|
218
268
|
}
|
|
219
269
|
//#endregion
|
|
220
|
-
export {
|
|
270
|
+
export { getJsonSchema as a, parsePositionalConfig as c, detectShell as d, escapeRegExp as f, extractSchemaMetadata as i, preprocessArgs as l, writeToRcFile as m, coerceArgs as n, isArrayField as o, getRcFile as p, detectUnknownArgs as r, isAsyncStreamField as s, applyValues as t, camelToKebab as u };
|
|
221
271
|
|
|
222
|
-
//# sourceMappingURL=args-
|
|
272
|
+
//# sourceMappingURL=args-Cnq0nwSM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args-Cnq0nwSM.mjs","names":[],"sources":["../src/util/shell-utils.ts","../src/core/args.ts"],"sourcesContent":["/**\n * Convert a camelCase string to kebab-case.\n * Returns null if the string has no uppercase letters (no conversion needed).\n */\nexport function camelToKebab(str: string): string | null {\n if (!/[A-Z]/.test(str)) return null;\n return str.replace(/[A-Z]/g, (ch) => `-${ch.toLowerCase()}`);\n}\n\nexport type ShellType = 'bash' | 'zsh' | 'fish' | 'powershell';\n\n/**\n * Detects the current shell from environment variables and process info.\n * @returns The detected shell type, or undefined if unknown\n */\nexport async function detectShell(): Promise<ShellType | undefined> {\n if (typeof process === 'undefined') return undefined;\n\n // Method 1: Check SHELL environment variable (most common)\n const shellEnv = process.env.SHELL || '';\n if (shellEnv.includes('zsh')) return 'zsh';\n if (shellEnv.includes('bash')) return 'bash';\n if (shellEnv.includes('fish')) return 'fish';\n\n // Method 2: Check Windows-specific shells\n if (process.env.PSModulePath || process.env.POWERSHELL_DISTRIBUTION_CHANNEL) {\n return 'powershell';\n }\n\n // Method 3: Check parent process on Unix-like systems\n try {\n const ppid = process.ppid;\n if (ppid) {\n const { execSync } = (await import('node:child_process')) as typeof import('node:child_process');\n const processName = execSync(`ps -p ${ppid} -o comm=`, {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'ignore'],\n }).trim();\n\n if (processName.includes('zsh')) return 'zsh';\n if (processName.includes('bash')) return 'bash';\n if (processName.includes('fish')) return 'fish';\n }\n } catch {\n // Ignore errors (e.g., ps not available)\n }\n\n return undefined;\n}\n\nexport async function getRcFile(shell: ShellType, home?: string): Promise<string | null> {\n const { homedir } = await import('node:os');\n const { join } = await import('node:path');\n const h = home ?? homedir();\n switch (shell) {\n case 'bash':\n return join(h, '.bashrc');\n case 'zsh':\n return join(h, '.zshrc');\n case 'fish':\n return join(h, '.config', 'fish', 'config.fish');\n case 'powershell':\n return (\n (typeof process !== 'undefined' ? process.env.PROFILE : undefined) ||\n join(h, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1')\n );\n default:\n return null;\n }\n}\n\nexport function escapeRegExp(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\n/**\n * Writes a snippet to a shell config file using begin/end markers for idempotency.\n * If a block with the same begin marker exists, it is replaced. Otherwise the snippet is appended.\n */\nexport async function writeToRcFile(\n rcFile: string,\n snippet: string,\n beginMarker: string,\n endMarker: string,\n): Promise<{ file: string; updated: boolean }> {\n const { existsSync, mkdirSync, readFileSync, writeFileSync } = await import('node:fs');\n const { dirname } = await import('node:path');\n const existing = existsSync(rcFile) ? readFileSync(rcFile, 'utf-8') : '';\n\n if (existing.includes(beginMarker)) {\n const pattern = new RegExp(`${escapeRegExp(beginMarker)}[\\\\s\\\\S]*?${escapeRegExp(endMarker)}`);\n writeFileSync(rcFile, existing.replace(pattern, snippet));\n return { file: rcFile, updated: true };\n }\n\n mkdirSync(dirname(rcFile), { recursive: true });\n const separator = existing.length > 0 && !existing.endsWith('\\n') ? '\\n' : '';\n writeFileSync(rcFile, `${existing}${separator}\\n${snippet}\\n`);\n return { file: rcFile, updated: false };\n}\n","import type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';\nimport type { PadroneFieldMeta } from '../types/args-meta.ts';\nimport { camelToKebab } from '../util/shell-utils.ts';\nimport { asyncStreamRegistry } from '../util/stream.ts';\n\nexport type { PadroneArgsSchemaMeta, PadroneFieldMeta, SingleChar, StdinConfig } from '../types/args-meta.ts';\n\n/** Extract the JSON schema from a Standard Schema, returning it as a plain record. */\nexport function getJsonSchema(schema: StandardJSONSchemaV1): Record<string, any> {\n return schema['~standard'].jsonSchema.input({\n target: 'draft-2020-12',\n libraryOptions: { unrepresentable: 'any' },\n }) as Record<string, any>;\n}\n\nfunction getFieldJsonSchema(schema: StandardJSONSchemaV1 | undefined, field: string): Record<string, any> | undefined {\n if (!schema) return undefined;\n try {\n const jsonSchema = getJsonSchema(schema);\n if (jsonSchema.type === 'object' && jsonSchema.properties) return jsonSchema.properties[field];\n } catch {}\n return undefined;\n}\n\n/**\n * Checks if a field in the schema is an array type (e.g. `z.string().array()`).\n */\nexport function isArrayField(schema: StandardJSONSchemaV1 | undefined, field: string): boolean {\n return getFieldJsonSchema(schema, field)?.type === 'array';\n}\n\n/**\n * Checks if a field is an async stream (marked with `asyncStream()` metadata).\n * Returns the item schema if provided, or `true` if it's a plain string stream.\n */\nexport function isAsyncStreamField(schema: StandardJSONSchemaV1 | undefined, field: string): { itemSchema?: StandardSchemaV1 } | false {\n const prop = getFieldJsonSchema(schema, field);\n const asyncStreamId = prop?.asyncStream;\n if (asyncStreamId && asyncStreamRegistry.has(asyncStreamId)) {\n const meta = asyncStreamRegistry.get(asyncStreamId);\n return { itemSchema: meta?.itemSchema };\n }\n\n return false;\n}\n\n/**\n * Parse positional configuration to extract names and variadic info.\n */\nexport function parsePositionalConfig(positional: readonly string[]): { name: string; variadic: boolean }[] {\n return positional.map((p) => {\n const variadic = p.startsWith('...');\n const name = variadic ? p.slice(3) : p;\n return { name, variadic };\n });\n}\n\n/**\n * Result type for extractSchemaMetadata function.\n */\ninterface SchemaMetadataResult {\n /** Single-char flags: maps flag char → full arg name (e.g. `{ v: 'verbose' }`) */\n flags: Record<string, string>;\n /** Multi-char aliases: maps alias → full arg name (e.g. `{ 'dry-run': 'dryRun' }`) */\n aliases: Record<string, string>;\n}\n\nfunction addEntries(target: Record<string, string>, key: string, items: string | readonly string[], filter?: (item: string) => boolean) {\n const list = typeof items === 'string' ? [items] : items;\n for (const item of list) {\n if (typeof item === 'string' && item && item !== key && !(item in target) && (!filter || filter(item))) {\n target[item] = key;\n }\n }\n}\n\n/**\n * Extract all arg metadata from schema and meta in a single pass.\n * Returns flags (single-char, stackable) and aliases (multi-char, long names) separately.\n * When `autoAlias` is true (default), camelCase property names automatically get kebab-case aliases.\n */\nexport function extractSchemaMetadata(\n schema: StandardJSONSchemaV1,\n meta?: Record<string, PadroneFieldMeta | undefined>,\n autoAlias?: boolean,\n): SchemaMetadataResult {\n const flags: Record<string, string> = {};\n const aliases: Record<string, string> = {};\n\n // Extract from meta object\n if (meta) {\n for (const [key, value] of Object.entries(meta)) {\n if (!value) continue;\n\n if (value.flags) {\n addEntries(flags, key, value.flags, (item) => item.length === 1);\n }\n if (value.alias) {\n addEntries(aliases, key, value.alias, (item) => item.length > 1);\n }\n }\n }\n\n // Extract from JSON schema properties\n try {\n const jsonSchema = getJsonSchema(schema) as Record<string, any>;\n if (jsonSchema.type === 'object' && jsonSchema.properties) {\n for (const [propertyName, propertySchema] of Object.entries(jsonSchema.properties as Record<string, any>)) {\n if (!propertySchema) continue;\n\n // Extract flags from schema `.meta({ flags: ... })`\n const propFlags = propertySchema.flags;\n if (propFlags) {\n addEntries(flags, propertyName, propFlags, (item) => item.length === 1);\n }\n\n // Extract aliases from schema `.meta({ alias: ... })`\n const propAlias = propertySchema.alias;\n if (propAlias) {\n const list = typeof propAlias === 'string' ? [propAlias] : propAlias;\n if (Array.isArray(list)) {\n addEntries(aliases, propertyName, list, (item) => item.length > 1);\n }\n }\n\n // Auto-generate kebab-case alias for camelCase property names\n if (autoAlias !== false) {\n const kebab = camelToKebab(propertyName);\n if (kebab && !(kebab in aliases)) {\n aliases[kebab] = propertyName;\n }\n }\n }\n }\n } catch {\n // Ignore errors from JSON schema generation\n }\n\n return { flags, aliases };\n}\n\nfunction preprocessMappings(data: Record<string, unknown>, mappings: Record<string, string>): Record<string, unknown> {\n const result = { ...data };\n\n for (const [mappedKey, fullArgName] of Object.entries(mappings)) {\n if (mappedKey in data && mappedKey !== fullArgName) {\n const mappedValue = data[mappedKey];\n // Prefer full arg name if it exists\n if (!(fullArgName in result)) result[fullArgName] = mappedValue;\n delete result[mappedKey];\n }\n }\n\n return result;\n}\n\n/**\n * Apply values to arguments using \"set if not present\" semantics.\n * Existing values take precedence — only fills in undefined or missing keys.\n */\nexport function applyValues(data: Record<string, unknown>, values: Record<string, unknown>): Record<string, unknown> {\n const result = { ...data };\n\n for (const [key, value] of Object.entries(values)) {\n if (key in result && result[key] !== undefined) continue;\n if (value !== undefined) {\n result[key] = value;\n }\n }\n\n return result;\n}\n\n/** Applies flag and alias mappings to raw arguments. */\nexport function preprocessArgs(\n data: Record<string, unknown>,\n ctx: { flags?: Record<string, string>; aliases?: Record<string, string> },\n): Record<string, unknown> {\n let result = { ...data };\n\n if (ctx.flags && Object.keys(ctx.flags).length > 0) {\n result = preprocessMappings(result, ctx.flags);\n }\n if (ctx.aliases && Object.keys(ctx.aliases).length > 0) {\n result = preprocessMappings(result, ctx.aliases);\n }\n\n return result;\n}\n\n/**\n * Auto-coerce CLI string values to match the expected schema types.\n * Handles: string → number, string → boolean for primitive schema fields.\n * Arrays of primitives are also coerced element-wise.\n */\nexport function coerceArgs(data: Record<string, unknown>, schema: StandardJSONSchemaV1): Record<string, unknown> {\n let properties: Record<string, any>;\n try {\n const jsonSchema = getJsonSchema(schema) as Record<string, any>;\n if (jsonSchema.type !== 'object' || !jsonSchema.properties) return data;\n properties = jsonSchema.properties;\n } catch {\n return data;\n }\n\n const result = { ...data };\n\n for (const [key, value] of Object.entries(result)) {\n const prop = properties[key];\n if (!prop) continue;\n\n const targetType = prop.type as string | undefined;\n\n if (targetType === 'number' || targetType === 'integer') {\n if (typeof value === 'string') {\n const num = Number(value);\n if (!Number.isNaN(num)) result[key] = num;\n }\n } else if (targetType === 'boolean') {\n if (typeof value === 'string') {\n const lower = value.toLowerCase();\n if (lower === 'true' || lower === '1' || lower === 'yes' || lower === 'on') result[key] = true;\n else if (lower === 'false' || lower === '0' || lower === 'no' || lower === 'off') result[key] = false;\n }\n } else if (targetType === 'array') {\n // Coerce single items to array\n const arr = Array.isArray(value) ? value : [value];\n const itemType = prop.items?.type as string | undefined;\n if (itemType === 'number' || itemType === 'integer') {\n result[key] = arr.map((v) => {\n if (typeof v === 'string') {\n const num = Number(v);\n return Number.isNaN(num) ? v : num;\n }\n return v;\n });\n } else if (itemType === 'boolean') {\n result[key] = arr.map((v) => {\n if (typeof v === 'string') {\n const lower = v.toLowerCase();\n if (lower === 'true' || lower === '1' || lower === 'yes' || lower === 'on') return true;\n if (lower === 'false' || lower === '0' || lower === 'no' || lower === 'off') return false;\n }\n return v;\n });\n } else if (!Array.isArray(value)) {\n result[key] = arr;\n }\n }\n }\n\n return result;\n}\n\n/**\n * Detect unknown keys in the args that don't match any schema property.\n * Returns an array of { key } for each unknown key.\n * Framework-reserved keys (--config, -c) are always allowed.\n */\nexport function detectUnknownArgs(\n data: Record<string, unknown>,\n schema: StandardJSONSchemaV1,\n flags: Record<string, string>,\n aliases: Record<string, string>,\n): { key: string }[] {\n let properties: Record<string, any>;\n let isLoose = false;\n try {\n const jsonSchema = getJsonSchema(schema) as Record<string, any>;\n if (jsonSchema.type !== 'object' || !jsonSchema.properties) return [];\n properties = jsonSchema.properties;\n // If additionalProperties is set (true, {}, or a schema), the schema allows extra keys\n if (jsonSchema.additionalProperties !== undefined && jsonSchema.additionalProperties !== false) isLoose = true;\n } catch {\n return [];\n }\n\n if (isLoose) return [];\n\n const knownKeys = new Set<string>([\n ...Object.keys(properties),\n ...Object.keys(flags),\n ...Object.values(flags),\n ...Object.keys(aliases),\n ...Object.values(aliases),\n ]);\n const unknowns: { key: string }[] = [];\n\n for (const key of Object.keys(data)) {\n if (!knownKeys.has(key)) {\n unknowns.push({ key });\n }\n }\n\n return unknowns;\n}\n"],"mappings":";;;;;;AAIA,SAAgB,aAAa,KAA4B;AACvD,KAAI,CAAC,QAAQ,KAAK,IAAI,CAAE,QAAO;AAC/B,QAAO,IAAI,QAAQ,WAAW,OAAO,IAAI,GAAG,aAAa,GAAG;;;;;;AAS9D,eAAsB,cAA8C;AAClE,KAAI,OAAO,YAAY,YAAa,QAAO,KAAA;CAG3C,MAAM,WAAW,QAAQ,IAAI,SAAS;AACtC,KAAI,SAAS,SAAS,MAAM,CAAE,QAAO;AACrC,KAAI,SAAS,SAAS,OAAO,CAAE,QAAO;AACtC,KAAI,SAAS,SAAS,OAAO,CAAE,QAAO;AAGtC,KAAI,QAAQ,IAAI,gBAAgB,QAAQ,IAAI,gCAC1C,QAAO;A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AAI,IAAI,CACrB,UAAS,KAAK,EAAE,KAAK,CAAC;AAI1B,QAAO"}
|
package/dist/codegen/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { dirname, join, resolve } from "node:path";
|
|
1
|
+
import { a as getJsonSchema } from "../args-Cnq0nwSM.mjs";
|
|
4
2
|
import { execFile } from "node:child_process";
|
|
5
3
|
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
//#region src/codegen/code-builder.ts
|
|
7
7
|
var CodeBuilderImpl = class CodeBuilderImpl {
|
|
8
8
|
imports = /* @__PURE__ */ new Map();
|
|
@@ -1161,7 +1161,7 @@ function jsonSchemaPropertyToZod(prop, required, ambiguous) {
|
|
|
1161
1161
|
*/
|
|
1162
1162
|
function schemaToCode(schema) {
|
|
1163
1163
|
try {
|
|
1164
|
-
return jsonSchemaToCode(schema
|
|
1164
|
+
return jsonSchemaToCode(getJsonSchema(schema));
|
|
1165
1165
|
} catch {
|
|
1166
1166
|
return {
|
|
1167
1167
|
code: "z.unknown()",
|