import chalk from 'chalk' ; import { ICLIArguments } from './types' ; const ora = require ( 'ora' ) ; param message export function log ( message ) { console . log ( `${ chalk . white ( '»' ) }  ${ chalk . gray ( message ) }` ) ; } param text export function success ( text ) { console . log ( `${ chalk . green ( '✔' ) }  ${ chalk . white ( text ) }` ) ; } param err export function error ( err ) { const msg = err instanceof Error ? err . message : err ; const stack = err instanceof Error ? `\nStack:\n${ err . stack }` : '' ; console . log ( `${ chalk . red ( '✖' ) }  ${ chalk . bgRed ( chalk . white ( msg ) ) }${ stack }` ) ; } param text param fn export async function spinWhile < T > ( text , fn ) { const spinner = ora ( ' ' + chalk . gray ( text ) ) . start ( ) ; try { return await fn ( ) ; } finally { spinner . stop ( ) ; } } param argv export function parseArguments ( argv ) { const flags = { } ; const args = [ ] ; for ( const arg of argv ) { if ( arg . startsWith ( '--' ) ) { if ( arg . includes ( '=' ) ) { const idx = arg . indexOf ( '=' ) ; const afterEq = arg . substring ( idx + 1 ) ; flags [ arg . substring ( 2 , idx ) ] = afterEq ; } else { flags [ arg . substring ( 2 ) ] = true ; } } else { args . push ( arg ) ; } } return { flags , args } ; }