Skip to content

Commit 27b4c22

Browse files
committed
Fix PR comments + refactoring
1 parent 6ce1cd8 commit 27b4c22

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

PublicAPI.md

+42
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const tns = require("nativescript");
5353
* [sysInfo](#sysinfo)
5454
* [getSupportedNodeVersionRange](#getsupportednodeversionrange)
5555
* [getSystemWarnings](#getsystemwarnings)
56+
* [devicesService](#devicesService)
57+
* [getAvailableEmulators](#getAvailableEmulators)
58+
* [startEmulator](#startEmulator)
5659

5760
## Module projectService
5861

@@ -1198,6 +1201,45 @@ tns.sysInfo.getSystemWarnings()
11981201
.catch(err => console.error(`Error while trying to get system warnings: ${err}`));
11991202
```
12001203
1204+
## devicesService
1205+
The `devicesService` module allows interaction with devices and emulators. You can get a list of the available emulators or start a specific emulator.
1206+
1207+
### getAvailableEmulators
1208+
The `getAvailableEmulators` method returns object of all running and available emulators. The result is in the following format:
1209+
```JavaScript
1210+
{
1211+
android: {
1212+
devices: Mobile.IDeviceInfo[],
1213+
errors: string[]
1214+
},
1215+
ios: {
1216+
devices: Mobile.IDeviceInfo[],
1217+
errors: string[]
1218+
}
1219+
}
1220+
```
1221+
1222+
This method accepts platform parameter. If provided only devices by specified platform will be returned.
1223+
1224+
* Usage
1225+
```TypeScript
1226+
tns.devicesService.getAvailableEmulators()
1227+
.then(availableEmulatorsOutput => {
1228+
Object.keys(availableEmulatorsOutput)
1229+
.forEach(platform => {
1230+
availableEmulatorsOutput[platform].devices.forEach(device => console.log(device));
1231+
})
1232+
})
1233+
```
1234+
1235+
### startEmulator
1236+
The `startEmulator` method starts the emulator specified by provided options. Returns an array of errors if something unexpected happens or null otherwise.
1237+
* Usage
1238+
```TypeScript
1239+
tns.devicesService.startEmulator({imageIdentifier: "my emulator imageIdentifier"})
1240+
.then(errors => { });
1241+
```
1242+
12011243
## How to add a new method to Public API
12021244
CLI is designed as command line tool and when it is used as a library, it does not give you access to all of the methods. This is mainly implementation detail. Most of the CLI's code is created to work in command line, not as a library, so before adding method to public API, most probably it will require some modification.
12031245
For example the `$options` injected module contains information about all `--` options passed on the terminal. When the CLI is used as a library, the options are not populated. Before adding method to public API, make sure its implementation does not rely on `$options`.

lib/common

lib/definitions/debug.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ interface IDebugOptions {
9191
* If not provided, defaults to 10 seconds.
9292
*/
9393
timeout?: string;
94+
/**
95+
* The sdk version of the emulator.
96+
*/
9497
sdk?: string;
9598
}
9699

test/platform-service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ describe('Platform Service Tests', () => {
258258
return {
259259
frameworkPackageName: packageName,
260260
platformProjectService: new stubs.PlatformProjectServiceStub(),
261-
emulatorServices: undefined,
262261
projectRoot: "",
263262
normalizedPlatformName: "",
264263
appDestinationDirectoryPath: "",

test/stubs.ts

-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ export class InjectorStub extends Yok implements IInjector {
835835
this.register("hooksService", HooksServiceStub);
836836
this.register('projectDataService', ProjectDataService);
837837
this.register('devicePlatformsConstants', DevicePlatformsConstants);
838-
this.register("emulatorPlatformService", EmulatorPlatformService);
839838
this.register("androidResourcesMigrationService", AndroidResourcesMigrationServiceStub);
840839
this.register("platformService", PlatformServiceStub);
841840
this.register("commandsService", CommandsService);

0 commit comments

Comments
 (0)