Skip to content

Commit 5e70199

Browse files
author
Yosif Yosifov
committed
Add initial teams selector. not fully func yet.
1 parent 39375f6 commit 5e70199

File tree

3 files changed

+120
-2
lines changed

3 files changed

+120
-2
lines changed

src/debug-adapter/webKitDebugAdapter.ts

+56-2
Original file line numberDiff line numberDiff line change
@@ -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

692746
function scriptIdToSourceReference(scriptId: WebKitProtocol.Debugger.ScriptId): number {

src/ipc/extensionClient.ts

+4
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ export class ExtensionClient {
5959
public runRunCommand(args: extProtocol.AnalyticsRunRunCommandArgs): Promise<any> {
6060
return this.callRemoteMethod('runRunCommand', args);
6161
}
62+
63+
public selectTeam(): Promise<{ id: string, name: string }> {
64+
return this.callRemoteMethod('selectTeam');
65+
}
6266
}

src/ipc/extensionServer.ts

+60
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from 'path';
22
import * as os from 'os';
3+
import * as fs from 'fs';
34
import * as crypto from 'crypto';
45
import * as vscode from 'vscode';
56
import * as extProtocol from './extensionProtocol';
@@ -68,4 +69,63 @@ export class ExtensionServer {
6869
public runRunCommand(args: extProtocol.AnalyticsRunRunCommandArgs): Promise<any> {
6970
return Services.analyticsService().runRunCommand(args.platform);
7071
}
72+
73+
public selectTeam() : Promise<{ id: string, name: string }> {
74+
return new Promise((resolve, reject) => {
75+
let developmentTeams = this.getDevelopmentTeams();
76+
if(developmentTeams.length > 1) {
77+
let quickPickItems = developmentTeams.map((team) => {
78+
return {
79+
label: team.name,
80+
description: team.id
81+
};
82+
});
83+
vscode.window.showQuickPick(quickPickItems)
84+
.then(val => resolve({
85+
id: val.description,
86+
label: val.label
87+
}));
88+
} else {
89+
resolve();
90+
}
91+
});
92+
}
93+
94+
private getDevelopmentTeams(): Array<{ id: string, name: string }> {
95+
let dir = path.join(process.env.HOME, "Library/MobileDevice/Provisioning Profiles/");
96+
let files = fs.readdirSync(dir);
97+
let teamIds: any = {};
98+
for (let file of files) {
99+
let filePath = path.join(dir, file);
100+
let data = fs.readFileSync(filePath, { encoding: "utf8" });
101+
let teamId = this.getProvisioningProfileValue("TeamIdentifier", data);
102+
let teamName = this.getProvisioningProfileValue("TeamName", data);
103+
if (teamId) {
104+
teamIds[teamId] = teamName;
105+
}
106+
}
107+
108+
let teamIdsArray = new Array<{ id: string, name: string }>();
109+
for (let teamId in teamIds) {
110+
teamIdsArray.push({ id: teamId, name: teamIds[teamId] });
111+
}
112+
113+
return teamIdsArray;
114+
}
115+
116+
private getProvisioningProfileValue(name: string, text: string): string {
117+
let findStr = "<key>" + name + "</key>";
118+
let index = text.indexOf(findStr);
119+
if (index > 0) {
120+
index = text.indexOf("<string>", index + findStr.length);
121+
if (index > 0) {
122+
index += "<string>".length;
123+
let endIndex = text.indexOf("</string>", index);
124+
let result = text.substring(index, endIndex);
125+
return result;
126+
}
127+
}
128+
129+
return null;
130+
}
71131
}

0 commit comments

Comments
 (0)