@nmakarov/cli-toolkit 0.5.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 +44 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +32 -1
- package/dist/index.js.map +1 -1
- package/dist/screen.cjs +69 -11
- package/dist/screen.cjs.map +1 -1
- package/dist/screen.js +32 -1
- 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
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
Args: () => Args,
|
|
34
|
+
Box: () => import_ink5.Box,
|
|
34
35
|
Db: () => Db,
|
|
35
36
|
Divider: () => Divider,
|
|
36
37
|
FileDatabase: () => FileDatabase,
|
|
@@ -43,12 +44,14 @@ __export(src_exports, {
|
|
|
43
44
|
MultiColumnListComponent: () => MultiColumnListComponent,
|
|
44
45
|
MultiColumnListWithPreviewComponent: () => MultiColumnListWithPreviewComponent,
|
|
45
46
|
Params: () => Params,
|
|
47
|
+
React: () => import_react5.default,
|
|
46
48
|
ScreenBody: () => ScreenBody,
|
|
47
49
|
ScreenContainer: () => ScreenContainer,
|
|
48
50
|
ScreenDivider: () => ScreenDivider,
|
|
49
51
|
ScreenFooter: () => ScreenFooter,
|
|
50
52
|
ScreenRow: () => ScreenRow,
|
|
51
53
|
ScreenTitle: () => ScreenTitle,
|
|
54
|
+
Text: () => import_ink5.Text,
|
|
52
55
|
TextBlock: () => TextBlock,
|
|
53
56
|
buildBreadcrumb: () => buildBreadcrumb,
|
|
54
57
|
buildDetailBreadcrumb: () => buildDetailBreadcrumb,
|
|
@@ -57,8 +60,10 @@ __export(src_exports, {
|
|
|
57
60
|
defaultVersionSynopsisFunction: () => defaultVersionSynopsisFunction,
|
|
58
61
|
getArgsInstance: () => getArgsInstance,
|
|
59
62
|
getParamsInstance: () => getParamsInstance,
|
|
63
|
+
h: () => import_react5.createElement,
|
|
60
64
|
joiEdateType: () => joiEdateType,
|
|
61
65
|
joiStringArrayType: () => joiStringArrayType,
|
|
66
|
+
load: () => load,
|
|
62
67
|
organizeFooterMessages: () => organizeFooterMessages,
|
|
63
68
|
setupContext: () => setupContext,
|
|
64
69
|
showListScreen: () => showListScreen,
|
|
@@ -66,7 +71,13 @@ __export(src_exports, {
|
|
|
66
71
|
showMultiColumnListScreen: () => showMultiColumnListScreen,
|
|
67
72
|
showMultiColumnListWithPreviewScreen: () => showMultiColumnListWithPreviewScreen,
|
|
68
73
|
showScreen: () => showScreen,
|
|
69
|
-
showWordGridScreen: () => showWordGridScreen
|
|
74
|
+
showWordGridScreen: () => showWordGridScreen,
|
|
75
|
+
useCallback: () => import_react5.useCallback,
|
|
76
|
+
useEffect: () => import_react5.useEffect,
|
|
77
|
+
useInput: () => import_ink5.useInput,
|
|
78
|
+
useMemo: () => import_react5.useMemo,
|
|
79
|
+
useRef: () => import_react5.useRef,
|
|
80
|
+
useState: () => import_react5.useState
|
|
70
81
|
});
|
|
71
82
|
module.exports = __toCommonJS(src_exports);
|
|
72
83
|
|
|
@@ -799,6 +810,10 @@ var Params = class {
|
|
|
799
810
|
var paramsInstance = null;
|
|
800
811
|
var getParamsInstance = () => paramsInstance;
|
|
801
812
|
|
|
813
|
+
// src/screen/index.ts
|
|
814
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
815
|
+
var import_ink5 = require("ink");
|
|
816
|
+
|
|
802
817
|
// src/screen/screens.ts
|
|
803
818
|
var import_react3 = require("react");
|
|
804
819
|
var import_ink3 = require("ink");
|
|
@@ -1779,6 +1794,22 @@ function organizeFooterMessages(messages) {
|
|
|
1779
1794
|
return lines;
|
|
1780
1795
|
}
|
|
1781
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
|
+
|
|
1782
1813
|
// src/filedatabase/index.ts
|
|
1783
1814
|
var import_fs4 = __toESM(require("fs"), 1);
|
|
1784
1815
|
var import_path4 = __toESM(require("path"), 1);
|
|
@@ -3246,6 +3277,7 @@ function setupContext(opts = {}) {
|
|
|
3246
3277
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3247
3278
|
0 && (module.exports = {
|
|
3248
3279
|
Args,
|
|
3280
|
+
Box,
|
|
3249
3281
|
Db,
|
|
3250
3282
|
Divider,
|
|
3251
3283
|
FileDatabase,
|
|
@@ -3258,12 +3290,14 @@ function setupContext(opts = {}) {
|
|
|
3258
3290
|
MultiColumnListComponent,
|
|
3259
3291
|
MultiColumnListWithPreviewComponent,
|
|
3260
3292
|
Params,
|
|
3293
|
+
React,
|
|
3261
3294
|
ScreenBody,
|
|
3262
3295
|
ScreenContainer,
|
|
3263
3296
|
ScreenDivider,
|
|
3264
3297
|
ScreenFooter,
|
|
3265
3298
|
ScreenRow,
|
|
3266
3299
|
ScreenTitle,
|
|
3300
|
+
Text,
|
|
3267
3301
|
TextBlock,
|
|
3268
3302
|
buildBreadcrumb,
|
|
3269
3303
|
buildDetailBreadcrumb,
|
|
@@ -3272,8 +3306,10 @@ function setupContext(opts = {}) {
|
|
|
3272
3306
|
defaultVersionSynopsisFunction,
|
|
3273
3307
|
getArgsInstance,
|
|
3274
3308
|
getParamsInstance,
|
|
3309
|
+
h,
|
|
3275
3310
|
joiEdateType,
|
|
3276
3311
|
joiStringArrayType,
|
|
3312
|
+
load,
|
|
3277
3313
|
organizeFooterMessages,
|
|
3278
3314
|
setupContext,
|
|
3279
3315
|
showListScreen,
|
|
@@ -3281,6 +3317,12 @@ function setupContext(opts = {}) {
|
|
|
3281
3317
|
showMultiColumnListScreen,
|
|
3282
3318
|
showMultiColumnListWithPreviewScreen,
|
|
3283
3319
|
showScreen,
|
|
3284
|
-
showWordGridScreen
|
|
3320
|
+
showWordGridScreen,
|
|
3321
|
+
useCallback,
|
|
3322
|
+
useEffect,
|
|
3323
|
+
useInput,
|
|
3324
|
+
useMemo,
|
|
3325
|
+
useRef,
|
|
3326
|
+
useState
|
|
3285
3327
|
});
|
|
3286
3328
|
//# sourceMappingURL=index.cjs.map
|