Skip to content

Commit 54435dc

Browse files
committed
fix: fix get-file and list-files commands
1 parent de36eaa commit 54435dc

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

lib/common/commands/device/get-file.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export class GetFileCommand implements ICommand {
22
constructor(private $devicesService: Mobile.IDevicesService,
33
private $stringParameter: ICommandParameter,
4-
private $project: Project.IProjectBase,
4+
private $projectData: IProjectData,
55
private $errors: IErrors,
66
private $options: IOptions) { }
77

@@ -11,13 +11,17 @@ export class GetFileCommand implements ICommand {
1111
await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true });
1212
let appIdentifier = args[1];
1313

14-
if (!appIdentifier && !this.$project.projectData) {
15-
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
14+
if (!appIdentifier) {
15+
this.$projectData.initializeProjectDataSafe();
16+
if (!this.$projectData.projectIdentifiers) {
17+
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
18+
}
1619
}
1720

18-
appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
19-
20-
const action = (device: Mobile.IDevice) => device.fileSystem.getFile(args[0], appIdentifier, this.$options.file);
21+
const action = async (device: Mobile.IDevice) => {
22+
appIdentifier = appIdentifier || this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()];
23+
await device.fileSystem.getFile(args[0], appIdentifier, this.$options.file);
24+
};
2125
await this.$devicesService.execute(action);
2226
}
2327
}

lib/common/commands/device/list-files.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export class ListFilesCommand implements ICommand {
22
constructor(private $devicesService: Mobile.IDevicesService,
33
private $stringParameter: ICommandParameter,
44
private $options: IOptions,
5-
private $project: Project.IProjectBase,
5+
private $projectData: IProjectData,
66
private $errors: IErrors) { }
77

88
public allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter];
@@ -12,13 +12,17 @@ export class ListFilesCommand implements ICommand {
1212
const pathToList = args[0];
1313
let appIdentifier = args[1];
1414

15-
if (!appIdentifier && !this.$project.projectData) {
16-
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
15+
if (!appIdentifier) {
16+
this.$projectData.initializeProjectDataSafe();
17+
if (!this.$projectData.projectIdentifiers) {
18+
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
19+
}
1720
}
1821

19-
appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
20-
21-
const action = (device: Mobile.IDevice) => device.fileSystem.listFiles(pathToList, appIdentifier);
22+
const action = async (device: Mobile.IDevice) => {
23+
appIdentifier = appIdentifier || this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()];
24+
await device.fileSystem.listFiles(pathToList, appIdentifier);
25+
};
2226
await this.$devicesService.execute(action);
2327
}
2428
}

lib/common/commands/device/put-file.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export class PutFileCommand implements ICommand {
22
constructor(private $devicesService: Mobile.IDevicesService,
33
private $stringParameter: ICommandParameter,
44
private $options: IOptions,
5-
private $project: Project.IProjectBase,
5+
private $projectData: IProjectData,
66
private $errors: IErrors) { }
77

88
allowedParameters: ICommandParameter[] = [this.$stringParameter, this.$stringParameter, this.$stringParameter];
@@ -11,12 +11,17 @@ export class PutFileCommand implements ICommand {
1111
await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true });
1212
let appIdentifier = args[2];
1313

14-
if (!appIdentifier && !this.$project.projectData) {
15-
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
14+
if (!appIdentifier) {
15+
this.$projectData.initializeProjectDataSafe();
16+
if (!this.$projectData.projectIdentifiers) {
17+
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
18+
}
1619
}
1720

18-
appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
19-
const action = (device: Mobile.IDevice) => device.fileSystem.putFile(args[0], args[1], appIdentifier);
21+
const action = async (device: Mobile.IDevice) => {
22+
appIdentifier = appIdentifier || this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()];
23+
await device.fileSystem.putFile(args[0], args[1], appIdentifier);
24+
};
2025
await this.$devicesService.execute(action);
2126
}
2227
}

lib/definitions/project.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ interface IProjectData extends ICreateProjectData {
104104
* @returns {void}
105105
*/
106106
initializeProjectData(projectDir?: string): void;
107+
initializeProjectDataSafe(projectDir?: string): void;
107108
initializeProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): void;
108109
getAppDirectoryPath(projectDir?: string): string;
109110
getAppDirectoryRelativePath(): string;

lib/project-data.ts

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ export class ProjectData implements IProjectData {
9090
this.errorInvalidProject(projectDir);
9191
}
9292

93+
public initializeProjectDataSafe(projectDir?: string): void {
94+
try {
95+
return this.initializeProjectData(projectDir);
96+
} catch (err) {
97+
// ignore the error
98+
}
99+
}
100+
93101
public initializeProjectDataFromContent(packageJsonContent: string, nsconfigContent: string, projectDir?: string): void {
94102
projectDir = projectDir || this.$projectHelper.projectDir || "";
95103
const projectFilePath = this.getProjectFilePath(projectDir);

test/stubs.ts

+3
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ export class ProjectDataStub implements IProjectData {
336336
this.projectIdentifiers = { android: "", ios: "" };
337337
this.projectId = "";
338338
}
339+
public initializeProjectDataSafe(projectDir?: string): void {
340+
this.initializeProjectData(projectDir);
341+
}
339342
public initializeProjectDataFromContent(): void {
340343
return;
341344
}

0 commit comments

Comments
 (0)