Skip to content

Commit c200586

Browse files
author
Dimitar Kerezov
committed
Fix run with --release and --clean
1 parent c6127ea commit c200586

File tree

4 files changed

+71
-33
lines changed

4 files changed

+71
-33
lines changed

lib/commands/run.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,26 @@ export class RunCommandBase implements ICommand {
8585
}
8686

8787
if (this.$options.release) {
88-
const deployOpts: IRunPlatformOptions = {
88+
const runPlatformOptions: IRunPlatformOptions = {
8989
device: this.$options.device,
9090
emulator: this.$options.emulator,
9191
justlaunch: this.$options.justlaunch,
9292
};
9393

94-
await this.$platformService.startApplication(args[0], deployOpts, this.$projectData.projectId);
94+
const deployOptions = _.merge<IDeployPlatformOptions>({ projectDir: this.$projectData.projectDir, clean: true }, this.$options);
95+
96+
await this.$platformService.deployPlatform(args[0], this.$options, deployOptions, this.$projectData, this.$options);
97+
await this.$platformService.startApplication(args[0], runPlatformOptions, this.$projectData.projectId);
9598
return this.$platformService.trackProjectType(this.$projectData);
9699
}
97100

98-
const liveSyncInfo: ILiveSyncInfo = { projectDir: this.$projectData.projectDir, skipWatcher: !this.$options.watch, watchAllFiles: this.$options.syncAllFiles };
101+
const liveSyncInfo: ILiveSyncInfo = {
102+
projectDir: this.$projectData.projectDir,
103+
skipWatcher: !this.$options.watch,
104+
watchAllFiles: this.$options.syncAllFiles,
105+
clean: this.$options.clean
106+
};
107+
99108
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
100109
}
101110
}

lib/common

lib/definitions/livesync.d.ts

+19
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ interface ILiveSyncInfo {
115115
* NOTE: Currently this is available only for iOS.
116116
*/
117117
useLiveEdit?: boolean;
118+
119+
/**
120+
* Forces a build before the initial livesync.
121+
*/
122+
clean?: boolean;
118123
}
119124

120125
interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }
@@ -125,6 +130,20 @@ interface ILiveSyncBuildInfo {
125130
pathToBuildItem: string;
126131
}
127132

133+
/**
134+
* Desribes object that can be passed to ensureLatestAppPackageIsInstalledOnDevice method.
135+
*/
136+
interface IEnsureLatestAppPackageIsInstalledOnDeviceOptions {
137+
device: Mobile.IDevice;
138+
preparedPlatforms: string[];
139+
rebuiltInformation: ILiveSyncBuildInfo[];
140+
projectData: IProjectData;
141+
deviceBuildInfoDescriptor: ILiveSyncDeviceInfo;
142+
settings: ILatestAppPackageInstalledSettings;
143+
liveSyncData?: ILiveSyncInfo;
144+
modifiedFiles?: string[];
145+
}
146+
128147
/**
129148
* Describes LiveSync operations.
130149
*/

lib/services/livesync/livesync-service.ts

+39-29
Original file line numberDiff line numberDiff line change
@@ -145,60 +145,54 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
145145
throw new Error(`Invalid platform ${platform}. Supported platforms are: ${this.$mobileHelper.platformNames.join(", ")}`);
146146
}
147147

148-
private async ensureLatestAppPackageIsInstalledOnDevice(device: Mobile.IDevice,
149-
preparedPlatforms: string[],
150-
rebuiltInformation: ILiveSyncBuildInfo[],
151-
projectData: IProjectData,
152-
deviceBuildInfoDescriptor: ILiveSyncDeviceInfo,
153-
settings: ILatestAppPackageInstalledSettings,
154-
modifiedFiles?: string[]): Promise<void> {
155-
const platform = device.deviceInfo.platform;
156-
if (preparedPlatforms.indexOf(platform) === -1) {
157-
preparedPlatforms.push(platform);
148+
private async ensureLatestAppPackageIsInstalledOnDevice(options: IEnsureLatestAppPackageIsInstalledOnDeviceOptions): Promise<void> {
149+
const platform = options.device.deviceInfo.platform;
150+
if (options.preparedPlatforms.indexOf(platform) === -1) {
151+
options.preparedPlatforms.push(platform);
158152
// TODO: Pass provision and sdk as a fifth argument here
159153
await this.$platformService.preparePlatform(platform, {
160154
bundle: false,
161155
release: false,
162-
}, null, projectData, <any>{}, modifiedFiles);
156+
}, null, options.projectData, <any>{}, options.modifiedFiles);
163157
}
164158

165-
const rebuildInfo = _.find(rebuiltInformation, info => info.isEmulator === device.isEmulator && info.platform === platform);
159+
const rebuildInfo = _.find(options.rebuiltInformation, info => info.isEmulator === options.device.isEmulator && info.platform === platform);
166160

167161
if (rebuildInfo) {
168162
// Case where we have three devices attached, a change that requires build is found,
169163
// we'll rebuild the app only for the first device, but we should install new package on all three devices.
170-
await this.$platformService.installApplication(device, { release: false }, projectData, rebuildInfo.pathToBuildItem, deviceBuildInfoDescriptor.outputPath);
164+
await this.$platformService.installApplication(options.device, { release: false }, options.projectData, rebuildInfo.pathToBuildItem, options.deviceBuildInfoDescriptor.outputPath);
171165
return;
172166
}
173167

174168
// TODO: Pass provision and sdk as a fifth argument here
175-
const shouldBuild = await this.$platformService.shouldBuild(platform, projectData, <any>{ buildForDevice: !device.isEmulator }, deviceBuildInfoDescriptor.outputPath);
169+
const shouldBuild = await this.$platformService.shouldBuild(platform, options.projectData, <any>{ buildForDevice: !options.device.isEmulator, clean: options.liveSyncData && options.liveSyncData.clean }, options.deviceBuildInfoDescriptor.outputPath);
176170
let pathToBuildItem = null;
177171
let action = LiveSyncTrackActionNames.LIVESYNC_OPERATION;
178172
if (shouldBuild) {
179-
pathToBuildItem = await deviceBuildInfoDescriptor.buildAction();
173+
pathToBuildItem = await options.deviceBuildInfoDescriptor.buildAction();
180174
// Is it possible to return shouldBuild for two devices? What about android device and android emulator?
181-
rebuiltInformation.push({ isEmulator: device.isEmulator, platform, pathToBuildItem });
175+
options.rebuiltInformation.push({ isEmulator: options.device.isEmulator, platform, pathToBuildItem });
182176
action = LiveSyncTrackActionNames.LIVESYNC_OPERATION_BUILD;
183177
}
184178

185-
if (!settings[platform][device.deviceInfo.type]) {
186-
let isForDevice = !device.isEmulator;
187-
settings[platform][device.deviceInfo.type] = true;
179+
if (!options.settings[platform][options.device.deviceInfo.type]) {
180+
let isForDevice = !options.device.isEmulator;
181+
options.settings[platform][options.device.deviceInfo.type] = true;
188182
if (this.$mobileHelper.isAndroidPlatform(platform)) {
189-
settings[platform][DeviceTypes.Emulator] = true;
190-
settings[platform][DeviceTypes.Device] = true;
183+
options.settings[platform][DeviceTypes.Emulator] = true;
184+
options.settings[platform][DeviceTypes.Device] = true;
191185
isForDevice = null;
192186
}
193187

194188
await this.$platformService.trackActionForPlatform({ action, platform, isForDevice });
195189
}
196190

197-
await this.$platformService.trackActionForPlatform({ action: LiveSyncTrackActionNames.DEVICE_INFO, platform, isForDevice: !device.isEmulator, deviceOsVersion: device.deviceInfo.version });
191+
await this.$platformService.trackActionForPlatform({ action: LiveSyncTrackActionNames.DEVICE_INFO, platform, isForDevice: !options.device.isEmulator, deviceOsVersion: options.device.deviceInfo.version });
198192

199-
const shouldInstall = await this.$platformService.shouldInstall(device, projectData, deviceBuildInfoDescriptor.outputPath);
193+
const shouldInstall = await this.$platformService.shouldInstall(options.device, options.projectData, options.deviceBuildInfoDescriptor.outputPath);
200194
if (shouldInstall) {
201-
await this.$platformService.installApplication(device, { release: false }, projectData, pathToBuildItem, deviceBuildInfoDescriptor.outputPath);
195+
await this.$platformService.installApplication(options.device, { release: false }, options.projectData, pathToBuildItem, options.deviceBuildInfoDescriptor.outputPath);
202196
}
203197
}
204198

@@ -217,9 +211,17 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
217211
});
218212

219213
const platform = device.deviceInfo.platform;
220-
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
221-
222-
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor, settings);
214+
const deviceBuildInfoDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
215+
216+
await this.ensureLatestAppPackageIsInstalledOnDevice({
217+
device,
218+
preparedPlatforms,
219+
rebuiltInformation,
220+
projectData,
221+
deviceBuildInfoDescriptor,
222+
liveSyncData,
223+
settings
224+
});
223225

224226
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({
225227
projectData, device,
@@ -305,9 +307,17 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
305307

306308
await this.$devicesService.execute(async (device: Mobile.IDevice) => {
307309
const liveSyncProcessInfo = this.liveSyncProcessesInfo[projectData.projectDir];
308-
const deviceDescriptor = _.find(liveSyncProcessInfo.deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
310+
const deviceBuildInfoDescriptor = _.find(liveSyncProcessInfo.deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
309311

310-
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor, latestAppPackageInstalledSettings, allModifiedFiles);
312+
await this.ensureLatestAppPackageIsInstalledOnDevice({
313+
device,
314+
preparedPlatforms,
315+
rebuiltInformation,
316+
projectData,
317+
deviceBuildInfoDescriptor,
318+
settings: latestAppPackageInstalledSettings,
319+
modifiedFiles: allModifiedFiles
320+
});
311321

312322
const service = this.getLiveSyncService(device.deviceInfo.platform);
313323
const settings: ILiveSyncWatchInfo = {

0 commit comments

Comments
 (0)