Skip to content

Commit f81fc16

Browse files
committed
chore: fix comments of PR
1 parent ccd692a commit f81fc16

File tree

7 files changed

+43
-27
lines changed

7 files changed

+43
-27
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ $injector.require("deployCommandHelper", "./helpers/deploy-command-helper");
122122

123123
$injector.requirePublicClass("localBuildService", "./services/local-build-service");
124124
$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service");
125-
$injector.requirePublicClass("androidLivesyncLibrary", "./services/livesync/android-livesync-library");
125+
$injector.requirePublicClass("androidLivesyncTool", "./services/livesync/android-livesync-tool");
126126
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");
127127
$injector.require("iOSLiveSyncService", "./services/livesync/ios-livesync-service");
128128
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript

lib/definitions/livesync.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,19 @@ interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase
356356
* Removes specified files from a connected device
357357
* @param {Mobile.IDeviceAppData} deviceAppData Data about device and app.
358358
* @param {Mobile.ILocalToDevicePathData[]} localToDevicePaths Object containing a mapping of file paths from the system to the device.
359+
* @param {string} projectFilesPath The Path to the app folder inside platforms folder
359360
* @return {Promise<void>}
360361
*/
361362
removeFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath?: string): Promise<void>;
363+
364+
/**
365+
* Transfers specified files to a connected device
366+
* @param {Mobile.IDeviceAppData} deviceAppData Data about device and app.
367+
* @param {Mobile.ILocalToDevicePathData[]} localToDevicePaths Object containing a mapping of file paths from the system to the device.
368+
* @param {string} projectFilesPath The Path to the app folder inside platforms folder
369+
* @param {boolean} isFullSync Indicates if the operation is part of a fullSync
370+
* @return {Promise<Mobile.ILocalToDevicePathData[]>} Returns the ILocalToDevicePathData of all transfered files
371+
*/
362372
transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<Mobile.ILocalToDevicePathData[]>;
363373
}
364374

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { DeviceAndroidDebugBridge } from "../../common/mobile/android/device-and
22
import { AndroidDeviceHashService } from "../../common/mobile/android/android-device-hash-service";
33
import { DeviceLiveSyncServiceBase } from "./device-livesync-service-base";
44
import { APP_FOLDER_NAME } from "../../constants";
5-
import { AndroidLivesyncTool } from "./android-livesync-library";
5+
import { AndroidLivesyncTool } from "./android-livesync-tool";
66
import * as path from "path";
77

88
export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService, INativeScriptDeviceLiveSyncService {
99
private livesyncTool: IAndroidLivesyncTool;
10+
private static STATUS_UPDATE_INTERVAL = 10000;
1011

1112
constructor(
1213
private data: IProjectData,
@@ -30,8 +31,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
3031
}
3132

3233
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
33-
const canExecuteFastSync = !liveSyncInfo.isFullSync && !_.some(liveSyncInfo.modifiedFilesData,
34-
(localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
34+
const canExecuteFastSync = !liveSyncInfo.isFullSync && this.canExecuteFastSyncForPaths(liveSyncInfo.modifiedFilesData, projectData, this.device.deviceInfo.platform);
3535

3636
if (liveSyncInfo.modifiedFilesData.length) {
3737
const operationIdentifier = this.livesyncTool.generateOperationIdentifier();
@@ -41,7 +41,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
4141
if (this.livesyncTool.isOperationInProgress(operationIdentifier)) {
4242
this.$logger.info("Sync operation in progress...");
4343
}
44-
}, 10000);
44+
}, AndroidDeviceSocketsLiveSyncService.STATUS_UPDATE_INTERVAL);
4545

4646
const clearSyncInterval = () => {
4747
clearInterval(syncInterval);
@@ -83,28 +83,28 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
8383
}
8484

8585
private async _transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> {
86-
let transferedFiles: Mobile.ILocalToDevicePathData[];
86+
let transferredLocalToDevicePaths : Mobile.ILocalToDevicePathData[];
8787
const deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
8888
const currentShasums: IStringDictionary = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths);
8989
const oldShasums = await deviceHashService.getShasumsFromDevice();
9090

9191
if (this.$options.force || !oldShasums) {
9292
await this.livesyncTool.sendDirectory(projectFilesPath);
9393
await deviceHashService.uploadHashFileToDevice(currentShasums);
94-
transferedFiles = localToDevicePaths;
94+
transferredLocalToDevicePaths = localToDevicePaths;
9595
} else {
96-
const changedShasums = deviceHashService.getChnagedShasums(oldShasums, currentShasums);
96+
const changedShasums = deviceHashService.getChangedShasums(oldShasums, currentShasums);
9797
const changedFiles = _.keys(changedShasums);
9898
if (changedFiles.length) {
9999
await this.livesyncTool.sendFiles(changedFiles);
100100
await deviceHashService.uploadHashFileToDevice(currentShasums);
101-
transferedFiles = localToDevicePaths.filter(localToDevicePathData => changedFiles.indexOf(localToDevicePathData.getLocalPath()) >= 0);
101+
transferredLocalToDevicePaths = localToDevicePaths.filter(localToDevicePathData => changedFiles.indexOf(localToDevicePathData.getLocalPath()) >= 0);
102102
} else {
103-
transferedFiles = [];
103+
transferredLocalToDevicePaths = [];
104104
}
105105
}
106106

107-
return transferedFiles;
107+
return transferredLocalToDevicePaths ;
108108
}
109109

110110
private async connectLivesyncTool(projectFilesPath: string, appIdentifier: string) {

lib/services/livesync/android-livesync-library.md renamed to lib/services/livesync/android-livesync-tool.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# android-livesync-library
2-
Library for livesyncing changes to a NativeScript application on Android.
1+
# android-livesync-tool
2+
Tool for livesyncing changes to a NativeScript application on Android.
33

44
## Usage
5-
The library has a few public methods that allow file manipulation to the files of a NativeScript application and provide control for refreshing the application. Restarting the application if necessary should be done by the user of this library.
5+
The tool has a few public methods that allow file manipulation to the files of a NativeScript application and provide control for refreshing the application. Restarting the application if necessary should be done by the user of this tool.
66

77
### Getting an instance
88

@@ -12,7 +12,7 @@ const globalModulesPath = require("global-modules-path");
1212
const cliPath = globalModulesPath.getPath("nativescript", "tns");
1313
cli = require(cliPath);
1414

15-
const liveSyncTool = cli.androidLivesyncLibrary;
15+
const liveSyncTool = cli.androidLivesyncTool;
1616
```
1717

1818

lib/services/livesync/android-livesync-library.ts renamed to lib/services/livesync/android-livesync-tool.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ const ERROR_REPORT = 1;
1212
const OPERATION_END_REPORT = 2;
1313
const OPERATION_END_NO_REFRESH_REPORT_CODE = 3;
1414
const REPORT_LENGTH = 1;
15+
const SYNC_OPERATION_TIMEOUT = 60000;
16+
const TRY_CONNECT_TIMEOUT = 30000;
1517
const DEFAULT_LOCAL_HOST_ADDRESS = "127.0.0.1";
1618

1719
export class AndroidLivesyncTool implements IAndroidLivesyncTool {
1820
private operationPromises: IDictionary<any>;
1921
private socketError: string | Error;
2022
private socketConnection: IDuplexSocket;
2123
private configuration: IAndroidLivesyncToolConfiguration;
22-
private appPlatformsPath: string;
2324

2425
constructor(private $androidProcessService: Mobile.IAndroidProcessService,
2526
private $errors: IErrors,
@@ -49,7 +50,6 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
4950
}
5051

5152
this.configuration = configuration;
52-
this.appPlatformsPath = this.configuration.appPlatformsPath;
5353
this.socketError = null;
5454

5555
const port = await this.$androidProcessService.forwardFreeTcpToAbstractPort({
@@ -58,7 +58,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
5858
abstractPort: `localabstract:${configuration.appIdentifier}-livesync`
5959
});
6060

61-
const connectionResult = await this.connectEventuallyUntilTimeout(this.createSocket.bind(this, port), 30000);
61+
const connectionResult = await this.connectEventuallyUntilTimeout(this.createSocket.bind(this, port), TRY_CONNECT_TIMEOUT);
6262
this.handleConnection(connectionResult);
6363
}
6464

@@ -141,7 +141,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
141141
if (this.isOperationInProgress(id)) {
142142
this.handleSocketError(socketId, "Sync operation is taking too long");
143143
}
144-
}, 60000);
144+
}, SYNC_OPERATION_TIMEOUT);
145145
});
146146

147147
return operationPromise;
@@ -282,18 +282,18 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
282282
private connectEventuallyUntilTimeout(factory: () => IDuplexSocket, timeout: number): Promise<{socket: IDuplexSocket, data: NodeBuffer | string}> {
283283
return new Promise((resolve, reject) => {
284284
let lastKnownError: Error | string,
285-
isResolved = false;
285+
isConnected = false;
286286

287287
setTimeout(() => {
288-
if (!isResolved) {
289-
isResolved = true;
288+
if (!isConnected) {
289+
isConnected = true;
290290
reject(lastKnownError);
291291
}
292292
}, timeout);
293293

294294
const tryConnect = () => {
295295
const tryConnectAfterTimeout = (error: Error) => {
296-
if (isResolved) {
296+
if (isConnected) {
297297
return;
298298
}
299299

@@ -310,7 +310,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
310310
socket.once("data", data => {
311311
socket.removeListener("close", tryConnectAfterTimeout);
312312
socket.removeListener("error", tryConnectAfterTimeout);
313-
isResolved = true;
313+
isConnected = true;
314314
resolve({ socket, data });
315315
});
316316
socket.on("close", tryConnectAfterTimeout);
@@ -391,9 +391,9 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
391391
}
392392

393393
private resolveRelativePath(filePath: string): string {
394-
const relativeFilePath = path.relative(this.appPlatformsPath, filePath);
394+
const relativeFilePath = path.relative(this.configuration.appPlatformsPath, filePath);
395395

396396
return this.$mobileHelper.buildDevicePath(relativeFilePath);
397397
}
398398
}
399-
$injector.register("androidLivesyncLibrary", AndroidLivesyncTool);
399+
$injector.register("androidLivesyncTool", AndroidLivesyncTool);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export abstract class DeviceLiveSyncServiceBase {
1414
return _.includes(fastSyncFileExtensions, path.extname(filePath));
1515
}
1616

17+
protected canExecuteFastSyncForPaths(localToDevicePaths: Mobile.ILocalToDevicePathData[], projectData: IProjectData, platform: string) {
18+
return !_.some(localToDevicePaths,
19+
(localToDevicePath: Mobile.ILocalToDevicePathData) =>
20+
!this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
21+
}
22+
1723
@cache()
1824
private getFastLiveSyncFileExtensions(platform: string, projectData: IProjectData): string[] {
1925
const platformData = this.$platformsData.getPlatformData(platform, projectData);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen
6161
constants.LIVESYNC_EXCLUDED_FILE_PATTERNS.forEach(pattern => scriptRelatedFiles = _.concat(scriptRelatedFiles, localToDevicePaths.filter(file => minimatch(file.getDevicePath(), pattern, { nocase: true }))));
6262

6363
const otherFiles = _.difference(localToDevicePaths, _.concat(scriptFiles, scriptRelatedFiles));
64-
const shouldRestart = _.some(otherFiles, (localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, deviceAppData.platform));
64+
const shouldRestart = this.canExecuteFastSyncForPaths(otherFiles, projectData, deviceAppData.platform);
6565

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

0 commit comments

Comments
 (0)