@maz-ui/node 4.1.8-beta.1 → 4.2.1-alpha.9
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 +180 -40
- package/dist/index.d.mts +40 -9
- package/dist/index.d.ts +40 -9
- package/dist/index.mjs +52 -19
- package/package.json +11 -12
package/README.md
CHANGED
|
@@ -11,11 +11,13 @@ npm install @maz-ui/node
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
13
|
- 🚀 **Promise-based command execution** with detailed logging
|
|
14
|
-
- 🎨 **
|
|
14
|
+
- 🎨 **Elegant console logging** powered by [consola](https://github.com/unjs/consola)
|
|
15
|
+
- 📊 **Configurable log levels** (0-5) with fancy formatting
|
|
15
16
|
- ⚡ **TypeScript support** with full type safety
|
|
16
17
|
- 📦 **Lightweight** - minimal dependencies
|
|
17
|
-
- 🔧 **
|
|
18
|
+
- 🔧 **Highly configurable** - custom loggers with different levels and reporters
|
|
18
19
|
- 🛡️ **Error handling** - comprehensive error management
|
|
20
|
+
- 🎯 **Multiple log types** - info, debug, trace, start, ready, fail, box
|
|
19
21
|
|
|
20
22
|
## Usage
|
|
21
23
|
|
|
@@ -59,97 +61,226 @@ interface ExecOptions {
|
|
|
59
61
|
|
|
60
62
|
### Logger
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
Elegant console logging powered by [consola](https://github.com/unjs/consola) with configurable log levels and fancy formatting.
|
|
63
65
|
|
|
64
66
|
```typescript
|
|
65
67
|
import { logger } from '@maz-ui/node'
|
|
66
68
|
|
|
67
69
|
// Basic logging
|
|
68
70
|
logger.log('Regular message')
|
|
71
|
+
logger.info('Information message')
|
|
69
72
|
logger.success('Operation completed successfully!')
|
|
70
73
|
logger.warn('Warning message')
|
|
71
74
|
logger.error('Error occurred', errorObject)
|
|
72
75
|
|
|
76
|
+
// Development logging (requires level >= 4)
|
|
77
|
+
logger.debug('Debug information')
|
|
78
|
+
logger.trace('Detailed trace information')
|
|
79
|
+
|
|
80
|
+
// Status logging
|
|
81
|
+
logger.ready('System is ready!')
|
|
82
|
+
logger.fail('Operation failed')
|
|
83
|
+
logger.fatal('Fatal error occurred')
|
|
84
|
+
|
|
73
85
|
// Special formatters
|
|
74
86
|
logger.brand('🎨 Maz-UI Brand Message') // Blue bright
|
|
75
|
-
logger.
|
|
87
|
+
logger.box('Important Message in a Box')
|
|
88
|
+
logger.divider() // Prints separator line (adapts to terminal width)
|
|
76
89
|
logger.eot() // End of transmission (empty line)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
logger.clear() // Clear console
|
|
91
|
+
logger.silent('This message is always silent')
|
|
92
|
+
logger.verbose('Verbose information')
|
|
93
|
+
|
|
94
|
+
// Dynamic log level control using semantic names
|
|
95
|
+
logger.setLevel('debug') // Enable debug logs
|
|
96
|
+
logger.setLevel('silent') // Disable all logs
|
|
97
|
+
logger.setLevel('verbose') // Enable all logs with maximum verbosity
|
|
98
|
+
logger.setLevel('default') // Back to default (level 3)
|
|
85
99
|
```
|
|
86
100
|
|
|
87
101
|
#### Logger Methods
|
|
88
102
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
103
|
+
All methods accept `InputLogObject | any` and additional arguments for flexibility.
|
|
104
|
+
|
|
105
|
+
##### Core Logging Methods
|
|
106
|
+
|
|
107
|
+
- **`log(...args)`** - Standard console log (level 2)
|
|
108
|
+
- **`info(...args)`** - Information messages (level 3)
|
|
109
|
+
- **`success(...args)`** - Success messages with green styling (level 3)
|
|
110
|
+
- **`warn(...args)`** - Warning messages with yellow styling (level 1)
|
|
111
|
+
- **`error(...args)`** - Error messages with red styling (level 0)
|
|
112
|
+
- **`debug(...args)`** - Debug messages (level 4)
|
|
113
|
+
- **`trace(...args)`** - Trace messages for detailed debugging (level 5)
|
|
114
|
+
- **`verbose(...args)`** - Verbose messages (highest level)
|
|
115
|
+
- **`fatal(...args)`** - Fatal error messages (level 0)
|
|
116
|
+
- **`silent(...args)`** - Silent messages (never shown)
|
|
117
|
+
|
|
118
|
+
##### Status Methods
|
|
119
|
+
|
|
120
|
+
- **`ready(...args)`** - Ready/completion indicator (level 3)
|
|
121
|
+
- **`fail(...args)`** - Failure messages (level 0)
|
|
122
|
+
|
|
123
|
+
##### Formatting Methods
|
|
124
|
+
|
|
125
|
+
- **`box(...args)`** - Display message in a fancy box
|
|
93
126
|
- **`brand(message)`** - Blue bright branded messages
|
|
94
|
-
- **`divider()`** - Prints a separator line
|
|
127
|
+
- **`divider()`** - Prints a separator line that adapts to terminal width
|
|
95
128
|
- **`eot()`** - Prints an empty line (end of transmission)
|
|
129
|
+
- **`clear()`** - Clear the console
|
|
130
|
+
|
|
131
|
+
##### Configuration Methods
|
|
132
|
+
|
|
133
|
+
- **`setLevel(level)`** - Change log level dynamically using semantic names:
|
|
134
|
+
- `'silent'` - No logs (-∞)
|
|
135
|
+
- `'error'` - Fatal and Error only (0)
|
|
136
|
+
- `'warning'` - Warnings and above (1)
|
|
137
|
+
- `'normal'` - Normal logs and above (2)
|
|
138
|
+
- `'default'` - Informational logs (3)
|
|
139
|
+
- `'debug'` - Debug logs and above (4)
|
|
140
|
+
- `'trace'` - All logs including trace (5)
|
|
141
|
+
- `'verbose'` - Maximum verbosity (+∞)
|
|
142
|
+
|
|
143
|
+
#### Log Levels
|
|
144
|
+
|
|
145
|
+
The logger supports semantic log levels for better readability. Default is `'default'` (level 3).
|
|
146
|
+
|
|
147
|
+
| Level | Value | Description |
|
|
148
|
+
| ----------- | ----- | ---------------------------- |
|
|
149
|
+
| `'silent'` | -∞ | No logs displayed |
|
|
150
|
+
| `'error'` | 0 | Fatal and Error only |
|
|
151
|
+
| `'warning'` | 1 | Warnings and above |
|
|
152
|
+
| `'normal'` | 2 | Normal logs and above |
|
|
153
|
+
| `'default'` | 3 | Informational logs (default) |
|
|
154
|
+
| `'debug'` | 4 | Debug logs and above |
|
|
155
|
+
| `'trace'` | 5 | All logs including trace |
|
|
156
|
+
| `'verbose'` | +∞ | Maximum verbosity |
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { logger } from '@maz-ui/node'
|
|
160
|
+
|
|
161
|
+
// Change level at runtime
|
|
162
|
+
logger.setLevel('debug')
|
|
163
|
+
logger.debug('Debug info') // Now visible
|
|
164
|
+
|
|
165
|
+
logger.setLevel('error') // Only errors
|
|
166
|
+
logger.log('Regular log') // Won't be displayed
|
|
167
|
+
|
|
168
|
+
logger.setLevel('silent') // Disable all logs
|
|
169
|
+
logger.error('Error message') // Won't be displayed
|
|
170
|
+
|
|
171
|
+
logger.setLevel('verbose') // Maximum verbosity
|
|
172
|
+
logger.trace('Trace message') // Will be displayed
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### Custom Logger Instances
|
|
176
|
+
|
|
177
|
+
Create custom logger instances with different configurations:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { createLogger } from '@maz-ui/node'
|
|
181
|
+
|
|
182
|
+
// Create a debug logger
|
|
183
|
+
const debugLogger = createLogger({
|
|
184
|
+
level: 4, // or use the numeric level directly
|
|
185
|
+
tag: 'debug'
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
debugLogger.debug('Debug information')
|
|
189
|
+
debugLogger.trace('Detailed trace')
|
|
190
|
+
|
|
191
|
+
// Create a minimal logger for CI environments
|
|
192
|
+
const ciLogger = createLogger({
|
|
193
|
+
level: 2 // normal level
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
// Create a silent logger
|
|
197
|
+
const silentLogger = createLogger({
|
|
198
|
+
level: Number.NEGATIVE_INFINITY
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
// Create a verbose logger for development
|
|
202
|
+
const devLogger = createLogger({
|
|
203
|
+
level: Number.POSITIVE_INFINITY
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
// Then use setLevel with semantic names
|
|
207
|
+
debugLogger.setLevel('verbose')
|
|
208
|
+
ciLogger.setLevel('error')
|
|
209
|
+
```
|
|
96
210
|
|
|
97
211
|
## Advanced Examples
|
|
98
212
|
|
|
99
213
|
### Custom Logger Integration
|
|
100
214
|
|
|
101
215
|
```typescript
|
|
102
|
-
import
|
|
103
|
-
import { execPromise, logger } from '@maz-ui/node'
|
|
216
|
+
import { createLogger, execPromise } from '@maz-ui/node'
|
|
104
217
|
|
|
105
|
-
// Create custom logger
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
console.log('[CUSTOM]', ...args)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
218
|
+
// Create custom logger for specific use case
|
|
219
|
+
const buildLogger = createLogger({
|
|
220
|
+
level: 3, // default level
|
|
221
|
+
tag: 'build'
|
|
222
|
+
})
|
|
113
223
|
|
|
114
224
|
// Use with execPromise
|
|
115
225
|
await execPromise('npm test', {
|
|
116
|
-
logger:
|
|
226
|
+
logger: buildLogger,
|
|
117
227
|
packageName: 'test-suite'
|
|
118
228
|
})
|
|
229
|
+
|
|
230
|
+
// Create a logger for different environments
|
|
231
|
+
const isCI = process.env.CI === 'true'
|
|
232
|
+
const envLogger = createLogger({
|
|
233
|
+
level: isCI ? 2 : 4 // normal in CI, debug in dev
|
|
234
|
+
})
|
|
119
235
|
```
|
|
120
236
|
|
|
121
237
|
### Build Script Example
|
|
122
238
|
|
|
123
239
|
```typescript
|
|
124
|
-
import {
|
|
240
|
+
import { createLogger, execPromise } from '@maz-ui/node'
|
|
125
241
|
|
|
126
242
|
async function buildProject() {
|
|
127
|
-
logger
|
|
243
|
+
const logger = createLogger({
|
|
244
|
+
level: 3, // default level
|
|
245
|
+
tag: 'build'
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
logger.box('🚀 Starting build process')
|
|
128
249
|
logger.divider()
|
|
129
250
|
|
|
130
251
|
try {
|
|
131
252
|
// Install dependencies
|
|
253
|
+
logger.info('Installing dependencies...')
|
|
132
254
|
await execPromise('npm install', {
|
|
133
255
|
packageName: 'setup',
|
|
134
|
-
noStdout: true
|
|
256
|
+
noStdout: true,
|
|
257
|
+
logger
|
|
135
258
|
})
|
|
259
|
+
logger.ready('Dependencies installed')
|
|
136
260
|
|
|
137
261
|
// Run tests
|
|
262
|
+
logger.info('Running tests...')
|
|
138
263
|
await execPromise('npm test', {
|
|
139
264
|
packageName: 'test',
|
|
140
|
-
noStdout: true
|
|
265
|
+
noStdout: true,
|
|
266
|
+
logger
|
|
141
267
|
})
|
|
268
|
+
logger.ready('Tests passed')
|
|
142
269
|
|
|
143
270
|
// Build project
|
|
271
|
+
logger.info('Building project...')
|
|
144
272
|
await execPromise('npm run build', {
|
|
145
|
-
packageName: 'build'
|
|
273
|
+
packageName: 'build',
|
|
274
|
+
logger
|
|
146
275
|
})
|
|
276
|
+
logger.ready('Build completed')
|
|
147
277
|
|
|
148
278
|
logger.eot()
|
|
149
279
|
logger.success('✅ Build completed successfully!')
|
|
150
280
|
}
|
|
151
281
|
catch (error) {
|
|
152
|
-
logger.
|
|
282
|
+
logger.fail('❌ Build failed')
|
|
283
|
+
logger.error(error)
|
|
153
284
|
process.exit(1)
|
|
154
285
|
}
|
|
155
286
|
}
|
|
@@ -160,9 +291,13 @@ buildProject()
|
|
|
160
291
|
### CI/CD Integration
|
|
161
292
|
|
|
162
293
|
```typescript
|
|
163
|
-
import {
|
|
294
|
+
import { createLogger, execPromise } from '@maz-ui/node'
|
|
164
295
|
|
|
165
296
|
async function ciPipeline() {
|
|
297
|
+
const logger = createLogger({
|
|
298
|
+
level: 2 // normal level for CI
|
|
299
|
+
})
|
|
300
|
+
|
|
166
301
|
const steps = [
|
|
167
302
|
{ name: 'Lint', command: 'npm run lint' },
|
|
168
303
|
{ name: 'Test', command: 'npm test' },
|
|
@@ -170,20 +305,23 @@ async function ciPipeline() {
|
|
|
170
305
|
{ name: 'Package', command: 'npm pack' }
|
|
171
306
|
]
|
|
172
307
|
|
|
173
|
-
logger.
|
|
308
|
+
logger.box('🔄 CI Pipeline Started')
|
|
174
309
|
logger.divider()
|
|
175
310
|
|
|
176
311
|
for (const step of steps) {
|
|
177
|
-
logger.
|
|
312
|
+
logger.info(`Running ${step.name}...`)
|
|
178
313
|
|
|
179
314
|
try {
|
|
180
315
|
await execPromise(step.command, {
|
|
181
316
|
packageName: step.name.toLowerCase(),
|
|
182
|
-
noStdout: true
|
|
317
|
+
noStdout: true,
|
|
318
|
+
logger
|
|
183
319
|
})
|
|
320
|
+
logger.ready(`${step.name} completed`)
|
|
184
321
|
}
|
|
185
322
|
catch (error) {
|
|
186
|
-
logger.
|
|
323
|
+
logger.fail(`${step.name} failed`)
|
|
324
|
+
logger.error(error)
|
|
187
325
|
process.exit(1)
|
|
188
326
|
}
|
|
189
327
|
}
|
|
@@ -191,6 +329,8 @@ async function ciPipeline() {
|
|
|
191
329
|
logger.eot()
|
|
192
330
|
logger.success('🎉 All pipeline steps completed!')
|
|
193
331
|
}
|
|
332
|
+
|
|
333
|
+
ciPipeline()
|
|
194
334
|
```
|
|
195
335
|
|
|
196
336
|
## API Reference
|
|
@@ -222,7 +362,7 @@ All logger methods automatically handle error objects using `getErrorMessage` ut
|
|
|
222
362
|
|
|
223
363
|
## Dependencies
|
|
224
364
|
|
|
225
|
-
- **
|
|
365
|
+
- **consola** - Elegant console logging with fancy formatting
|
|
226
366
|
- **@maz-ui/utils** - Error message formatting
|
|
227
367
|
- **Node.js built-ins** - child_process for command execution
|
|
228
368
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import { ConsolaOptions, InputLogObject, ConsolaReporter, ConsolaInstance } from 'consola';
|
|
2
|
+
export { ConsolaOptions } from 'consola';
|
|
3
|
+
|
|
4
|
+
declare const LogLevelMap: {
|
|
5
|
+
silent: number;
|
|
6
|
+
error: number;
|
|
7
|
+
warning: number;
|
|
8
|
+
normal: number;
|
|
9
|
+
default: number;
|
|
10
|
+
debug: number;
|
|
11
|
+
trace: number;
|
|
12
|
+
verbose: number;
|
|
13
|
+
};
|
|
14
|
+
declare function createLogger(options?: LoggerOptions): {
|
|
15
|
+
start: (message: InputLogObject | any, ...args: any[]) => void;
|
|
16
|
+
log: (message: InputLogObject | any, ...args: any[]) => void;
|
|
17
|
+
warn: (message: InputLogObject | any, ...args: any[]) => void;
|
|
18
|
+
error: (message: InputLogObject | any, ...args: any[]) => void;
|
|
19
|
+
box: (message: InputLogObject | any, ...args: any[]) => void;
|
|
20
|
+
fail: (message: InputLogObject | any, ...args: any[]) => void;
|
|
21
|
+
success: (message: InputLogObject | any, ...args: any[]) => void;
|
|
22
|
+
info: (message: InputLogObject | any, ...args: any[]) => void;
|
|
23
|
+
debug: (message: InputLogObject | any, ...args: any[]) => void;
|
|
24
|
+
trace: (message: InputLogObject | any, ...args: any[]) => void;
|
|
25
|
+
verbose: (message: InputLogObject | any, ...args: any[]) => void;
|
|
26
|
+
fatal: (message: InputLogObject | any, ...args: any[]) => void;
|
|
27
|
+
ready: (message: InputLogObject | any, ...args: any[]) => void;
|
|
28
|
+
silent: (message: InputLogObject | any, ...args: any[]) => void;
|
|
2
29
|
divider: () => void;
|
|
3
30
|
eot: () => void;
|
|
4
31
|
brand: (message: string) => void;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
32
|
+
clear: () => void;
|
|
33
|
+
addReporter: (reporter: ConsolaReporter) => ConsolaInstance;
|
|
34
|
+
removeReporter: (reporter: ConsolaReporter) => ConsolaInstance | ConsolaReporter[];
|
|
35
|
+
setLevel: (level: LogLevel) => void;
|
|
9
36
|
};
|
|
10
|
-
|
|
37
|
+
declare const logger: Logger;
|
|
38
|
+
|
|
39
|
+
type LoggerOptions = Partial<ConsolaOptions>;
|
|
40
|
+
type LogLevel = keyof typeof LogLevelMap;
|
|
41
|
+
type Logger = ReturnType<typeof createLogger>;
|
|
11
42
|
|
|
12
|
-
declare function execPromise(command: string, { logger, packageName, noSuccess, noStdout, noStderr }?: {
|
|
43
|
+
declare function execPromise(command: string, { logger, packageName, noSuccess, noStdout, noStderr, }?: {
|
|
13
44
|
logger?: Logger;
|
|
14
45
|
packageName?: string;
|
|
15
46
|
noSuccess?: boolean;
|
|
@@ -20,5 +51,5 @@ declare function execPromise(command: string, { logger, packageName, noSuccess,
|
|
|
20
51
|
stderr: string;
|
|
21
52
|
}>;
|
|
22
53
|
|
|
23
|
-
export { execPromise, logger };
|
|
24
|
-
export type { Logger };
|
|
54
|
+
export { createLogger, execPromise, logger };
|
|
55
|
+
export type { LogLevel, Logger, LoggerOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import { ConsolaOptions, InputLogObject, ConsolaReporter, ConsolaInstance } from 'consola';
|
|
2
|
+
export { ConsolaOptions } from 'consola';
|
|
3
|
+
|
|
4
|
+
declare const LogLevelMap: {
|
|
5
|
+
silent: number;
|
|
6
|
+
error: number;
|
|
7
|
+
warning: number;
|
|
8
|
+
normal: number;
|
|
9
|
+
default: number;
|
|
10
|
+
debug: number;
|
|
11
|
+
trace: number;
|
|
12
|
+
verbose: number;
|
|
13
|
+
};
|
|
14
|
+
declare function createLogger(options?: LoggerOptions): {
|
|
15
|
+
start: (message: InputLogObject | any, ...args: any[]) => void;
|
|
16
|
+
log: (message: InputLogObject | any, ...args: any[]) => void;
|
|
17
|
+
warn: (message: InputLogObject | any, ...args: any[]) => void;
|
|
18
|
+
error: (message: InputLogObject | any, ...args: any[]) => void;
|
|
19
|
+
box: (message: InputLogObject | any, ...args: any[]) => void;
|
|
20
|
+
fail: (message: InputLogObject | any, ...args: any[]) => void;
|
|
21
|
+
success: (message: InputLogObject | any, ...args: any[]) => void;
|
|
22
|
+
info: (message: InputLogObject | any, ...args: any[]) => void;
|
|
23
|
+
debug: (message: InputLogObject | any, ...args: any[]) => void;
|
|
24
|
+
trace: (message: InputLogObject | any, ...args: any[]) => void;
|
|
25
|
+
verbose: (message: InputLogObject | any, ...args: any[]) => void;
|
|
26
|
+
fatal: (message: InputLogObject | any, ...args: any[]) => void;
|
|
27
|
+
ready: (message: InputLogObject | any, ...args: any[]) => void;
|
|
28
|
+
silent: (message: InputLogObject | any, ...args: any[]) => void;
|
|
2
29
|
divider: () => void;
|
|
3
30
|
eot: () => void;
|
|
4
31
|
brand: (message: string) => void;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
32
|
+
clear: () => void;
|
|
33
|
+
addReporter: (reporter: ConsolaReporter) => ConsolaInstance;
|
|
34
|
+
removeReporter: (reporter: ConsolaReporter) => ConsolaInstance | ConsolaReporter[];
|
|
35
|
+
setLevel: (level: LogLevel) => void;
|
|
9
36
|
};
|
|
10
|
-
|
|
37
|
+
declare const logger: Logger;
|
|
38
|
+
|
|
39
|
+
type LoggerOptions = Partial<ConsolaOptions>;
|
|
40
|
+
type LogLevel = keyof typeof LogLevelMap;
|
|
41
|
+
type Logger = ReturnType<typeof createLogger>;
|
|
11
42
|
|
|
12
|
-
declare function execPromise(command: string, { logger, packageName, noSuccess, noStdout, noStderr }?: {
|
|
43
|
+
declare function execPromise(command: string, { logger, packageName, noSuccess, noStdout, noStderr, }?: {
|
|
13
44
|
logger?: Logger;
|
|
14
45
|
packageName?: string;
|
|
15
46
|
noSuccess?: boolean;
|
|
@@ -20,5 +51,5 @@ declare function execPromise(command: string, { logger, packageName, noSuccess,
|
|
|
20
51
|
stderr: string;
|
|
21
52
|
}>;
|
|
22
53
|
|
|
23
|
-
export { execPromise, logger };
|
|
24
|
-
export type { Logger };
|
|
54
|
+
export { createLogger, execPromise, logger };
|
|
55
|
+
export type { LogLevel, Logger, LoggerOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,58 @@
|
|
|
1
1
|
import { exec } from 'node:child_process';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { blueBright } from 'colorette';
|
|
4
|
+
import { createConsola } from 'consola';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
log(red(message), errorMessage ? red(errorMessage) : "");
|
|
15
|
-
},
|
|
16
|
-
warn: (message, error) => {
|
|
17
|
-
const errorMessage = error ? getErrorMessage(error) : "";
|
|
18
|
-
log(yellow(message), errorMessage ? yellow(errorMessage) : "");
|
|
19
|
-
}
|
|
6
|
+
const LogLevelMap = {
|
|
7
|
+
silent: Number.NEGATIVE_INFINITY,
|
|
8
|
+
error: 0,
|
|
9
|
+
warning: 1,
|
|
10
|
+
normal: 2,
|
|
11
|
+
default: 3,
|
|
12
|
+
debug: 4,
|
|
13
|
+
trace: 5,
|
|
14
|
+
verbose: Number.POSITIVE_INFINITY
|
|
20
15
|
};
|
|
16
|
+
function createLogger(options) {
|
|
17
|
+
const consola = createConsola({
|
|
18
|
+
...options,
|
|
19
|
+
level: options?.level ?? LogLevelMap.default
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
start: (message, ...args) => consola.start(message, ...args),
|
|
23
|
+
log: (message, ...args) => consola.log(message, ...args),
|
|
24
|
+
warn: (message, ...args) => consola.warn(message, ...args),
|
|
25
|
+
error: (message, ...args) => consola.error(message, ...args),
|
|
26
|
+
box: (message, ...args) => consola.box(message, ...args),
|
|
27
|
+
fail: (message, ...args) => consola.fail(message, ...args),
|
|
28
|
+
success: (message, ...args) => consola.success(message, ...args),
|
|
29
|
+
info: (message, ...args) => consola.info(message, ...args),
|
|
30
|
+
debug: (message, ...args) => consola.debug(message, ...args),
|
|
31
|
+
trace: (message, ...args) => consola.trace(message, ...args),
|
|
32
|
+
verbose: (message, ...args) => consola.verbose(message, ...args),
|
|
33
|
+
fatal: (message, ...args) => consola.fatal(message, ...args),
|
|
34
|
+
ready: (message, ...args) => consola.ready(message, ...args),
|
|
35
|
+
silent: (message, ...args) => consola.silent(message, ...args),
|
|
36
|
+
divider: () => console.log("-".repeat(process.stdout.columns ?? 20)),
|
|
37
|
+
eot: () => console.log(),
|
|
38
|
+
brand: (message) => console.log(blueBright(message)),
|
|
39
|
+
clear: () => console.clear(),
|
|
40
|
+
addReporter: (reporter) => consola.addReporter(reporter),
|
|
41
|
+
removeReporter: (reporter) => consola.removeReporter(reporter),
|
|
42
|
+
setLevel: (level) => {
|
|
43
|
+
consola.level = LogLevelMap[level];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const logger = createLogger();
|
|
21
48
|
|
|
22
|
-
async function execPromise(command, {
|
|
49
|
+
async function execPromise(command, {
|
|
50
|
+
logger: logger$1,
|
|
51
|
+
packageName,
|
|
52
|
+
noSuccess,
|
|
53
|
+
noStdout,
|
|
54
|
+
noStderr
|
|
55
|
+
} = {}) {
|
|
23
56
|
const internalLogger = logger$1 ?? logger;
|
|
24
57
|
const packageNameStr = packageName ? `[${packageName}]` : "";
|
|
25
58
|
return await new Promise((resolve, reject) => {
|
|
@@ -43,4 +76,4 @@ async function execPromise(command, { logger: logger$1, packageName, noSuccess,
|
|
|
43
76
|
});
|
|
44
77
|
}
|
|
45
78
|
|
|
46
|
-
export { execPromise, logger };
|
|
79
|
+
export { createLogger, execPromise, logger };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maz-ui/node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1
|
|
4
|
+
"version": "4.2.1-alpha.9",
|
|
5
5
|
"description": "Node utilities for Maz-UI library",
|
|
6
6
|
"author": "Louis Mazel <me@loicmazuel.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,16 +38,9 @@
|
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=18.0.0"
|
|
40
40
|
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"build": "unbuild",
|
|
43
|
-
"dev": "unbuild --stub",
|
|
44
|
-
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
45
|
-
"lint": "cross-env NODE_ENV=production eslint .",
|
|
46
|
-
"lint:fix": "pnpm lint --fix"
|
|
47
|
-
},
|
|
48
41
|
"dependencies": {
|
|
49
|
-
"
|
|
50
|
-
"
|
|
42
|
+
"colorette": "^2.0.20",
|
|
43
|
+
"consola": "^3.4.2"
|
|
51
44
|
},
|
|
52
45
|
"devDependencies": {
|
|
53
46
|
"unbuild": "^3.6.1"
|
|
@@ -57,5 +50,11 @@
|
|
|
57
50
|
"eslint --fix"
|
|
58
51
|
]
|
|
59
52
|
},
|
|
60
|
-
"
|
|
61
|
-
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "unbuild",
|
|
55
|
+
"dev": "unbuild --stub",
|
|
56
|
+
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
57
|
+
"lint": "cross-env NODE_ENV=production eslint .",
|
|
58
|
+
"lint:fix": "pnpm lint --fix"
|
|
59
|
+
}
|
|
60
|
+
}
|