-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlist-devices.ts
92 lines (73 loc) · 3.66 KB
/
list-devices.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { createTable, formatListOfNames } from "../../helpers";
export class ListDevicesCommand implements ICommand {
constructor(private $devicesService: Mobile.IDevicesService,
private $errors: IErrors,
private $emulatorHelper: Mobile.IEmulatorHelper,
private $logger: ILogger,
private $stringParameter: ICommandParameter,
private $mobileHelper: Mobile.IMobileHelper,
private $options: IOptions) { }
public allowedParameters = [this.$stringParameter];
public async execute(args: string[]): Promise<void> {
if (this.$options.availableDevices) {
const platform = this.$mobileHelper.normalizePlatformName(args[0]);
if (!platform && args[0]) {
this.$errors.failWithoutHelp(`${args[0]} is not a valid device platform. The valid platforms are ${formatListOfNames(this.$mobileHelper.platformNames)}`);
}
const availableEmulatorsOutput = await this.$devicesService.getEmulatorImages({ platform });
const emulators = this.$emulatorHelper.getEmulatorsFromAvailableEmulatorsOutput(availableEmulatorsOutput);
this.printEmulators("\nAvailable emulators", emulators);
}
this.$logger.info("\nConnected devices & emulators");
let index = 1;
await this.$devicesService.initialize({ platform: args[0], deviceId: null, skipInferPlatform: true, skipDeviceDetectionInterval: true, skipEmulatorStart: true });
const table: any = createTable(["#", "Device Name", "Platform", "Device Identifier", "Type", "Status"], []);
let action: (_device: Mobile.IDevice) => Promise<void>;
if (this.$options.json) {
action = async (device) => {
this.$logger.info(JSON.stringify(device.deviceInfo));
};
} else {
action = async (device) => {
table.push([(index++).toString(), device.deviceInfo.displayName || '',
device.deviceInfo.platform || '', device.deviceInfo.identifier || '',
device.deviceInfo.type || '', device.deviceInfo.status || '']);
};
}
await this.$devicesService.execute(action, undefined, { allowNoDevices: true });
if (!this.$options.json && table.length) {
this.$logger.info(table.toString());
}
}
private printEmulators(title: string, emulators: Mobile.IDeviceInfo[]) {
this.$logger.info(title);
const table: any = createTable(["Device Name", "Platform", "Version", "Device Identifier", "Image Identifier", "Error Help"], []);
for (const info of emulators) {
table.push([info.displayName, info.platform, info.version, info.identifier || "", info.imageIdentifier || "", info.errorHelp || ""]);
}
this.$logger.info(table.toString());
}
}
$injector.registerCommand(["device|*list", "devices|*list"], ListDevicesCommand);
class ListAndroidDevicesCommand implements ICommand {
constructor(private $injector: IInjector,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) { }
public allowedParameters: ICommandParameter[] = [];
public async execute(args: string[]): Promise<void> {
const listDevicesCommand: ICommand = this.$injector.resolve(ListDevicesCommand);
const platform = this.$devicePlatformsConstants.Android;
await listDevicesCommand.execute([platform]);
}
}
$injector.registerCommand(["device|android", "devices|android"], ListAndroidDevicesCommand);
class ListiOSDevicesCommand implements ICommand {
constructor(private $injector: IInjector,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) { }
public allowedParameters: ICommandParameter[] = [];
public async execute(args: string[]): Promise<void> {
const listDevicesCommand: ICommand = this.$injector.resolve(ListDevicesCommand);
const platform = this.$devicePlatformsConstants.iOS;
await listDevicesCommand.execute([platform]);
}
}
$injector.registerCommand(["device|ios", "devices|ios"], ListiOSDevicesCommand);