import * as dot from 'dot-wild' ; const echo = require ( './../../dist' ) ; export class Cli { type { any } options : any ; /**
     * Create new CLI instance.
     */ constructor ( ) { this . options = echo . options ; } type { any } envVariables : any = { APP_DEFAULT_ALLOWED_ORIGINS : 'appManager.array.apps.0.allowedOrigins' , APP_DEFAULT_ENABLE_STATS : 'appManager.array.apps.0.enableStats' , APP_DEFAULT_ID : 'appManager.array.apps.0.id' , APP_DEFAULT_KEY : 'appManager.array.apps.0.key' , APP_DEFAULT_MAX_CONNS : 'appManager.array.apps.0.maxConnections' , APP_DEFAULT_SECRET : 'appManager.array.apps.0.secret' , APPS_LIST : 'appManager.array.apps' , APPS_MANAGER_DRIVER : 'appManager.driver' , APPS_MANAGER_ENDPOINT : 'appManager.api.endpoint' , APPS_MANAGER_HOST : 'appManager.api.host' , APPS_MANAGER_TOKEN : 'appManager.api.token' , CLOSING_GRACE_PERIOD : 'closingGracePeriod' , CORS_ALLOWED_ORIGINS : 'cors.origin' , DATABASE_DRIVER : 'database.driver' , DEBUG : 'development' , STATS_ENABLED : 'stats.enabled' , STATS_DRIVER : 'stats.driver' , STATS_SNAPSHOTS_INTERVAL : 'stats.snapshots.interval' , STATS_RETENTION_PERIOD : 'stats.retention.period' , REDIS_HOST : 'database.redis.host' , REDIS_PORT : 'database.redis.port' , REDIS_PASSWORD : 'database.redis.password' , REDIS_PREFIX : 'database.redis.keyPrefix' , SOCKET_HOST : 'host' , SOCKET_PORT : 'port' , SOCKET_PROTOCOL : 'protocol' , SSL_CERT : 'ssl.certPath' , SSL_KEY : 'ssl.keyPath' , SSL_CA : 'ssl.caPath' , SSL_PASS : 'ssl.passphrase' , } ; return { void } protected overwriteOptionsFromEnv ( ) { require ( 'dotenv' ) . config ( ) ; for ( let envVar in this . envVariables ) { let value = process . env [ envVar ] || process . env [ `ECHO_SERVER_${ envVar }` ] || null ; let optionKey = this . envVariables [ envVar . replace ( 'ECHO_SERVER_' , '' ) ] ; if ( value !== null ) { let json = null ; if ( typeof value === 'string' ) { try { json = JSON . parse ( value ) ; } catch ( e ) { json = null ; } if ( json !== null ) { value = json ; } } this . options = dot . set ( this . options , optionKey , value ) ; } } } return { Promise < any > } start ( yargs ) { this . overwriteOptionsFromEnv ( ) ; const handleFailure = async ( ) => { await echo . stop ( ) ; process . exit ( ) ; } ; process . on ( 'SIGINT' , handleFailure ) ; process . on ( 'SIGHUP' , handleFailure ) ; process . on ( 'SIGTERM' , handleFailure ) ; return echo . start ( this . options ) ; } return { Promise < any > } stop ( ) { return new Promise ( ( resolve , reject ) => { echo . stop ( ) ; } ) ; } }