import { ImperativeConfig , IProfileLoaded , CliProfileManager , IProfile , Logger , ImperativeError } from "@zowe/imperative" ; import * as path from "path" ; returns { string } export function getZoweDir ( ) { if ( ImperativeConfig . instance . loadedConfig == null ) { ImperativeConfig . instance . loadedConfig = { defaultHome : path . join ( require ( "os" ) . homedir ( ) , ".zowe" ) , envVariablePrefix : "ZOWE" } ; } return ImperativeConfig . instance . cliHome ; } param { string } profileType param { boolean } mergeWithBase returns { IProfile } export async function getDefaultProfile ( profileType , mergeWithBase ? ) { const profileRootDir = path . join ( getZoweDir ( ) , "profiles" ) ; const logger = Logger . getImperativeLogger ( ) ; let profileManager ; let profileLoaded ; try { profileManager = new CliProfileManager ( { profileRootDirectory : profileRootDir , type : profileType } ) ; profileLoaded = await profileManager . load ( { loadDefault : true } ) ; } catch ( err ) { logger . warn ( err . message ) ; } if ( ( ! profileLoaded || ! profileLoaded . profile ) && ! mergeWithBase ) { throw new ImperativeError ( { msg : `Failed to load default profile of type "${ profileType }"` } ) ; } if ( mergeWithBase === false ) { return profileLoaded . profile ; } let baseProfileManager ; let baseProfileLoaded ; try { baseProfileManager = new CliProfileManager ( { profileRootDirectory : profileRootDir , type : "base" } ) ; baseProfileLoaded = await baseProfileManager . load ( { loadDefault : true } ) ; } catch ( err ) { logger . warn ( err . message ) ; } if ( ( ! baseProfileLoaded || ! baseProfileLoaded . profile ) && ( profileLoaded && profileLoaded . profile ) ) { return profileLoaded . profile ; } else if ( baseProfileLoaded && baseProfileLoaded . profile && ( ! profileLoaded || ! profileLoaded . profile ) ) { return baseProfileLoaded . profile ; } else if ( ( ! baseProfileLoaded || ! baseProfileLoaded . profile ) && ( ! profileLoaded || ! profileLoaded . profile ) ) { throw new ImperativeError ( { msg : `Failed to load default profiles of types "${ profileType }" and "base"` } ) ; } const combinedProfile = JSON . parse ( JSON . stringify ( baseProfileLoaded . profile ) ) ; for ( const propertyName in profileLoaded . profile ) { if ( profileLoaded . profile [ propertyName ] != null ) { combinedProfile [ propertyName ] = profileLoaded . profile [ propertyName ] ; } } return combinedProfile ; }