@nmakarov/cli-toolkit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,490 @@
1
+ # @nmakarov/cli-toolkit
2
+
3
+ A comprehensive TypeScript toolkit for building CLI applications with advanced argument parsing, configuration loading, environment management, and interactive terminal UI components.
4
+
5
+ ## 🚀 Quick Start
6
+
7
+ ```bash
8
+ npm install @nmakarov/cli-toolkit
9
+ ```
10
+
11
+ ```typescript
12
+ // Argument parsing
13
+ import { Args } from '@nmakarov/cli-toolkit';
14
+
15
+ const args = new Args({
16
+ aliases: { 'v': 'verbose', 'd': 'debug' },
17
+ defaults: { timeout: 5000 }
18
+ });
19
+
20
+ console.log(args.get('verbose')); // true if --verbose or -v passed
21
+ console.log(args.hasCommand('build')); // true if 'build' command passed
22
+
23
+ // Interactive terminal UI
24
+ import { showListScreen, buildBreadcrumb } from '@nmakarov/cli-toolkit/screen';
25
+ import React, { createElement as h, Text, Box } from 'react';
26
+
27
+ const choice = await showListScreen({
28
+ title: buildBreadcrumb(["Main Menu"]),
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
+ ```
37
+
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
+ ```bash
86
+ # Basic usage
87
+ npx tsx examples/args/show-args.ts --verbose --debug
88
+
89
+ # Environment-specific
90
+ npx tsx examples/args/show-args.ts --env=production
91
+
92
+ # Config files
93
+ npx tsx examples/args/show-args.ts --config=config.json
94
+
95
+ # Short flags
96
+ npx tsx examples/args/show-args.ts -vsd --output=file.txt
97
+ ```
98
+
99
+ ### Interactive Terminal UI
100
+ ```bash
101
+ # Screen system examples
102
+ npx tsx examples/screen/basic.ts
103
+
104
+ # Interactive argument runner
105
+ npx tsx examples/args/show-args-runner.ts
106
+ ```
107
+
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
+ ```bash
116
+ git clone https://github.com/nmakarov/cli-toolkit.git
117
+ cd cli-toolkit
118
+ npm install
119
+ ```
120
+
121
+ ### Development Workflow
122
+
123
+ #### Build
124
+ ```bash
125
+ npm run build # Build for production
126
+ npm run dev # Build in watch mode
127
+ ```
128
+
129
+ #### Type Checking
130
+ ```bash
131
+ npm run type-check # TypeScript type checking
132
+ ```
133
+
134
+ #### Linting
135
+ ```bash
136
+ npm run lint # ESLint checking
137
+ ```
138
+
139
+ #### Testing
140
+ ```bash
141
+ npm test # Run entire vitest suite
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
150
+ ```
151
+
152
+ ### Project Structure
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
191
+
192
+ 1. Fork the repository
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
201
+
202
+ ### Versioning
203
+
204
+ This project follows [Semantic Versioning](https://semver.org/) (SemVer):
205
+
206
+ - **MAJOR** (1.0.0): Breaking changes
207
+ - **MINOR** (0.1.0): New features (backward compatible)
208
+ - **PATCH** (0.0.1): Bug fixes (backward compatible)
209
+
210
+ #### Version Commands
211
+ ```bash
212
+ # Patch version (0.0.1 → 0.0.2)
213
+ npm version patch
214
+
215
+ # Minor version (0.0.1 → 0.1.0)
216
+ npm version minor
217
+
218
+ # Major version (0.0.1 → 1.0.0)
219
+ npm version major
220
+
221
+ # Pre-release versions
222
+ npm version prerelease --preid=alpha # 0.0.1 → 0.0.2-alpha.0
223
+ npm version prerelease --preid=beta # 0.0.1 → 0.0.2-beta.0
224
+ npm version prerelease --preid=rc # 0.0.1 → 0.0.2-rc.0
225
+ ```
226
+
227
+ ### Publishing
228
+
229
+ #### Prerequisites
230
+ ```bash
231
+ # Login to npm (if not already logged in)
232
+ npm login
233
+
234
+ # Verify you're logged in
235
+ npm whoami
236
+ ```
237
+
238
+ #### Publishing Process
239
+
240
+ 1. **Update version:**
241
+ ```bash
242
+ npm version patch # or minor/major
243
+ ```
244
+
245
+ 2. **Build the project:**
246
+ ```bash
247
+ npm run build
248
+ ```
249
+
250
+ 3. **Run tests (when available):**
251
+ ```bash
252
+ npm test
253
+ ```
254
+
255
+ 4. **Publish to npm:**
256
+ ```bash
257
+ npm publish
258
+ ```
259
+
260
+ 5. **Push changes to git:**
261
+ ```bash
262
+ git push origin main --tags
263
+ ```
264
+
265
+ #### Pre-release Publishing
266
+
267
+ For testing or beta releases:
268
+
269
+ ```bash
270
+ # Create pre-release version
271
+ npm version prerelease --preid=beta
272
+
273
+ # Publish pre-release
274
+ npm publish --tag beta
275
+
276
+ # Install pre-release
277
+ npm install @nmakarov/cli-toolkit@beta
278
+ ```
279
+
280
+ #### Updating Published Package
281
+
282
+ ```bash
283
+ # Update patch version
284
+ npm version patch && npm publish
285
+
286
+ # Update minor version
287
+ npm version minor && npm publish
288
+
289
+ # Update major version
290
+ npm version major && npm publish
291
+ ```
292
+
293
+ #### Package Verification
294
+
295
+ ```bash
296
+ # Check what will be published
297
+ npm pack --dry-run
298
+
299
+ # Verify package contents
300
+ npm pack
301
+ tar -tzf nmakarov-cli-toolkit-*.tgz
302
+
303
+ # Test installation
304
+ npm install ./nmakarov-cli-toolkit-*.tgz
305
+ ```
306
+
307
+ ### Release Process
308
+
309
+ 1. **Update version in `package.json`:**
310
+ ```bash
311
+ npm version patch # or minor/major
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
+ }
352
+ ```
353
+
354
+ ### Troubleshooting
355
+
356
+ #### Common Issues
357
+
358
+ **"Package already exists":**
359
+ ```bash
360
+ # Check current version
361
+ npm view @nmakarov/cli-toolkit version
362
+
363
+ # Update version if needed
364
+ npm version patch
365
+ ```
366
+
367
+ **"Not authorized":**
368
+ ```bash
369
+ # Re-login to npm
370
+ npm logout
371
+ npm login
372
+ ```
373
+
374
+ **"Invalid package name":**
375
+ - Ensure package name matches `@nmakarov/cli-toolkit`
376
+ - Check `package.json` name field
377
+
378
+ **"Missing files":**
379
+ ```bash
380
+ # Check files field in package.json
381
+ npm pack --dry-run
382
+ ```
383
+
384
+ ## 🔧 Maintenance
385
+
386
+ ### Security Audits
387
+
388
+ Regular security audits help keep the project secure:
389
+
390
+ ```bash
391
+ # Check for security vulnerabilities
392
+ npm audit
393
+
394
+ # Fix vulnerabilities automatically (if possible)
395
+ npm audit fix
396
+
397
+ # Force fix with potential breaking changes
398
+ npm audit fix --force
399
+ ```
400
+
401
+ ### Dependency Updates
402
+
403
+ Keep dependencies up to date:
404
+
405
+ ```bash
406
+ # Check for outdated packages
407
+ npm outdated
408
+
409
+ # Update specific packages
410
+ npm install package-name@latest
411
+
412
+ # Update all packages (use with caution)
413
+ npm update
414
+ ```
415
+
416
+ ### Security Update Strategy
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
462
+ ```
463
+
464
+ #### Breaking Changes
465
+ ```bash
466
+ # If updates break functionality, rollback
467
+ git checkout -- package.json package-lock.json
468
+ npm install
469
+ ```
470
+
471
+ #### Package Resolution Issues
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
+ ```
478
+
479
+ ### Maintenance Checklist
480
+
481
+ - [ ] Run `npm audit` monthly
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
487
+
488
+ ## 📄 License
489
+
490
+ MIT