Skip to content

Commit 4dfc040

Browse files
rosen-vladimirovDimitar Kerezov
authored andcommitted
Remove livesync-provider
Remove livesyncProvider and introduce a base class for device specific livesync services.
1 parent 0f9c0aa commit 4dfc040

File tree

5 files changed

+34
-139
lines changed

5 files changed

+34
-139
lines changed

lib/bootstrap.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ $injector.require("commandsServiceProvider", "./providers/commands-service-provi
7575
$injector.require("deviceAppDataProvider", "./providers/device-app-data-provider");
7676

7777
$injector.require("deviceLogProvider", "./common/mobile/device-log-provider");
78-
$injector.require("liveSyncProvider", "./providers/livesync-provider");
7978
$injector.require("projectFilesProvider", "./providers/project-files-provider");
8079

8180
$injector.require("nodeModulesBuilder", "./tools/node-modules/node-modules-builder");

lib/providers/livesync-provider.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

lib/services/livesync/android-device-livesync-service.ts

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
import { DeviceAndroidDebugBridge } from "../../common/mobile/android/device-android-debug-bridge";
22
import { AndroidDeviceHashService } from "../../common/mobile/android/android-device-hash-service";
3+
import { DeviceLiveSyncServiceBase } from "./device-livesync-service-base";
34
import * as helpers from "../../common/helpers";
45
import { SYNC_DIR_NAME, FULLSYNC_DIR_NAME, REMOVEDSYNC_DIR_NAME } from "../../constants";
56
import { cache } from "../../common/decorators";
67
import * as path from "path";
78
import * as net from "net";
8-
import { EOL } from "os";
9-
10-
export class AndroidDeviceLiveSyncService implements IAndroidNativeScriptDeviceLiveSyncService {
11-
private static FAST_SYNC_FILE_EXTENSIONS = [".css", ".xml", ".html"];
129

10+
export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService {
1311
private static BACKEND_PORT = 18182;
1412
private device: Mobile.IAndroidDevice;
1513

1614
constructor(_device: Mobile.IDevice,
1715
private $mobileHelper: Mobile.IMobileHelper,
1816
private $injector: IInjector,
19-
private $logger: ILogger,
20-
private $androidDebugService: IPlatformDebugService,
21-
private $platformsData: IPlatformsData) {
17+
protected $platformsData: IPlatformsData) {
18+
super($platformsData);
2219
this.device = <Mobile.IAndroidDevice>(_device);
2320
}
2421

25-
public get debugService(): IPlatformDebugService {
26-
return this.$androidDebugService;
27-
}
28-
2922
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
3023
const deviceAppData = liveSyncInfo.deviceAppData;
3124
const localToDevicePaths = liveSyncInfo.modifiedFilesData;
@@ -38,7 +31,7 @@ export class AndroidDeviceLiveSyncService implements IAndroidNativeScriptDeviceL
3831
`/data/local/tmp/${deviceAppData.appIdentifier}/sync`]
3932
);
4033

41-
let canExecuteFastSync = !liveSyncInfo.isFullSync && !_.some(localToDevicePaths,
34+
const canExecuteFastSync = !liveSyncInfo.isFullSync && !_.some(localToDevicePaths,
4235
(localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
4336

4437
if (canExecuteFastSync) {
@@ -48,25 +41,6 @@ export class AndroidDeviceLiveSyncService implements IAndroidNativeScriptDeviceL
4841
return this.restartApplication(deviceAppData);
4942
}
5043

51-
@cache()
52-
private getFastLiveSyncFileExtensions(platform: string, projectData: IProjectData): string[] {
53-
const platformData = this.$platformsData.getPlatformData(platform, projectData);
54-
const fastSyncFileExtensions = AndroidDeviceLiveSyncService.FAST_SYNC_FILE_EXTENSIONS.concat(platformData.fastLivesyncFileExtensions);
55-
return fastSyncFileExtensions;
56-
}
57-
58-
public canExecuteFastSync(filePath: string, projectData: IProjectData, platform: string): boolean {
59-
console.log("called canExecuteFastSync for file: ", filePath);
60-
const fastSyncFileExtensions = this.getFastLiveSyncFileExtensions(platform, projectData);
61-
return _.includes(fastSyncFileExtensions, path.extname(filePath));
62-
}
63-
64-
protected printDebugInformation(information: string[]): void {
65-
_.each(information, i => {
66-
this.$logger.info(`To start debugging, open the following URL in Chrome:${EOL}${i}${EOL}`.cyan);
67-
});
68-
}
69-
7044
private async restartApplication(deviceAppData: Mobile.IDeviceAppData): Promise<void> {
7145
let devicePathRoot = `/data/data/${deviceAppData.appIdentifier}/files`;
7246
let devicePath = this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { cache } from "../../common/decorators";
2+
import * as path from "path";
3+
4+
export abstract class DeviceLiveSyncServiceBase {
5+
private static FAST_SYNC_FILE_EXTENSIONS = [".css", ".xml", ".html"];
6+
7+
constructor(protected $platformsData: IPlatformsData) { }
8+
9+
public canExecuteFastSync(filePath: string, projectData: IProjectData, platform: string): boolean {
10+
const fastSyncFileExtensions = this.getFastLiveSyncFileExtensions(platform, projectData);
11+
return _.includes(fastSyncFileExtensions, path.extname(filePath));
12+
}
13+
14+
@cache()
15+
private getFastLiveSyncFileExtensions(platform: string, projectData: IProjectData): string[] {
16+
const platformData = this.$platformsData.getPlatformData(platform, projectData);
17+
const fastSyncFileExtensions = DeviceLiveSyncServiceBase.FAST_SYNC_FILE_EXTENSIONS.concat(platformData.fastLivesyncFileExtensions);
18+
return fastSyncFileExtensions;
19+
}
20+
21+
}

lib/services/livesync/ios-device-livesync-service.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import * as helpers from "../../common/helpers";
22
import * as constants from "../../constants";
33
import * as minimatch from "minimatch";
44
import * as net from "net";
5+
import { DeviceLiveSyncServiceBase } from "./device-livesync-service-base";
56

67
let currentPageReloadId = 0;
78

8-
export class IOSDeviceLiveSyncService implements INativeScriptDeviceLiveSyncService {
9+
export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implements INativeScriptDeviceLiveSyncService {
910
private static BACKEND_PORT = 18181;
1011
private socket: net.Socket;
1112
private device: Mobile.IiOSDevice;
@@ -15,18 +16,13 @@ export class IOSDeviceLiveSyncService implements INativeScriptDeviceLiveSyncServ
1516
private $iOSNotification: IiOSNotification,
1617
private $iOSEmulatorServices: Mobile.IiOSSimulatorService,
1718
private $logger: ILogger,
18-
private $iOSDebugService: IDebugService,
1919
private $fs: IFileSystem,
20-
private $liveSyncProvider: ILiveSyncProvider,
21-
private $processService: IProcessService) {
22-
20+
private $processService: IProcessService,
21+
protected $platformsData: IPlatformsData) {
22+
super($platformsData);
2323
this.device = _device;
2424
}
2525

26-
public get debugService(): IDebugService {
27-
return this.$iOSDebugService;
28-
}
29-
3026
private async setupSocketIfNeeded(projectId: string): Promise<boolean> {
3127
if (this.socket) {
3228
return true;
@@ -64,11 +60,11 @@ export class IOSDeviceLiveSyncService implements INativeScriptDeviceLiveSyncServ
6460
}
6561

6662
let scriptRelatedFiles: Mobile.ILocalToDevicePathData[] = [];
67-
let scriptFiles = _.filter(localToDevicePaths, localToDevicePath => _.endsWith(localToDevicePath.getDevicePath(), ".js"));
63+
const scriptFiles = _.filter(localToDevicePaths, localToDevicePath => _.endsWith(localToDevicePath.getDevicePath(), ".js"));
6864
constants.LIVESYNC_EXCLUDED_FILE_PATTERNS.forEach(pattern => scriptRelatedFiles = _.concat(scriptRelatedFiles, localToDevicePaths.filter(file => minimatch(file.getDevicePath(), pattern, { nocase: true }))));
6965

70-
let otherFiles = _.difference(localToDevicePaths, _.concat(scriptFiles, scriptRelatedFiles));
71-
let shouldRestart = _.some(otherFiles, (localToDevicePath: Mobile.ILocalToDevicePathData) => !this.$liveSyncProvider.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, deviceAppData.platform));
66+
const otherFiles = _.difference(localToDevicePaths, _.concat(scriptFiles, scriptRelatedFiles));
67+
const shouldRestart = _.some(otherFiles, (localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, deviceAppData.platform));
7268

7369
if (shouldRestart || (!liveSyncInfo.useLiveEdit && scriptFiles.length)) {
7470
await this.restartApplication(deviceAppData, projectData.projectName);

0 commit comments

Comments
 (0)