@nmakarov/cli-toolkit 0.6.0 → 0.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/README.md +41 -4
- package/dist/index.cjs +18 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -1
- package/dist/screen.cjs +47 -11
- package/dist/screen.cjs.map +1 -1
- package/dist/screen.js +17 -0
- package/dist/screen.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,13 +33,15 @@ npm install @nmakarov/cli-toolkit
|
|
|
33
33
|
## Requirements
|
|
34
34
|
|
|
35
35
|
- **Node.js**: v20.0.0 or higher (recommended: v24+)
|
|
36
|
-
- **For Screen module**: `ink` and `react` as peer dependencies
|
|
36
|
+
- **For Screen module**: `ink` and `react` as peer dependencies (ESM-only packages)
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
# Install peer dependencies for interactive UIs
|
|
40
40
|
npm install ink react
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
**Note**: The Screen module has special requirements for CommonJS usage. See [CommonJS Support](#screen-module---esm-only-dependencies) for details.
|
|
44
|
+
|
|
43
45
|
## Quick Start
|
|
44
46
|
|
|
45
47
|
### Args - Parse Command Line Arguments
|
|
@@ -194,9 +196,8 @@ const client = new HttpClient({ useTestServer: 'http://localhost:5030' });
|
|
|
194
196
|
### Screen - Interactive Terminal UIs
|
|
195
197
|
|
|
196
198
|
```typescript
|
|
199
|
+
// ESM (recommended)
|
|
197
200
|
import { showListScreen } from '@nmakarov/cli-toolkit/screen';
|
|
198
|
-
import { createElement as h } from 'react';
|
|
199
|
-
import { Text } from 'ink';
|
|
200
201
|
|
|
201
202
|
const choice = await showListScreen({
|
|
202
203
|
title: "Main Menu",
|
|
@@ -212,6 +213,8 @@ const choice = await showListScreen({
|
|
|
212
213
|
console.log(`Selected: ${choice}`);
|
|
213
214
|
```
|
|
214
215
|
|
|
216
|
+
**Note**: The Screen module requires ESM dependencies (`ink` and `react`). For CommonJS usage, see [CommonJS Support](#screen-module---esm-only-dependencies) section.
|
|
217
|
+
|
|
215
218
|
[📖 Full Screen Documentation](docs/SCREEN.md)
|
|
216
219
|
|
|
217
220
|
### Logger - Structured Logging
|
|
@@ -385,16 +388,50 @@ const logger = new CliToolkitLogger({ prefix: 'APP' });
|
|
|
385
388
|
|
|
386
389
|
## CommonJS Support
|
|
387
390
|
|
|
388
|
-
|
|
391
|
+
Most modules support both ESM and CommonJS:
|
|
389
392
|
|
|
390
393
|
```javascript
|
|
391
394
|
// ESM (TypeScript/Modern Node)
|
|
392
395
|
import { Args } from '@nmakarov/cli-toolkit/args';
|
|
396
|
+
import { Params } from '@nmakarov/cli-toolkit/params';
|
|
397
|
+
import { CliToolkitLogger } from '@nmakarov/cli-toolkit/logger';
|
|
393
398
|
|
|
394
399
|
// CommonJS (Traditional Node.js)
|
|
395
400
|
const { Args } = require('@nmakarov/cli-toolkit/args');
|
|
401
|
+
const { Params } = require('@nmakarov/cli-toolkit/params');
|
|
402
|
+
const { CliToolkitLogger } = require('@nmakarov/cli-toolkit/logger');
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Screen Module - ESM-Only Dependencies
|
|
406
|
+
|
|
407
|
+
⚠️ **Important**: The `screen` module depends on `ink` and `react`, which are ESM-only packages. Due to Node.js limitations, synchronous `require()` cannot load ESM modules.
|
|
408
|
+
|
|
409
|
+
**Recommended (ESM):**
|
|
410
|
+
```javascript
|
|
411
|
+
// Use ESM import (recommended)
|
|
412
|
+
import { showScreen, showListScreen } from '@nmakarov/cli-toolkit/screen';
|
|
396
413
|
```
|
|
397
414
|
|
|
415
|
+
**CommonJS Workaround:**
|
|
416
|
+
If you must use CommonJS, you need to pre-load the ESM dependencies:
|
|
417
|
+
|
|
418
|
+
```javascript
|
|
419
|
+
// CommonJS with async pre-loading
|
|
420
|
+
const screen = require('@nmakarov/cli-toolkit/screen');
|
|
421
|
+
|
|
422
|
+
(async () => {
|
|
423
|
+
// Pre-load ESM dependencies before using the module
|
|
424
|
+
await screen.load();
|
|
425
|
+
|
|
426
|
+
// Now you can use screen functions
|
|
427
|
+
const { showScreen, showListScreen } = screen;
|
|
428
|
+
|
|
429
|
+
await showScreen({ /* ... */ });
|
|
430
|
+
})();
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
See the [Screen Module Documentation](docs/SCREEN.md#commonjs-usage) for more details.
|
|
434
|
+
|
|
398
435
|
## Contributing
|
|
399
436
|
|
|
400
437
|
Contributions are welcome! Please read the [development documentation](docs/README.md) for details.
|
package/dist/index.cjs
CHANGED
|
@@ -63,6 +63,7 @@ __export(src_exports, {
|
|
|
63
63
|
h: () => import_react5.createElement,
|
|
64
64
|
joiEdateType: () => joiEdateType,
|
|
65
65
|
joiStringArrayType: () => joiStringArrayType,
|
|
66
|
+
load: () => load,
|
|
66
67
|
organizeFooterMessages: () => organizeFooterMessages,
|
|
67
68
|
setupContext: () => setupContext,
|
|
68
69
|
showListScreen: () => showListScreen,
|
|
@@ -1793,6 +1794,22 @@ function organizeFooterMessages(messages) {
|
|
|
1793
1794
|
return lines;
|
|
1794
1795
|
}
|
|
1795
1796
|
|
|
1797
|
+
// src/screen/index.ts
|
|
1798
|
+
var loadPromise = null;
|
|
1799
|
+
async function load() {
|
|
1800
|
+
if (loadPromise) return loadPromise;
|
|
1801
|
+
loadPromise = Promise.all([
|
|
1802
|
+
import("react"),
|
|
1803
|
+
import("ink")
|
|
1804
|
+
]).then(() => {
|
|
1805
|
+
});
|
|
1806
|
+
return loadPromise;
|
|
1807
|
+
}
|
|
1808
|
+
if (typeof window === "undefined") {
|
|
1809
|
+
load().catch(() => {
|
|
1810
|
+
});
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1796
1813
|
// src/filedatabase/index.ts
|
|
1797
1814
|
var import_fs4 = __toESM(require("fs"), 1);
|
|
1798
1815
|
var import_path4 = __toESM(require("path"), 1);
|
|
@@ -3292,6 +3309,7 @@ function setupContext(opts = {}) {
|
|
|
3292
3309
|
h,
|
|
3293
3310
|
joiEdateType,
|
|
3294
3311
|
joiStringArrayType,
|
|
3312
|
+
load,
|
|
3295
3313
|
organizeFooterMessages,
|
|
3296
3314
|
setupContext,
|
|
3297
3315
|
showListScreen,
|