-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlivesync-service.ts
67 lines (56 loc) · 2.82 KB
/
livesync-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
///<reference path="../../.d.ts"/>
"use strict";
import * as constants from "../../constants";
import * as path from "path";
import * as semver from "semver";
class LiveSyncService implements ILiveSyncService {
private _isInitialized = false;
constructor(private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $liveSyncServiceBase: ILiveSyncServiceBase,
private $platformsData: IPlatformsData,
private $platformService: IPlatformService,
private $projectData: IProjectData,
private $projectDataService: IProjectDataService,
private $prompter: IPrompter) { }
private ensureAndroidFrameworkVersion(platformData: IPlatformData): IFuture<void> { // TODO: this can be moved inside command or canExecute function
return (() => {
this.$projectDataService.initialize(this.$projectData.projectDir);
let frameworkVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).wait().version;
if (platformData.normalizedPlatformName.toLowerCase() === this.$devicePlatformsConstants.Android.toLowerCase()) {
if (semver.lt(frameworkVersion, "1.2.1")) {
let shouldUpdate = this.$prompter.confirm("You need Android Runtime 1.2.1 or later for LiveSync to work properly. Do you want to update your runtime now?").wait();
if (shouldUpdate) {
this.$platformService.updatePlatforms([this.$devicePlatformsConstants.Android.toLowerCase()]).wait();
} else {
return;
}
}
}
}).future<void>()();
}
public get isInitialized(): boolean { // This function is used from https://github.com/NativeScript/nativescript-dev-typescript/blob/master/lib/before-prepare.js#L4
return this._isInitialized;
}
public liveSync(platform: string): IFuture<void> {
return (() => {
platform = this.$liveSyncServiceBase.getPlatform(platform).wait();
let platformLowerCase = platform.toLowerCase();
if (!this.$platformService.preparePlatform(platformLowerCase).wait()) {
this.$errors.failWithoutHelp("Verify that listed files are well-formed and try again the operation.");
}
this._isInitialized = true; // If we want before-prepare hooks to work properly, this should be set after preparePlatform function
let platformData = this.$platformsData.getPlatformData(platformLowerCase);
this.ensureAndroidFrameworkVersion(platformData).wait();
let liveSyncData: ILiveSyncData = {
platform: platform,
appIdentifier: this.$projectData.projectId,
projectFilesPath: path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME),
syncWorkingDirectory: path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME),
excludedProjectDirsAndFiles: ["**/*.js.map", "**/*.ts"]
};
this.$liveSyncServiceBase.sync(liveSyncData).wait();
}).future<void>()();
}
}
$injector.register("usbLiveSyncService", LiveSyncService);