Skip to content

Commit 1c04282

Browse files
author
Fatme
authored
Merge pull request #4285 from NativeScript/fatme/fix-ios-device-commands
fix: fix `device list-files`, `device get-file` and `device put-file` commands
2 parents 98558ff + 1b01435 commit 1c04282

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

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

+14-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,21 @@ 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+
try {
16+
this.$projectData.initializeProjectData();
17+
} catch (err) {
18+
// ignore the error
19+
}
20+
if (!this.$projectData.projectIdentifiers) {
21+
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
22+
}
1623
}
1724

18-
appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
19-
20-
const action = (device: Mobile.IDevice) => device.fileSystem.getFile(args[0], appIdentifier, this.$options.file);
25+
const action = async (device: Mobile.IDevice) => {
26+
appIdentifier = appIdentifier || this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()];
27+
await device.fileSystem.getFile(args[0], appIdentifier, this.$options.file);
28+
};
2129
await this.$devicesService.execute(action);
2230
}
2331
}

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

+14-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,21 @@ 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+
try {
17+
this.$projectData.initializeProjectData();
18+
} catch (err) {
19+
// ignore the error
20+
}
21+
if (!this.$projectData.projectIdentifiers) {
22+
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
23+
}
1724
}
1825

19-
appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
20-
21-
const action = (device: Mobile.IDevice) => device.fileSystem.listFiles(pathToList, appIdentifier);
26+
const action = async (device: Mobile.IDevice) => {
27+
appIdentifier = appIdentifier || this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()];
28+
await device.fileSystem.listFiles(pathToList, appIdentifier);
29+
};
2230
await this.$devicesService.execute(action);
2331
}
2432
}

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

+14-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,21 @@ 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+
try {
16+
this.$projectData.initializeProjectData();
17+
} catch (err) {
18+
// ignore the error
19+
}
20+
if (!this.$projectData.projectIdentifiers) {
21+
this.$errors.failWithoutHelp("Please enter application identifier or execute this command in project.");
22+
}
1623
}
1724

18-
appIdentifier = appIdentifier || this.$project.projectData.AppIdentifier;
19-
const action = (device: Mobile.IDevice) => device.fileSystem.putFile(args[0], args[1], appIdentifier);
25+
const action = async (device: Mobile.IDevice) => {
26+
appIdentifier = appIdentifier || this.$projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()];
27+
await device.fileSystem.putFile(args[0], args[1], appIdentifier);
28+
};
2029
await this.$devicesService.execute(action);
2130
}
2231
}

0 commit comments

Comments
 (0)