import type * as d from '../../declarations' ; import { isAbsolute , join } from 'path' ; export const getAbsolutePath = ( config , dir ) => { if ( ! isAbsolute ( dir ) ) { dir = join ( config . rootDir , dir ) ; } return dir ; } ; export const setBooleanConfig = ( config , configName , flagName , defaultValue ) => { if ( flagName ) { if ( typeof config . flags [ flagName ] === 'boolean' ) { config [ configName ] = config . flags [ flagName ] ; } } const userConfigName = getUserConfigName ( config , configName ) ; if ( typeof config [ userConfigName ] === 'function' ) { config [ userConfigName ] = ! ! config [ userConfigName ] ( ) ; } if ( typeof config [ userConfigName ] === 'boolean' ) { config [ configName ] = config [ userConfigName ] ; } else { config [ configName ] = defaultValue ; } } ; export const setNumberConfig = ( config , configName , _flagName , defaultValue ) => { const userConfigName = getUserConfigName ( config , configName ) ; if ( typeof config [ userConfigName ] === 'function' ) { config [ userConfigName ] = config [ userConfigName ] ( ) ; } if ( typeof config [ userConfigName ] === 'number' ) { config [ configName ] = config [ userConfigName ] ; } else { config [ configName ] = defaultValue ; } } ; export const setStringConfig = ( config , configName , defaultValue ) => { const userConfigName = getUserConfigName ( config , configName ) ; if ( typeof config [ userConfigName ] === 'function' ) { config [ userConfigName ] = config [ userConfigName ] ( ) ; } if ( typeof config [ userConfigName ] === 'string' ) { config [ configName ] = config [ userConfigName ] ; } else { config [ configName ] = defaultValue ; } } ; export const setArrayConfig = ( config , configName , defaultValue ? ) => { const userConfigName = getUserConfigName ( config , configName ) ; if ( typeof config [ userConfigName ] === 'function' ) { config [ userConfigName ] = config [ userConfigName ] ( ) ; } if ( ! Array . isArray ( config [ configName ] ) ) { if ( Array . isArray ( defaultValue ) ) { config [ configName ] = defaultValue . slice ( ) ; } else { config [ configName ] = [ ] ; } } } ; const getUserConfigName = ( config , correctConfigName ) => { const userConfigNames = Object . keys ( config ) ; for ( const userConfigName of userConfigNames ) { if ( userConfigName . toLowerCase ( ) === correctConfigName . toLowerCase ( ) ) { if ( userConfigName !== correctConfigName ) { config . logger . warn ( `config "${ userConfigName }" should be "${ correctConfigName }"` ) ; return userConfigName ; } break ; } } return correctConfigName ; } ;