From 54435dce01198f0159a499622a54de904a763c09 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 9 Jan 2019 09:32:52 +0200 Subject: [PATCH 1/2] fix: fix get-file and list-files commands --- lib/common/commands/device/get-file.ts | 16 ++++++++++------ lib/common/commands/device/list-files.ts | 16 ++++++++++------ lib/common/commands/device/put-file.ts | 15 ++++++++++----- lib/definitions/project.d.ts | 1 + lib/project-data.ts | 8 ++++++++ test/stubs.ts | 3 +++ 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/lib/common/commands/device/get-file.ts b/lib/common/commands/device/get-file.ts index e9e69f3612..a88ed6c79a 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,17 @@ 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) { + this.$projectData.initializeProjectDataSafe(); + 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..bd40cac7e6 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,17 @@ 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) { + this.$projectData.initializeProjectDataSafe(); + 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..87b8f055da 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,17 @@ 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) { + this.$projectData.initializeProjectDataSafe(); + 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); } } diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index c2d89f1611..d207170ae8 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -104,6 +104,7 @@ interface IProjectData extends ICreateProjectData { * @returns {void} */ initializeProjectData(projectDir?: string): void; + initializeProjectDataSafe(projectDir?: string): void; initializeProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): void; getAppDirectoryPath(projectDir?: string): string; getAppDirectoryRelativePath(): string; diff --git a/lib/project-data.ts b/lib/project-data.ts index 3e2fc860c1..b7520902a3 100644 --- a/lib/project-data.ts +++ b/lib/project-data.ts @@ -90,6 +90,14 @@ export class ProjectData implements IProjectData { this.errorInvalidProject(projectDir); } + public initializeProjectDataSafe(projectDir?: string): void { + try { + return this.initializeProjectData(projectDir); + } catch (err) { + // ignore the error + } + } + public initializeProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): void { projectDir = projectDir || this.$projectHelper.projectDir || ""; const projectFilePath = this.getProjectFilePath(projectDir); diff --git a/test/stubs.ts b/test/stubs.ts index 76daa39a7e..4f226f9b89 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -336,6 +336,9 @@ export class ProjectDataStub implements IProjectData { this.projectIdentifiers = { android: "", ios: "" }; this.projectId = ""; } + public initializeProjectDataSafe(projectDir?: string): void { + this.initializeProjectData(projectDir); + } public initializeProjectDataFromContent(): void { return; } From 1b0143596df80e88dce7b377caa1624eac037af8 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 16 Jan 2019 21:32:46 +0200 Subject: [PATCH 2/2] chore: remove initializeProjectDataSafe and use try/catch instead --- lib/common/commands/device/get-file.ts | 6 +++++- lib/common/commands/device/list-files.ts | 6 +++++- lib/common/commands/device/put-file.ts | 6 +++++- lib/definitions/project.d.ts | 1 - lib/project-data.ts | 8 -------- test/stubs.ts | 3 --- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/common/commands/device/get-file.ts b/lib/common/commands/device/get-file.ts index a88ed6c79a..1b46ae267e 100644 --- a/lib/common/commands/device/get-file.ts +++ b/lib/common/commands/device/get-file.ts @@ -12,7 +12,11 @@ export class GetFileCommand implements ICommand { let appIdentifier = args[1]; if (!appIdentifier) { - this.$projectData.initializeProjectDataSafe(); + 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."); } diff --git a/lib/common/commands/device/list-files.ts b/lib/common/commands/device/list-files.ts index bd40cac7e6..0e4ea0042a 100644 --- a/lib/common/commands/device/list-files.ts +++ b/lib/common/commands/device/list-files.ts @@ -13,7 +13,11 @@ export class ListFilesCommand implements ICommand { let appIdentifier = args[1]; if (!appIdentifier) { - this.$projectData.initializeProjectDataSafe(); + 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."); } diff --git a/lib/common/commands/device/put-file.ts b/lib/common/commands/device/put-file.ts index 87b8f055da..0323c9b993 100644 --- a/lib/common/commands/device/put-file.ts +++ b/lib/common/commands/device/put-file.ts @@ -12,7 +12,11 @@ export class PutFileCommand implements ICommand { let appIdentifier = args[2]; if (!appIdentifier) { - this.$projectData.initializeProjectDataSafe(); + 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."); } diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index d207170ae8..c2d89f1611 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -104,7 +104,6 @@ interface IProjectData extends ICreateProjectData { * @returns {void} */ initializeProjectData(projectDir?: string): void; - initializeProjectDataSafe(projectDir?: string): void; initializeProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): void; getAppDirectoryPath(projectDir?: string): string; getAppDirectoryRelativePath(): string; diff --git a/lib/project-data.ts b/lib/project-data.ts index b7520902a3..3e2fc860c1 100644 --- a/lib/project-data.ts +++ b/lib/project-data.ts @@ -90,14 +90,6 @@ export class ProjectData implements IProjectData { this.errorInvalidProject(projectDir); } - public initializeProjectDataSafe(projectDir?: string): void { - try { - return this.initializeProjectData(projectDir); - } catch (err) { - // ignore the error - } - } - public initializeProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): void { projectDir = projectDir || this.$projectHelper.projectDir || ""; const projectFilePath = this.getProjectFilePath(projectDir); diff --git a/test/stubs.ts b/test/stubs.ts index 4f226f9b89..76daa39a7e 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -336,9 +336,6 @@ export class ProjectDataStub implements IProjectData { this.projectIdentifiers = { android: "", ios: "" }; this.projectId = ""; } - public initializeProjectDataSafe(projectDir?: string): void { - this.initializeProjectData(projectDir); - } public initializeProjectDataFromContent(): void { return; }