@reliverse/rempts-core 1.6.1 → 2.3.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 +398 -102
- package/dist/cli.d.ts +32 -0
- package/dist/cli.js +731 -0
- package/dist/config-loader.d.ts +42 -0
- package/dist/config-loader.js +20 -0
- package/dist/config.d.ts +99 -0
- package/dist/config.js +188 -0
- package/dist/file-loader.d.ts +43 -0
- package/dist/file-loader.js +199 -0
- package/dist/global-flags.d.ts +36 -0
- package/dist/global-flags.js +36 -0
- package/dist/mod.d.ts +13 -0
- package/dist/mod.js +19 -0
- package/dist/parser.d.ts +6 -0
- package/dist/parser.js +137 -0
- package/dist/plugin/context.d.ts +13 -0
- package/dist/plugin/context.js +53 -0
- package/dist/plugin/create.d.ts +92 -0
- package/dist/plugin/create.js +61 -0
- package/dist/plugin/loader.d.ts +12 -0
- package/dist/plugin/loader.js +65 -0
- package/dist/plugin/manager.d.ts +53 -0
- package/dist/plugin/manager.js +135 -0
- package/dist/plugin/mod.d.ts +10 -0
- package/dist/plugin/mod.js +27 -0
- package/dist/plugin/store.d.ts +45 -0
- package/dist/plugin/store.js +60 -0
- package/dist/plugin/testing.d.ts +38 -0
- package/dist/plugin/testing.js +175 -0
- package/dist/plugin/types.d.ts +146 -0
- package/dist/tui/registry.d.ts +8 -0
- package/dist/tui/registry.js +10 -0
- package/dist/tui/types.d.ts +58 -0
- package/dist/tui/types.js +10 -0
- package/dist/types.d.ts +178 -0
- package/dist/types.js +25 -0
- package/dist/utils/logger.d.ts +10 -0
- package/dist/utils/logger.js +27 -0
- package/dist/utils/merge.d.ts +13 -0
- package/dist/utils/merge.js +25 -0
- package/dist/utils/mod.d.ts +6 -0
- package/dist/utils/mod.js +2 -0
- package/dist/utils/type-helpers.d.ts +41 -0
- package/dist/utils/type-helpers.js +0 -0
- package/dist/validation.d.ts +30 -0
- package/dist/validation.js +121 -0
- package/package.json +47 -44
- package/src/cli.ts +1049 -0
- package/src/config-loader.ts +71 -0
- package/src/config.ts +270 -0
- package/src/file-loader.ts +346 -0
- package/src/global-flags.ts +50 -0
- package/src/mod.ts +74 -0
- package/src/parser.ts +212 -0
- package/src/plugin/context.ts +88 -0
- package/src/plugin/create.ts +174 -0
- package/src/plugin/loader.ts +111 -0
- package/src/plugin/manager.ts +244 -0
- package/src/plugin/mod.ts +51 -0
- package/src/plugin/store.ts +124 -0
- package/src/plugin/testing.ts +236 -0
- package/src/plugin/types.ts +206 -0
- package/src/tui/registry.ts +22 -0
- package/src/tui/types.ts +79 -0
- package/src/types.ts +285 -0
- package/src/utils/logger.ts +43 -0
- package/src/utils/merge.ts +54 -0
- package/src/utils/mod.ts +7 -0
- package/src/utils/type-helpers.ts +151 -0
- package/src/validation.ts +177 -0
- package/LICENSE +0 -21
- package/bin/core-impl/anykey/anykey-mod.d.ts +0 -12
- package/bin/core-impl/anykey/anykey-mod.js +0 -125
- package/bin/core-impl/date/date.d.ts +0 -2
- package/bin/core-impl/date/date.js +0 -236
- package/bin/core-impl/editor/editor-mod.d.ts +0 -25
- package/bin/core-impl/editor/editor-mod.js +0 -896
- package/bin/core-impl/figures/figures-mod.d.ts +0 -233
- package/bin/core-impl/figures/figures-mod.js +0 -286
- package/bin/core-impl/figures/figures.test.d.ts +0 -1
- package/bin/core-impl/figures/figures.test.js +0 -474
- package/bin/core-impl/input/confirm-prompt.d.ts +0 -5
- package/bin/core-impl/input/confirm-prompt.js +0 -173
- package/bin/core-impl/input/input-prompt.d.ts +0 -16
- package/bin/core-impl/input/input-prompt.js +0 -370
- package/bin/core-impl/launcher/_parser.d.ts +0 -2
- package/bin/core-impl/launcher/_parser.js +0 -122
- package/bin/core-impl/launcher/_utils.d.ts +0 -8
- package/bin/core-impl/launcher/_utils.js +0 -29
- package/bin/core-impl/launcher/args.d.ts +0 -3
- package/bin/core-impl/launcher/args.js +0 -89
- package/bin/core-impl/launcher/command.d.ts +0 -8
- package/bin/core-impl/launcher/command.js +0 -68
- package/bin/core-impl/launcher/launcher-mod.d.ts +0 -8
- package/bin/core-impl/launcher/launcher-mod.js +0 -34
- package/bin/core-impl/launcher/usage.d.ts +0 -3
- package/bin/core-impl/launcher/usage.js +0 -104
- package/bin/core-impl/msg-fmt/colors.d.ts +0 -30
- package/bin/core-impl/msg-fmt/colors.js +0 -42
- package/bin/core-impl/msg-fmt/logger.d.ts +0 -17
- package/bin/core-impl/msg-fmt/logger.js +0 -106
- package/bin/core-impl/msg-fmt/mapping.d.ts +0 -3
- package/bin/core-impl/msg-fmt/mapping.js +0 -49
- package/bin/core-impl/msg-fmt/messages.d.ts +0 -35
- package/bin/core-impl/msg-fmt/messages.js +0 -314
- package/bin/core-impl/msg-fmt/terminal.d.ts +0 -15
- package/bin/core-impl/msg-fmt/terminal.js +0 -59
- package/bin/core-impl/msg-fmt/variants.d.ts +0 -11
- package/bin/core-impl/msg-fmt/variants.js +0 -52
- package/bin/core-impl/next-steps/next-steps.d.ts +0 -14
- package/bin/core-impl/next-steps/next-steps.js +0 -24
- package/bin/core-impl/number/number-mod.d.ts +0 -28
- package/bin/core-impl/number/number-mod.js +0 -197
- package/bin/core-impl/results/results.d.ts +0 -7
- package/bin/core-impl/results/results.js +0 -27
- package/bin/core-impl/select/multiselect-prompt.d.ts +0 -2
- package/bin/core-impl/select/multiselect-prompt.js +0 -341
- package/bin/core-impl/select/nummultiselect-prompt.d.ts +0 -6
- package/bin/core-impl/select/nummultiselect-prompt.js +0 -105
- package/bin/core-impl/select/numselect-prompt.d.ts +0 -7
- package/bin/core-impl/select/numselect-prompt.js +0 -115
- package/bin/core-impl/select/select-prompt.d.ts +0 -33
- package/bin/core-impl/select/select-prompt.js +0 -302
- package/bin/core-impl/select/toggle-prompt.d.ts +0 -5
- package/bin/core-impl/select/toggle-prompt.js +0 -208
- package/bin/core-impl/st-end/end.d.ts +0 -2
- package/bin/core-impl/st-end/end.js +0 -42
- package/bin/core-impl/st-end/start.d.ts +0 -17
- package/bin/core-impl/st-end/start.js +0 -66
- package/bin/core-impl/task/progress.d.ts +0 -2
- package/bin/core-impl/task/progress.js +0 -57
- package/bin/core-impl/task/spinner.d.ts +0 -15
- package/bin/core-impl/task/spinner.js +0 -110
- package/bin/core-impl/utils/colorize.d.ts +0 -2
- package/bin/core-impl/utils/colorize.js +0 -134
- package/bin/core-impl/utils/errors.d.ts +0 -1
- package/bin/core-impl/utils/errors.js +0 -15
- package/bin/core-impl/utils/prevent.d.ts +0 -10
- package/bin/core-impl/utils/prevent.js +0 -69
- package/bin/core-impl/utils/prompt-end.d.ts +0 -8
- package/bin/core-impl/utils/prompt-end.js +0 -33
- package/bin/core-impl/utils/stream-text.d.ts +0 -18
- package/bin/core-impl/utils/stream-text.js +0 -136
- package/bin/core-impl/utils/system.d.ts +0 -6
- package/bin/core-impl/utils/system.js +0 -7
- package/bin/core-impl/utils/validate.d.ts +0 -22
- package/bin/core-impl/utils/validate.js +0 -17
- package/bin/core-impl/visual/animate/animate.d.ts +0 -14
- package/bin/core-impl/visual/animate/animate.js +0 -64
- package/bin/core-impl/visual/ascii-art/ascii-art.d.ts +0 -6
- package/bin/core-impl/visual/ascii-art/ascii-art.js +0 -12
- package/bin/core-types.d.ts +0 -434
- package/bin/main.d.ts +0 -41
- package/bin/main.js +0 -96
- /package/{bin/core-types.js → dist/plugin/types.js} +0 -0
package/README.md
CHANGED
|
@@ -1,102 +1,398 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
1
|
+
# rempts-core
|
|
2
|
+
|
|
3
|
+
The minimal, type-safe CLI framework for Bun.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add rempts-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { defineCommand, option } from '@reliverse/rempts-core'
|
|
15
|
+
import { type } from 'arktype'
|
|
16
|
+
|
|
17
|
+
export default defineCommand({
|
|
18
|
+
name: 'greet',
|
|
19
|
+
description: 'A friendly greeting',
|
|
20
|
+
options: {
|
|
21
|
+
name: option(
|
|
22
|
+
type("string", ">0"),
|
|
23
|
+
{ description: 'Name to greet', short: 'n' }
|
|
24
|
+
),
|
|
25
|
+
excited: option(
|
|
26
|
+
type("boolean", "=", false),
|
|
27
|
+
{ description: 'Add excitement', short: 'e' }
|
|
28
|
+
)
|
|
29
|
+
},
|
|
30
|
+
handler: async ({ flags }) => {
|
|
31
|
+
const greeting = `Hello, ${flags.name}${flags.excited ? '!' : '.'}`
|
|
32
|
+
console.log(greeting)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- 🚀 **Type-safe** - Full TypeScript support with automatic type inference
|
|
40
|
+
- ⚡ **Fast** - Powered by Bun's native speed
|
|
41
|
+
- 📦 **Zero config** - Works out of the box with sensible defaults
|
|
42
|
+
- 🎯 **Minimal API** - Learn once, use everywhere
|
|
43
|
+
- 🔌 **Extensible** - Plugin system for custom functionality
|
|
44
|
+
- 🧪 **Testable** - First-class testing utilities included
|
|
45
|
+
|
|
46
|
+
## Core Concepts
|
|
47
|
+
|
|
48
|
+
### Commands
|
|
49
|
+
|
|
50
|
+
Define commands with automatic type inference:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { defineCommand } from '@reliverse/rempts-core'
|
|
54
|
+
|
|
55
|
+
export default defineCommand({
|
|
56
|
+
name: 'build',
|
|
57
|
+
description: 'Build the project',
|
|
58
|
+
handler: async () => {
|
|
59
|
+
console.log('Building...')
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Options
|
|
65
|
+
|
|
66
|
+
Use the `option` helper with Standard Schema validation:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { defineCommand, option } from '@reliverse/rempts-core'
|
|
70
|
+
import { type } from 'arktype'
|
|
71
|
+
|
|
72
|
+
export default defineCommand({
|
|
73
|
+
name: 'deploy',
|
|
74
|
+
options: {
|
|
75
|
+
env: option(
|
|
76
|
+
type("'dev'|'staging'|'prod'"),
|
|
77
|
+
{ description: 'Target environment' }
|
|
78
|
+
),
|
|
79
|
+
force: option(
|
|
80
|
+
type("boolean", "=", false),
|
|
81
|
+
{ description: 'Force deployment', short: 'f' }
|
|
82
|
+
)
|
|
83
|
+
},
|
|
84
|
+
handler: async ({ flags }) => {
|
|
85
|
+
// TypeScript knows:
|
|
86
|
+
// flags.env is 'dev' | 'staging' | 'prod'
|
|
87
|
+
// flags.force is boolean
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Multi-Command CLIs
|
|
93
|
+
|
|
94
|
+
Create complex CLIs with multiple commands:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { createCLI } from '@reliverse/rempts-core'
|
|
98
|
+
import build from './commands/build'
|
|
99
|
+
import deploy from './commands/deploy'
|
|
100
|
+
import test from './commands/test'
|
|
101
|
+
|
|
102
|
+
const cli = createCLI({
|
|
103
|
+
name: 'my-tool',
|
|
104
|
+
version: '1.0.0',
|
|
105
|
+
description: 'My awesome CLI tool',
|
|
106
|
+
commands: [build, deploy, test]
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
await cli.run()
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## API Reference
|
|
113
|
+
|
|
114
|
+
### `defineCommand(config)`
|
|
115
|
+
|
|
116
|
+
Creates a command definition with full type inference.
|
|
117
|
+
|
|
118
|
+
### `option(schema, config)`
|
|
119
|
+
|
|
120
|
+
Creates a typed option with schema validation.
|
|
121
|
+
|
|
122
|
+
### `createCLI(config)`
|
|
123
|
+
|
|
124
|
+
Creates a multi-command CLI application.
|
|
125
|
+
|
|
126
|
+
### `defineConfig(config)`
|
|
127
|
+
|
|
128
|
+
Defines shared configuration for your CLI.
|
|
129
|
+
|
|
130
|
+
## Plugin System
|
|
131
|
+
|
|
132
|
+
Rempts provides a powerful plugin system with compile-time type safety:
|
|
133
|
+
|
|
134
|
+
### Basic Plugin
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { RemptsPlugin, createPlugin } from '@reliverse/rempts-core'
|
|
138
|
+
|
|
139
|
+
interface MyPluginStore {
|
|
140
|
+
apiKey: string
|
|
141
|
+
isAuthenticated: boolean
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const myPlugin: RemptsPlugin<MyPluginStore> = {
|
|
145
|
+
name: 'my-plugin',
|
|
146
|
+
version: '1.0.0',
|
|
147
|
+
|
|
148
|
+
// Define the plugin's store
|
|
149
|
+
store: {
|
|
150
|
+
apiKey: '',
|
|
151
|
+
isAuthenticated: false
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
// Lifecycle hooks
|
|
155
|
+
setup(context) {
|
|
156
|
+
// One-time initialization
|
|
157
|
+
context.updateConfig({ customField: 'value' })
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
configResolved(config) {
|
|
161
|
+
// Called after all configuration is resolved
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
beforeCommand(context) {
|
|
165
|
+
// Called before each command - context.store is type-safe!
|
|
166
|
+
context.store.apiKey = process.env.API_KEY || ''
|
|
167
|
+
context.store.isAuthenticated = !!context.store.apiKey
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
afterCommand(context) {
|
|
171
|
+
// Called after each command with results
|
|
172
|
+
if (context.error) {
|
|
173
|
+
console.error('Command failed:', context.error)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Plugin Factory
|
|
180
|
+
|
|
181
|
+
Use `createPlugin` for better ergonomics:
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { createPlugin } from '@reliverse/rempts-core'
|
|
185
|
+
|
|
186
|
+
export const authPlugin = createPlugin((options: AuthOptions) => {
|
|
187
|
+
return {
|
|
188
|
+
name: 'auth-plugin',
|
|
189
|
+
store: {
|
|
190
|
+
token: '',
|
|
191
|
+
user: null as User | null
|
|
192
|
+
},
|
|
193
|
+
async beforeCommand(context) {
|
|
194
|
+
const token = await loadToken()
|
|
195
|
+
context.store.token = token
|
|
196
|
+
context.store.user = await fetchUser(token)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Using Plugins with Type Safety
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
const cli = await createCLI({
|
|
206
|
+
name: 'my-cli',
|
|
207
|
+
version: '1.0.0',
|
|
208
|
+
plugins: [
|
|
209
|
+
authPlugin({ provider: 'github' }),
|
|
210
|
+
myPlugin
|
|
211
|
+
]
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
// In your command files (e.g., cmds/deploy/cmd.ts), the store is fully typed!
|
|
215
|
+
// cmds/deploy/cmd.ts
|
|
216
|
+
import { defineCommand } from '@reliverse/rempts-core'
|
|
217
|
+
|
|
218
|
+
export default defineCommand({
|
|
219
|
+
name: 'deploy',
|
|
220
|
+
handler: async ({ context }) => {
|
|
221
|
+
// TypeScript knows about all plugin stores!
|
|
222
|
+
if (!context?.store.isAuthenticated) {
|
|
223
|
+
throw new Error('Not authenticated')
|
|
224
|
+
}
|
|
225
|
+
console.log(`Deploying as ${context.store.user?.name}`)
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Plugin Development Utilities
|
|
231
|
+
|
|
232
|
+
Rempts provides utilities for plugin development and testing:
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import {
|
|
236
|
+
createTestPlugin,
|
|
237
|
+
composePlugins,
|
|
238
|
+
createMockPluginContext,
|
|
239
|
+
testPluginHooks,
|
|
240
|
+
assertPluginBehavior
|
|
241
|
+
} from '@reliverse/rempts-core/plugin'
|
|
242
|
+
|
|
243
|
+
// Create a test plugin
|
|
244
|
+
const testPlugin = createTestPlugin(
|
|
245
|
+
{ count: 0, message: '' },
|
|
246
|
+
{
|
|
247
|
+
beforeCommand(context) {
|
|
248
|
+
context.store.count++
|
|
249
|
+
console.log(`Count: ${context.store.count}`)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
// Compose multiple plugins
|
|
255
|
+
const composedPlugin = composePlugins(
|
|
256
|
+
authPlugin({ provider: 'github' }),
|
|
257
|
+
loggingPlugin({ level: 'debug' }),
|
|
258
|
+
metricsPlugin({ enabled: true })
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
// Test plugin behavior
|
|
262
|
+
const results = await testPluginHooks(testPlugin, {
|
|
263
|
+
config: { name: 'test-cli', version: '1.0.0' },
|
|
264
|
+
store: { count: 0, message: 'test' }
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
assertPluginBehavior(results, {
|
|
268
|
+
beforeCommandShouldSucceed: true
|
|
269
|
+
})
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Module Augmentation
|
|
273
|
+
|
|
274
|
+
Plugins can extend Rempts's interfaces:
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
declare module '@reliverse/rempts-core' {
|
|
278
|
+
interface EnvironmentInfo {
|
|
279
|
+
isCI: boolean
|
|
280
|
+
ciProvider?: string
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Runtime Validation
|
|
286
|
+
|
|
287
|
+
Rempts provides runtime validation utilities for dynamic type checking:
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import {
|
|
291
|
+
validateValue,
|
|
292
|
+
validateValues,
|
|
293
|
+
isValueOfType,
|
|
294
|
+
createValidator,
|
|
295
|
+
createBatchValidator
|
|
296
|
+
} from '@reliverse/rempts-core'
|
|
297
|
+
|
|
298
|
+
// Validate a single value
|
|
299
|
+
const result = await validateValue(
|
|
300
|
+
'hello',
|
|
301
|
+
type("string", ">0"),
|
|
302
|
+
{ option: 'message', command: 'greet' }
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
// Validate multiple values
|
|
306
|
+
const validated = await validateValues(
|
|
307
|
+
{ name: 'John', age: 25 },
|
|
308
|
+
{
|
|
309
|
+
name: type("string"),
|
|
310
|
+
age: type("number")
|
|
311
|
+
},
|
|
312
|
+
'user'
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
// Check value types
|
|
316
|
+
if (isValueOfType(value, 'string')) {
|
|
317
|
+
console.log('Value is a string')
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Create reusable validators
|
|
321
|
+
const nameValidator = createValidator(type("string", ">0"))
|
|
322
|
+
const userValidator = createBatchValidator({
|
|
323
|
+
name: type("string"),
|
|
324
|
+
age: type("number")
|
|
325
|
+
})
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Type Utilities
|
|
329
|
+
|
|
330
|
+
Rempts exports advanced TypeScript type utilities for complex type manipulation:
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
import {
|
|
334
|
+
UnionToIntersection,
|
|
335
|
+
MergeAll,
|
|
336
|
+
Expand,
|
|
337
|
+
DeepPartial,
|
|
338
|
+
Constrain,
|
|
339
|
+
NonEmptyArray,
|
|
340
|
+
IsNever,
|
|
341
|
+
IsAny,
|
|
342
|
+
IsUnknown
|
|
343
|
+
} from '@reliverse/rempts-core'
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Key Utilities
|
|
347
|
+
|
|
348
|
+
**UnionToIntersection** - Convert union types to intersection types:
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
type Example = UnionToIntersection<{ a: string } | { b: number }>
|
|
352
|
+
// Result: { a: string } & { b: number }
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**MergeAll** - Merge multiple object types:
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
type Example = MergeAll<[{ a: string }, { b: number }, { c: boolean }]>
|
|
359
|
+
// Result: { a: string; b: number; c: boolean }
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
**Expand** - Expand complex types for better IntelliSense:
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
type Example = Expand<{ nested: { deep: { value: string } } }>
|
|
366
|
+
// Shows full type structure in IDE
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
**DeepPartial** - Make all properties optional recursively:
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
type Example = DeepPartial<{ user: { name: string; age: number } }>
|
|
373
|
+
// Result: { user?: { name?: string; age?: number } }
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Constrain** - Constrain types with fallback:
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
type Example = Constrain<string, 'a' | 'b' | 'c', 'a'>
|
|
380
|
+
// Result: 'a' | 'b' | 'c' (or 'a' if string doesn't match)
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
## Related Packages
|
|
385
|
+
|
|
386
|
+
- **[rempts-generator](/docs/packages/generator)** - Generate TypeScript definitions from commands
|
|
387
|
+
- **[rempts-utils](/docs/packages/utils)** - Shared utilities for CLI development
|
|
388
|
+
- **[rempts-test](/docs/packages/test)** - Testing utilities for CLI applications
|
|
389
|
+
|
|
390
|
+
## Documentation
|
|
391
|
+
|
|
392
|
+
- [Getting Started](/docs/getting-started) - Step-by-step tutorial
|
|
393
|
+
- [Type Generation Guide](/docs/guides/type-generation) - Learn about code generation
|
|
394
|
+
- [API Reference](/docs/api) - Complete API documentation
|
|
395
|
+
|
|
396
|
+
## License
|
|
397
|
+
|
|
398
|
+
MIT © blefnk
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { MergePluginStores, Plugin } from "./plugin/types.js";
|
|
2
|
+
import type { CLI, RemptsConfig } from "./types.js";
|
|
3
|
+
export declare function createApp<TPlugins extends readonly Plugin[] = [], TDefaultCommand extends string | undefined = undefined>(options?: {
|
|
4
|
+
/**
|
|
5
|
+
* CLI configuration override
|
|
6
|
+
*/
|
|
7
|
+
config?: Partial<RemptsConfig> & {
|
|
8
|
+
plugins?: TPlugins;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Default command to run when no arguments are provided
|
|
12
|
+
*/
|
|
13
|
+
defaultCommand?: TDefaultCommand;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to auto-initialize commands from config
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
autoInit?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Custom config directory (overrides --cwd detection)
|
|
21
|
+
*/
|
|
22
|
+
configDir?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Entry file path (e.g., import.meta.path or __filename)
|
|
25
|
+
* If not provided, will be auto-detected from call stack
|
|
26
|
+
* Commands directory will be <entry-file-dir>/cmds
|
|
27
|
+
*/
|
|
28
|
+
entryFile?: string;
|
|
29
|
+
}): Promise<CLI<MergePluginStores<TPlugins>>>;
|
|
30
|
+
export declare function createCLI<TPlugins extends readonly Plugin[] = []>(configOverride?: Partial<RemptsConfig> & {
|
|
31
|
+
plugins?: TPlugins;
|
|
32
|
+
}, entryFile?: string): Promise<CLI<MergePluginStores<TPlugins>>>;
|