[READ-ONLY] a fast, modern browser for the npm registry
at main 70 lines 1.5 kB view raw
1import { styleText } from 'node:util' 2import * as p from '@clack/prompts' 3import { createDebug } from 'obug' 4 5let isInitialized = false 6 7/** 8 * Initialize the logger with intro message 9 */ 10export function initLogger(): void { 11 if (isInitialized) return 12 isInitialized = true 13 p.intro(styleText(['bgCyan', 'black'], ' npmx connector ')) 14} 15 16/** 17 * Log when starting to execute a command 18 */ 19export function logCommand(command: string): void { 20 p.log.step(`${styleText('dim', '$ ')}${styleText('cyan', command)}`) 21} 22 23/** 24 * Log successful command completion 25 */ 26export function logSuccess(message: string): void { 27 p.log.success(styleText('green', message)) 28} 29 30/** 31 * Log command failure 32 */ 33export function logError(message: string): void { 34 p.log.error(styleText('red', message)) 35} 36 37/** 38 * Log warning 39 */ 40export function logWarning(message: string): void { 41 p.log.warn(styleText('yellow', message)) 42} 43 44/** 45 * Log info message 46 */ 47export function logInfo(message: string): void { 48 p.log.info(message) 49} 50 51/** 52 * Log a debug message with `obug` (minimal fork of `debug`) 53 */ 54export const logDebug = createDebug('npmx-connector') 55 56/** 57 * Show the connection token in a nice box 58 */ 59export function showToken(token: string, port: number, frontendUrl: string): void { 60 const connectUrl = `${frontendUrl}?token=${token}&port=${port}` 61 62 p.note( 63 [ 64 `Open: ${styleText(['bold', 'underline', 'cyan'], connectUrl)}`, 65 '', 66 styleText('dim', `Or paste token manually: ${token}`), 67 ].join('\n'), 68 'Click to connect', 69 ) 70}