From 607e642a09edf002e15907675c558daa43c66429 Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Wed, 22 Mar 2017 09:05:27 +0200 Subject: [PATCH 1/2] 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) --- docs/man_pages/project/testing/run-android.md | 18 +++++++++--------- docs/man_pages/project/testing/run-ios.md | 18 +++++++++--------- lib/bootstrap.ts | 1 - lib/commands/devices.ts | 17 ----------------- lib/commands/emulate.ts | 8 ++++++-- lib/commands/run.ts | 15 ++++----------- lib/common | 2 +- lib/services/emulator-platform-service.ts | 2 -- lib/services/platform-service.ts | 6 ++++-- 9 files changed, 33 insertions(+), 54 deletions(-) delete mode 100644 lib/commands/devices.ts diff --git a/docs/man_pages/project/testing/run-android.md b/docs/man_pages/project/testing/run-android.md index 68172a9ffc..01fe8bcadc 100644 --- a/docs/man_pages/project/testing/run-android.md +++ b/docs/man_pages/project/testing/run-android.md @@ -4,26 +4,26 @@ run android Usage | Synopsis ---|--- Run on all connected devices and running emulators | `$ tns run android [--key-store-path --key-store-password --key-store-alias --key-store-alias-password ] [--release] [--justlaunch]` -Run on a selected connected device or running emulator | `$ tns run android --device [--key-store-path --key-store-password --key-store-alias --key-store-alias-password ] [--release] [--justlaunch]` -Start an emulator and run the app inside it | `$ tns run android --emulator [] [--key-store-path --key-store-password --key-store-alias --key-store-alias-password ] [--release] [--justlaunch]` +Run on a selected connected device or running emulator. Will start emulator with specified `Device Identifier`, if not already running. | `$ tns run android --device [--key-store-path --key-store-password --key-store-alias --key-store-alias-password ] [--release] [--justlaunch]` +Start a default emulator if none are running, or run application on all connected emulators. | `$ tns run android --emulator [--key-store-path --key-store-password --key-store-alias --key-store-alias-password ] [--release] [--justlaunch]` 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. ### Options +* `--available-devices` - Shows a list of available emulators to be started and a list of already connected devices. +* `--device` - Specifies a connected device/emulator to start and run the app. +* `--emulator` - If set, runs the app in all available and configured android emulators. It will start an emulator if none are already running. +* `--justlaunch` - If set, does not print the application output in the console. +* `--clean` - If set, forces rebuilding the native application. * `--no-watch` - If set, changes in your code will not be reflected during the execution of this command. -* `--device` - Specifies a connected device/emulator on which to run the app. -* `--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`. * `--release` - If set, produces a release build. Otherwise, produces a debug build. When set, you must also specify the `--key-store-*` options. * `--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. * `--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. * `--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. * `--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. -* `--justlaunch` - If set, does not print the application output in the console. -* `--clean` - If set, forces rebuilding the native application. ### Attributes -* `` is the index or name of the target device as listed by `$ tns device android` -* `` is any valid combination of options as listed by `$ tns help emulate android` +* `` is the index or `Device Identifier` of the target device as listed by `$ tns run android --available-devices` <% if(isHtml) { %> ### Prerequisites: @@ -57,4 +57,4 @@ Command | Description [test init](test-init.html) | Configures your project for unit testing with a selected framework. [test android](test-android.html) | Runs the tests in your project on Android devices or native emulators. [test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator. -<% } %> \ No newline at end of file +<% } %> diff --git a/docs/man_pages/project/testing/run-ios.md b/docs/man_pages/project/testing/run-ios.md index 49503d47ef..637dbb020d 100644 --- a/docs/man_pages/project/testing/run-ios.md +++ b/docs/man_pages/project/testing/run-ios.md @@ -4,8 +4,8 @@ run ios Usage | Synopsis ---|--- Run on all connected devices | `$ tns run ios [--release] [--justlaunch]` -Run on a selected connected device | `$ tns run ios [--device ] [--release] [--justlaunch]` -Start an emulator and run the app inside it | `$ tns run ios --emulator [] [--release]` +Run on a selected connected device. Will start simulator with specified `Device Identifier`, if not already running. | `$ tns run ios [--device ] [--release] [--justlaunch]` +Start an emulator and run the app inside it | `$ tns run ios --emulator [--release]` 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. @@ -14,16 +14,16 @@ Runs your project on a connected iOS device or in the iOS Simulator, if configur <% 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).<% } %> ### Options -* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command. -* `--device` - Specifies a connected device on which to run the app. -* `--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. -* `--release` - If set, produces a release build. Otherwise, produces a debug build. +* `--available-devices` - Shows a list of available simulators to be started and a list of already connected devices. +* `--device` - Specifies a connected device/simulator to start and run the app. +* `--emulator` - If set, runs the app in all available and configured ios simulators. It will start a simulator if none are already running. * `--justlaunch` - If set, does not print the application output in the console. * `--clean` - If set, forces rebuilding the native application. +* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command. +* `--release` - If set, produces a release build. Otherwise, produces a debug build. ### Attributes -* `` is the index or name of the target device as listed by `$ tns device ios` -* `` is any valid combination of options as listed by `$ tns help emulate ios` +* `` is the index or `Device Identifier` of the target device as listed by `$ tns run ios --available-devices` <% } %> <% if(isHtml) { %> ### Prerequisites @@ -56,4 +56,4 @@ Command | Description [test init](test-init.html) | Configures your project for unit testing with a selected framework. [test android](test-android.html) | Runs the tests in your project on Android devices or native emulators. [test ios](test-ios.html) | Runs the tests in your project on iOS devices or the iOS Simulator. -<% } %> \ No newline at end of file +<% } %> diff --git a/lib/bootstrap.ts b/lib/bootstrap.ts index 94edf302dd..9b2f649c9f 100644 --- a/lib/bootstrap.ts +++ b/lib/bootstrap.ts @@ -115,7 +115,6 @@ $injector.require("iOSSocketRequestExecutor", "./device-sockets/ios/socket-reque $injector.require("messages", "./common/messages/messages"); $injector.require("xmlValidator", "./xml-validator"); -$injector.requireCommand("devices", "./commands/devices"); $injector.requireCommand("post-install-cli", "./commands/post-install"); $injector.requireCommand("update", "./commands/update"); diff --git a/lib/commands/devices.ts b/lib/commands/devices.ts deleted file mode 100644 index a67704572b..0000000000 --- a/lib/commands/devices.ts +++ /dev/null @@ -1,17 +0,0 @@ -export class DevicesCommand implements ICommand { - public allowedParameters: ICommandParameter[] = [this.$stringParameter]; - - constructor( - private $stringParameter: ICommandParameter, - private $emulatorPlatformService: IEmulatorPlatformService, - private $options: IOptions) {} - - public async execute(args: string[]): Promise { - if (this.$options.availableDevices) { - return this.$emulatorPlatformService.listAvailableEmulators(args[0]); - } - return $injector.resolveCommand("device").execute(args); - } -} - -$injector.registerCommand("devices", DevicesCommand); diff --git a/lib/commands/emulate.ts b/lib/commands/emulate.ts index 368bacc9f7..214f43bb6a 100644 --- a/lib/commands/emulate.ts +++ b/lib/commands/emulate.ts @@ -1,11 +1,13 @@ export class EmulateCommandBase { constructor(private $options: IOptions, private $projectData: IProjectData, + private $logger: ILogger, private $platformService: IPlatformService) { this.$projectData.initializeProjectData(); } public async executeCore(args: string[]): Promise { + this.$logger.warn(`Emulate command is deprecated and will soon be removed. Please use "tns run " instead. All options available for emulate are present in "tns run" command.`); this.$options.emulator = true; const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release }; const emulateOptions: IEmulatePlatformOptions = { @@ -34,9 +36,10 @@ export class EmulateIosCommand extends EmulateCommandBase implements ICommand { constructor($options: IOptions, $projectData: IProjectData, + $logger: ILogger, $platformService: IPlatformService, private $platformsData: IPlatformsData) { - super($options, $projectData, $platformService); + super($options, $projectData, $logger, $platformService); } public async execute(args: string[]): Promise { @@ -49,9 +52,10 @@ $injector.registerCommand("emulate|ios", EmulateIosCommand); export class EmulateAndroidCommand extends EmulateCommandBase implements ICommand { constructor($options: IOptions, $projectData: IProjectData, + $logger: ILogger, $platformService: IPlatformService, private $platformsData: IPlatformsData) { - super($options, $projectData, $platformService); + super($options, $projectData, $logger, $platformService); } public allowedParameters: ICommandParameter[] = []; diff --git a/lib/commands/run.ts b/lib/commands/run.ts index 3c9bd6f6da..087abf72be 100644 --- a/lib/commands/run.ts +++ b/lib/commands/run.ts @@ -3,17 +3,12 @@ export class RunCommandBase { protected $usbLiveSyncService: ILiveSyncService, protected $projectData: IProjectData, protected $options: IOptions, - protected $emulatorPlatformService: IEmulatorPlatformService, - private $mobileHelper: Mobile.IMobileHelper) { + protected $emulatorPlatformService: IEmulatorPlatformService) { this.$projectData.initializeProjectData(); } public async executeCore(args: string[]): Promise { - if (this.$options.availableDevices) { - return this.$emulatorPlatformService.listAvailableEmulators(this.$mobileHelper.validatePlatformName(args[0])); - } - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release }; const deployOptions: IDeployPlatformOptions = { clean: this.$options.clean, @@ -58,9 +53,8 @@ export class RunIosCommand extends RunCommandBase implements ICommand { $usbLiveSyncService: ILiveSyncService, $projectData: IProjectData, $options: IOptions, - $emulatorPlatformService: IEmulatorPlatformService, - $mobileHelper: Mobile.IMobileHelper) { - super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService, $mobileHelper); + $emulatorPlatformService: IEmulatorPlatformService) { + super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService); } public async execute(args: string[]): Promise { @@ -83,9 +77,8 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand { $projectData: IProjectData, $options: IOptions, $emulatorPlatformService: IEmulatorPlatformService, - $mobileHelper: Mobile.IMobileHelper, private $errors: IErrors) { - super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService, $mobileHelper); + super($platformService, $usbLiveSyncService, $projectData, $options, $emulatorPlatformService); } public async execute(args: string[]): Promise { diff --git a/lib/common b/lib/common index 29dbbeb4a3..363a40e3db 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 29dbbeb4a3dcebe3de8d7bc30f29096deeb57519 +Subproject commit 363a40e3db862bfb98c00242a21a602a9237dde4 diff --git a/lib/services/emulator-platform-service.ts b/lib/services/emulator-platform-service.ts index e414651d16..6bcd24de6f 100644 --- a/lib/services/emulator-platform-service.ts +++ b/lib/services/emulator-platform-service.ts @@ -115,8 +115,6 @@ export class EmulatorPlatformService implements IEmulatorPlatformService { } this.outputEmulators("\nAvailable emulators", emulators); - this.$logger.out("\nConnected devices & emulators"); - await $injector.resolveCommand("device").execute(platform ? [platform] : []); } public async getiOSEmulators(): Promise { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 841175a125..1111b38345 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -452,8 +452,10 @@ export class PlatformService extends EventEmitter implements IPlatformService { public async deployPlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, deployOptions: IDeployPlatformOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise { await this.preparePlatform(platform, appFilesUpdaterOptions, deployOptions.platformTemplate, projectData, platformSpecificData); - this.$logger.out("Searching for devices..."); - await this.$devicesService.initialize({ platform: platform, deviceId: deployOptions.device }); + let options: Mobile.IDevicesServicesInitializationOptions = { + platform: platform, deviceId: deployOptions.device, emulator: deployOptions.emulator + }; + await this.$devicesService.initialize(options); let action = async (device: Mobile.IDevice): Promise => { let buildConfig: IBuildConfig = { buildForDevice: !this.$devicesService.isiOSSimulator(device), From b7ea4fdc81318080e7b1ce5b568c70915f89295a Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Tue, 28 Mar 2017 11:53:21 +0300 Subject: [PATCH 2/2] update submodule (move functionality to master) --- lib/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common b/lib/common index 363a40e3db..11415a5b1c 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 363a40e3db862bfb98c00242a21a602a9237dde4 +Subproject commit 11415a5b1c13aa4fcbde25911706fd8569954698