import { isEnvironmentSelected , createAdvplCompile } from './extension' ; var INI = require ( 'ini' ) ; export interface IIniEnvironment { Environment : string ; SourcePath : string ; RootPath : string ; } export class IniManagement { private _Environments : IIniEnvironment [ ] ; public get Environments ( ) : IIniEnvironment [ ] { return this . _Environments ; } private _IniContent : string ; public get IniContent ( ) : string { return this . _IniContent ; } private _IniObject : Object ; public get IniObject ( ) : Object { return this . _IniObject ; } constructor ( iniContent ? ) { if ( ! iniContent ) { this . _IniContent = iniContent ; } this . _Environments = [ ] ; } public GetIniContent ( ) { var that = this ; return new Promise ( ( resolve ) => { if ( ! isEnvironmentSelected ( ) ) { return ; } let compile = createAdvplCompile ( null , null ) ; if ( ! ( compile == null ) ) { compile . getINI ( function ( iniContent ) { that . _IniContent = iniContent ; resolve ( ) ; } ) ; } } ) ; } public GetEnvironments ( ) { if ( this . IniContent ) { this . _IniObject = INI . decode ( this . IniContent ) ; Object . keys ( this . _IniObject ) . map ( key => { if ( this . _IniObject [ key ] . hasOwnProperty ( "SourcePath" ) ) { this . _Environments . push ( { Environment : key . toUpperCase ( ) , SourcePath : this . _IniObject [ key ] [ "SourcePath" ] , RootPath : this . _IniObject [ key ] [ "RootPath" ] } ) ; } } ) ; } return this ; } }