Skip to content

Commit 8ccf75f

Browse files
rosen-vladimirovDimitar Kerezov
authored andcommitted
New LiveSync
1 parent 33d79ab commit 8ccf75f

21 files changed

+569
-433
lines changed

lib/bootstrap.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ $injector.requireCommand("platform|clean", "./commands/platform-clean");
105105
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
106106
$injector.require("iosLiveSyncServiceLocator", "./services/livesync/ios-device-livesync-service");
107107
$injector.require("androidLiveSyncServiceLocator", "./services/livesync/android-device-livesync-service");
108-
$injector.require("platformLiveSyncService", "./services/livesync/platform-livesync-service");
109108

110109
$injector.require("sysInfo", "./sys-info");
111110

lib/commands/appstore-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export class ListiOSApps implements ICommand {
1212
private $platformService: IPlatformService,
1313
private $errors: IErrors,
1414
private $prompter: IPrompter) {
15-
this.$projectData.initializeProjectData();
16-
}
15+
this.$projectData.initializeProjectData();
16+
}
1717

1818
public async execute(args: string[]): Promise<void> {
1919
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {

lib/commands/debug.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export abstract class DebugPlatformCommand implements ICommand {
5656
this.printDebugInformation(await this.debugService.debug<string[]>(debugData, debugOptions));
5757
};
5858

59-
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, this.$projectData, applicationReloadAction);
59+
// TODO: Fix this call
60+
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, this.$projectData, applicationReloadAction, this.$options);
6061
}
6162

6263
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export class RunCommandBase {
4242
return this.$platformService.trackProjectType(this.$projectData);
4343
}
4444

45-
return this.$usbLiveSyncService.liveSync(args[0], this.$projectData);
45+
// TODO: Fix this call
46+
return this.$usbLiveSyncService.liveSync(args[0], this.$projectData, null, this.$options);
4647
}
4748
}
4849

lib/declarations.d.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ interface IOpener {
257257
open(target: string, appname: string): void;
258258
}
259259

260+
// TODO: Fix
260261
interface ILiveSyncService {
261-
liveSync(platform: string, projectData: IProjectData, applicationReloadAction?: (deviceAppData: Mobile.IDeviceAppData) => Promise<void>): Promise<void>;
262+
liveSync(platform: string, projectData: IProjectData, applicationReloadAction?: (deviceAppData: Mobile.IDeviceAppData) => Promise<void>, options?: IOptions): Promise<void>;
262263
}
263264

264265
interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase {
@@ -282,12 +283,6 @@ interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase
282283
afterInstallApplicationAction?(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectId: string): Promise<boolean>;
283284
}
284285

285-
interface IPlatformLiveSyncService {
286-
fullSync(projectData: IProjectData, postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => Promise<void>): Promise<void>;
287-
partialSync(event: string, filePath: string, dispatcher: IFutureDispatcher, afterFileSyncAction: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => Promise<void>, projectData: IProjectData): Promise<void>;
288-
refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], isFullSync: boolean, projectData: IProjectData): Promise<void>;
289-
}
290-
291286
interface IBundle {
292287
bundle: boolean;
293288
}

lib/definitions/platform.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interface IPlatformService extends NodeJS.EventEmitter {
5858
* @param {IBuildConfig} buildConfig Indicates whether the build is for device or emulator.
5959
* @returns {boolean} true indicates that the platform should be build.
6060
*/
61-
shouldBuild(platform: string, projectData: IProjectData, buildConfig?: IBuildConfig): Promise<boolean>;
61+
shouldBuild(platform: string, projectData: IProjectData, buildConfig?: IBuildConfig, outputPath?: string): Promise<boolean>;
6262

6363
/**
6464
* Builds the native project for the specified platform for device or emulator.
@@ -79,7 +79,7 @@ interface IPlatformService extends NodeJS.EventEmitter {
7979
* @param {IProjectData} projectData DTO with information about the project.
8080
* @returns {Promise<boolean>} true indicates that the application should be installed.
8181
*/
82-
shouldInstall(device: Mobile.IDevice, projectData: IProjectData): Promise<boolean>;
82+
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean>;
8383

8484
/**
8585
* Installs the application on specified device.
@@ -90,7 +90,7 @@ interface IPlatformService extends NodeJS.EventEmitter {
9090
* @param {IProjectData} projectData DTO with information about the project.
9191
* @returns {void}
9292
*/
93-
installApplication(device: Mobile.IDevice, options: IRelease, projectData: IProjectData): Promise<void>;
93+
installApplication(device: Mobile.IDevice, options: IRelease, projectData: IProjectData, pathToBuiltApp?: string, outputPath?: string): Promise<void>;
9494

9595
/**
9696
* Gets first chance to validate the options provided as command line arguments.

lib/definitions/project.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ interface IProjectDataService {
105105
* @returns {void}
106106
*/
107107
removeDependency(projectDir: string, dependencyName: string): void;
108+
109+
getProjectData(projectDir: string): IProjectData;
108110
}
109111

110112
/**

lib/services/android-project-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
6565

6666
return [
6767
`${packageName}-${buildMode}.apk`,
68-
`${projectData.projectName}-${buildMode}.apk`
68+
`${projectData.projectName}-${buildMode}.apk`,
69+
`${projectData.projectName}.apk`
6970
];
7071
},
7172
frameworkFilesExtensions: [".jar", ".dat", ".so"],

lib/services/ios-project-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
503503
let project = this.createPbxProj(projectData);
504504
let frameworkName = path.basename(frameworkPath, path.extname(frameworkPath));
505505
let frameworkBinaryPath = path.join(frameworkPath, frameworkName);
506-
let isDynamic = _.includes((await this.$childProcess.spawnFromEvent(path.join(__dirname, "..", "..", "vendor", "file", "file.exe"), [frameworkBinaryPath], "close")).stdout, "dynamically linked");
506+
const pathToFileCommand = this.$hostInfo.isWindows ? path.join(__dirname, "..", "..", "vendor", "file", "file.exe") : "file";
507+
let isDynamic = _.includes((await this.$childProcess.spawnFromEvent(pathToFileCommand, [frameworkBinaryPath], "close")).stdout, "dynamically linked");
507508

508509
let frameworkAddOptions: IXcode.Options = { customFramework: true };
509510

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

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,54 @@ import { AndroidDeviceHashService } from "../../common/mobile/android/android-de
33
import * as helpers from "../../common/helpers";
44
import * as path from "path";
55
import * as net from "net";
6+
import { EOL } from "os";
67

7-
class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncService {
8+
export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncService {
89
private static BACKEND_PORT = 18182;
910
private device: Mobile.IAndroidDevice;
1011

1112
constructor(_device: Mobile.IDevice,
1213
private $mobileHelper: Mobile.IMobileHelper,
1314
private $injector: IInjector,
14-
private $androidDebugService: IDebugService,
15+
private $logger: ILogger,
16+
private $androidDebugService: IPlatformDebugService,
1517
private $liveSyncProvider: ILiveSyncProvider) {
1618
this.device = <Mobile.IAndroidDevice>(_device);
1719
}
1820

19-
public get debugService(): IDebugService {
21+
public get debugService(): IPlatformDebugService {
2022
return this.$androidDebugService;
2123
}
2224

23-
public async refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], forceExecuteFullSync: boolean, projectData: IProjectData): Promise<void> {
25+
public async refreshApplication(deviceAppData: Mobile.IDeviceAppData,
26+
localToDevicePaths: Mobile.ILocalToDevicePathData[],
27+
forceExecuteFullSync: boolean,
28+
projectData: IProjectData,
29+
outputFilePath?: string,
30+
debugData?: IDebugData,
31+
debugOptions?: IOptions): Promise<void> {
32+
33+
if (debugData) {
34+
// TODO: Move this outside of here
35+
await this.debugService.debugStop();
36+
37+
let applicationId = deviceAppData.appIdentifier;
38+
await deviceAppData.device.applicationManager.stopApplication(applicationId, projectData.projectName);
39+
40+
debugData.pathToAppPackage = outputFilePath;
41+
const debugInfo = await this.debugService.debug<string[]>(debugData, debugOptions);
42+
this.printDebugInformation(debugInfo);
43+
44+
return;
45+
}
46+
2447
await this.device.adb.executeShellCommand(
2548
["chmod",
26-
"777",
27-
await deviceAppData.getDeviceProjectRootPath(),
28-
`/data/local/tmp/${deviceAppData.appIdentifier}`,
29-
`/data/local/tmp/${deviceAppData.appIdentifier}/sync`]
30-
);
49+
"777",
50+
await deviceAppData.getDeviceProjectRootPath(),
51+
`/data/local/tmp/${deviceAppData.appIdentifier}`,
52+
`/data/local/tmp/${deviceAppData.appIdentifier}/sync`]
53+
);
3154

3255
let canExecuteFastSync = !forceExecuteFullSync && !_.some(localToDevicePaths, (localToDevicePath: any) => !this.$liveSyncProvider.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, deviceAppData.platform));
3356

@@ -38,6 +61,12 @@ class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncService {
3861
return this.restartApplication(deviceAppData);
3962
}
4063

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+
4170
private async restartApplication(deviceAppData: Mobile.IDeviceAppData): Promise<void> {
4271
let devicePathRoot = `/data/data/${deviceAppData.appIdentifier}/files`;
4372
let devicePath = this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb");

0 commit comments

Comments
 (0)