@zokugun/cli-utils 0.2.1 → 0.3.1

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.
@@ -3,18 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.begin = begin;
6
+ exports.beginTimer = beginTimer;
7
7
  exports.check = check;
8
+ exports.createSpinner = createSpinner;
9
+ exports.createStep = createStep;
10
+ exports.debug = debug;
8
11
  exports.error = error;
9
12
  exports.fatal = fatal;
10
- exports.finish = finish;
13
+ exports.finishTimer = finishTimer;
11
14
  exports.info = info;
12
15
  exports.newLine = newLine;
13
- exports.pause = pause;
14
- exports.progress = progress;
15
- exports.resume = resume;
16
- exports.step = step;
17
- exports.stop = stop;
16
+ exports.pauseProgress = pauseProgress;
17
+ exports.print = print;
18
+ exports.resumeProgress = resumeProgress;
19
+ exports.showProgress = showProgress;
20
+ exports.stopProgress = stopProgress;
18
21
  exports.success = success;
19
22
  exports.warn = warn;
20
23
  const node_process_1 = __importDefault(require("node:process"));
@@ -25,32 +28,52 @@ const { dots } = cli_spinners_1.default;
25
28
  let $loading;
26
29
  let $progessFn;
27
30
  let $start = 0;
28
- function begin() {
31
+ function beginTimer() {
29
32
  $start = Date.now();
30
33
  } // }}}
31
34
  function check(message) {
32
35
  log_update_plus_1.stdout.persist(`${ansi_colors_1.default.green(ansi_colors_1.default.symbols.check)} ${message}`);
33
36
  } // }}}
37
+ function createSpinner(label) {
38
+ showProgress(label);
39
+ return {
40
+ fail: () => {
41
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.red(ansi_colors_1.default.symbols.cross)} ${label}`);
42
+ },
43
+ succeed: () => {
44
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.green(ansi_colors_1.default.symbols.check)} ${label}`);
45
+ },
46
+ };
47
+ } // }}}
48
+ function createStep(label) {
49
+ showProgress(ansi_colors_1.default.bold(label) + ansi_colors_1.default.dim('...'));
50
+ return () => {
51
+ check(ansi_colors_1.default.bold(`${label}:`) + ansi_colors_1.default.dim(' done'));
52
+ };
53
+ } // }}}
54
+ function debug(message) {
55
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.gray(ansi_colors_1.default.symbols.pointerSmall)} ${message}`);
56
+ } // }}}
34
57
  function error(message) {
35
58
  log_update_plus_1.stdout.persist(`${ansi_colors_1.default.red(ansi_colors_1.default.symbols.cross)} ${ansi_colors_1.default.bold('Error!')}`);
36
59
  log_update_plus_1.stdout.persist(message);
37
60
  } // }}}
38
61
  function fatal(message, code = 1) {
39
- stop();
62
+ stopProgress();
40
63
  log_update_plus_1.stdout.persist(`${ansi_colors_1.default.red(ansi_colors_1.default.symbols.cross)} ${ansi_colors_1.default.bold('Fatal!')}`);
41
64
  log_update_plus_1.stdout.persist(message);
42
65
  // eslint-disable-next-line unicorn/no-process-exit
43
66
  node_process_1.default.exit(code);
44
67
  } // }}}
45
- function finish(duration) {
68
+ function finishTimer(duration) {
46
69
  if (typeof duration !== 'number') {
47
70
  if ($start === 0) {
48
- stop(`🏁 ${ansi_colors_1.default.bold('Done')}`);
71
+ stopProgress(`🏁 ${ansi_colors_1.default.bold('Done')}`);
49
72
  return;
50
73
  }
51
74
  duration = Math.ceil((Date.now() - $start) / 1000);
52
75
  }
53
- stop(`🏁 ${ansi_colors_1.default.bold('Done')} (in ${duration}s).`);
76
+ stopProgress(`🏁 ${ansi_colors_1.default.bold('Done')} (in ${duration}s).`);
54
77
  } // }}}
55
78
  function info(message) {
56
79
  log_update_plus_1.stdout.persist(`${ansi_colors_1.default.cyan(ansi_colors_1.default.symbols.bullet)} ${message}`);
@@ -58,11 +81,19 @@ function info(message) {
58
81
  function newLine() {
59
82
  log_update_plus_1.stdout.persist('');
60
83
  } // }}}
61
- function pause() {
84
+ function pauseProgress() {
62
85
  clearInterval($loading);
63
86
  log_update_plus_1.stdout.render('');
64
87
  } // }}}
65
- function progress(label) {
88
+ function print(message) {
89
+ log_update_plus_1.stdout.persist(message);
90
+ } // }}}
91
+ function resumeProgress() {
92
+ if ($progessFn) {
93
+ $loading = setInterval($progessFn, cli_spinners_1.default.dots.interval);
94
+ }
95
+ } // }}}
96
+ function showProgress(label) {
66
97
  clearInterval($loading);
67
98
  let index = 0;
68
99
  $progessFn = () => {
@@ -73,18 +104,7 @@ function progress(label) {
73
104
  };
74
105
  $loading = setInterval($progessFn, cli_spinners_1.default.dots.interval);
75
106
  } // }}}
76
- function resume() {
77
- if ($progessFn) {
78
- $loading = setInterval($progessFn, cli_spinners_1.default.dots.interval);
79
- }
80
- } // }}}
81
- function step(label) {
82
- progress(ansi_colors_1.default.bold(label) + ansi_colors_1.default.dim('...'));
83
- return () => {
84
- check(ansi_colors_1.default.bold(`${label}:`) + ansi_colors_1.default.dim(' done'));
85
- };
86
- } // }}}
87
- function stop(message = '') {
107
+ function stopProgress(message = '') {
88
108
  clearInterval($loading);
89
109
  $loading = undefined;
90
110
  $progessFn = undefined;
@@ -98,18 +118,21 @@ function warn(message) {
98
118
  } // }}}
99
119
  // eslint-disable-next-line import/no-anonymous-default-export
100
120
  exports.default = {
101
- begin,
121
+ beginTimer,
102
122
  check,
123
+ createSpinner,
124
+ createStep,
125
+ debug,
103
126
  error,
104
127
  fatal,
105
- finish,
128
+ finishTimer,
106
129
  info,
107
130
  newLine,
108
- pause,
109
- progress,
110
- resume,
111
- step,
112
- stop,
131
+ pauseProgress,
132
+ print,
133
+ resumeProgress,
134
+ showProgress,
135
+ stopProgress,
113
136
  success,
114
137
  warn,
115
138
  };
@@ -1,31 +1,41 @@
1
1
  export type IndicatorLoading = ReturnType<typeof setInterval>;
2
- export declare function begin(): void;
2
+ export type Spinner = {
3
+ fail: () => void;
4
+ succeed: () => void;
5
+ };
6
+ export declare function beginTimer(): void;
3
7
  export declare function check(message: string): void;
8
+ export declare function createSpinner(label: string): Spinner;
9
+ export declare function createStep(label: string): () => void;
10
+ export declare function debug(message: string): void;
4
11
  export declare function error(message: string): void;
5
12
  export declare function fatal(message: string, code?: number): never;
6
- export declare function finish(duration?: number): void;
13
+ export declare function finishTimer(duration?: number): void;
7
14
  export declare function info(message: string): void;
8
15
  export declare function newLine(): void;
9
- export declare function pause(): void;
10
- export declare function progress(label: string): void;
11
- export declare function resume(): void;
12
- export declare function step(label: string): () => void;
13
- export declare function stop(message?: string): void;
16
+ export declare function pauseProgress(): void;
17
+ export declare function print(message: string): void;
18
+ export declare function resumeProgress(): void;
19
+ export declare function showProgress(label: string): void;
20
+ export declare function stopProgress(message?: string): void;
14
21
  export declare function success(message: string): void;
15
22
  export declare function warn(message: string): void;
16
23
  declare const _default: {
17
- begin: typeof begin;
24
+ beginTimer: typeof beginTimer;
18
25
  check: typeof check;
26
+ createSpinner: typeof createSpinner;
27
+ createStep: typeof createStep;
28
+ debug: typeof debug;
19
29
  error: typeof error;
20
30
  fatal: typeof fatal;
21
- finish: typeof finish;
31
+ finishTimer: typeof finishTimer;
22
32
  info: typeof info;
23
33
  newLine: typeof newLine;
24
- pause: typeof pause;
25
- progress: typeof progress;
26
- resume: typeof resume;
27
- step: typeof step;
28
- stop: typeof stop;
34
+ pauseProgress: typeof pauseProgress;
35
+ print: typeof print;
36
+ resumeProgress: typeof resumeProgress;
37
+ showProgress: typeof showProgress;
38
+ stopProgress: typeof stopProgress;
29
39
  success: typeof success;
30
40
  warn: typeof warn;
31
41
  };
@@ -1,31 +1,41 @@
1
1
  export type IndicatorLoading = ReturnType<typeof setInterval>;
2
- export declare function begin(): void;
2
+ export type Spinner = {
3
+ fail: () => void;
4
+ succeed: () => void;
5
+ };
6
+ export declare function beginTimer(): void;
3
7
  export declare function check(message: string): void;
8
+ export declare function createSpinner(label: string): Spinner;
9
+ export declare function createStep(label: string): () => void;
10
+ export declare function debug(message: string): void;
4
11
  export declare function error(message: string): void;
5
12
  export declare function fatal(message: string, code?: number): never;
6
- export declare function finish(duration?: number): void;
13
+ export declare function finishTimer(duration?: number): void;
7
14
  export declare function info(message: string): void;
8
15
  export declare function newLine(): void;
9
- export declare function pause(): void;
10
- export declare function progress(label: string): void;
11
- export declare function resume(): void;
12
- export declare function step(label: string): () => void;
13
- export declare function stop(message?: string): void;
16
+ export declare function pauseProgress(): void;
17
+ export declare function print(message: string): void;
18
+ export declare function resumeProgress(): void;
19
+ export declare function showProgress(label: string): void;
20
+ export declare function stopProgress(message?: string): void;
14
21
  export declare function success(message: string): void;
15
22
  export declare function warn(message: string): void;
16
23
  declare const _default: {
17
- begin: typeof begin;
24
+ beginTimer: typeof beginTimer;
18
25
  check: typeof check;
26
+ createSpinner: typeof createSpinner;
27
+ createStep: typeof createStep;
28
+ debug: typeof debug;
19
29
  error: typeof error;
20
30
  fatal: typeof fatal;
21
- finish: typeof finish;
31
+ finishTimer: typeof finishTimer;
22
32
  info: typeof info;
23
33
  newLine: typeof newLine;
24
- pause: typeof pause;
25
- progress: typeof progress;
26
- resume: typeof resume;
27
- step: typeof step;
28
- stop: typeof stop;
34
+ pauseProgress: typeof pauseProgress;
35
+ print: typeof print;
36
+ resumeProgress: typeof resumeProgress;
37
+ showProgress: typeof showProgress;
38
+ stopProgress: typeof stopProgress;
29
39
  success: typeof success;
30
40
  warn: typeof warn;
31
41
  };
@@ -6,32 +6,52 @@ const { dots } = cliSpinners;
6
6
  let $loading;
7
7
  let $progessFn;
8
8
  let $start = 0;
9
- export function begin() {
9
+ export function beginTimer() {
10
10
  $start = Date.now();
11
11
  } // }}}
12
12
  export function check(message) {
13
13
  stdout.persist(`${c.green(c.symbols.check)} ${message}`);
14
14
  } // }}}
15
+ export function createSpinner(label) {
16
+ showProgress(label);
17
+ return {
18
+ fail: () => {
19
+ stdout.persist(`${c.red(c.symbols.cross)} ${label}`);
20
+ },
21
+ succeed: () => {
22
+ stdout.persist(`${c.green(c.symbols.check)} ${label}`);
23
+ },
24
+ };
25
+ } // }}}
26
+ export function createStep(label) {
27
+ showProgress(c.bold(label) + c.dim('...'));
28
+ return () => {
29
+ check(c.bold(`${label}:`) + c.dim(' done'));
30
+ };
31
+ } // }}}
32
+ export function debug(message) {
33
+ stdout.persist(`${c.gray(c.symbols.pointerSmall)} ${message}`);
34
+ } // }}}
15
35
  export function error(message) {
16
36
  stdout.persist(`${c.red(c.symbols.cross)} ${c.bold('Error!')}`);
17
37
  stdout.persist(message);
18
38
  } // }}}
19
39
  export function fatal(message, code = 1) {
20
- stop();
40
+ stopProgress();
21
41
  stdout.persist(`${c.red(c.symbols.cross)} ${c.bold('Fatal!')}`);
22
42
  stdout.persist(message);
23
43
  // eslint-disable-next-line unicorn/no-process-exit
24
44
  process.exit(code);
25
45
  } // }}}
26
- export function finish(duration) {
46
+ export function finishTimer(duration) {
27
47
  if (typeof duration !== 'number') {
28
48
  if ($start === 0) {
29
- stop(`🏁 ${c.bold('Done')}`);
49
+ stopProgress(`🏁 ${c.bold('Done')}`);
30
50
  return;
31
51
  }
32
52
  duration = Math.ceil((Date.now() - $start) / 1000);
33
53
  }
34
- stop(`🏁 ${c.bold('Done')} (in ${duration}s).`);
54
+ stopProgress(`🏁 ${c.bold('Done')} (in ${duration}s).`);
35
55
  } // }}}
36
56
  export function info(message) {
37
57
  stdout.persist(`${c.cyan(c.symbols.bullet)} ${message}`);
@@ -39,11 +59,19 @@ export function info(message) {
39
59
  export function newLine() {
40
60
  stdout.persist('');
41
61
  } // }}}
42
- export function pause() {
62
+ export function pauseProgress() {
43
63
  clearInterval($loading);
44
64
  stdout.render('');
45
65
  } // }}}
46
- export function progress(label) {
66
+ export function print(message) {
67
+ stdout.persist(message);
68
+ } // }}}
69
+ export function resumeProgress() {
70
+ if ($progessFn) {
71
+ $loading = setInterval($progessFn, cliSpinners.dots.interval);
72
+ }
73
+ } // }}}
74
+ export function showProgress(label) {
47
75
  clearInterval($loading);
48
76
  let index = 0;
49
77
  $progessFn = () => {
@@ -54,18 +82,7 @@ export function progress(label) {
54
82
  };
55
83
  $loading = setInterval($progessFn, cliSpinners.dots.interval);
56
84
  } // }}}
57
- export function resume() {
58
- if ($progessFn) {
59
- $loading = setInterval($progessFn, cliSpinners.dots.interval);
60
- }
61
- } // }}}
62
- export function step(label) {
63
- progress(c.bold(label) + c.dim('...'));
64
- return () => {
65
- check(c.bold(`${label}:`) + c.dim(' done'));
66
- };
67
- } // }}}
68
- export function stop(message = '') {
85
+ export function stopProgress(message = '') {
69
86
  clearInterval($loading);
70
87
  $loading = undefined;
71
88
  $progessFn = undefined;
@@ -79,18 +96,21 @@ export function warn(message) {
79
96
  } // }}}
80
97
  // eslint-disable-next-line import/no-anonymous-default-export
81
98
  export default {
82
- begin,
99
+ beginTimer,
83
100
  check,
101
+ createSpinner,
102
+ createStep,
103
+ debug,
84
104
  error,
85
105
  fatal,
86
- finish,
106
+ finishTimer,
87
107
  info,
88
108
  newLine,
89
- pause,
90
- progress,
91
- resume,
92
- step,
93
- stop,
109
+ pauseProgress,
110
+ print,
111
+ resumeProgress,
112
+ showProgress,
113
+ stopProgress,
94
114
  success,
95
115
  warn,
96
116
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zokugun/cli-utils",
3
3
  "description": "Utils for CLI app",
4
- "version": "0.2.1",
4
+ "version": "0.3.1",
5
5
  "author": {
6
6
  "name": "Baptiste Augrain",
7
7
  "email": "daiyam@zokugun.org"
@@ -101,7 +101,7 @@
101
101
  "@commitlint/cli": "19.8.1",
102
102
  "@commitlint/config-conventional": "19.8.1",
103
103
  "@types/node": "20.19.39",
104
- "@zokugun/tsc-leda": "0.3.1",
104
+ "@zokugun/tsc-leda": "0.3.2",
105
105
  "fixpack": "4.0.0",
106
106
  "husky": "9.1.7",
107
107
  "lint-staged": "16.4.0",