import env from 'flex-plugins-utils-env' ; import { logger } from '../../logger' ; export type Callback < R > = ( ) => Promise < R > ; interface OraOptions { text : string ; isEnabled ? : boolean ; } interface Progress { start : ( ) => void ; succeed : ( ) => void ; fail : ( text ? : string ) => void ; } let ora = null ; const _getOra = ( ) => { if ( ora ) { return ora ; } ora = require ( 'ora' ) ; return ora ; } ; param title param disabled export const _getSpinner = ( text , disabled ) : Progress => { if ( disabled ) { return { start : ( ) => { } , succeed : ( ) => { } , fail : ( ) => { } , } ; } const options = { text } ; if ( env . isDebug ( ) || env . isTrace ( ) ) { options . isEnabled = false ; } return _getOra ( ) ( options ) ; } ; /**
 * An  ora progress wrapper
 *
 *  param title param action param disabled export const progress = async < R > ( title , action , disabled = env . isQuiet ( ) ) : Promise < R > => { const spinner = _getSpinner ( logger . markdown ( title ) || '' , disabled ) ; try { spinner . start ( ) ; const response = await action ( ) ; spinner . succeed ( ) ; return response ; } catch ( e ) { spinner . fail ( e . message ) ; throw e ; } } ; export default progress ;