@maz-ui/node 4.0.0-beta.7 → 4.0.0-beta.8

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.
Files changed (2) hide show
  1. package/dist/index.mjs +156 -4
  2. package/package.json +4 -6
package/dist/index.mjs CHANGED
@@ -1,6 +1,158 @@
1
1
  import { exec } from 'node:child_process';
2
- import { getErrorMessage } from '@maz-ui/utils/helpers/getErrorMessage';
3
- import { yellow, red, green, blueBright } from 'colorette';
2
+ import * as tty from 'tty';
3
+
4
+ function e(t) {
5
+ return t instanceof Error ? t.message : typeof t == "string" ? t : t && typeof t == "object" && "message" in t ? String(t.message) : t ? String(t) : "An unexpected error occurred";
6
+ }
7
+
8
+ const {
9
+ env = {},
10
+ argv = [],
11
+ platform = "",
12
+ } = typeof process === "undefined" ? {} : process;
13
+
14
+ const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
15
+ const isForced = "FORCE_COLOR" in env || argv.includes("--color");
16
+ const isWindows = platform === "win32";
17
+ const isDumbTerminal = env.TERM === "dumb";
18
+
19
+ const isCompatibleTerminal =
20
+ tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
21
+
22
+ const isCI =
23
+ "CI" in env &&
24
+ ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
25
+
26
+ const isColorSupported =
27
+ !isDisabled &&
28
+ (isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI);
29
+
30
+ const replaceClose = (
31
+ index,
32
+ string,
33
+ close,
34
+ replace,
35
+ head = string.substring(0, index) + replace,
36
+ tail = string.substring(index + close.length),
37
+ next = tail.indexOf(close)
38
+ ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
39
+
40
+ const clearBleed = (index, string, open, close, replace) =>
41
+ index < 0
42
+ ? open + string + close
43
+ : open + replaceClose(index, string, close, replace) + close;
44
+
45
+ const filterEmpty =
46
+ (open, close, replace = open, at = open.length + 1) =>
47
+ (string) =>
48
+ string || !(string === "" || string === undefined)
49
+ ? clearBleed(
50
+ ("" + string).indexOf(close, at),
51
+ string,
52
+ open,
53
+ close,
54
+ replace
55
+ )
56
+ : "";
57
+
58
+ const init = (open, close, replace) =>
59
+ filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
60
+
61
+ const colors = {
62
+ reset: init(0, 0),
63
+ bold: init(1, 22, "\x1b[22m\x1b[1m"),
64
+ dim: init(2, 22, "\x1b[22m\x1b[2m"),
65
+ italic: init(3, 23),
66
+ underline: init(4, 24),
67
+ inverse: init(7, 27),
68
+ hidden: init(8, 28),
69
+ strikethrough: init(9, 29),
70
+ black: init(30, 39),
71
+ red: init(31, 39),
72
+ green: init(32, 39),
73
+ yellow: init(33, 39),
74
+ blue: init(34, 39),
75
+ magenta: init(35, 39),
76
+ cyan: init(36, 39),
77
+ white: init(37, 39),
78
+ gray: init(90, 39),
79
+ bgBlack: init(40, 49),
80
+ bgRed: init(41, 49),
81
+ bgGreen: init(42, 49),
82
+ bgYellow: init(43, 49),
83
+ bgBlue: init(44, 49),
84
+ bgMagenta: init(45, 49),
85
+ bgCyan: init(46, 49),
86
+ bgWhite: init(47, 49),
87
+ blackBright: init(90, 39),
88
+ redBright: init(91, 39),
89
+ greenBright: init(92, 39),
90
+ yellowBright: init(93, 39),
91
+ blueBright: init(94, 39),
92
+ magentaBright: init(95, 39),
93
+ cyanBright: init(96, 39),
94
+ whiteBright: init(97, 39),
95
+ bgBlackBright: init(100, 49),
96
+ bgRedBright: init(101, 49),
97
+ bgGreenBright: init(102, 49),
98
+ bgYellowBright: init(103, 49),
99
+ bgBlueBright: init(104, 49),
100
+ bgMagentaBright: init(105, 49),
101
+ bgCyanBright: init(106, 49),
102
+ bgWhiteBright: init(107, 49),
103
+ };
104
+
105
+ const createColors = ({ useColor = isColorSupported } = {}) =>
106
+ useColor
107
+ ? colors
108
+ : Object.keys(colors).reduce(
109
+ (colors, key) => ({ ...colors, [key]: String }),
110
+ {}
111
+ );
112
+
113
+ const {
114
+ reset,
115
+ bold,
116
+ dim,
117
+ italic,
118
+ underline,
119
+ inverse,
120
+ hidden,
121
+ strikethrough,
122
+ black,
123
+ red,
124
+ green,
125
+ yellow,
126
+ blue,
127
+ magenta,
128
+ cyan,
129
+ white,
130
+ gray,
131
+ bgBlack,
132
+ bgRed,
133
+ bgGreen,
134
+ bgYellow,
135
+ bgBlue,
136
+ bgMagenta,
137
+ bgCyan,
138
+ bgWhite,
139
+ blackBright,
140
+ redBright,
141
+ greenBright,
142
+ yellowBright,
143
+ blueBright,
144
+ magentaBright,
145
+ cyanBright,
146
+ whiteBright,
147
+ bgBlackBright,
148
+ bgRedBright,
149
+ bgGreenBright,
150
+ bgYellowBright,
151
+ bgBlueBright,
152
+ bgMagentaBright,
153
+ bgCyanBright,
154
+ bgWhiteBright,
155
+ } = createColors();
4
156
 
5
157
  const log = console.log;
6
158
  const logger = {
@@ -10,11 +162,11 @@ const logger = {
10
162
  log: (...message) => log(...message),
11
163
  success: (...message) => log(...message.map((m) => green(m))),
12
164
  error: (message, error) => {
13
- const errorMessage = error ? getErrorMessage(error) : "";
165
+ const errorMessage = error ? e(error) : "";
14
166
  log(red(message), errorMessage ? red(errorMessage) : "");
15
167
  },
16
168
  warn: (message, error) => {
17
- const errorMessage = error ? getErrorMessage(error) : "";
169
+ const errorMessage = error ? e(error) : "";
18
170
  log(yellow(message), errorMessage ? yellow(errorMessage) : "");
19
171
  }
20
172
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maz-ui/node",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.7",
4
+ "version": "4.0.0-beta.8",
5
5
  "packageManager": "pnpm@10.13.1",
6
6
  "description": "Node utilities for Maz-UI library",
7
7
  "author": "Louis Mazel <me@loicmazuel.com>",
@@ -47,11 +47,9 @@
47
47
  "lint:fix": "eslint . --fix",
48
48
  "pre-commit": "lint-staged"
49
49
  },
50
- "dependencies": {
51
- "@maz-ui/utils": "4.0.0-beta.7",
52
- "colorette": "^2.0.20"
53
- },
54
50
  "devDependencies": {
51
+ "@maz-ui/utils": "4.0.0-beta.8",
52
+ "colorette": "^2.0.20",
55
53
  "typescript": "^5.8.3",
56
54
  "unbuild": "^3.5.0"
57
55
  },
@@ -60,5 +58,5 @@
60
58
  "eslint --fix"
61
59
  ]
62
60
  },
63
- "gitHead": "b64fa54fbf3c645a1f2009f44c50da350bd8461e"
61
+ "gitHead": "fef4d097f7e992f20980cc628216f070a516644e"
64
62
  }