@nmakarov/cli-toolkit 0.1.3 → 0.2.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 +205 -394
- package/dist/args.cjs +1 -1
- package/dist/args.cjs.map +1 -1
- package/dist/args.js +1 -1
- package/dist/args.js.map +1 -1
- package/dist/filestore.cjs +794 -0
- package/dist/filestore.cjs.map +1 -0
- package/dist/filestore.js +754 -0
- package/dist/filestore.js.map +1 -0
- package/dist/index.cjs +747 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +743 -7
- package/dist/index.js.map +1 -1
- package/dist/params.cjs +0 -2
- package/dist/params.cjs.map +1 -1
- package/dist/params.js +0 -2
- package/dist/params.js.map +1 -1
- package/package.json +13 -2
package/README.md
CHANGED
|
@@ -1,490 +1,301 @@
|
|
|
1
1
|
# @nmakarov/cli-toolkit
|
|
2
2
|
|
|
3
|
-
A comprehensive TypeScript toolkit for building CLI applications with
|
|
3
|
+
A comprehensive TypeScript toolkit for building professional CLI applications with argument parsing, parameter validation, interactive terminal UIs, and structured logging.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@nmakarov/cli-toolkit)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
npm install @nmakarov/cli-toolkit
|
|
9
|
-
```
|
|
8
|
+
## Features
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
- 🎯 **Args** - Powerful argument parser with config files, environment variables, and precedence rules
|
|
11
|
+
- ✅ **Params** - Type-safe parameter validation with Joi schemas and cross-parameter references
|
|
12
|
+
- 🖥️ **Screen** - Interactive terminal UIs with React/Ink (lists, menus, grids, navigation)
|
|
13
|
+
- 📝 **Logger** - Structured logging with levels, progress tracking, and IPC routing
|
|
14
|
+
- ⚡ **Errors** - Custom error classes for framework-specific error handling
|
|
15
|
+
- 🕐 **Date/Time** - ISO8601 timestamps with timezone support and relative time expressions
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
aliases: { 'v': 'verbose', 'd': 'debug' },
|
|
17
|
-
defaults: { timeout: 5000 }
|
|
18
|
-
});
|
|
17
|
+
## Installation
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
```bash
|
|
20
|
+
npm install @nmakarov/cli-toolkit
|
|
21
|
+
```
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
import { showListScreen, buildBreadcrumb } from '@nmakarov/cli-toolkit/screen';
|
|
25
|
-
import React, { createElement as h, Text, Box } from 'react';
|
|
23
|
+
## Requirements
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
items: [
|
|
30
|
-
{ value: "build", title: "Build Project" },
|
|
31
|
-
{ value: "test", title: "Run Tests" }
|
|
32
|
-
],
|
|
33
|
-
onSelect: (item) => item.value,
|
|
34
|
-
footer: "↑↓ to navigate, enter to select, esc to exit"
|
|
35
|
-
});
|
|
36
|
-
```
|
|
25
|
+
- **Node.js**: v20.0.0 or higher (recommended: v24+)
|
|
26
|
+
- **For Screen module**: `ink` and `react` as peer dependencies
|
|
37
27
|
|
|
38
|
-
## 📋 Precedence Order
|
|
39
|
-
|
|
40
|
-
**Short Version:** `overrides > CLI args > config files > env vars > defaults`
|
|
41
|
-
|
|
42
|
-
**Detailed:**
|
|
43
|
-
1. **Overrides** (constructor config) - Highest precedence
|
|
44
|
-
2. **CLI args** (command line) - `--verbose`, `-v`, `--key=value`
|
|
45
|
-
3. **Config files** (loaded from files) - `config.json`, `config.local.json`
|
|
46
|
-
4. **Environment variables** - `VERBOSE=true`, `KEY=value`
|
|
47
|
-
5. **Defaults** (constructor config) - Lowest precedence
|
|
48
|
-
|
|
49
|
-
## 🔧 Key Features
|
|
50
|
-
|
|
51
|
-
### Argument Parsing
|
|
52
|
-
- **Case-insensitive** argument parsing
|
|
53
|
-
- **Environment-specific** configs and env vars
|
|
54
|
-
- **Short flag bundling** (`-vsd` = `-v -s -d`)
|
|
55
|
-
- **Negative flags** (`--no-debug`, `--not-verbose`)
|
|
56
|
-
- **Config file loading** (JSON/JS with environment support)
|
|
57
|
-
- **Dotenv integration** with environment-specific files
|
|
58
|
-
- **Singleton pattern** support
|
|
59
|
-
|
|
60
|
-
### Terminal UI System
|
|
61
|
-
- **Interactive lists** with custom rendering, sorting, and scrolling
|
|
62
|
-
- **Multi-column layouts** with preview panes
|
|
63
|
-
- **Breadcrumb navigation** for clear hierarchy
|
|
64
|
-
- **Customizable UI elements** (text blocks, dividers, input fields)
|
|
65
|
-
- **Keyboard navigation** with customizable key bindings
|
|
66
|
-
- **Responsive design** that adapts to terminal width
|
|
67
|
-
|
|
68
|
-
### Development
|
|
69
|
-
- **TypeScript** with full type safety
|
|
70
|
-
- **Clean builds** with no warnings
|
|
71
|
-
- **Dual module support** (ESM/CJS)
|
|
72
|
-
- **Comprehensive documentation**
|
|
73
|
-
|
|
74
|
-
## 📖 Documentation
|
|
75
|
-
|
|
76
|
-
- **[Complete Documentation](./docs/README.md)** - Full API reference and usage guide
|
|
77
|
-
- **[API Reference](./docs/API.md)** - Complete API documentation
|
|
78
|
-
- **[Screen System Guide](./docs/screen/README.md)** - Terminal UI components and patterns
|
|
79
|
-
- **[Quick Reference](./docs/QUICK_REFERENCE.md)** - Cheat sheet for common patterns
|
|
80
|
-
- **[Examples](./docs/EXAMPLES.md)** - Real-world usage examples
|
|
81
|
-
|
|
82
|
-
## 🎯 Examples
|
|
83
|
-
|
|
84
|
-
### Argument Parsing
|
|
85
28
|
```bash
|
|
86
|
-
#
|
|
87
|
-
|
|
29
|
+
# Install peer dependencies for interactive UIs
|
|
30
|
+
npm install ink react
|
|
31
|
+
```
|
|
88
32
|
|
|
89
|
-
|
|
90
|
-
npx tsx examples/args/show-args.ts --env=production
|
|
33
|
+
## Quick Start
|
|
91
34
|
|
|
92
|
-
|
|
93
|
-
npx tsx examples/args/show-args.ts --config=config.json
|
|
35
|
+
### Args - Parse Command Line Arguments
|
|
94
36
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
```
|
|
37
|
+
```typescript
|
|
38
|
+
import { Args } from '@nmakarov/cli-toolkit/args';
|
|
98
39
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
npx tsx examples/screen/basic.ts
|
|
40
|
+
const args = new Args({
|
|
41
|
+
aliases: { v: 'verbose', p: 'port' }
|
|
42
|
+
});
|
|
103
43
|
|
|
104
|
-
|
|
105
|
-
|
|
44
|
+
console.log(args.get('port')); // Get value
|
|
45
|
+
console.log(args.getCommands()); // Get commands
|
|
46
|
+
console.log(args.getUnused()); // Get unused keys
|
|
106
47
|
```
|
|
107
48
|
|
|
108
|
-
## 🛠️ Development
|
|
109
|
-
|
|
110
|
-
### Prerequisites
|
|
111
|
-
- **Node.js**: v20.0.0 or higher (recommended: v24+)
|
|
112
|
-
- **npm**: v8.0.0 or higher
|
|
113
|
-
|
|
114
|
-
### Setup
|
|
115
49
|
```bash
|
|
116
|
-
|
|
117
|
-
cd cli-toolkit
|
|
118
|
-
npm install
|
|
50
|
+
node app.js --verbose --port=8080 build deploy
|
|
119
51
|
```
|
|
120
52
|
|
|
121
|
-
|
|
53
|
+
[📖 Full Args Documentation](docs/ARGS.md)
|
|
122
54
|
|
|
123
|
-
|
|
124
|
-
```bash
|
|
125
|
-
npm run build # Build for production
|
|
126
|
-
npm run dev # Build in watch mode
|
|
127
|
-
```
|
|
55
|
+
### Params - Validate Parameters
|
|
128
56
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
57
|
+
```typescript
|
|
58
|
+
import { Params } from '@nmakarov/cli-toolkit/params';
|
|
59
|
+
import { Args } from '@nmakarov/cli-toolkit/args';
|
|
60
|
+
|
|
61
|
+
const args = new Args();
|
|
62
|
+
const params = new Params({ args });
|
|
63
|
+
|
|
64
|
+
const config = params.getAll({
|
|
65
|
+
name: 'string required',
|
|
66
|
+
port: 'number default 3000',
|
|
67
|
+
debug: 'boolean default false',
|
|
68
|
+
tags: 'array(string)',
|
|
69
|
+
startDate: 'date' // Enhanced date with relative time
|
|
70
|
+
});
|
|
133
71
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
72
|
+
console.log(config.name); // Type-safe, validated
|
|
73
|
+
console.log(config.port); // Number (3000 if not provided)
|
|
74
|
+
console.log(config.startDate); // ISO8601 string
|
|
137
75
|
```
|
|
138
76
|
|
|
139
|
-
#### Testing
|
|
140
77
|
```bash
|
|
141
|
-
|
|
142
|
-
npm run test:watch # Run tests in watch mode
|
|
143
|
-
npm run test:ci # Run *.ci.test.ts across components with coverage
|
|
144
|
-
npm run test:args # Run all Args component tests
|
|
145
|
-
npm run test:args:ci # Run Args CI tests with coverage
|
|
146
|
-
npm run test:params # Run all Params component tests
|
|
147
|
-
npm run test:params:ci # Run Params CI tests with coverage
|
|
148
|
-
npm run test:screen # Run all Screen component tests
|
|
149
|
-
npm run test:screen:ci # Run Screen CI tests with coverage
|
|
78
|
+
node app.js --name="My App" --port=8080 --tags="api,web" --startDate="-7d"
|
|
150
79
|
```
|
|
151
80
|
|
|
152
|
-
|
|
153
|
-
```
|
|
154
|
-
├── src/ # Source code
|
|
155
|
-
│ ├── args/ # Args module implementation
|
|
156
|
-
│ │ ├── index.ts # Args class and helpers
|
|
157
|
-
│ │ └── tests/ # Args component tests
|
|
158
|
-
│ ├── args.ts # Args export surface
|
|
159
|
-
│ ├── params/ # Params module implementation
|
|
160
|
-
│ │ ├── custom-types.ts# Joi custom types
|
|
161
|
-
│ │ ├── index.ts # Params class and helpers
|
|
162
|
-
│ │ └── tests/ # Params component tests
|
|
163
|
-
│ ├── params.ts # Params export surface
|
|
164
|
-
│ ├── screen/ # Screen system components
|
|
165
|
-
│ │ ├── index.ts # Screen exports
|
|
166
|
-
│ │ ├── components.ts # Layout components
|
|
167
|
-
│ │ ├── ui-elements.ts # UI elements
|
|
168
|
-
│ │ ├── list-components.ts # List components
|
|
169
|
-
│ │ ├── screens.ts # Screen functions
|
|
170
|
-
│ │ ├── utils.ts # Utilities
|
|
171
|
-
│ │ ├── footer-builder.ts # Footer builder
|
|
172
|
-
│ │ └── tests/ # Screen component tests
|
|
173
|
-
│ └── index.ts # Main exports
|
|
174
|
-
├── dist/ # Built files
|
|
175
|
-
├── examples/ # Example scripts
|
|
176
|
-
│ ├── args/ # Args-specific demos
|
|
177
|
-
│ │ ├── functionality-examples.ts
|
|
178
|
-
│ │ └── show-args-runner.ts
|
|
179
|
-
│ │ └── show-args.ts
|
|
180
|
-
│ ├── params/ # Params-specific demos
|
|
181
|
-
│ │ └── show-params.ts
|
|
182
|
-
│ └── screen/ # Screen system examples
|
|
183
|
-
├── examples/example-runner.ts # Main interactive example launcher
|
|
184
|
-
├── docs/ # Documentation
|
|
185
|
-
│ └── screen/ # Screen system docs
|
|
186
|
-
├── legacy/ # Legacy reference implementation
|
|
187
|
-
└── package.json # Package configuration
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
### Contributing
|
|
81
|
+
[📖 Full Params Documentation](docs/PARAMS.md)
|
|
191
82
|
|
|
192
|
-
|
|
193
|
-
2. Create a feature branch: `git checkout -b feature/your-feature`
|
|
194
|
-
3. Make your changes
|
|
195
|
-
4. Run tests: `npm test`
|
|
196
|
-
5. Run linting: `npm run lint`
|
|
197
|
-
6. Build: `npm run build`
|
|
198
|
-
7. Commit your changes: `git commit -m 'Add your feature'`
|
|
199
|
-
8. Push to the branch: `git push origin feature/your-feature`
|
|
200
|
-
9. Submit a pull request
|
|
83
|
+
### Screen - Interactive Terminal UIs
|
|
201
84
|
|
|
202
|
-
|
|
85
|
+
```typescript
|
|
86
|
+
import { showListScreen } from '@nmakarov/cli-toolkit/screen';
|
|
87
|
+
import { createElement as h } from 'react';
|
|
88
|
+
import { Text } from 'ink';
|
|
203
89
|
|
|
204
|
-
|
|
90
|
+
const choice = await showListScreen({
|
|
91
|
+
title: "Main Menu",
|
|
92
|
+
items: [
|
|
93
|
+
{ name: "Build", value: "build" },
|
|
94
|
+
{ name: "Test", value: "test" },
|
|
95
|
+
{ name: "Deploy", value: "deploy" }
|
|
96
|
+
],
|
|
97
|
+
onSelect: (value) => value,
|
|
98
|
+
onEscape: () => null
|
|
99
|
+
});
|
|
205
100
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
- **PATCH** (0.0.1): Bug fixes (backward compatible)
|
|
101
|
+
console.log(`Selected: ${choice}`);
|
|
102
|
+
```
|
|
209
103
|
|
|
210
|
-
|
|
211
|
-
```bash
|
|
212
|
-
# Patch version (0.0.1 → 0.0.2)
|
|
213
|
-
npm version patch
|
|
104
|
+
[📖 Full Screen Documentation](docs/SCREEN.md)
|
|
214
105
|
|
|
215
|
-
|
|
216
|
-
npm version minor
|
|
106
|
+
### Logger - Structured Logging
|
|
217
107
|
|
|
218
|
-
|
|
219
|
-
|
|
108
|
+
```typescript
|
|
109
|
+
import { CliToolkitLogger } from '@nmakarov/cli-toolkit/logger';
|
|
220
110
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
111
|
+
const logger = new CliToolkitLogger({
|
|
112
|
+
prefix: 'APP',
|
|
113
|
+
timestamp: true,
|
|
114
|
+
progress: { withTimes: true }
|
|
115
|
+
});
|
|
226
116
|
|
|
227
|
-
|
|
117
|
+
logger.info('Application started');
|
|
118
|
+
logger.debug('Debug details', { config: true });
|
|
119
|
+
logger.warn('Warning message');
|
|
120
|
+
logger.error('Error occurred', new Error('Details'));
|
|
228
121
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
122
|
+
// Progress tracking with throttling
|
|
123
|
+
for (let i = 1; i <= 100; i++) {
|
|
124
|
+
logger.progress('Processing', { prefix: 'task', count: i, total: 100 });
|
|
125
|
+
}
|
|
233
126
|
|
|
234
|
-
|
|
235
|
-
npm whoami
|
|
127
|
+
logger.results({ processed: 100, errors: 0 });
|
|
236
128
|
```
|
|
237
129
|
|
|
238
|
-
|
|
130
|
+
[📖 Full Logger Documentation](docs/LOGGER.md)
|
|
239
131
|
|
|
240
|
-
|
|
241
|
-
```bash
|
|
242
|
-
npm version patch # or minor/major
|
|
243
|
-
```
|
|
132
|
+
### Errors - Custom Error Classes
|
|
244
133
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
npm run build
|
|
248
|
-
```
|
|
134
|
+
```typescript
|
|
135
|
+
import { ParamError, InitError, CriticalRequestError } from '@nmakarov/cli-toolkit/errors';
|
|
249
136
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
137
|
+
// Throw framework-specific errors
|
|
138
|
+
throw new ParamError('Invalid parameter: port must be a number');
|
|
139
|
+
throw new InitError('Failed to initialize database connection');
|
|
140
|
+
throw new CriticalRequestError('API endpoint unreachable');
|
|
141
|
+
```
|
|
254
142
|
|
|
255
|
-
|
|
256
|
-
```bash
|
|
257
|
-
npm publish
|
|
258
|
-
```
|
|
143
|
+
## Module Overview
|
|
259
144
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
145
|
+
| Module | Purpose | Import Path |
|
|
146
|
+
|--------|---------|-------------|
|
|
147
|
+
| **Args** | Parse CLI arguments with config/env support | `@nmakarov/cli-toolkit/args` |
|
|
148
|
+
| **Params** | Type-safe parameter validation with Joi | `@nmakarov/cli-toolkit/params` |
|
|
149
|
+
| **Screen** | Interactive terminal UIs with React/Ink | `@nmakarov/cli-toolkit/screen` |
|
|
150
|
+
| **Logger** | Structured logging with progress tracking | `@nmakarov/cli-toolkit/logger` |
|
|
151
|
+
| **Errors** | Custom error classes | `@nmakarov/cli-toolkit/errors` |
|
|
264
152
|
|
|
265
|
-
|
|
153
|
+
## Examples
|
|
266
154
|
|
|
267
|
-
|
|
155
|
+
Try the interactive example launcher:
|
|
268
156
|
|
|
269
157
|
```bash
|
|
270
|
-
#
|
|
271
|
-
|
|
158
|
+
# Clone the repository
|
|
159
|
+
git clone https://github.com/nmakarov/cli-toolkit.git
|
|
160
|
+
cd cli-toolkit
|
|
272
161
|
|
|
273
|
-
#
|
|
274
|
-
npm
|
|
162
|
+
# Install dependencies
|
|
163
|
+
npm install
|
|
275
164
|
|
|
276
|
-
#
|
|
277
|
-
|
|
165
|
+
# Launch interactive examples
|
|
166
|
+
npx tsx examples/example-runner.ts
|
|
278
167
|
```
|
|
279
168
|
|
|
280
|
-
|
|
169
|
+
Or run individual examples:
|
|
281
170
|
|
|
282
171
|
```bash
|
|
283
|
-
#
|
|
284
|
-
|
|
172
|
+
# Args examples
|
|
173
|
+
npx tsx examples/args/show-args.ts --verbose --output=file.txt
|
|
174
|
+
npx tsx examples/args/show-args-runner.ts # Interactive
|
|
175
|
+
|
|
176
|
+
# Params examples
|
|
177
|
+
npx tsx examples/params/show-params-defaults.ts --name="My App"
|
|
178
|
+
npx tsx examples/params/time-params-playground.ts --startDate="2025-01-01T00:00:00Z" --endDate="@startDate+30d"
|
|
285
179
|
|
|
286
|
-
#
|
|
287
|
-
|
|
180
|
+
# Screen examples
|
|
181
|
+
npx tsx examples/screen/basic.ts # Interactive demo
|
|
288
182
|
|
|
289
|
-
#
|
|
290
|
-
|
|
183
|
+
# Logger examples
|
|
184
|
+
npx tsx examples/logger/basic.ts
|
|
291
185
|
```
|
|
292
186
|
|
|
293
|
-
|
|
187
|
+
## Documentation
|
|
294
188
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
189
|
+
- **[Full Documentation](docs/README.md)** - Complete reference
|
|
190
|
+
- **[Args Module](docs/ARGS.md)** - Argument parsing details
|
|
191
|
+
- **[Params Module](docs/PARAMS.md)** - Parameter validation guide
|
|
192
|
+
- **[Screen Module](docs/SCREEN.md)** - Terminal UI framework
|
|
193
|
+
- **[Logger Module](docs/LOGGER.md)** - Logging capabilities
|
|
194
|
+
- **[Quick Reference](docs/QUICK_REFERENCE.md)** - Cheat sheet
|
|
195
|
+
- **[Examples](docs/EXAMPLES.md)** - Code examples
|
|
196
|
+
- **[API Reference](docs/API.md)** - Full API documentation
|
|
197
|
+
- **[Deployment Guide](DEPLOYMENT.md)** - Publishing workflow
|
|
298
198
|
|
|
299
|
-
|
|
300
|
-
npm pack
|
|
301
|
-
tar -tzf nmakarov-cli-toolkit-*.tgz
|
|
199
|
+
## Testing
|
|
302
200
|
|
|
303
|
-
|
|
304
|
-
npm
|
|
201
|
+
```bash
|
|
202
|
+
npm test # Run all tests
|
|
203
|
+
npm run test:ci # Run CI smoke tests with coverage
|
|
204
|
+
npm run test:args # Test Args module
|
|
205
|
+
npm run test:params # Test Params module
|
|
206
|
+
npm run test:screen # Test Screen module
|
|
207
|
+
npm run test:logger # Test Logger module
|
|
208
|
+
npm run test:coverage # Generate coverage report
|
|
305
209
|
```
|
|
306
210
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
2. **Update `CHANGELOG.md`** with new features/fixes
|
|
315
|
-
|
|
316
|
-
3. **Build and test:**
|
|
317
|
-
```bash
|
|
318
|
-
npm run build
|
|
319
|
-
npm run test # when tests are available
|
|
320
|
-
npm run lint
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
4. **Publish:**
|
|
324
|
-
```bash
|
|
325
|
-
npm publish
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
5. **Create GitHub release:**
|
|
329
|
-
```bash
|
|
330
|
-
git push origin main --tags
|
|
331
|
-
# Then create release on GitHub with changelog
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
### Package Configuration
|
|
335
|
-
|
|
336
|
-
The package is configured for dual module support (ESM/CJS):
|
|
337
|
-
|
|
338
|
-
```json
|
|
339
|
-
{
|
|
340
|
-
"type": "module",
|
|
341
|
-
"main": "./dist/index.js",
|
|
342
|
-
"module": "./dist/index.js",
|
|
343
|
-
"types": "./dist/index.d.ts",
|
|
344
|
-
"exports": {
|
|
345
|
-
".": {
|
|
346
|
-
"import": "./dist/index.js",
|
|
347
|
-
"require": "./dist/index.cjs",
|
|
348
|
-
"types": "./dist/index.d.ts"
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
211
|
+
## Building
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
npm run build # Build ESM and CommonJS outputs
|
|
215
|
+
npm run dev # Watch mode for development
|
|
352
216
|
```
|
|
353
217
|
|
|
354
|
-
|
|
218
|
+
## Key Concepts
|
|
355
219
|
|
|
356
|
-
|
|
220
|
+
### Precedence Order (Args & Params)
|
|
357
221
|
|
|
358
|
-
|
|
359
|
-
```bash
|
|
360
|
-
# Check current version
|
|
361
|
-
npm view @nmakarov/cli-toolkit version
|
|
222
|
+
Values are resolved in this order (highest to lowest priority):
|
|
362
223
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
224
|
+
1. **Overrides** - Explicitly set overrides
|
|
225
|
+
2. **Getters** - Registered getter functions
|
|
226
|
+
3. **CLI Arguments** - Command-line flags and options
|
|
227
|
+
4. **Environment Variables** - `.env` files and process.env
|
|
228
|
+
5. **Config Files** - JSON/JS configuration files
|
|
229
|
+
6. **Constructor Options** - Values passed to constructor
|
|
230
|
+
7. **Defaults** - Default values from definitions
|
|
231
|
+
|
|
232
|
+
### Cross-Parameter References (Params)
|
|
233
|
+
|
|
234
|
+
Calculate values based on other parameters:
|
|
366
235
|
|
|
367
|
-
**"Not authorized":**
|
|
368
236
|
```bash
|
|
369
|
-
#
|
|
370
|
-
|
|
371
|
-
npm login
|
|
237
|
+
# endDate is calculated as 2 hours after startDate
|
|
238
|
+
node app.js --startDate="2025-01-01T10:00:00Z" --endDate="@startDate+2h"
|
|
372
239
|
```
|
|
373
240
|
|
|
374
|
-
|
|
375
|
-
- Ensure package name matches `@nmakarov/cli-toolkit`
|
|
376
|
-
- Check `package.json` name field
|
|
241
|
+
### Relative Time Expressions (Params)
|
|
377
242
|
|
|
378
|
-
**"Missing files":**
|
|
379
243
|
```bash
|
|
380
|
-
|
|
381
|
-
|
|
244
|
+
node app.js --startDate="now" # Current timestamp
|
|
245
|
+
node app.js --startDate="-7d" # 7 days ago
|
|
246
|
+
node app.js --startDate="+2h" # 2 hours from now
|
|
247
|
+
node app.js --endDate="@start+30d" # 30 days after start param
|
|
382
248
|
```
|
|
383
249
|
|
|
384
|
-
|
|
250
|
+
Supported units: `s` (seconds), `m` (minutes), `h` (hours), `d` (days), `w` (weeks), `y` (years)
|
|
385
251
|
|
|
386
|
-
###
|
|
252
|
+
### ISO8601 Internal Representation
|
|
387
253
|
|
|
388
|
-
|
|
254
|
+
All timestamps are stored internally as UTC ISO8601 strings:
|
|
255
|
+
- **Format**: `YYYY-MM-DDTHH:mm:ss.sssZ`
|
|
256
|
+
- **Example**: `2025-01-01T10:30:00.000Z`
|
|
257
|
+
- **Benefits**: PostgreSQL compatible, JSON serializable, timezone unambiguous
|
|
389
258
|
|
|
390
|
-
|
|
391
|
-
# Check for security vulnerabilities
|
|
392
|
-
npm audit
|
|
259
|
+
## TypeScript Support
|
|
393
260
|
|
|
394
|
-
|
|
395
|
-
npm audit fix
|
|
261
|
+
The toolkit is written in TypeScript with full type definitions:
|
|
396
262
|
|
|
397
|
-
|
|
398
|
-
|
|
263
|
+
```typescript
|
|
264
|
+
import { Args } from '@nmakarov/cli-toolkit/args';
|
|
265
|
+
import { Params } from '@nmakarov/cli-toolkit/params';
|
|
266
|
+
import { showListScreen } from '@nmakarov/cli-toolkit/screen';
|
|
267
|
+
import { CliToolkitLogger } from '@nmakarov/cli-toolkit/logger';
|
|
268
|
+
|
|
269
|
+
// Full IntelliSense and type checking
|
|
270
|
+
const args = new Args({ aliases: { v: 'verbose' } });
|
|
271
|
+
const params = new Params({ args });
|
|
272
|
+
const logger = new CliToolkitLogger({ prefix: 'APP' });
|
|
399
273
|
```
|
|
400
274
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
Keep dependencies up to date:
|
|
404
|
-
|
|
405
|
-
```bash
|
|
406
|
-
# Check for outdated packages
|
|
407
|
-
npm outdated
|
|
275
|
+
## CommonJS Support
|
|
408
276
|
|
|
409
|
-
|
|
410
|
-
npm install package-name@latest
|
|
277
|
+
All modules support both ESM and CommonJS:
|
|
411
278
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
279
|
+
```javascript
|
|
280
|
+
// ESM (TypeScript/Modern Node)
|
|
281
|
+
import { Args } from '@nmakarov/cli-toolkit/args';
|
|
415
282
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
When `npm audit` shows vulnerabilities:
|
|
419
|
-
|
|
420
|
-
1. **Check current status:**
|
|
421
|
-
```bash
|
|
422
|
-
npm audit
|
|
423
|
-
npm outdated
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
2. **Update packages individually (recommended):**
|
|
427
|
-
```bash
|
|
428
|
-
# Update TypeScript first (usually safe)
|
|
429
|
-
npm install typescript@latest
|
|
430
|
-
|
|
431
|
-
# Update build tools
|
|
432
|
-
npm install tsup@latest
|
|
433
|
-
npm install vitest@latest
|
|
434
|
-
|
|
435
|
-
# Update other dev dependencies
|
|
436
|
-
npm install typedoc@latest
|
|
437
|
-
npm install @types/node@latest
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
3. **Handle peer dependency conflicts:**
|
|
441
|
-
```bash
|
|
442
|
-
# If conflicts occur, use legacy peer deps
|
|
443
|
-
npm install package-name@latest --legacy-peer-deps
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
4. **Verify everything works:**
|
|
447
|
-
```bash
|
|
448
|
-
npm run build
|
|
449
|
-
npm run type-check
|
|
450
|
-
npm run lint
|
|
451
|
-
npm audit # Should show 0 vulnerabilities
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
### Common Update Issues
|
|
455
|
-
|
|
456
|
-
#### Peer Dependency Conflicts
|
|
457
|
-
```bash
|
|
458
|
-
# Error: ERESOLVE could not resolve
|
|
459
|
-
# Solution: Update conflicting packages first
|
|
460
|
-
npm install typedoc@latest
|
|
461
|
-
npm install tsup@latest
|
|
283
|
+
// CommonJS (Traditional Node.js)
|
|
284
|
+
const { Args } = require('@nmakarov/cli-toolkit/args');
|
|
462
285
|
```
|
|
463
286
|
|
|
464
|
-
|
|
465
|
-
```bash
|
|
466
|
-
# If updates break functionality, rollback
|
|
467
|
-
git checkout -- package.json package-lock.json
|
|
468
|
-
npm install
|
|
469
|
-
```
|
|
287
|
+
## Contributing
|
|
470
288
|
|
|
471
|
-
|
|
472
|
-
```bash
|
|
473
|
-
# Clear npm cache if needed
|
|
474
|
-
npm cache clean --force
|
|
475
|
-
rm -rf node_modules package-lock.json
|
|
476
|
-
npm install
|
|
477
|
-
```
|
|
289
|
+
Contributions are welcome! Please read the [development documentation](docs/README.md) for details.
|
|
478
290
|
|
|
479
|
-
|
|
291
|
+
## License
|
|
480
292
|
|
|
481
|
-
|
|
482
|
-
- [ ] Check `npm outdated` quarterly
|
|
483
|
-
- [ ] Update dependencies when security issues found
|
|
484
|
-
- [ ] Test build after each update
|
|
485
|
-
- [ ] Update documentation if APIs change
|
|
486
|
-
- [ ] Create release notes for significant updates
|
|
293
|
+
MIT © nmakarov
|
|
487
294
|
|
|
488
|
-
##
|
|
295
|
+
## Links
|
|
489
296
|
|
|
490
|
-
|
|
297
|
+
- **GitHub**: https://github.com/nmakarov/cli-toolkit
|
|
298
|
+
- **npm**: https://www.npmjs.com/package/@nmakarov/cli-toolkit
|
|
299
|
+
- **Issues**: https://github.com/nmakarov/cli-toolkit/issues
|
|
300
|
+
- **Changelog**: [CHANGELOG.md](CHANGELOG.md)
|
|
301
|
+
- **Feature Tracker**: [FEATURES.md](FEATURES.md)
|