Skip to content

Commit f4aa067

Browse files
Fix run command
Fix run command by setting correct platform.
1 parent 69a01e3 commit f4aa067

File tree

5 files changed

+51
-47
lines changed

5 files changed

+51
-47
lines changed

lib/commands/debug.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export class DebugPlatformCommand implements ICommand {
3737

3838
const selectedDeviceForDebug = await this.getDeviceForDebug();
3939

40-
const { deviceDescriptors, liveSyncInfo } = await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo(args, [selectedDeviceForDebug]);
41-
await this.$debugLiveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
40+
await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo([selectedDeviceForDebug], this.$debugLiveSyncService, this.platform);
4241
}
4342

4443
public async getDeviceForDebug(): Promise<Mobile.IDevice> {

lib/commands/run.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
22
import { cache } from "../common/decorators";
33

44
export class RunCommandBase implements ICommand {
5-
protected platform: string;
65

6+
public platform: string;
77
constructor(protected $platformService: IPlatformService,
88
protected $liveSyncService: ILiveSyncService,
99
protected $projectData: IProjectData,
@@ -59,8 +59,7 @@ export class RunCommandBase implements ICommand {
5959
await this.$devicesService.detectCurrentlyAttachedDevices();
6060
let devices = this.$devicesService.getDeviceInstances();
6161
devices = devices.filter(d => !this.platform || d.deviceInfo.platform.toLowerCase() === this.platform.toLowerCase());
62-
const { deviceDescriptors, liveSyncInfo } = await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo(args, devices);
63-
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
62+
await this.$liveSyncCommandHelper.getDevicesLiveSyncInfo(devices, this.$liveSyncService, this.platform);
6463
}
6564
}
6665

@@ -70,7 +69,9 @@ export class RunIosCommand implements ICommand {
7069

7170
@cache()
7271
private get runCommand(): RunCommandBase {
73-
return this.$injector.resolve<RunCommandBase>(RunCommandBase);
72+
const runCommand = this.$injector.resolve<RunCommandBase>(RunCommandBase);
73+
runCommand.platform = this.platform;
74+
return runCommand;
7475
}
7576

7677
public allowedParameters: ICommandParameter[] = [];
@@ -92,7 +93,7 @@ export class RunIosCommand implements ICommand {
9293
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
9394
}
9495

95-
return this.runCommand.executeCore([this.$platformsData.availablePlatforms.iOS]);
96+
return this.runCommand.executeCore(args);
9697
}
9798

9899
public async canExecute(args: string[]): Promise<boolean> {
@@ -106,7 +107,9 @@ export class RunAndroidCommand implements ICommand {
106107

107108
@cache()
108109
private get runCommand(): RunCommandBase {
109-
return this.$injector.resolve<RunCommandBase>(RunCommandBase);
110+
const runCommand = this.$injector.resolve<RunCommandBase>(RunCommandBase);
111+
runCommand.platform = this.platform;
112+
return runCommand;
110113
}
111114

112115
public allowedParameters: ICommandParameter[] = [];
@@ -124,11 +127,12 @@ export class RunAndroidCommand implements ICommand {
124127
}
125128

126129
public async execute(args: string[]): Promise<void> {
127-
return this.runCommand.executeCore([this.$platformsData.availablePlatforms.Android]);
130+
return this.runCommand.executeCore(args);
128131
}
129132

130133
public async canExecute(args: string[]): Promise<boolean> {
131134
await this.runCommand.canExecute(args);
135+
132136
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.Android, this.$projectData)) {
133137
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.Android} can not be built on this OS`);
134138
}

lib/definitions/livesync.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,5 @@ interface IDevicePathProvider {
256256
}
257257

258258
interface ILiveSyncCommandHelper {
259-
getDevicesLiveSyncInfo(args: string[], devices: Mobile.IDevice[]): Promise<IDevicesDescriptorsLiveSyncInfo>;
260-
}
261-
262-
interface IDevicesDescriptorsLiveSyncInfo {
263-
deviceDescriptors: ILiveSyncDeviceInfo[]
264-
liveSyncInfo: ILiveSyncInfo
259+
getDevicesLiveSyncInfo(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void>;
265260
}

lib/services/livesync/livesync-command-helper.ts

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
2-
protected platform: string;
32

43
constructor(protected $platformService: IPlatformService,
54
protected $projectData: IProjectData,
65
protected $options: IOptions,
76
protected $devicesService: Mobile.IDevicesService,
87
private $iosDeviceOperations: IIOSDeviceOperations,
9-
private $mobileHelper: Mobile.IMobileHelper) {
8+
private $mobileHelper: Mobile.IMobileHelper,
9+
private $platformsData: IPlatformsData) {
1010
}
1111

12-
public async getDevicesLiveSyncInfo(args: string[], devices: Mobile.IDevice[]): Promise<IDevicesDescriptorsLiveSyncInfo> {
12+
public async getDevicesLiveSyncInfo(devices: Mobile.IDevice[], liveSyncService: ILiveSyncService, platform: string): Promise<void> {
1313
await this.$devicesService.detectCurrentlyAttachedDevices();
14+
15+
const workingWithiOSDevices = !platform || this.$mobileHelper.isiOSPlatform(platform);
16+
const shouldKeepProcessAlive = this.$options.watch || !this.$options.justlaunch;
17+
if (workingWithiOSDevices && shouldKeepProcessAlive) {
18+
this.$iosDeviceOperations.setShouldDispose(false);
19+
}
20+
21+
if (this.$options.release || this.$options.bundle) {
22+
await this.runInReleaseMode(platform);
23+
return;
24+
}
25+
1426
// Now let's take data for each device:
1527
const deviceDescriptors: ILiveSyncDeviceInfo[] = devices
1628
.map(d => {
@@ -40,41 +52,35 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
4052
return info;
4153
});
4254

43-
const workingWithiOSDevices = !this.platform || this.$mobileHelper.isiOSPlatform(this.platform);
44-
const shouldKeepProcessAlive = this.$options.watch || !this.$options.justlaunch;
45-
if (workingWithiOSDevices && shouldKeepProcessAlive) {
46-
this.$iosDeviceOperations.setShouldDispose(false);
47-
}
48-
49-
// TODO: test it, might have isuues with `tns run` (no args)
50-
if (this.$options.release || this.$options.bundle) {
51-
const runPlatformOptions: IRunPlatformOptions = {
52-
device: this.$options.device,
53-
emulator: this.$options.emulator,
54-
justlaunch: this.$options.justlaunch
55-
};
56-
57-
const deployOptions = _.merge<IDeployPlatformOptions>({
58-
projectDir: this.$projectData.projectDir,
59-
clean: true,
60-
}, this.$options.argv);
61-
62-
await this.$platformService.deployPlatform(args[0], this.$options, deployOptions, this.$projectData, this.$options);
63-
await this.$platformService.startApplication(args[0], runPlatformOptions, this.$projectData.projectId);
64-
this.$platformService.trackProjectType(this.$projectData);
65-
}
66-
6755
const liveSyncInfo: ILiveSyncInfo = {
6856
projectDir: this.$projectData.projectDir,
6957
skipWatcher: !this.$options.watch,
7058
watchAllFiles: this.$options.syncAllFiles,
7159
clean: this.$options.clean
7260
};
7361

74-
return {
75-
deviceDescriptors,
76-
liveSyncInfo
62+
await liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
63+
64+
}
65+
66+
private async runInReleaseMode(platform: string): Promise<void> {
67+
const runPlatformOptions: IRunPlatformOptions = {
68+
device: this.$options.device,
69+
emulator: this.$options.emulator,
70+
justlaunch: this.$options.justlaunch
7771
};
72+
73+
const deployOptions = _.merge<IDeployPlatformOptions>({
74+
projectDir: this.$projectData.projectDir,
75+
clean: true,
76+
}, this.$options.argv);
77+
78+
const availablePlatforms = platform ? [platform] : _.values<string>(this.$platformsData.availablePlatforms);
79+
for (const currentPlatform of availablePlatforms) {
80+
await this.$platformService.deployPlatform(currentPlatform, this.$options, deployOptions, this.$projectData, this.$options);
81+
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, this.$projectData.projectId);
82+
this.$platformService.trackProjectType(this.$projectData);
83+
}
7884
}
7985
}
8086

test/debug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ function createTestInjector(): IInjector {
6969
testInjector.register("prompter", {});
7070
testInjector.registerCommand("debug|android", DebugAndroidCommand);
7171
testInjector.register("liveSyncCommandHelper", {
72-
getDevicesLiveSyncInfo: async (): Promise<IDevicesDescriptorsLiveSyncInfo> => {
73-
return { deviceDescriptors: [], liveSyncInfo: null };
72+
getDevicesLiveSyncInfo: async (): Promise<void> => {
73+
return null;
7474
}
7575
});
7676

0 commit comments

Comments
 (0)