Skip to content

Commit 76094c1

Browse files
author
Tsvetan Raikov
committed
Added support for debug with livesync
1 parent c6e3e9a commit 76094c1

File tree

3 files changed

+58
-42
lines changed

3 files changed

+58
-42
lines changed

package.json

+23-32
Original file line numberDiff line numberDiff line change
@@ -105,84 +105,70 @@
105105
"runtime": "node",
106106
"initialConfigurations": [
107107
{
108-
"name": "Launch on iOS Device",
108+
"name": "Launch on iOS",
109109
"type": "nativescript",
110110
"platform": "ios",
111111
"request": "launch",
112112
"appRoot": "${workspaceRoot}",
113113
"sourceMaps": true,
114114
"diagnosticLogging": false,
115-
"emulator": false
115+
"emulator": false,
116+
"rebuild": false
116117
},
117118
{
118-
"name": "Attach on iOS Device",
119-
"type": "nativescript",
120-
"platform": "ios",
121-
"request": "attach",
122-
"appRoot": "${workspaceRoot}",
123-
"sourceMaps": true,
124-
"diagnosticLogging": false,
125-
"emulator": false
126-
},
127-
{
128-
"name": "Launch on iOS Emulator",
119+
"name": "Rebuild and launch on iOS",
129120
"type": "nativescript",
130121
"platform": "ios",
131122
"request": "launch",
132123
"appRoot": "${workspaceRoot}",
133124
"sourceMaps": true,
134125
"diagnosticLogging": false,
135-
"emulator": true
126+
"emulator": false,
127+
"rebuild": true
136128
},
137129
{
138-
"name": "Attach on iOS Emulator",
130+
"name": "Rebuild and attach on iOS",
139131
"type": "nativescript",
140132
"platform": "ios",
141133
"request": "attach",
142134
"appRoot": "${workspaceRoot}",
143135
"sourceMaps": true,
144136
"diagnosticLogging": false,
145-
"emulator": true
137+
"emulator": false,
138+
"rebuild": true
146139
},
147140
{
148-
"name": "Launch on Android Device",
141+
"name": "Launch on Android",
149142
"type": "nativescript",
150143
"platform": "android",
151144
"request": "launch",
152145
"appRoot": "${workspaceRoot}",
153146
"sourceMaps": true,
154147
"diagnosticLogging": false,
155-
"emulator": false
148+
"emulator": false,
149+
"rebuild": false
156150
},
157151
{
158-
"name": "Launch on Android Emulator",
152+
"name": "Rebuild and launch on Android",
159153
"type": "nativescript",
160154
"platform": "android",
161155
"request": "launch",
162156
"appRoot": "${workspaceRoot}",
163157
"sourceMaps": true,
164158
"diagnosticLogging": false,
165-
"emulator": true
159+
"emulator": false,
160+
"rebuild": true
166161
},
167162
{
168-
"name": "Attach on Android Device",
163+
"name": "Rebuild and attach on Android",
169164
"type": "nativescript",
170165
"platform": "android",
171166
"request": "attach",
172167
"appRoot": "${workspaceRoot}",
173168
"sourceMaps": true,
174169
"diagnosticLogging": false,
175-
"emulator": false
176-
},
177-
{
178-
"name": "Attach on Android Emulator",
179-
"type": "nativescript",
180-
"platform": "android",
181-
"request": "attach",
182-
"appRoot": "${workspaceRoot}",
183-
"sourceMaps": true,
184-
"diagnosticLogging": false,
185-
"emulator": true
170+
"emulator": false,
171+
"rebuild": true
186172
}
187173
],
188174
"configurationAttributes": {
@@ -234,6 +220,11 @@
234220
"type": "boolean",
235221
"description": "Whether the app to run in emulator or on a physical device.",
236222
"default": false
223+
},
224+
"rebuild": {
225+
"type": "boolean",
226+
"description": "Whether the app should be rebuild before start.",
227+
"default": true
237228
}
238229
}
239230
},

src/debug-adapter/webKitAdapterInterfaces.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface ILaunchRequestArgs extends DebugProtocol.LaunchRequestArguments
1212
request: string;
1313
tnsArgs?: string[];
1414
tnsOutput?: string;
15+
rebuild?: boolean;
1516
}
1617

1718
export interface IAttachRequestArgs extends DebugProtocol.AttachRequestArguments {
@@ -23,6 +24,7 @@ export interface IAttachRequestArgs extends DebugProtocol.AttachRequestArguments
2324
request: string;
2425
tnsArgs?: string[];
2526
tnsOutput?: string;
27+
rebuild?: boolean;
2628
}
2729

2830
export interface ISetBreakpointsArgs extends DebugProtocol.SetBreakpointsArguments {

src/services/NsCliService.ts

+33-10
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export class IosProject extends NSProject {
144144
.appendParamIf("--emulator", args.emulator)
145145
.appendParamIf("--start", args.request === "attach")
146146
.appendParamIf("--debug-brk", args.request === "launch")
147+
.appendParamIf("--no-rebuild", !args.rebuild)
147148
.appendParam("--no-client")
148149
.appendParams(args.tnsArgs)
149150
.build();
@@ -155,12 +156,19 @@ export class IosProject extends NSProject {
155156
return new Promise<string>((resolve, reject) => {
156157
// run NativeScript CLI command
157158
let child: ChildProcess = this.spawnProcess(command.path, command.args, args.tnsOutput);
159+
let synced = false;
158160

159161
child.stdout.on('data', (data) => {
160162
let strData: string = data.toString();
161163
this.emit('TNS.outputMessage', strData, 'log');
162164
this.writeToTnsOutputFile(strData);
163-
if(!readyToConnect) {
165+
if (!synced && !args.rebuild && strData.indexOf('Successfully synced application') > -1) {
166+
synced = true;
167+
//wait a little before trying to connect, this gives a changes for adb to be able to connect to the debug socket
168+
setTimeout(() => {
169+
resolve();
170+
}, 500);
171+
} else if(!readyToConnect) {
164172
let matches: RegExpMatchArray = strData.match(socketPathPattern);
165173
if(matches && matches.length > 0) {
166174
readyToConnect = true;
@@ -175,7 +183,13 @@ export class IosProject extends NSProject {
175183
});
176184

177185
child.on('close', (code, signal) => {
178-
reject("The debug process exited unexpectedly code:" + code);
186+
if (!args.rebuild) {
187+
setTimeout(() => {
188+
reject("The debug process exited unexpectedly code:" + code);
189+
}, 3000);
190+
} else {
191+
reject("The debug process exited unexpectedly code:" + code);
192+
}
179193
});
180194
});
181195
}
@@ -220,6 +234,7 @@ export class AndroidProject extends NSProject {
220234
.appendParam("debug")
221235
.appendParam(this.platform())
222236
.appendParamIf("--emulator", args.emulator)
237+
.appendParamIf("--no-rebuild", args.rebuild !== true)
223238
.appendParam("--debug-brk")
224239
.appendParam("--no-client")
225240
.appendParams(args.tnsArgs)
@@ -233,13 +248,14 @@ export class AndroidProject extends NSProject {
233248
let strData: string = data.toString();
234249
that.emit('TNS.outputMessage', data.toString(), 'log');
235250
that.writeToTnsOutputFile(strData);
236-
if (!launched && args.request === "launch" && strData.indexOf('# NativeScript Debugger started #') > -1) {
237-
launched = true;
238-
239-
//wait a little before trying to connect, this gives a changes for adb to be able to connect to the debug socket
240-
setTimeout(() => {
241-
resolve();
242-
}, 500);
251+
if (!launched) {
252+
if (args.request === "launch" && ((strData.indexOf('# NativeScript Debugger started #') > -1) || strData.indexOf('Successfully synced application') > -1)) {
253+
launched = true;
254+
//wait a little before trying to connect, this gives a changes for adb to be able to connect to the debug socket
255+
setTimeout(() => {
256+
resolve();
257+
}, 500);
258+
}
243259
}
244260
});
245261

@@ -249,7 +265,14 @@ export class AndroidProject extends NSProject {
249265
});
250266

251267
child.on('close', function(code) {
252-
reject("The debug process exited unexpectedly code:" + code);
268+
if (!args.rebuild) {
269+
setTimeout(() => {
270+
reject("The debug process exited unexpectedly code:" + code);
271+
}, 3000);
272+
}
273+
else {
274+
reject("The debug process exited unexpectedly code:" + code);
275+
}
253276
});
254277
});
255278
}

0 commit comments

Comments
 (0)