Skip to content

Commit f9eb2f9

Browse files
author
Dimitar Kerezov
committed
Expose enable/disable debugging
Expose enable/disable debugging when CLI is required as a library. Includes: * Unify `debug-livesync-service` and `livesync-service` into one class. Enable said class to attach a debugger at runtime during LiveSync * Remove redundant `debugLivesync` property from `$config` and its every usage * Remove redundant `debugStop` code in `android-debug-service` * Raise events in the event of inability to start/stop the app on iOS
1 parent a25fa75 commit f9eb2f9

23 files changed

+307
-238
lines changed

lib/bootstrap.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ $injector.requireCommand("platform|clean", "./commands/platform-clean");
106106

107107
$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service");
108108
$injector.require("liveSyncCommandHelper", "./services/livesync/livesync-command-helper");
109-
$injector.require("debugLiveSyncService", "./services/livesync/debug-livesync-service");
110109
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");
111110
$injector.require("iOSLiveSyncService", "./services/livesync/ios-livesync-service");
112111
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript

lib/commands/debug.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,29 @@ export class DebugPlatformCommand implements ICommand {
1616
protected $logger: ILogger,
1717
protected $errors: IErrors,
1818
private $debugDataService: IDebugDataService,
19-
private $debugLiveSyncService: IDebugLiveSyncService,
20-
private $config: IConfiguration,
19+
private $liveSyncService: IDebugLiveSyncService,
2120
private $prompter: IPrompter,
2221
private $liveSyncCommandHelper: ILiveSyncCommandHelper) {
2322
}
2423

2524
public async execute(args: string[]): Promise<void> {
26-
const debugOptions = this.$options;
25+
const debugOptions = <IDebugOptions>_.cloneDeep(this.$options.argv);
2726

2827
let debugData = this.$debugDataService.createDebugData(this.$projectData, this.$options);
2928

3029
await this.$platformService.trackProjectType(this.$projectData);
31-
3230
const selectedDeviceForDebug = await this.getDeviceForDebug();
3331
debugData.deviceIdentifier = selectedDeviceForDebug.deviceInfo.identifier;
3432

3533
if (this.$options.start) {
36-
return this.$debugLiveSyncService.printDebugInformation(await this.debugService.debug(debugData, debugOptions));
34+
return this.$liveSyncService.printDebugInformation(await this.debugService.debug(debugData, debugOptions));
3735
}
3836

39-
this.$config.debugLivesync = true;
40-
4137
await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this.platform });
4238

43-
await this.$liveSyncCommandHelper.executeLiveSyncOperation([selectedDeviceForDebug], this.$debugLiveSyncService, this.platform);
39+
await this.$liveSyncCommandHelper.executeLiveSyncOperation([selectedDeviceForDebug], this.platform, {
40+
[selectedDeviceForDebug.deviceInfo.identifier]: true
41+
});
4442
}
4543

4644
public async getDeviceForDebug(): Promise<Mobile.IDevice> {
@@ -104,6 +102,10 @@ export class DebugPlatformCommand implements ICommand {
104102
this.$errors.fail(`Applications for platform ${this.platform} can not be built on this OS`);
105103
}
106104

105+
if (this.$options.release) {
106+
this.$errors.fail("--release flag is not applicable to this command");
107+
}
108+
107109
const platformData = this.$platformsData.getPlatformData(this.platform, this.$projectData);
108110
const platformProjectService = platformData.platformProjectService;
109111
await platformProjectService.validate(this.$projectData);

lib/commands/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class RunCommandBase implements ICommand {
5959
await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this.platform });
6060
let devices = this.$devicesService.getDeviceInstances();
6161
devices = devices.filter(d => !this.platform || d.deviceInfo.platform.toLowerCase() === this.platform.toLowerCase());
62-
await this.$liveSyncCommandHelper.executeLiveSyncOperation(devices, this.$liveSyncService, this.platform);
62+
await this.$liveSyncCommandHelper.executeLiveSyncOperation(devices, this.platform);
6363
}
6464
}
6565

lib/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export class Configuration extends ConfigBase implements IConfiguration { // Use
88
TYPESCRIPT_COMPILER_OPTIONS = {};
99
ANDROID_DEBUG_UI: string = null;
1010
USE_POD_SANDBOX: boolean = false;
11-
debugLivesync: boolean = false;
1211

1312
/*don't require logger and everything that has logger as dependency in config.js due to cyclic dependency*/
1413
constructor(protected $fs: IFileSystem) {

lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export const ANGULAR_NAME = "angular";
8585
export const TYPESCRIPT_NAME = "typescript";
8686
export const BUILD_OUTPUT_EVENT_NAME = "buildOutput";
8787
export const CONNECTION_ERROR_EVENT_NAME = "connectionError";
88+
export const USER_INTERACTION_NEEDED_EVENT_NAME = "userInteractionNeeded";
89+
export const DEBUGGER_ATTACHED_EVENT_NAME = "debuggerAttached";
8890
export const VERSION_STRING = "version";
8991
export const INSPECTOR_CACHE_DIRNAME = "ios-inspector";
9092
export const POST_INSTALL_COMMAND_NAME = "post-install-cli";

lib/declarations.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ interface IStaticConfig extends Config.IStaticConfig { }
311311
interface IConfiguration extends Config.IConfig {
312312
ANDROID_DEBUG_UI: string;
313313
USE_POD_SANDBOX: boolean;
314-
debugLivesync: boolean;
315314
}
316315

317316
interface IApplicationPackage {
@@ -405,8 +404,7 @@ interface IDeviceEmulator extends IEmulator, IDeviceIdentifier { }
405404

406405
interface IRunPlatformOptions extends IJustLaunch, IDeviceEmulator { }
407406

408-
interface IDeployPlatformOptions extends IAndroidReleaseOptions, IPlatformTemplate, IRelease, IClean, IDeviceEmulator, IProvision, ITeamIdentifier {
409-
projectDir: string;
407+
interface IDeployPlatformOptions extends IAndroidReleaseOptions, IPlatformTemplate, IRelease, IClean, IDeviceEmulator, IProvision, ITeamIdentifier, IProjectDir {
410408
forceInstall?: boolean;
411409
}
412410

lib/definitions/debug.d.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
/**
22
* Describes information for starting debug process.
33
*/
4-
interface IDebugData {
5-
/**
6-
* Id of the device on which the debug process will be started.
7-
*/
8-
deviceIdentifier: string;
9-
4+
interface IDebugData extends Mobile.IDeviceIdentifier {
105
/**
116
* Application identifier of the app that it will be debugged.
127
*/
@@ -116,13 +111,13 @@ interface IDebugServiceBase extends NodeJS.EventEmitter {
116111
}
117112

118113
interface IDebugService {
119-
getDebugService(device: Mobile.IDevice): IPlatformDebugService;
114+
getDebugService(platform: string): IPlatformDebugService;
120115
}
121116

122117
/**
123118
* Describes actions required for debugging on specific platform (Android or iOS).
124119
*/
125-
interface IPlatformDebugService extends IDebugServiceBase {
120+
interface IPlatformDebugService extends IDebugServiceBase, IPlatform {
126121
/**
127122
* Starts debug operation.
128123
* @param {IDebugData} debugData Describes information for device and application that will be debugged.
@@ -135,10 +130,5 @@ interface IPlatformDebugService extends IDebugServiceBase {
135130
* Stops debug operation.
136131
* @returns {Promise<void>}
137132
*/
138-
debugStop(): Promise<void>
139-
140-
/**
141-
* Mobile platform of the device - Android or iOS.
142-
*/
143-
platform: string;
133+
debugStop(): Promise<void>;
144134
}

lib/definitions/emulator-platform-service.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
interface IEmulatorInfo {
1+
interface IEmulatorInfo extends IPlatform {
22
name: string;
33
version: string;
4-
platform: string;
54
id: string;
65
type: string;
76
isRunning?: boolean;

lib/definitions/livesync.d.ts

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,19 @@ interface ILiveSyncProcessInfo {
6868
currentSyncAction: Promise<any>;
6969
}
7070

71+
interface IOptionalOutputPath {
72+
/**
73+
* Path where the build result is located (directory containing .ipa, .apk or .zip).
74+
* This is required for initial checks where LiveSync will skip the rebuild in case there's already a build result and no change requiring rebuild is made since then.
75+
* In case it is not passed, the default output for local builds will be used.
76+
*/
77+
outputPath?: string;
78+
}
79+
7180
/**
7281
* Describes information for LiveSync on a device.
7382
*/
74-
interface ILiveSyncDeviceInfo {
83+
interface ILiveSyncDeviceInfo extends IOptionalOutputPath {
7584
/**
7685
* Device identifier.
7786
*/
@@ -84,16 +93,14 @@ interface ILiveSyncDeviceInfo {
8493
buildAction: () => Promise<string>;
8594

8695
/**
87-
* Path where the build result is located (directory containing .ipa, .apk or .zip).
88-
* This is required for initial checks where LiveSync will skip the rebuild in case there's already a build result and no change requiring rebuild is made since then.
89-
* In case it is not passed, the default output for local builds will be used.
96+
* Whether to skip preparing the native platform.
9097
*/
91-
outputPath?: string;
98+
skipNativePrepare?: boolean;
9299

93100
/**
94-
* Whether to skip preparing the native platform.
101+
* Whether debugging has been enabled for this device or not
95102
*/
96-
skipNativePrepare?: boolean;
103+
debugggingEnabled?: boolean;
97104

98105
/**
99106
* Describes options specific for each platform, like provision for iOS, target sdk for Android, etc.
@@ -104,12 +111,7 @@ interface ILiveSyncDeviceInfo {
104111
/**
105112
* Describes a LiveSync operation.
106113
*/
107-
interface ILiveSyncInfo {
108-
/**
109-
* Directory of the project that will be synced.
110-
*/
111-
projectDir: string;
112-
114+
interface ILiveSyncInfo extends IProjectDir, IOptionalDebuggingOptions {
113115
/**
114116
* Defines if the watcher should be skipped. If not passed, fs.Watcher will be started.
115117
*/
@@ -135,9 +137,11 @@ interface ILiveSyncInfo {
135137

136138
interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }
137139

138-
interface ILiveSyncBuildInfo {
139-
platform: string;
140+
interface IIsEmulator {
140141
isEmulator: boolean;
142+
}
143+
144+
interface ILiveSyncBuildInfo extends IIsEmulator, IPlatform {
141145
pathToBuildItem: string;
142146
}
143147

@@ -206,6 +210,52 @@ interface IDebugLiveSyncService extends ILiveSyncService {
206210
* @returns {void}
207211
*/
208212
printDebugInformation(information: string): void;
213+
214+
/**
215+
* Enables debugging for a specified device
216+
* @param {IEnableDebuggingDeviceOptions[]} deviceOpts Settings used for enabling debugging for each device.
217+
* @param {IDebuggingAdditionalOptions} enableDebuggingOptions Settings used for enabling debugging.
218+
* @returns {Promise<void>[]}
219+
*/
220+
enableDebugging(deviceOpts: IEnableDebuggingDeviceOptions[], enableDebuggingOptions: IDebuggingAdditionalOptions): Promise<void>[];
221+
}
222+
223+
/**
224+
* Describes additional debugging settings.
225+
*/
226+
interface IDebuggingAdditionalOptions extends IProjectDir { }
227+
228+
/**
229+
* Describes settings used when disabling debugging.
230+
*/
231+
interface IDisableDebuggingDeviceOptions extends Mobile.IDeviceIdentifier { }
232+
233+
interface IOptionalDebuggingOptions {
234+
/**
235+
* Optional debug options - can be used to control the start of a debug process.
236+
*/
237+
debugOptions?: IDebugOptions;
238+
}
239+
240+
/**
241+
* Describes settings used when enabling debugging.
242+
*/
243+
interface IEnableDebuggingDeviceOptions extends Mobile.IDeviceIdentifier, IOptionalDebuggingOptions { }
244+
245+
/**
246+
* Describes settings passed to livesync service in order to control event emitting during refresh application.
247+
*/
248+
interface IShouldSkipEmitLiveSyncNotification {
249+
/**
250+
* Whether to skip emitting an event during refresh. Default is false.
251+
*/
252+
shouldSkipEmitLiveSyncNotification: boolean;
253+
}
254+
255+
/**
256+
* Describes settings used for attaching a debugger.
257+
*/
258+
interface IAttachDebuggerOptions extends IDebuggingAdditionalOptions, IEnableDebuggingDeviceOptions, IIsEmulator, IPlatform, IOptionalOutputPath {
209259
}
210260

211261
interface ILiveSyncWatchInfo {
@@ -284,10 +334,10 @@ interface ILiveSyncCommandHelper {
284334
/**
285335
* Method sets up configuration, before calling livesync and expects that devices are already discovered.
286336
* @param {Mobile.IDevice[]} devices List of discovered devices
287-
* @param {ILiveSyncService} liveSyncService Service expected to do the actual livesyncing
288337
* @param {string} platform The platform for which the livesync will be ran
338+
* @param {IDictionary<boolean>} deviceDebugMap @optional A map representing devices which have debugging enabled initially.
289339
* @returns {Promise<void>}
290340
*/
291-
executeLiveSyncOperation(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void>;
341+
executeLiveSyncOperation(devices: Mobile.IDevice[], platform: string, deviceDebugMap?: IDictionary<boolean>): Promise<void>;
292342
getPlatformsForOperation(platform: string): string[];
293343
}

0 commit comments

Comments
 (0)