Skip to content

Commit e7edf2d

Browse files
committed
Add warnings for plugins not presented in preview app on device
1 parent 5986b60 commit e7edf2d

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lib/services/livesync/playground/preview-app-livesync-service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
1010
private $platformsData: IPlatformsData,
1111
private $projectDataService: IProjectDataService,
1212
private $previewSdkService: IPreviewSdkService,
13+
private $previewAppPluginsService: IPreviewAppPluginsService,
1314
private $projectFilesManager: IProjectFilesManager,
1415
private $qrCodeTerminalService: IQrCodeTerminalService) { }
1516

@@ -38,6 +39,8 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
3839
}
3940

4041
private async trySyncFilesOnDevice(data: IPreviewAppLiveSyncData, device: Device, files?: string[]): Promise<void> {
42+
await this.$previewAppPluginsService.comparePluginsOnDevice(device);
43+
4144
this.$logger.info(`Start syncing changes on device ${device.id}.`);
4245

4346
try {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as path from "path";
2+
import * as semver from "semver";
3+
import { Device } from "nativescript-preview-sdk";
4+
5+
export class PreviewAppPluginsService implements IPreviewAppPluginsService {
6+
constructor(private $fs: IFileSystem,
7+
private $logger: ILogger,
8+
private $projectData: IProjectData) { }
9+
10+
public async comparePluginsOnDevice(device: Device): Promise<void> {
11+
const devicePlugins = this.getDevicePlugins(device);
12+
const localPlugins = this.getLocalPlugins();
13+
14+
_.keys(localPlugins).forEach(localPlugin => {
15+
const localPluginVersion = localPlugins[localPlugin];
16+
const devicePluginVersion = devicePlugins[localPlugin];
17+
18+
this.$logger.trace(`Comparing plugin ${localPlugin} with localPluginVersion ${localPluginVersion} and devicePluginVersion ${devicePluginVersion}`);
19+
20+
if (!devicePluginVersion) {
21+
this.$logger.warn(`Plugin ${localPlugin} is not included in preview app and will not work.`);
22+
}
23+
24+
if (devicePluginVersion && semver.gt(semver.coerce(localPluginVersion), semver.coerce(devicePluginVersion))) {
25+
this.$logger.warn(`Plugin ${localPlugin} has local version ${localPluginVersion} but preview app has ${devicePluginVersion} version of plugin. Some functionalities may not work.`);
26+
}
27+
});
28+
}
29+
30+
private getDevicePlugins(device: Device): IStringDictionary {
31+
try {
32+
return JSON.parse(device.plugins);
33+
} catch (err) {
34+
this.$logger.trace(`Error while parsing plugins from device ${device.id}. Error is ${err.message}`);
35+
return {};
36+
}
37+
}
38+
39+
private getLocalPlugins(): IStringDictionary {
40+
const projectFilePath = path.join(this.$projectData.projectDir, "package.json");
41+
try {
42+
return this.$fs.readJson(projectFilePath).dependencies;
43+
} catch (err) {
44+
this.$logger.trace(`Error while parsing ${projectFilePath}. Error is ${err.message}`);
45+
return {};
46+
}
47+
}
48+
}
49+
$injector.register("previewAppPluginsService", PreviewAppPluginsService);

0 commit comments

Comments
 (0)