-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathlogger.ts
More file actions
91 lines (78 loc) · 1.71 KB
/
logger.ts
File metadata and controls
91 lines (78 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import * as p from '@clack/prompts'
import pc from 'picocolors'
import { createDebug } from 'obug'
let isInitialized = false
/**
* Initialize the logger with intro message
*/
export function initLogger(): void {
if (isInitialized) return
isInitialized = true
p.intro(pc.bgCyan(pc.black(' npmx connector ')))
}
/**
* Log when starting to execute a command
*/
export function logCommand(command: string): void {
p.log.step(pc.dim('$ ') + pc.cyan(command))
}
/**
* Log successful command completion
*/
export function logSuccess(message: string): void {
p.log.success(pc.green(message))
}
/**
* Log command failure
*/
export function logError(message: string): void {
p.log.error(pc.red(message))
}
/**
* Log warning
*/
export function logWarning(message: string): void {
p.log.warn(pc.yellow(message))
}
/**
* Log info message
*/
export function logInfo(message: string): void {
p.log.info(message)
}
/**
* Log a debug message with `obug` (minimal fork of `debug`)
*/
export const logDebug = createDebug('npmx-connector')
/**
* Log a message (generic)
*/
export function logMessage(message: string): void {
p.log.message(message)
}
/**
* Show the connection token in a nice box
*/
export function showToken(token: string, port: number): void {
const connectUrl = `https://npmx.dev/?token=${token}&port=${port}`
p.note(
[
`Open: ${pc.bold(pc.underline(pc.cyan(connectUrl)))}`,
'',
pc.dim(`Or paste token manually: ${token}`),
].join('\n'),
'Click to connect',
)
}
/**
* Show outro message
*/
export function showOutro(message: string): void {
p.outro(message)
}
/**
* Create a spinner for async operations
*/
export function createSpinner() {
return p.spinner()
}