Skip to content

Commit e738b45

Browse files
authored
Merge pull request #1902 from NativeScript/raikov/livesync-watch
Livesync without platform syncs all devices
2 parents 3a7d7fc + 80d3172 commit e738b45

File tree

8 files changed

+56
-21
lines changed

8 files changed

+56
-21
lines changed

lib/npm-installation-manager.ts

+5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ export class NpmInstallationManager implements INpmInstallationManager {
106106

107107
public install(packageName: string, opts?: INpmInstallOptions): IFuture<string> {
108108
return (() => {
109+
110+
while (this.$lockfile.check().wait()) {
111+
;
112+
}
113+
109114
this.$lockfile.lock().wait();
110115

111116
try {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as path from "path";
77
import * as net from "net";
88

99
class AndroidLiveSyncService extends liveSyncServiceBaseLib.LiveSyncServiceBase<Mobile.IAndroidDevice> implements IPlatformLiveSyncService {
10-
private static BACKEND_PORT = 18181;
10+
private static BACKEND_PORT = 18182;
1111

1212
constructor(_device: Mobile.IDevice,
1313
private $fs: IFileSystem,

lib/services/livesync/livesync-service.ts

+37-17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class LiveSyncService implements ILiveSyncService {
1616
private $projectDataService: IProjectDataService,
1717
private $prompter: IPrompter,
1818
private $injector: IInjector,
19+
private $mobileHelper: Mobile.IMobileHelper,
20+
private $devicesService: Mobile.IDevicesService,
1921
private $options: IOptions) { }
2022

2123
private ensureAndroidFrameworkVersion(platformData: IPlatformData): IFuture<void> { // TODO: this can be moved inside command or canExecute function
@@ -42,32 +44,50 @@ class LiveSyncService implements ILiveSyncService {
4244

4345
public liveSync(platform: string): IFuture<void> {
4446
return (() => {
45-
platform = this.$liveSyncServiceBase.getPlatform(platform).wait();
46-
let platformLowerCase = platform.toLowerCase();
47-
48-
if (!this.$platformService.preparePlatform(platformLowerCase).wait()) {
49-
this.$errors.failWithoutHelp("Verify that listed files are well-formed and try again the operation.");
47+
let liveSyncData: ILiveSyncData[] = [];
48+
this.$devicesService.initialize({ skipInferPlatform: true }).wait();
49+
if (platform) {
50+
liveSyncData.push(this.prepareLiveSyncData(platform));
51+
} else if (this.$options.device) {
52+
platform = this.$devicesService.getDeviceByIdentifier(this.$options.device).deviceInfo.platform;
53+
liveSyncData.push(this.prepareLiveSyncData(platform));
54+
} else {
55+
for(let installedPlatform of this.$platformService.getInstalledPlatforms().wait()) {
56+
liveSyncData.push(this.prepareLiveSyncData(installedPlatform));
57+
}
5058
}
5159

5260
this._isInitialized = true; // If we want before-prepare hooks to work properly, this should be set after preparePlatform function
5361

54-
this.liveSyncCore(platform).wait();
62+
this.liveSyncCore(liveSyncData).wait();
5563
}).future<void>()();
5664
}
5765

66+
private prepareLiveSyncData(platform: string): ILiveSyncData {
67+
platform = this.$liveSyncServiceBase.getPlatform(platform).wait();
68+
if (!this.$platformService.preparePlatform(platform.toLowerCase()).wait()) {
69+
this.$errors.failWithoutHelp("Verify that listed files are well-formed and try again the operation.");
70+
}
71+
72+
let platformData = this.$platformsData.getPlatformData(platform.toLowerCase());
73+
if (this.$mobileHelper.isAndroidPlatform(platform)) {
74+
this.ensureAndroidFrameworkVersion(platformData).wait();
75+
}
76+
let liveSyncData: ILiveSyncData = {
77+
platform: platform,
78+
appIdentifier: this.$projectData.projectId,
79+
projectFilesPath: path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME),
80+
syncWorkingDirectory: path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME),
81+
excludedProjectDirsAndFiles: this.$options.release ? constants.LIVESYNC_EXCLUDED_FILE_PATTERNS : [],
82+
forceExecuteFullSync: this.forceExecuteFullSync
83+
};
84+
85+
return liveSyncData;
86+
}
87+
5888
@helpers.hook('livesync')
59-
private liveSyncCore(platform: string): IFuture<void> {
89+
private liveSyncCore(liveSyncData: ILiveSyncData[]): IFuture<void> {
6090
return (() => {
61-
let platformData = this.$platformsData.getPlatformData(platform.toLowerCase());
62-
this.ensureAndroidFrameworkVersion(platformData).wait();
63-
let liveSyncData: ILiveSyncData = {
64-
platform: platform,
65-
appIdentifier: this.$projectData.projectId,
66-
projectFilesPath: path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME),
67-
syncWorkingDirectory: path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME),
68-
excludedProjectDirsAndFiles: this.$options.release ? constants.LIVESYNC_EXCLUDED_FILE_PATTERNS : [],
69-
forceExecuteFullSync: this.forceExecuteFullSync
70-
};
7191
this.$liveSyncServiceBase.sync(liveSyncData).wait();
7292
}).future<void>()();
7393
}

lib/services/platform-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class PlatformService implements IPlatformService {
322322
// Replace placeholders in configuration files
323323
platformData.platformProjectService.interpolateConfigurationFile().wait();
324324

325-
this.$logger.out("Project successfully prepared");
325+
this.$logger.out("Project successfully prepared ("+platform+")");
326326
return true;
327327
}).future<boolean>()();
328328
}

lib/services/test-execution-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class TestExecutionService implements ITestExecutionService {
231231
excludedProjectDirsAndFiles: this.$options.release ? constants.LIVESYNC_EXCLUDED_FILE_PATTERNS : []
232232
};
233233

234-
this.$liveSyncServiceBase.sync(liveSyncData).wait();
234+
this.$liveSyncServiceBase.sync([liveSyncData]).wait();
235235
}).future<void>()();
236236
}
237237
}

lib/tools/broccoli/builder.ts

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export class Builder implements IBroccoliBuilder {
3434
stat: true
3535
}, (er: Error, files: string[]) => {
3636
fiberBootstrap.run(() => {
37+
38+
while (this.$lockfile.check().wait()) {
39+
;
40+
}
41+
3742
this.$lockfile.lock().wait();
3843
if (er) {
3944
if (!future.isResolved()) {

test/stubs.ts

+5
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ export class HooksServiceStub implements IHooksService {
410410
}
411411

412412
export class LockFile {
413+
414+
check(): IFuture<boolean> {
415+
return (() => { return false; }).future<boolean>()();
416+
}
417+
413418
lock(): IFuture<void> {
414419
return (() => {}).future<void>()();
415420
}

0 commit comments

Comments
 (0)