Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit bc0955c

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Remove files from iOS simulator
Fixes NativeScript/nativescript-cli#1210
1 parent 2b0980f commit bc0955c

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

definitions/mobile.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,10 @@ declare module Mobile {
302302
interface IiOSSimulatorService extends IEmulatorPlatformServices {
303303
postDarwinNotification(notification: string): IFuture<void>;
304304
sync(appIdentifier: string, projectFilesPath: string, notRunningSimulatorAction: () => IFuture<void>, getApplicationPathForiOSSimulatorAction: () => IFuture<string>): IFuture<void>;
305-
syncFiles(appIdentifier: string, projectFilesPath: string, projectFiles: string[], notRunningSimulatorAction: () => IFuture<void>, getApplicationPathForiOSSimulatorAction: () => IFuture<string>, relativeToProjectBasePathAction?: (projectFile: string) => string): IFuture<void>;
305+
syncFiles(appIdentifier: string, projectFilesPath: string, projectFiles: string[], notRunningSimulatorAction: () => IFuture<void>, getApplicationPathForiOSSimulatorAction: () => IFuture<string>, relativeToProjectBasePathAction?: (projectFile: string) => string): IFuture<void>;
306306
isSimulatorRunning(): IFuture<boolean>;
307-
transferFiles(appIdentifier: string, projectFiles: string[], relativeToProjectBasePathAction?: (_projectFile: string) => string, applicationPath?: string): IFuture<void>
307+
transferFiles(appIdentifier: string, projectFiles: string[], relativeToProjectBasePathAction?: (_projectFile: string) => string, applicationPath?: string): IFuture<void>;
308+
removeFiles(appIdentifier: string, projectFilesPath: string, projectFiles: string[], notRunningSimulatorAction: () => IFuture<void>, getApplicationPathForiOSSimulatorAction: () => IFuture<string>, relativeToProjectBasePathAction?: (projectFile: string) => string): IFuture<void>;
308309
}
309310

310311
interface IEmulatorSettingsService {

mobile/ios/ios-emulator-services.ts

+16
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ class IosEmulatorServices implements Mobile.IiOSSimulatorService {
7272
return this.syncCore(appIdentifier, notRunningSimulatorAction, syncAction, getApplicationPathForiOSSimulatorAction);
7373
}
7474

75+
public removeFiles(appIdentifier: string, projectFilesPath: string, projectFiles: string[], notRunningSimulatorAction: () => IFuture<void>, getApplicationPathForiOSSimulatorAction: () => IFuture<string>, relativeToProjectBasePathAction?: (_projectFile: string) => string): IFuture<void> {
76+
let syncAction = (applicationPath: string) => this.removeFilesCore(appIdentifier, applicationPath, projectFilesPath, projectFiles, relativeToProjectBasePathAction);
77+
return this.syncCore(appIdentifier, notRunningSimulatorAction, syncAction, getApplicationPathForiOSSimulatorAction);
78+
}
79+
80+
private removeFilesCore(appIdentifier: string, applicationPath: string, projectFilesPath: string, projectFiles: string[], relativeToProjectBasePathAction?: (_projectFile: string) => string): IFuture<void> {
81+
return (() => {
82+
applicationPath = applicationPath || this.getApplicationPath(appIdentifier);
83+
_.each(projectFiles, projectFile => {
84+
let destinationFilePath = path.join(applicationPath, relativeToProjectBasePathAction(projectFile), path.relative(projectFilesPath, projectFile));
85+
this.$logger.trace(`Deleting ${destinationFilePath}.`);
86+
shell.rm(destinationFilePath);
87+
});
88+
}).future<void>()();
89+
}
90+
7591
public transferFiles(appIdentifier: string, projectFiles: string[], relativeToProjectBasePathAction?: (_projectFile: string) => string, applicationPath?: string): IFuture<void> {
7692
return (() => {
7793
applicationPath = applicationPath || this.getApplicationPath(appIdentifier);

services/usb-livesync-service-base.ts

+28-21
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,35 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
167167

168168
private processRemovedFile(data: ILiveSyncData, filePath: string): void {
169169
this.$dispatcher.dispatch(() => (() => {
170-
if (!this.isInitialized) {
171-
this.$devicesService.initialize({ platform: data.platform, deviceId: this.$options.device }).wait();
172-
}
170+
let synciOSSimulator = this.shouldSynciOSSimulator(data.platform).wait();
171+
if (synciOSSimulator) {
172+
let fileToSync = data.beforeBatchLiveSyncAction ? data.beforeBatchLiveSyncAction(filePath).wait() : filePath;
173+
this.$iOSEmulatorServices.removeFiles(data.appIdentifier, data.projectFilesPath, [fileToSync], data.notRunningiOSSimulatorAction, data.getApplicationPathForiOSSimulatorAction, data.iOSSimulatorRelativeToProjectBasePathAction).wait();
174+
} else {
175+
if (!this.isInitialized) {
176+
this.$devicesService.initialize({ platform: data.platform, deviceId: this.$options.device }).wait();
177+
}
173178

174-
let action = (device: Mobile.IDevice) => {
175-
return (() => {
176-
let fileToSync = data.beforeBatchLiveSyncAction ? data.beforeBatchLiveSyncAction(filePath).wait() : filePath;
177-
let localToDevicePaths = this.createLocalToDevicePaths(data.platform, data.appIdentifier, data.localProjectRootPath || data.projectFilesPath, [fileToSync]);
178-
let platformSpecificLiveSyncService = this.resolvePlatformSpecificLiveSyncService(data.platform, device, data.platformSpecificLiveSyncServices);
179-
platformSpecificLiveSyncService.removeFile(data.appIdentifier, localToDevicePaths).wait();
180-
181-
let canExecuteFastLiveSync = data.canExecuteFastLiveSync && data.canExecuteFastLiveSync(filePath);
182-
if (canExecuteFastLiveSync) {
183-
data.fastLiveSync(filePath);
184-
} else {
185-
let platform = data.platform ? this.$mobileHelper.normalizePlatformName(data.platform) : this.$devicesService.platform;
186-
let deviceAppData = this.$deviceAppDataFactory.create(data.appIdentifier, this.$mobileHelper.normalizePlatformName(platform));
187-
platformSpecificLiveSyncService.restartApplication(deviceAppData, localToDevicePaths).wait();
188-
}
189-
}).future<void>()();
190-
};
191-
this.$devicesService.execute(action).wait();
179+
let action = (device: Mobile.IDevice) => {
180+
return (() => {
181+
let fileToSync = data.beforeBatchLiveSyncAction ? data.beforeBatchLiveSyncAction(filePath).wait() : filePath;
182+
let localToDevicePaths = this.createLocalToDevicePaths(data.platform, data.appIdentifier, data.localProjectRootPath || data.projectFilesPath, [fileToSync]);
183+
let platformSpecificLiveSyncService = this.resolvePlatformSpecificLiveSyncService(data.platform, device, data.platformSpecificLiveSyncServices);
184+
platformSpecificLiveSyncService.removeFile(data.appIdentifier, localToDevicePaths).wait();
185+
186+
let canExecuteFastLiveSync = data.canExecuteFastLiveSync && data.canExecuteFastLiveSync(filePath);
187+
if (canExecuteFastLiveSync) {
188+
data.fastLiveSync(filePath);
189+
} else {
190+
let platform = data.platform ? this.$mobileHelper.normalizePlatformName(data.platform) : this.$devicesService.platform;
191+
let deviceAppData = this.$deviceAppDataFactory.create(data.appIdentifier, this.$mobileHelper.normalizePlatformName(platform));
192+
platformSpecificLiveSyncService.restartApplication(deviceAppData, localToDevicePaths).wait();
193+
}
194+
}).future<void>()();
195+
};
196+
197+
this.$devicesService.execute(action).wait();
198+
}
192199
}).future<void>()());
193200
}
194201

0 commit comments

Comments
 (0)