Skip to content

Commit 2f3878d

Browse files
authored
Plamen5kov/move emulate to run (#2647)
* run command uses startEmulatorIfNecessary updated submodule * happy path for android * added comments * fixed tests * fixed emulator by index * call start simulator with id updated docs remove commet removed comment updated submodule added message depricating the emulate command removed tns devices file and added option available-devices to common lib updated docs updated submodule returned starting of emulators to device-service to keep general behavior for all commands using the device updated submodule (reverted tests/refactoring after review) updated submodule (renamings/typo) update submodule (refactoring after review) * update submodule (move functionality to master)
1 parent 3ca6474 commit 2f3878d

File tree

9 files changed

+33
-54
lines changed

9 files changed

+33
-54
lines changed

docs/man_pages/project/testing/run-android.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ run android
44
Usage | Synopsis
55
---|---
66
Run on all connected devices and running emulators | `$ tns run android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
7-
Run on a selected connected device or running emulator | `$ tns run android --device <Device ID> [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
8-
Start an emulator and run the app inside it | `$ tns run android --emulator [<Emulator Options>] [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
7+
Run on a selected connected device or running emulator. Will start emulator with specified `Device Identifier`, if not already running. | `$ tns run android --device <Device ID> [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
8+
Start a default emulator if none are running, or run application on all connected emulators. | `$ tns run android --emulator [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
99

1010
Runs your project on a connected Android device or in a native Android emulator, if configured. This is shorthand for prepare, build and deploy. While your app is running, prints the output from the application in the console and watches for changes in your code. Once a change is detected, it synchronizes the change with all selected devices and restarts/refreshes the application.
1111

1212
### Options
13+
* `--available-devices` - Shows a list of available emulators to be started and a list of already connected devices.
14+
* `--device` - Specifies a connected device/emulator to start and run the app.
15+
* `--emulator` - If set, runs the app in all available and configured android emulators. It will start an emulator if none are already running.
16+
* `--justlaunch` - If set, does not print the application output in the console.
17+
* `--clean` - If set, forces rebuilding the native application.
1318
* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command.
14-
* `--device` - Specifies a connected device/emulator on which to run the app.
15-
* `--emulator` - If set, runs the app in a native emulator for the target platform, if configured. When set, you can also set any other valid combination of emulator options as listed by `$ tns help emulate android`.
1619
* `--release` - If set, produces a release build. Otherwise, produces a debug build. When set, you must also specify the `--key-store-*` options.
1720
* `--key-store-path` - Specifies the file path to the keystore file (P12) which you want to use to code sign your APK. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1821
* `--key-store-password` - Provides the password for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1922
* `--key-store-alias` - Provides the alias for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
2023
* `--key-store-alias-password` - Provides the password for the alias specified with `--key-store-alias-password`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
21-
* `--justlaunch` - If set, does not print the application output in the console.
22-
* `--clean` - If set, forces rebuilding the native application.
2324

2425
### Attributes
25-
* `<Device ID>` is the index or name of the target device as listed by `$ tns device android`
26-
* `<Emulator Options>` is any valid combination of options as listed by `$ tns help emulate android`
26+
* `<Device ID>` is the index or `Device Identifier` of the target device as listed by `$ tns run android --available-devices`
2727

2828
<% if(isHtml) { %>
2929
### Prerequisites:
@@ -57,4 +57,4 @@ Command | Description
5757
[test init](test-init.html) | Configures your project for unit testing with a selected framework.
5858
[test android](test-android.html) | Runs the tests in your project on Android devices or native emulators.
5959
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
60-
<% } %>
60+
<% } %>

docs/man_pages/project/testing/run-ios.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ run ios
44
Usage | Synopsis
55
---|---
66
Run on all connected devices | `$ tns run ios [--release] [--justlaunch]`
7-
Run on a selected connected device | `$ tns run ios [--device <Device ID>] [--release] [--justlaunch]`
8-
Start an emulator and run the app inside it | `$ tns run ios --emulator [<Emulator Options>] [--release]`
7+
Run on a selected connected device. Will start simulator with specified `Device Identifier`, if not already running. | `$ tns run ios [--device <Device ID>] [--release] [--justlaunch]`
8+
Start an emulator and run the app inside it | `$ tns run ios --emulator [--release]`
99

1010
Runs your project on a connected iOS device or in the iOS Simulator, if configured. This is shorthand for prepare, build and deploy. While your app is running, prints the output from the application in the console and watches for changes in your code. Once a change is detected, it synchronizes the change with all selected devices and restarts/refreshes the application.
1111

@@ -14,16 +14,16 @@ Runs your project on a connected iOS device or in the iOS Simulator, if configur
1414
<% if(isHtml) { %>> <% } %>IMPORTANT: Before building for iOS device, verify that you have configured a valid pair of certificate and provisioning profile on your OS X system. <% if(isHtml) { %>For more information, see [Obtaining Signing Identities and Downloading Provisioning Profiles](https://developer.apple.com/library/mac/recipes/xcode_help-accounts_preferences/articles/obtain_certificates_and_provisioning_profiles.html).<% } %>
1515

1616
### Options
17-
* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command.
18-
* `--device` - Specifies a connected device on which to run the app.
19-
* `--emulator` - If set, runs the app in a native emulator for the target platform, if configured. When set, you can also set any other valid combination of emulator options as listed by `$ tns help emulate ios`. You cannot use `--device` and `--emulator` simultaneously.
20-
* `--release` - If set, produces a release build. Otherwise, produces a debug build.
17+
* `--available-devices` - Shows a list of available simulators to be started and a list of already connected devices.
18+
* `--device` - Specifies a connected device/simulator to start and run the app.
19+
* `--emulator` - If set, runs the app in all available and configured ios simulators. It will start a simulator if none are already running.
2120
* `--justlaunch` - If set, does not print the application output in the console.
2221
* `--clean` - If set, forces rebuilding the native application.
22+
* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command.
23+
* `--release` - If set, produces a release build. Otherwise, produces a debug build.
2324

2425
### Attributes
25-
* `<Device ID>` is the index or name of the target device as listed by `$ tns device ios`
26-
* `<Emulator Options>` is any valid combination of options as listed by `$ tns help emulate ios`
26+
* `<Device ID>` is the index or `Device Identifier` of the target device as listed by `$ tns run ios --available-devices`
2727
<% } %>
2828
<% if(isHtml) { %>
2929
### Prerequisites
@@ -56,4 +56,4 @@ Command | Description
5656
[test init](test-init.html) | Configures your project for unit testing with a selected framework.
5757
[test android](test-android.html) | Runs the tests in your project on Android devices or native emulators.
5858
[test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator.
59-
<% } %>
59+
<% } %>

lib/bootstrap.ts

-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ $injector.require("iOSSocketRequestExecutor", "./device-sockets/ios/socket-reque
115115
$injector.require("messages", "./common/messages/messages");
116116
$injector.require("xmlValidator", "./xml-validator");
117117

118-
$injector.requireCommand("devices", "./commands/devices");
119118
$injector.requireCommand("post-install-cli", "./commands/post-install");
120119
$injector.requireCommand("update", "./commands/update");
121120

lib/commands/devices.ts

-17
This file was deleted.

lib/commands/emulate.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export class EmulateCommandBase {
22
constructor(private $options: IOptions,
33
private $projectData: IProjectData,
4+
private $logger: ILogger,
45
private $platformService: IPlatformService) {
56
this.$projectData.initializeProjectData();
67
}
78

89
public async executeCore(args: string[]): Promise<void> {
10+
this.$logger.warn(`Emulate command is deprecated and will soon be removed. Please use "tns run <platform>" instead. All options available for emulate are present in "tns run" command.`);
911
this.$options.emulator = true;
1012
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
1113
const emulateOptions: IEmulatePlatformOptions = {
@@ -34,9 +36,10 @@ export class EmulateIosCommand extends EmulateCommandBase implements ICommand {
3436

3537
constructor($options: IOptions,
3638
$projectData: IProjectData,
39+
$logger: ILogger,
3740
$platformService: IPlatformService,
3841
private $platformsData: IPlatformsData) {
39-
super($options, $projectData, $platformService);
42+
super($options, $projectData, $logger, $platformService);
4043
}
4144

4245
public async execute(args: string[]): Promise<void> {
@@ -49,9 +52,10 @@ $injector.registerCommand("emulate|ios", EmulateIosCommand);
4952
export class EmulateAndroidCommand extends EmulateCommandBase implements ICommand {
5053
constructor($options: IOptions,
5154
$projectData: IProjectData,
55+
$logger: ILogger,
5256
$platformService: IPlatformService,
5357
private $platformsData: IPlatformsData) {
54-
super($options, $projectData, $platformService);
58+
super($options, $projectData, $logger, $platformService);
5559
}
5660

5761
public allowedParameters: ICommandParameter[] = [];

lib/commands/run.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@ export class RunCommandBase {
33
protected $usbLiveSyncService: ILiveSyncService,
44
protected $projectData: IProjectData,
55
protected $options: IOptions,
6-
protected $emulatorPlatformService: IEmulatorPlatformService,
7-
private $mobileHelper: Mobile.IMobileHelper) {
6+
protected $emulatorPlatformService: IEmulatorPlatformService) {
87
this.$projectData.initializeProjectData();
98
}
109

1110
public async executeCore(args: string[]): Promise<void> {
1211

13-
if (this.$options.availableDevices) {
14-
return this.$emulatorPlatformService.listAvailableEmulators(this.$mobileHelper.validatePlatformName(args[0]));
15-
}
16-
1712
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
1813
const deployOptions: IDeployPlatformOptions = {
1914
clean: this.$options.clean,
@@ -58,9 +53,8 @@ export class RunIosCommand extends RunCommandBase implements ICommand {
5853
$usbLiveSyncService: ILiveSyncService,
5954
$projectData: IProjectData,
6055
$options: IOptions,
61-
$emulatorPlatformService: IEmulatorPlatformService,
62-
$mobileHelper: Mobile.IMobileHelper) {
63-
super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService, $mobileHelper);
56+
$emulatorPlatformService: IEmulatorPlatformService) {
57+
super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService);
6458
}
6559

6660
public async execute(args: string[]): Promise<void> {
@@ -83,9 +77,8 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand {
8377
$projectData: IProjectData,
8478
$options: IOptions,
8579
$emulatorPlatformService: IEmulatorPlatformService,
86-
$mobileHelper: Mobile.IMobileHelper,
8780
private $errors: IErrors) {
88-
super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService, $mobileHelper);
81+
super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService);
8982
}
9083

9184
public async execute(args: string[]): Promise<void> {

lib/services/emulator-platform-service.ts

-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ export class EmulatorPlatformService implements IEmulatorPlatformService {
115115
}
116116

117117
this.outputEmulators("\nAvailable emulators", emulators);
118-
this.$logger.out("\nConnected devices & emulators");
119-
await $injector.resolveCommand("device").execute(platform ? [platform] : []);
120118
}
121119

122120
public async getiOSEmulators(): Promise<IEmulatorInfo[]> {

lib/services/platform-service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
452452

453453
public async deployPlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, deployOptions: IDeployPlatformOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void> {
454454
await this.preparePlatform(platform, appFilesUpdaterOptions, deployOptions.platformTemplate, projectData, platformSpecificData);
455-
this.$logger.out("Searching for devices...");
456-
await this.$devicesService.initialize({ platform: platform, deviceId: deployOptions.device });
455+
let options: Mobile.IDevicesServicesInitializationOptions = {
456+
platform: platform, deviceId: deployOptions.device, emulator: deployOptions.emulator
457+
};
458+
await this.$devicesService.initialize(options);
457459
let action = async (device: Mobile.IDevice): Promise<void> => {
458460
let buildConfig: IBuildConfig = {
459461
buildForDevice: !this.$devicesService.isiOSSimulator(device),

0 commit comments

Comments
 (0)