@zokugun/cli-utils 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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2026-present Baptiste Augrain
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ [@zokugun/cli-utils](https://github.com/zokugun/node-cli-utils)
2
+ ==========================================================
3
+
4
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
5
+ [![NPM Version](https://img.shields.io/npm/v/@zokugun/cli-utils.svg?colorB=green)](https://www.npmjs.com/package/@zokugun/cli-utils)
6
+ [![Donation](https://img.shields.io/badge/donate-ko--fi-green)](https://ko-fi.com/daiyam)
7
+ [![Donation](https://img.shields.io/badge/donate-liberapay-green)](https://liberapay.com/daiyam/donate)
8
+ [![Donation](https://img.shields.io/badge/donate-paypal-green)](https://paypal.me/daiyam99)
9
+
10
+ A small collection of focused utilities to build user-friendly Node.js command-line applications.
11
+
12
+ It bundles lightweight helpers so you can compose rich CLI interactions without pulling in many separate packages:
13
+ - colored output (https://github.com/doowb/ansi-colors)
14
+ - spinner frames (https://github.com/sindresorhus/cli-spinners)
15
+ - prompt utilities (https://github.com/enquirer/enquirer)
16
+ - a tiny commander wrapper (https://github.com/tj/commander.js)
17
+ - a simple logger (use https://github.com/zokugun/node-log-update-plus)
18
+
19
+ Compatible with **Node.js 18.x**.
20
+
21
+ Installation
22
+ ------------
23
+
24
+ ```bash
25
+ npm install @zokugun/cli-utils
26
+ ```
27
+
28
+ Quick Start
29
+ -----------
30
+
31
+ ```typescript
32
+ import { logger } from '@zokugun/cli-utils';
33
+
34
+ logger.begin(); // start timer
35
+
36
+ logger.progress('Starting task'); // use spinner to indicate progress
37
+
38
+ logger.success('Task finished');
39
+
40
+ logger.finish(); // print "🏁 Done (in 1s)."
41
+ ```
42
+
43
+ Quick Reference
44
+ ---------------
45
+
46
+ - **ansi-colors**: small helpers for colored and styled terminal output.
47
+ - **cli-spinners**: common spinner frame sets and metadata for progress indicators.
48
+ - **commander**: thin convenience exports for building CLI commands.
49
+ - **enquirer**: prompt helpers for interactive prompts (+ patch and `confirm`, `Invisible`).
50
+ - **logger**: simple logging helpers for consistent CLI output.
51
+
52
+ Module entry points
53
+ -------------------
54
+
55
+ Choose the entry point that matches your environment and naming preferences:
56
+
57
+ | Import path | Description |
58
+ | --------------------------------- | -------------------------------- |
59
+ | `@zokugun/cli-utils` | All utilities |
60
+ | `@zokugun/cli-utils/ansi-colors` | colors from `ansi-colors` |
61
+ | `@zokugun/cli-utils/cli-spinners` | spinners from `cli-spinners` |
62
+ | `@zokugun/cli-utils/commander` | tiny command from `commander` |
63
+ | `@zokugun/cli-utils/enquirer` | prompt utilities from `enquirer` |
64
+ | `@zokugun/cli-utils/logger` | the logger |
65
+
66
+ Donations
67
+ ---------
68
+
69
+ Support this project by becoming a financial contributor.
70
+
71
+ <table>
72
+ <tr>
73
+ <td><img src="https://raw.githubusercontent.com/daiyam/assets/master/icons/256/funding_kofi.png" alt="Ko-fi" width="80px" height="80px"></td>
74
+ <td><a href="https://ko-fi.com/daiyam" target="_blank">ko-fi.com/daiyam</a></td>
75
+ </tr>
76
+ <tr>
77
+ <td><img src="https://raw.githubusercontent.com/daiyam/assets/master/icons/256/funding_liberapay.png" alt="Liberapay" width="80px" height="80px"></td>
78
+ <td><a href="https://liberapay.com/daiyam/donate" target="_blank">liberapay.com/daiyam/donate</a></td>
79
+ </tr>
80
+ <tr>
81
+ <td><img src="https://raw.githubusercontent.com/daiyam/assets/master/icons/256/funding_paypal.png" alt="PayPal" width="80px" height="80px"></td>
82
+ <td><a href="https://paypal.me/daiyam99" target="_blank">paypal.me/daiyam99</a></td>
83
+ </tr>
84
+ </table>
85
+
86
+ License
87
+ -------
88
+
89
+ Copyright &copy; 2026-present Baptiste Augrain
90
+
91
+ Licensed under the [MIT license](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ansi_colors_1 = __importDefault(require("ansi-colors"));
7
+ // eslint-disable-next-line unicorn/prefer-export-from
8
+ exports.default = ansi_colors_1.default;
@@ -0,0 +1,2 @@
1
+ import colors from 'ansi-colors';
2
+ export default colors;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("cli-spinners"), exports);
@@ -0,0 +1 @@
1
+ export * from 'cli-spinners';
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Command = void 0;
37
+ const commander = __importStar(require("commander"));
38
+ const commander_1 = require("commander");
39
+ Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return commander_1.Command; } });
40
+ exports.default = commander;
@@ -0,0 +1,4 @@
1
+ import * as commander from 'commander';
2
+ import { Command } from 'commander';
3
+ export default commander;
4
+ export { Command, };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.confirm = confirm;
7
+ const ansi_colors_1 = __importDefault(require("ansi-colors"));
8
+ function confirm(data) {
9
+ return {
10
+ type: 'confirm',
11
+ format(value) {
12
+ return value ? ansi_colors_1.default.cyan('Yes') : ansi_colors_1.default.cyan('No');
13
+ },
14
+ ...data,
15
+ };
16
+ }
@@ -0,0 +1,5 @@
1
+ import { type BooleanPromptOptions } from 'enquirer';
2
+ export declare function confirm(data: {
3
+ name: string;
4
+ message: string;
5
+ }): BooleanPromptOptions;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Invisible = void 0;
7
+ // eslint-disable-next-line import/extensions
8
+ const string_js_1 = __importDefault(require("enquirer/lib/types/string.js"));
9
+ class Invisible extends string_js_1.default {
10
+ constructor(options = {}) {
11
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
12
+ super(options);
13
+ }
14
+ format() {
15
+ return '';
16
+ }
17
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
18
+ async render() {
19
+ }
20
+ async run() {
21
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
22
+ return super.run();
23
+ }
24
+ }
25
+ exports.Invisible = Invisible;
@@ -0,0 +1,7 @@
1
+ import StringPrompt from 'enquirer/lib/types/string.js';
2
+ export declare class Invisible extends StringPrompt {
3
+ constructor(options?: {});
4
+ format(): string;
5
+ render(): Promise<void>;
6
+ run(): Promise<any>;
7
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Invisible = exports.enquirer = exports.confirm = void 0;
7
+ const enquirer_1 = __importDefault(require("enquirer"));
8
+ exports.enquirer = enquirer_1.default;
9
+ const confirm_js_1 = require("./enquirer/confirm.cjs");
10
+ Object.defineProperty(exports, "confirm", { enumerable: true, get: function () { return confirm_js_1.confirm; } });
11
+ const invisible_js_1 = require("./enquirer/invisible.cjs");
12
+ Object.defineProperty(exports, "Invisible", { enumerable: true, get: function () { return invisible_js_1.Invisible; } });
13
+ /* eslint-enable unicorn/prefer-export-from */
@@ -0,0 +1,4 @@
1
+ import enquirer, { type PromptOptions } from 'enquirer';
2
+ import { confirm } from './enquirer/confirm.cjs';
3
+ import { Invisible } from './enquirer/invisible.cjs';
4
+ export { type PromptOptions, confirm, enquirer, Invisible, };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.logger = exports.Invisible = exports.enquirer = exports.cliSpinners = exports.confirm = exports.commander = exports.colors = exports.c = void 0;
40
+ const ansi_colors_1 = __importDefault(require("ansi-colors"));
41
+ exports.c = ansi_colors_1.default;
42
+ exports.colors = ansi_colors_1.default;
43
+ const cli_spinners_1 = __importDefault(require("cli-spinners"));
44
+ exports.cliSpinners = cli_spinners_1.default;
45
+ const commander = __importStar(require("commander"));
46
+ exports.commander = commander;
47
+ const enquirer_1 = __importDefault(require("enquirer"));
48
+ exports.enquirer = enquirer_1.default;
49
+ const confirm_js_1 = require("./enquirer/confirm.cjs");
50
+ Object.defineProperty(exports, "confirm", { enumerable: true, get: function () { return confirm_js_1.confirm; } });
51
+ const invisible_js_1 = require("./enquirer/invisible.cjs");
52
+ Object.defineProperty(exports, "Invisible", { enumerable: true, get: function () { return invisible_js_1.Invisible; } });
53
+ const logger_js_1 = __importDefault(require("./logger.cjs"));
54
+ exports.logger = logger_js_1.default;
55
+ /* eslint-enable unicorn/prefer-export-from */
@@ -0,0 +1,8 @@
1
+ import colors from 'ansi-colors';
2
+ import cliSpinners from 'cli-spinners';
3
+ import * as commander from 'commander';
4
+ import enquirer, { type PromptOptions } from 'enquirer';
5
+ import { confirm } from './enquirer/confirm.cjs';
6
+ import { Invisible } from './enquirer/invisible.cjs';
7
+ import logger from './logger.cjs';
8
+ export { type PromptOptions, colors as c, colors, commander, confirm, cliSpinners, enquirer, Invisible, logger, };
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.begin = begin;
7
+ exports.check = check;
8
+ exports.error = error;
9
+ exports.finish = finish;
10
+ exports.info = info;
11
+ exports.newLine = newLine;
12
+ exports.pause = pause;
13
+ exports.progress = progress;
14
+ exports.resume = resume;
15
+ exports.step = step;
16
+ exports.stop = stop;
17
+ exports.success = success;
18
+ exports.warn = warn;
19
+ const log_update_plus_1 = require("@zokugun/log-update-plus");
20
+ const ansi_colors_1 = __importDefault(require("ansi-colors"));
21
+ const cli_spinners_1 = __importDefault(require("cli-spinners"));
22
+ const { dots } = cli_spinners_1.default;
23
+ let $loading;
24
+ let $progessFn;
25
+ let $start = 0;
26
+ function begin() {
27
+ $start = Date.now();
28
+ } // }}}
29
+ function check(message) {
30
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.green(ansi_colors_1.default.symbols.check)} ${message}`);
31
+ } // }}}
32
+ function error(message) {
33
+ stop(`${ansi_colors_1.default.red(ansi_colors_1.default.symbols.cross)} ${ansi_colors_1.default.bold('Error!')}`);
34
+ log_update_plus_1.stdout.persist(message);
35
+ } // }}}
36
+ function finish(duration) {
37
+ if (typeof duration !== 'number') {
38
+ if ($start === 0) {
39
+ stop(`🏁 ${ansi_colors_1.default.bold('Done')}`);
40
+ return;
41
+ }
42
+ duration = Math.ceil((Date.now() - $start) / 1000);
43
+ }
44
+ stop(`🏁 ${ansi_colors_1.default.bold('Done')} (in ${duration}s).`);
45
+ } // }}}
46
+ function info(message) {
47
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.cyan(ansi_colors_1.default.symbols.bullet)} ${message}`);
48
+ } // }}}
49
+ function newLine() {
50
+ log_update_plus_1.stdout.persist('');
51
+ } // }}}
52
+ function pause() {
53
+ clearInterval($loading);
54
+ log_update_plus_1.stdout.render('');
55
+ } // }}}
56
+ function progress(label) {
57
+ clearInterval($loading);
58
+ let index = 0;
59
+ $progessFn = () => {
60
+ if (!$loading) {
61
+ return;
62
+ }
63
+ log_update_plus_1.stdout.render(`${ansi_colors_1.default.cyan(dots.frames[index = ++index % dots.frames.length])} ${label}`);
64
+ };
65
+ $loading = setInterval($progessFn, cli_spinners_1.default.dots.interval);
66
+ } // }}}
67
+ function resume() {
68
+ if ($progessFn) {
69
+ $loading = setInterval($progessFn, cli_spinners_1.default.dots.interval);
70
+ }
71
+ } // }}}
72
+ function step(label) {
73
+ progress(ansi_colors_1.default.bold(label) + ansi_colors_1.default.dim('...'));
74
+ return () => {
75
+ check(ansi_colors_1.default.bold(`${label}:`) + ansi_colors_1.default.dim(' done'));
76
+ };
77
+ } // }}}
78
+ function stop(message = '') {
79
+ clearInterval($loading);
80
+ $loading = undefined;
81
+ $progessFn = undefined;
82
+ log_update_plus_1.stdout.render(message);
83
+ } // }}}
84
+ function success(message) {
85
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.green(ansi_colors_1.default.symbols.check)} ${message}`);
86
+ } // }}}
87
+ function warn(message) {
88
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.magenta(ansi_colors_1.default.symbols.warning)} ${message}`);
89
+ } // }}}
90
+ // eslint-disable-next-line import/no-anonymous-default-export
91
+ exports.default = {
92
+ begin,
93
+ check,
94
+ error,
95
+ finish,
96
+ info,
97
+ newLine,
98
+ pause,
99
+ progress,
100
+ resume,
101
+ step,
102
+ stop,
103
+ success,
104
+ warn,
105
+ };
@@ -0,0 +1,30 @@
1
+ export type IndicatorLoading = ReturnType<typeof setInterval>;
2
+ export declare function begin(): void;
3
+ export declare function check(message: string): void;
4
+ export declare function error(message: string): void;
5
+ export declare function finish(duration?: number): void;
6
+ export declare function info(message: string): void;
7
+ export declare function newLine(): void;
8
+ export declare function pause(): void;
9
+ export declare function progress(label: string): void;
10
+ export declare function resume(): void;
11
+ export declare function step(label: string): () => void;
12
+ export declare function stop(message?: string): void;
13
+ export declare function success(message: string): void;
14
+ export declare function warn(message: string): void;
15
+ declare const _default: {
16
+ begin: typeof begin;
17
+ check: typeof check;
18
+ error: typeof error;
19
+ finish: typeof finish;
20
+ info: typeof info;
21
+ newLine: typeof newLine;
22
+ pause: typeof pause;
23
+ progress: typeof progress;
24
+ resume: typeof resume;
25
+ step: typeof step;
26
+ stop: typeof stop;
27
+ success: typeof success;
28
+ warn: typeof warn;
29
+ };
30
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import colors from 'ansi-colors';
2
+ export default colors;
@@ -0,0 +1,3 @@
1
+ import colors from 'ansi-colors';
2
+ // eslint-disable-next-line unicorn/prefer-export-from
3
+ export default colors;
@@ -0,0 +1 @@
1
+ export * from 'cli-spinners';
@@ -0,0 +1 @@
1
+ export * from 'cli-spinners';
@@ -0,0 +1,4 @@
1
+ import * as commander from 'commander';
2
+ import { Command } from 'commander';
3
+ export default commander;
4
+ export { Command, };
@@ -0,0 +1,6 @@
1
+ import * as commander from 'commander';
2
+ import { Command } from 'commander';
3
+ export default commander;
4
+ export {
5
+ // eslint-disable-next-line unicorn/prefer-export-from
6
+ Command, };
@@ -0,0 +1,5 @@
1
+ import { type BooleanPromptOptions } from 'enquirer';
2
+ export declare function confirm(data: {
3
+ name: string;
4
+ message: string;
5
+ }): BooleanPromptOptions;
@@ -0,0 +1,10 @@
1
+ import c from 'ansi-colors';
2
+ export function confirm(data) {
3
+ return {
4
+ type: 'confirm',
5
+ format(value) {
6
+ return value ? c.cyan('Yes') : c.cyan('No');
7
+ },
8
+ ...data,
9
+ };
10
+ }
@@ -0,0 +1,7 @@
1
+ import StringPrompt from 'enquirer/lib/types/string.js';
2
+ export declare class Invisible extends StringPrompt {
3
+ constructor(options?: {});
4
+ format(): string;
5
+ render(): Promise<void>;
6
+ run(): Promise<any>;
7
+ }
@@ -0,0 +1,18 @@
1
+ // eslint-disable-next-line import/extensions
2
+ import StringPrompt from 'enquirer/lib/types/string.js';
3
+ export class Invisible extends StringPrompt {
4
+ constructor(options = {}) {
5
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
6
+ super(options);
7
+ }
8
+ format() {
9
+ return '';
10
+ }
11
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
12
+ async render() {
13
+ }
14
+ async run() {
15
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
16
+ return super.run();
17
+ }
18
+ }
@@ -0,0 +1,4 @@
1
+ import enquirer, { type PromptOptions } from 'enquirer';
2
+ import { confirm } from './enquirer/confirm.mjs';
3
+ import { Invisible } from './enquirer/invisible.mjs';
4
+ export { type PromptOptions, confirm, enquirer, Invisible, };
@@ -0,0 +1,6 @@
1
+ import enquirer from 'enquirer';
2
+ import { confirm } from './enquirer/confirm.mjs';
3
+ import { Invisible } from './enquirer/invisible.mjs';
4
+ /* eslint-disable unicorn/prefer-export-from */
5
+ export { confirm, enquirer, Invisible, };
6
+ /* eslint-enable unicorn/prefer-export-from */
@@ -0,0 +1,8 @@
1
+ import colors from 'ansi-colors';
2
+ import cliSpinners from 'cli-spinners';
3
+ import * as commander from 'commander';
4
+ import enquirer, { type PromptOptions } from 'enquirer';
5
+ import { confirm } from './enquirer/confirm.mjs';
6
+ import { Invisible } from './enquirer/invisible.mjs';
7
+ import logger from './logger.mjs';
8
+ export { type PromptOptions, colors as c, colors, commander, confirm, cliSpinners, enquirer, Invisible, logger, };
@@ -0,0 +1,10 @@
1
+ import colors from 'ansi-colors';
2
+ import cliSpinners from 'cli-spinners';
3
+ import * as commander from 'commander';
4
+ import enquirer from 'enquirer';
5
+ import { confirm } from './enquirer/confirm.mjs';
6
+ import { Invisible } from './enquirer/invisible.mjs';
7
+ import logger from './logger.mjs';
8
+ /* eslint-disable unicorn/prefer-export-from */
9
+ export { colors as c, colors, commander, confirm, cliSpinners, enquirer, Invisible, logger, };
10
+ /* eslint-enable unicorn/prefer-export-from */
@@ -0,0 +1,30 @@
1
+ export type IndicatorLoading = ReturnType<typeof setInterval>;
2
+ export declare function begin(): void;
3
+ export declare function check(message: string): void;
4
+ export declare function error(message: string): void;
5
+ export declare function finish(duration?: number): void;
6
+ export declare function info(message: string): void;
7
+ export declare function newLine(): void;
8
+ export declare function pause(): void;
9
+ export declare function progress(label: string): void;
10
+ export declare function resume(): void;
11
+ export declare function step(label: string): () => void;
12
+ export declare function stop(message?: string): void;
13
+ export declare function success(message: string): void;
14
+ export declare function warn(message: string): void;
15
+ declare const _default: {
16
+ begin: typeof begin;
17
+ check: typeof check;
18
+ error: typeof error;
19
+ finish: typeof finish;
20
+ info: typeof info;
21
+ newLine: typeof newLine;
22
+ pause: typeof pause;
23
+ progress: typeof progress;
24
+ resume: typeof resume;
25
+ step: typeof step;
26
+ stop: typeof stop;
27
+ success: typeof success;
28
+ warn: typeof warn;
29
+ };
30
+ export default _default;
@@ -0,0 +1,87 @@
1
+ import { stdout } from '@zokugun/log-update-plus';
2
+ import c from 'ansi-colors';
3
+ import cliSpinners from 'cli-spinners';
4
+ const { dots } = cliSpinners;
5
+ let $loading;
6
+ let $progessFn;
7
+ let $start = 0;
8
+ export function begin() {
9
+ $start = Date.now();
10
+ } // }}}
11
+ export function check(message) {
12
+ stdout.persist(`${c.green(c.symbols.check)} ${message}`);
13
+ } // }}}
14
+ export function error(message) {
15
+ stop(`${c.red(c.symbols.cross)} ${c.bold('Error!')}`);
16
+ stdout.persist(message);
17
+ } // }}}
18
+ export function finish(duration) {
19
+ if (typeof duration !== 'number') {
20
+ if ($start === 0) {
21
+ stop(`🏁 ${c.bold('Done')}`);
22
+ return;
23
+ }
24
+ duration = Math.ceil((Date.now() - $start) / 1000);
25
+ }
26
+ stop(`🏁 ${c.bold('Done')} (in ${duration}s).`);
27
+ } // }}}
28
+ export function info(message) {
29
+ stdout.persist(`${c.cyan(c.symbols.bullet)} ${message}`);
30
+ } // }}}
31
+ export function newLine() {
32
+ stdout.persist('');
33
+ } // }}}
34
+ export function pause() {
35
+ clearInterval($loading);
36
+ stdout.render('');
37
+ } // }}}
38
+ export function progress(label) {
39
+ clearInterval($loading);
40
+ let index = 0;
41
+ $progessFn = () => {
42
+ if (!$loading) {
43
+ return;
44
+ }
45
+ stdout.render(`${c.cyan(dots.frames[index = ++index % dots.frames.length])} ${label}`);
46
+ };
47
+ $loading = setInterval($progessFn, cliSpinners.dots.interval);
48
+ } // }}}
49
+ export function resume() {
50
+ if ($progessFn) {
51
+ $loading = setInterval($progessFn, cliSpinners.dots.interval);
52
+ }
53
+ } // }}}
54
+ export function step(label) {
55
+ progress(c.bold(label) + c.dim('...'));
56
+ return () => {
57
+ check(c.bold(`${label}:`) + c.dim(' done'));
58
+ };
59
+ } // }}}
60
+ export function stop(message = '') {
61
+ clearInterval($loading);
62
+ $loading = undefined;
63
+ $progessFn = undefined;
64
+ stdout.render(message);
65
+ } // }}}
66
+ export function success(message) {
67
+ stdout.persist(`${c.green(c.symbols.check)} ${message}`);
68
+ } // }}}
69
+ export function warn(message) {
70
+ stdout.persist(`${c.magenta(c.symbols.warning)} ${message}`);
71
+ } // }}}
72
+ // eslint-disable-next-line import/no-anonymous-default-export
73
+ export default {
74
+ begin,
75
+ check,
76
+ error,
77
+ finish,
78
+ info,
79
+ newLine,
80
+ pause,
81
+ progress,
82
+ resume,
83
+ step,
84
+ stop,
85
+ success,
86
+ warn,
87
+ };
package/package.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "@zokugun/cli-utils",
3
+ "description": "Utils for CLI app",
4
+ "version": "0.1.0",
5
+ "author": {
6
+ "name": "Baptiste Augrain",
7
+ "email": "daiyam@zokugun.org"
8
+ },
9
+ "license": "MIT",
10
+ "homepage": "https://github.com/zokugun/node-cli-utils",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/zokugun/node-cli-utils.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/zokugun/node-cli-utils/issues"
17
+ },
18
+ "type": "module",
19
+ "exports": {
20
+ ".": {
21
+ "import": "./lib/esm/index.mjs",
22
+ "require": "./lib/cjs/index.cjs"
23
+ },
24
+ "./ansi-colors": {
25
+ "import": "./lib/esm/ansi-colors.mjs",
26
+ "require": "./lib/cjs/ansi-colors.cjs"
27
+ },
28
+ "./cli-spinners": {
29
+ "import": "./lib/esm/cli-spinners.mjs",
30
+ "require": "./lib/cjs/cli-spinners.cjs"
31
+ },
32
+ "./commander": {
33
+ "import": "./lib/esm/commander.mjs",
34
+ "require": "./lib/cjs/commander.cjs"
35
+ },
36
+ "./enquirer": {
37
+ "import": "./lib/esm/enquirer.mjs",
38
+ "require": "./lib/cjs/enquirer.cjs"
39
+ },
40
+ "./logger": {
41
+ "import": "./lib/esm/logger.mjs",
42
+ "require": "./lib/cjs/logger.cjs"
43
+ }
44
+ },
45
+ "main": "lib/cjs/index.cjs",
46
+ "module": "lib/esm/index.mjs",
47
+ "typesVersions": {
48
+ "*": {
49
+ ".": [
50
+ "./lib/cjs/index.d.cts"
51
+ ],
52
+ "ansi-colors": [
53
+ "./lib/cjs/ansi-colors.d.cts"
54
+ ],
55
+ "cli-spinners": [
56
+ "./lib/cjs/cli-spinners.d.cts"
57
+ ],
58
+ "commander": [
59
+ "./lib/cjs/commander.d.cts"
60
+ ],
61
+ "enquirer": [
62
+ "./lib/cjs/enquirer.d.cts"
63
+ ],
64
+ "logger": [
65
+ "./lib/cjs/logger.d.cts"
66
+ ]
67
+ }
68
+ },
69
+ "scripts": {
70
+ "build": "npm run clean && npm run build:lib",
71
+ "build:lib": "tsc-leda generate",
72
+ "build:package": "tsc-leda update-package",
73
+ "clean": "rimraf lib .src",
74
+ "compile:src": "tsc -p src",
75
+ "lint": "xo",
76
+ "lint:fix": "xo --fix",
77
+ "postinstall": "patch-package",
78
+ "prepack": "npm run build",
79
+ "prepare": "husky; fixpack || true",
80
+ "release": "release-it",
81
+ "watch:src": "tsc-watch -p src"
82
+ },
83
+ "dependencies": {
84
+ "@zokugun/log-update-plus": "^0.1.0",
85
+ "ansi-colors": "^4.1.3",
86
+ "cli-spinners": "^3.4.0",
87
+ "commander": "^14.0.3",
88
+ "enquirer": "^2.4.1",
89
+ "patch-package": "^8.0.1"
90
+ },
91
+ "devDependencies": {
92
+ "@commitlint/cli": "^19.7.1",
93
+ "@commitlint/config-conventional": "^19.7.1",
94
+ "@types/node": "^20.14.8",
95
+ "@zokugun/tsc-leda": "^0.3.1",
96
+ "fixpack": "^4.0.0",
97
+ "husky": "^9.1.7",
98
+ "lint-staged": "^16.1.4",
99
+ "release-it": "^19.2.4",
100
+ "tsc-watch": "^7.2.0",
101
+ "typescript": "^5.7.3",
102
+ "xo": "0.60.0"
103
+ },
104
+ "overrides": {
105
+ "terser-webpack-plugin": {
106
+ "serialize-javascript": "^7.0.3"
107
+ }
108
+ },
109
+ "keywords": []
110
+ }