diff --git a/lib/common/commands/device/get-file.ts b/lib/common/commands/device/get-file.ts index e9e69f3612..1b46ae267e 100644 --- a/lib/common/commands/device/get-file.ts +++ b/lib/common/commands/device/get-file.ts @@ -1,7 +1,7 @@ export class GetFileCommand implements ICommand { constructor(private $devicesService: Mobile.IDevicesService, private $stringParameter: ICommandParameter, - private $project: Project.IProjectBase, + private $projectData: IProjectData, private $errors: IErrors, private $options: IOptions) { } @@ -11,13 +11,21 @@ export class GetFileCommand implements ICommand { await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true }); let appIdentifier = args[1]; - if (!appIdentifier && !this.$project.projectData) { - this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project."); + if (!appIdentifier) { + try { + this.$projectData.initializeProjectData(); + } catch (err) { + // ignore the error + } + if (!this.$projectData.projectIdentifiers) { + this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project."); + } } - appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier; - - const action = (device: Mobile.IDevice) => device.fileSystem.getFile(args[0], appIdentifier, this.$options.file); + const action = async (device: Mobile.IDevice) => { + appIdentifier = appIdentifier || this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()]; + await device.fileSystem.getFile(args[0], appIdentifier, this.$options.file); + }; await this.$devicesService.execute(action); } } diff --git a/lib/common/commands/device/list-files.ts b/lib/common/commands/device/list-files.ts index f3b3707da9..0e4ea0042a 100644 --- a/lib/common/commands/device/list-files.ts +++ b/lib/common/commands/device/list-files.ts @@ -2,7 +2,7 @@ export class ListFilesCommand implements ICommand { constructor(private $devicesService: Mobile.IDevicesService, private $stringParameter: ICommandParameter, private $options: IOptions, - private $project: Project.IProjectBase, + private $projectData: IProjectData, private $errors: IErrors) { } public allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter]; @@ -12,13 +12,21 @@ export class ListFilesCommand implements ICommand { const pathToList = args[0]; let appIdentifier = args[1]; - if (!appIdentifier && !this.$project.projectData) { - this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project."); + if (!appIdentifier) { + try { + this.$projectData.initializeProjectData(); + } catch (err) { + // ignore the error + } + if (!this.$projectData.projectIdentifiers) { + this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project."); + } } - appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier; - - const action = (device: Mobile.IDevice) => device.fileSystem.listFiles(pathToList, appIdentifier); + const action = async (device: Mobile.IDevice) => { + appIdentifier = appIdentifier || this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()]; + await device.fileSystem.listFiles(pathToList, appIdentifier); + }; await this.$devicesService.execute(action); } } diff --git a/lib/common/commands/device/put-file.ts b/lib/common/commands/device/put-file.ts index c65343d44b..0323c9b993 100644 --- a/lib/common/commands/device/put-file.ts +++ b/lib/common/commands/device/put-file.ts @@ -2,7 +2,7 @@ export class PutFileCommand implements ICommand { constructor(private $devicesService: Mobile.IDevicesService, private $stringParameter: ICommandParameter, private $options: IOptions, - private $project: Project.IProjectBase, + private $projectData: IProjectData, private $errors: IErrors) { } allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter, this.$stringParameter]; @@ -11,12 +11,21 @@ export class PutFileCommand implements ICommand { await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true }); let appIdentifier = args[2]; - if (!appIdentifier && !this.$project.projectData) { - this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project."); + if (!appIdentifier) { + try { + this.$projectData.initializeProjectData(); + } catch (err) { + // ignore the error + } + if (!this.$projectData.projectIdentifiers) { + this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project."); + } } - appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier; - const action = (device: Mobile.IDevice) => device.fileSystem.putFile(args[0], args[1], appIdentifier); + const action = async (device: Mobile.IDevice) => { + appIdentifier = appIdentifier || this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()]; + await device.fileSystem.putFile(args[0], args[1], appIdentifier); + }; await this.$devicesService.execute(action); } }