import chalk from 'chalk' ; import cli from 'cli-ux' ; import { IPromptOptions } from 'cli-ux/lib/prompt' ; export * from './paths' ; export * from './modules' ; export * from './watcher' ; export const confirmAndRespond = async ( log , message , if_yes = `Ok, proceeding...` , if_no = `Ok, exiting` ) => { const response = await confirm ( message ) ; if ( response ) { log ( if_yes ) ; } else { log ( if_no ) ; } return response ; } ; const HEART_GROUPS_REGEXP = /💛([\s\S]*?)💛|❤️([\s\S]*?)❤️|💚([\s\S]*?)💚|🖤([\s\S]*?)🖤/gm ; const HEART_REGEXP = /[💛❤️💚🖤]/gm ; function format ( str , indent = 0 , first_line_indent = 0 ) { return ( ' ' . repeat ( first_line_indent ) + str . replace ( HEART_GROUPS_REGEXP , ( susbstr , y , r , g , b ) => { if ( y ) return chalk . yellow ( y ) ; if ( r ) return chalk . red ( r ) ; if ( g ) return chalk . green ( g ) ; if ( b ) return chalk . grey ( b ) ; return '' ; } ) . replace ( /\.{3}/g , '…' ) . split ( '\n' ) . map ( ( line ) => line . trim ( ) ) . join ( `\n${ ' ' . repeat ( indent ) }` ) ) ; } const WIDTH = 14 ; type StrFn = ( d : string ) => string ; export const _log = ( full_prefix ) => { let needs_shortening = full_prefix . length > WIDTH ; const prefix = needs_shortening ? `🖤[…${ full_prefix . slice ( 1 - WIDTH ) }]🖤` : `🖤${ `${ ' ' . repeat ( WIDTH ) }[${ full_prefix }]` . slice ( - 2 - WIDTH ) }🖤` ; const indent = WIDTH + 5 ; const log = ( str ) => { if ( ! full_prefix ) { console . log ( format ( str ) ) ; } else { if ( needs_shortening ) { const first = full_prefix . slice ( 0 , WIDTH - 1 ) ; console . log ( format ( `🖤[${ first }…]🖤 ${ str }` , indent ) ) ; needs_shortening = false ; } else { console . log ( format ( `${ prefix } ${ str }` , indent ) ) ; } } return true ; } ; log . _last_time = 0 ; log . continue = ( str ) => { console . log ( format ( str , indent , indent ) ) ; } ; log . time = ( fn ) : void => { if ( typeof fn === 'string' ) return log . time ( ( ) => fn ) ; const now = + new Date ( ) ; log ( fn ( `💛${ ( ( now - log . _last_time ) / 1000 ) . toFixed ( 2 ) } seconds💛` ) ) ; log . _last_time = now ; } ; log . notify = ( str ) => { log ( chalk . yellow ( str ) ) ; } ; log . info = ( str ) => { log ( chalk . green ( str ) ) ; } ; log . error = ( str ) => { log ( chalk . red ( str ) ) ; } ; log . warn = ( str ) => { log ( chalk . red ( str ) ) ; } ; log . note = ( str ) => { log ( `💚NOTE:💚 ${ str }` ) ; } ; log . tick = ( str , indent = 0 ) => { log ( `💚${ ' ' . repeat ( indent ) }✔💚 ${ str }` ) ; } ; log . cross = ( str , indent = 0 ) => { log ( `${ ' ' . repeat ( indent ) }❌ ${ str }` ) ; } ; log . announce = ( str ) => { log ( `💎 💚${ str }💚 💎` ) ; } ; log . confirmAndRespond = ( message , if_yes ? , if_no ? ) => confirmAndRespond ( log , `\n${ message }` , if_yes , if_no ) ; log . strip = ( str ) : string => str . replace ( HEART_REGEXP , '' ) ; return log ; } ; export const log = _log ( '' ) ; export const confirm = ( message ) => cli . confirm ( format ( message ) ) ; export const prompt = ( message , opts ? ) => cli . prompt ( format ( message ) , opts ) ; export type Logger = ReturnType < typeof _log > ;