@@ -133,11 +133,11 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
133133 Services . logger ( ) . log ( `${ args . request } (${ JSON . stringify ( args ) } )` ) ;
134134 }
135135
136- private processRequest ( args : DebugProtocol . IRequestArgs ) : Promise < void > {
136+ private async processRequest ( args : DebugProtocol . IRequestArgs ) {
137137 // Initialize the request
138138 this . configureLoggingForRequest ( args ) ;
139139 Services . appRoot = args . appRoot ;
140- return Services . extensionClient ( ) . getInitSettings ( ) . then ( settings => {
140+ return Services . extensionClient ( ) . getInitSettings ( ) . then ( async settings => {
141141 Services . cliPath = settings . tnsPath || Services . cliPath ;
142142 this . _request = new DebugRequest ( args , Services . cli ( ) ) ;
143143 Services . extensionClient ( ) . analyticsLaunchDebugger ( { request : args . request , platform : args . platform } ) ;
@@ -147,6 +147,10 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
147147 Services . logger ( ) . log ( '[NSDebugAdapter] Running tns command...' , Tags . FrontendMessage ) ;
148148 let cliCommand : DebugResult ;
149149 if ( this . _request . isLaunch ) {
150+ let teamId = this . getTeamId ( Services . appRoot , this . _request . args . tnsArgs ) ;
151+ if ( ! teamId ) {
152+ teamId = ( await Services . extensionClient ( ) . selectTeam ( ) ) . id ;
153+ }
150154 cliCommand = this . _request . project . debug ( { stopOnEntry : this . _request . launchArgs . stopOnEntry , watch : this . _request . launchArgs . watch } , this . _request . args . tnsArgs ) ;
151155 }
152156 else if ( this . _request . isAttach ) {
@@ -687,6 +691,56 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
687691 private scriptIsNotUnknown ( scriptId : WebKitProtocol . Debugger . ScriptId ) : boolean {
688692 return ! ! this . _scriptsById . get ( scriptId ) ;
689693 }
694+
695+ private getTeamId ( appRoot : string , tnsArgs ?: string [ ] ) : string {
696+ // try to get the TeamId from the TnsArgs
697+ if ( tnsArgs ) {
698+ const teamIdArgIndex = tnsArgs . indexOf ( '--teamId' ) ;
699+ if ( teamIdArgIndex > 0 && teamIdArgIndex + 1 < tnsArgs . length ) {
700+ return tnsArgs [ teamIdArgIndex + 1 ] ;
701+ }
702+ }
703+
704+ // try to get the TeamId from the buildxcconfig or teamid file
705+ const teamIdFromConfig = this . readTeamId ( appRoot ) ;
706+ if ( teamIdFromConfig ) {
707+ return teamIdFromConfig ;
708+ }
709+
710+ // we should get the Teams from the machine and ask the user if they are more than 1
711+ return null ;
712+ }
713+
714+ private readXCConfig ( appRoot : string , flag : string ) : string {
715+ let xcconfigFile = path . join ( appRoot , "App_Resources/ios/build.xcconfig" ) ;
716+ if ( fs . exists ( xcconfigFile ) ) {
717+ let text = fs . readFileSync ( xcconfigFile , { encoding : 'utf8' } ) ;
718+ let teamId : string ;
719+ text . split ( / \r ? \n / ) . forEach ( ( line ) => {
720+ line = line . replace ( / \/ ( \/ ) [ ^ \n ] * $ / , "" ) ;
721+ if ( line . indexOf ( flag ) >= 0 ) {
722+ teamId = line . split ( "=" ) [ 1 ] . trim ( ) ;
723+ if ( teamId [ teamId . length - 1 ] === ';' ) {
724+ teamId = teamId . slice ( 0 , - 1 ) ;
725+ }
726+ }
727+ } ) ;
728+ if ( teamId ) {
729+ return teamId ;
730+ }
731+ }
732+
733+ let fileName = path . join ( appRoot , "teamid" ) ;
734+ if ( fs . exists ( fileName ) ) {
735+ return fs . readFileSync ( fileName , { encoding : 'utf8' } ) ;
736+ }
737+
738+ return null ;
739+ }
740+
741+ private readTeamId ( appRoot ) : string {
742+ return this . readXCConfig ( appRoot , "DEVELOPMENT_TEAM" ) ;
743+ }
690744}
691745
692746function scriptIdToSourceReference ( scriptId : WebKitProtocol . Debugger . ScriptId ) : number {
0 commit comments