@zokugun/cli-utils 0.2.1 → 0.3.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.
@@ -3,18 +3,20 @@ 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.resumeProgress = resumeProgress;
18
+ exports.showProgress = showProgress;
19
+ exports.stopProgress = stopProgress;
18
20
  exports.success = success;
19
21
  exports.warn = warn;
20
22
  const node_process_1 = __importDefault(require("node:process"));
@@ -25,32 +27,52 @@ const { dots } = cli_spinners_1.default;
25
27
  let $loading;
26
28
  let $progessFn;
27
29
  let $start = 0;
28
- function begin() {
30
+ function beginTimer() {
29
31
  $start = Date.now();
30
32
  } // }}}
31
33
  function check(message) {
32
34
  log_update_plus_1.stdout.persist(`${ansi_colors_1.default.green(ansi_colors_1.default.symbols.check)} ${message}`);
33
35
  } // }}}
36
+ function createSpinner(label) {
37
+ showProgress(label);
38
+ return {
39
+ fail: () => {
40
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.red(ansi_colors_1.default.symbols.cross)} ${label}`);
41
+ },
42
+ succeed: () => {
43
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.green(ansi_colors_1.default.symbols.check)} ${label}`);
44
+ },
45
+ };
46
+ } // }}}
47
+ function createStep(label) {
48
+ showProgress(ansi_colors_1.default.bold(label) + ansi_colors_1.default.dim('...'));
49
+ return () => {
50
+ check(ansi_colors_1.default.bold(`${label}:`) + ansi_colors_1.default.dim(' done'));
51
+ };
52
+ } // }}}
53
+ function debug(message) {
54
+ log_update_plus_1.stdout.persist(`${ansi_colors_1.default.gray(ansi_colors_1.default.symbols.pointerSmall)} ${message}`);
55
+ } // }}}
34
56
  function error(message) {
35
57
  log_update_plus_1.stdout.persist(`${ansi_colors_1.default.red(ansi_colors_1.default.symbols.cross)} ${ansi_colors_1.default.bold('Error!')}`);
36
58
  log_update_plus_1.stdout.persist(message);
37
59
  } // }}}
38
60
  function fatal(message, code = 1) {
39
- stop();
61
+ stopProgress();
40
62
  log_update_plus_1.stdout.persist(`${ansi_colors_1.default.red(ansi_colors_1.default.symbols.cross)} ${ansi_colors_1.default.bold('Fatal!')}`);
41
63
  log_update_plus_1.stdout.persist(message);
42
64
  // eslint-disable-next-line unicorn/no-process-exit
43
65
  node_process_1.default.exit(code);
44
66
  } // }}}
45
- function finish(duration) {
67
+ function finishTimer(duration) {
46
68
  if (typeof duration !== 'number') {
47
69
  if ($start === 0) {
48
- stop(`🏁 ${ansi_colors_1.default.bold('Done')}`);
70
+ stopProgress(`🏁 ${ansi_colors_1.default.bold('Done')}`);
49
71
  return;
50
72
  }
51
73
  duration = Math.ceil((Date.now() - $start) / 1000);
52
74
  }
53
- stop(`🏁 ${ansi_colors_1.default.bold('Done')} (in ${duration}s).`);
75
+ stopProgress(`🏁 ${ansi_colors_1.default.bold('Done')} (in ${duration}s).`);
54
76
  } // }}}
55
77
  function info(message) {
56
78
  log_update_plus_1.stdout.persist(`${ansi_colors_1.default.cyan(ansi_colors_1.default.symbols.bullet)} ${message}`);
@@ -58,11 +80,16 @@ function info(message) {
58
80
  function newLine() {
59
81
  log_update_plus_1.stdout.persist('');
60
82
  } // }}}
61
- function pause() {
83
+ function pauseProgress() {
62
84
  clearInterval($loading);
63
85
  log_update_plus_1.stdout.render('');
64
86
  } // }}}
65
- function progress(label) {
87
+ function resumeProgress() {
88
+ if ($progessFn) {
89
+ $loading = setInterval($progessFn, cli_spinners_1.default.dots.interval);
90
+ }
91
+ } // }}}
92
+ function showProgress(label) {
66
93
  clearInterval($loading);
67
94
  let index = 0;
68
95
  $progessFn = () => {
@@ -73,18 +100,7 @@ function progress(label) {
73
100
  };
74
101
  $loading = setInterval($progessFn, cli_spinners_1.default.dots.interval);
75
102
  } // }}}
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 = '') {
103
+ function stopProgress(message = '') {
88
104
  clearInterval($loading);
89
105
  $loading = undefined;
90
106
  $progessFn = undefined;
@@ -98,18 +114,20 @@ function warn(message) {
98
114
  } // }}}
99
115
  // eslint-disable-next-line import/no-anonymous-default-export
100
116
  exports.default = {
101
- begin,
117
+ beginTimer,
102
118
  check,
119
+ createSpinner,
120
+ createStep,
121
+ debug,
103
122
  error,
104
123
  fatal,
105
- finish,
124
+ finishTimer,
106
125
  info,
107
126
  newLine,
108
- pause,
109
- progress,
110
- resume,
111
- step,
112
- stop,
127
+ pauseProgress,
128
+ resumeProgress,
129
+ showProgress,
130
+ stopProgress,
113
131
  success,
114
132
  warn,
115
133
  };
@@ -1,31 +1,39 @@
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 resumeProgress(): void;
18
+ export declare function showProgress(label: string): void;
19
+ export declare function stopProgress(message?: string): void;
14
20
  export declare function success(message: string): void;
15
21
  export declare function warn(message: string): void;
16
22
  declare const _default: {
17
- begin: typeof begin;
23
+ beginTimer: typeof beginTimer;
18
24
  check: typeof check;
25
+ createSpinner: typeof createSpinner;
26
+ createStep: typeof createStep;
27
+ debug: typeof debug;
19
28
  error: typeof error;
20
29
  fatal: typeof fatal;
21
- finish: typeof finish;
30
+ finishTimer: typeof finishTimer;
22
31
  info: typeof info;
23
32
  newLine: typeof newLine;
24
- pause: typeof pause;
25
- progress: typeof progress;
26
- resume: typeof resume;
27
- step: typeof step;
28
- stop: typeof stop;
33
+ pauseProgress: typeof pauseProgress;
34
+ resumeProgress: typeof resumeProgress;
35
+ showProgress: typeof showProgress;
36
+ stopProgress: typeof stopProgress;
29
37
  success: typeof success;
30
38
  warn: typeof warn;
31
39
  };
@@ -1,31 +1,39 @@
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 resumeProgress(): void;
18
+ export declare function showProgress(label: string): void;
19
+ export declare function stopProgress(message?: string): void;
14
20
  export declare function success(message: string): void;
15
21
  export declare function warn(message: string): void;
16
22
  declare const _default: {
17
- begin: typeof begin;
23
+ beginTimer: typeof beginTimer;
18
24
  check: typeof check;
25
+ createSpinner: typeof createSpinner;
26
+ createStep: typeof createStep;
27
+ debug: typeof debug;
19
28
  error: typeof error;
20
29
  fatal: typeof fatal;
21
- finish: typeof finish;
30
+ finishTimer: typeof finishTimer;
22
31
  info: typeof info;
23
32
  newLine: typeof newLine;
24
- pause: typeof pause;
25
- progress: typeof progress;
26
- resume: typeof resume;
27
- step: typeof step;
28
- stop: typeof stop;
33
+ pauseProgress: typeof pauseProgress;
34
+ resumeProgress: typeof resumeProgress;
35
+ showProgress: typeof showProgress;
36
+ stopProgress: typeof stopProgress;
29
37
  success: typeof success;
30
38
  warn: typeof warn;
31
39
  };
@@ -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,16 @@ 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 resumeProgress() {
67
+ if ($progessFn) {
68
+ $loading = setInterval($progessFn, cliSpinners.dots.interval);
69
+ }
70
+ } // }}}
71
+ export function showProgress(label) {
47
72
  clearInterval($loading);
48
73
  let index = 0;
49
74
  $progessFn = () => {
@@ -54,18 +79,7 @@ export function progress(label) {
54
79
  };
55
80
  $loading = setInterval($progessFn, cliSpinners.dots.interval);
56
81
  } // }}}
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 = '') {
82
+ export function stopProgress(message = '') {
69
83
  clearInterval($loading);
70
84
  $loading = undefined;
71
85
  $progessFn = undefined;
@@ -79,18 +93,20 @@ export function warn(message) {
79
93
  } // }}}
80
94
  // eslint-disable-next-line import/no-anonymous-default-export
81
95
  export default {
82
- begin,
96
+ beginTimer,
83
97
  check,
98
+ createSpinner,
99
+ createStep,
100
+ debug,
84
101
  error,
85
102
  fatal,
86
- finish,
103
+ finishTimer,
87
104
  info,
88
105
  newLine,
89
- pause,
90
- progress,
91
- resume,
92
- step,
93
- stop,
106
+ pauseProgress,
107
+ resumeProgress,
108
+ showProgress,
109
+ stopProgress,
94
110
  success,
95
111
  warn,
96
112
  };
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.0",
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",