Skip to content

Commit e2205c6

Browse files
author
Dimitar Kerezov
committed
Fix comments vol. I
1 parent 03f0537 commit e2205c6

16 files changed

+123
-107
lines changed

PublicAPI.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ tns.liveSyncService.on("liveSyncStarted", data => {
625625
});
626626
```
627627
628-
* liveSyncExecuted - raised whenever CLI finishes a LiveSync operation for specific device. When `liveSync` method is called, the initial LiveSync operation will emit `liveSyncExecuted` for each specified device once it finishes the operation. After that the event will be emitted whenever a change is detected (in case file system watcher is staretd) and the LiveSync operation is executed for each device. The event is raised with the following data:
628+
* liveSyncExecuted - raised whenever CLI finishes a LiveSync operation for specific device. When `liveSync` method is called, the initial LiveSync operation will emit `liveSyncExecuted` for each specified device once it finishes the operation. After that the event will be emitted whenever a change is detected (in case file system watcher is started) and the LiveSync operation is executed for each device. The event is raised with the following data:
629629
```TypeScript
630630
{
631631
projectDir: string;
@@ -641,7 +641,7 @@ tns.liveSyncService.on("liveSyncStarted", data => {
641641
Example:
642642
```JavaScript
643643
tns.liveSyncService.on("liveSyncExecuted", data => {
644-
console.log(`Executed LiveSync on ${data.deviceIdentifier} for ${data.applicationIdentifier}. Uploaded files are: ${syncedFiles.join(" ")}.`);
644+
console.log(`Executed LiveSync on ${data.deviceIdentifier} for ${data.applicationIdentifier}. Uploaded files are: ${data.syncedFiles.join(" ")}.`);
645645
});
646646
```
647647
@@ -680,7 +680,7 @@ tns.liveSyncService.on("liveSyncStopped", data => {
680680
Example:
681681
```JavaScript
682682
tns.liveSyncService.on("liveSyncError", data => {
683-
console.log(`Error detected during LiveSync on ${data.deviceIdentifier} for ${data.projectDir}. Error: ${err.message}.`);
683+
console.log(`Error detected during LiveSync on ${data.deviceIdentifier} for ${data.projectDir}. Error: ${data.error.message}.`);
684684
});
685685
```
686686
@@ -697,7 +697,7 @@ tns.liveSyncService.on("liveSyncError", data => {
697697
Example:
698698
```JavaScript
699699
tns.liveSyncService.on("notify", data => {
700-
console.log(`Notification: ${notification} for LiveSync operation on ${data.deviceIdentifier} for ${data.projectDir}. `);
700+
console.log(`Notification: ${data.notification} for LiveSync operation on ${data.deviceIdentifier} for ${data.projectDir}. `);
701701
});
702702
```
703703

lib/bootstrap.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,11 @@ $injector.require("devicePathProvider", "./device-path-provider");
104104

105105
$injector.requireCommand("platform|clean", "./commands/platform-clean");
106106

107-
$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
107+
$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service");
108108
$injector.require("debugLiveSyncService", "./services/livesync/debug-livesync-service");
109109
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");
110110
$injector.require("iOSLiveSyncService", "./services/livesync/ios-livesync-service");
111111
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
112-
$injector.require("iosLiveSyncServiceLocator", "./services/livesync/ios-device-livesync-service");
113112
$injector.require("sysInfo", "./sys-info");
114113

115114
$injector.require("iOSNotificationService", "./services/ios-notification-service");

lib/commands/build.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export class BuildCommandBase {
22
constructor(protected $options: IOptions,
3+
protected $errors: IErrors,
34
protected $projectData: IProjectData,
45
protected $platformsData: IPlatformsData,
56
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
@@ -30,29 +31,32 @@ export class BuildCommandBase {
3031
this.$platformService.copyLastOutput(platform, this.$options.copyTo, buildConfig, this.$projectData);
3132
}
3233
}
34+
35+
protected validatePlatform(platform: string): void {
36+
if (!this.$platformService.isPlatformSupportedForOS(platform, this.$projectData)) {
37+
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS - ${process.platform}`);
38+
}
39+
}
3340
}
3441

3542
export class BuildIosCommand extends BuildCommandBase implements ICommand {
3643
public allowedParameters: ICommandParameter[] = [];
3744

3845
constructor(protected $options: IOptions,
39-
private $errors: IErrors,
46+
$errors: IErrors,
4047
$projectData: IProjectData,
4148
$platformsData: IPlatformsData,
4249
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
4350
$platformService: IPlatformService) {
44-
super($options, $projectData, $platformsData, $devicePlatformsConstants, $platformService);
51+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService);
4552
}
4653

4754
public async execute(args: string[]): Promise<void> {
4855
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
4956
}
5057

5158
public canExecute(args: string[]): Promise<boolean> {
52-
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
53-
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.iOS, process.platform);
54-
}
55-
59+
super.validatePlatform(this.$devicePlatformsConstants.iOS);
5660
return args.length === 0 && this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
5761
}
5862
}
@@ -63,23 +67,20 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
6367
public allowedParameters: ICommandParameter[] = [];
6468

6569
constructor(protected $options: IOptions,
66-
private $errors: IErrors,
70+
protected $errors: IErrors,
6771
$projectData: IProjectData,
6872
$platformsData: IPlatformsData,
6973
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
7074
$platformService: IPlatformService) {
71-
super($options, $projectData, $platformsData, $devicePlatformsConstants, $platformService);
75+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService);
7276
}
7377

7478
public async execute(args: string[]): Promise<void> {
7579
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
7680
}
7781

7882
public async canExecute(args: string[]): Promise<boolean> {
79-
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.Android, this.$projectData)) {
80-
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", this.$devicePlatformsConstants.Android, process.platform);
81-
}
82-
83+
super.validatePlatform(this.$devicePlatformsConstants.Android);
8384
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
8485
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
8586
}

lib/commands/debug.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export abstract class DebugPlatformCommand implements ICommand {
3030

3131
this.$config.debugLivesync = true;
3232

33-
// TODO: Fix this call
3433
await this.$devicesService.initialize({ deviceId: this.$options.device, platform: this.platform, skipDeviceDetectionInterval: true, skipInferPlatform: true });
3534
await this.$devicesService.detectCurrentlyAttachedDevices();
3635

@@ -42,7 +41,7 @@ export abstract class DebugPlatformCommand implements ICommand {
4241
identifier: d.deviceInfo.identifier,
4342
buildAction: async (): Promise<string> => {
4443
const buildConfig: IBuildConfig = {
45-
buildForDevice: !d.isEmulator, // this.$options.forDevice,
44+
buildForDevice: !d.isEmulator,
4645
projectDir: this.$options.path,
4746
clean: this.$options.clean,
4847
teamId: this.$options.teamId,
@@ -133,7 +132,7 @@ export class DebugIOSCommand extends DebugPlatformCommand {
133132
}
134133
}
135134

136-
public platform = "iOS";
135+
public platform = this.$devicePlatformsConstants.iOS;
137136
}
138137

139138
$injector.registerCommand("debug|ios", DebugIOSCommand);
@@ -162,7 +161,7 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
162161
return await super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
163162
}
164163

165-
public platform = "Android";
164+
public platform = this.$devicePlatformsConstants.Android;
166165
}
167166

168167
$injector.registerCommand("debug|android", DebugAndroidCommand);

lib/commands/run.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export class RunCommandBase implements ICommand {
7272
return info;
7373
});
7474

75-
if ((!this.platform || this.$mobileHelper.isiOSPlatform(this.platform)) && (this.$options.watch || !this.$options.justlaunch)) {
75+
const workingWithiOSDevices = !this.platform || this.$mobileHelper.isiOSPlatform(this.platform);
76+
const shouldKeepProcessAlive = this.$options.watch || !this.$options.justlaunch;
77+
if (workingWithiOSDevices && shouldKeepProcessAlive) {
7678
this.$iosDeviceOperations.setShouldDispose(false);
7779
}
7880

lib/constants.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ class ItunesConnectApplicationTypesClass implements IiTunesConnectApplicationTyp
7373
}
7474

7575
export const ItunesConnectApplicationTypes = new ItunesConnectApplicationTypesClass();
76-
export const SYNC_DIR_NAME = "sync";
77-
export const REMOVEDSYNC_DIR_NAME = "removedsync";
78-
export const FULLSYNC_DIR_NAME = "fullsync";
79-
export const IOS_DEVICE_PROJECT_ROOT_PATH = "Library/Application Support/LiveSync/app";
80-
export const IOS_DEVICE_SYNC_ZIP_PATH = "Library/Application Support/LiveSync/sync.zip";
76+
export class LiveSyncPaths {
77+
static SYNC_DIR_NAME = "sync";
78+
static REMOVEDSYNC_DIR_NAME = "removedsync";
79+
static FULLSYNC_DIR_NAME = "fullsync";
80+
static IOS_DEVICE_PROJECT_ROOT_PATH = "Library/Application Support/LiveSync";
81+
static IOS_DEVICE_SYNC_ZIP_PATH = "Library/Application Support/LiveSync/sync.zip";
82+
};
8183
export const ANGULAR_NAME = "angular";
8284
export const TYPESCRIPT_NAME = "typescript";
8385
export const BUILD_OUTPUT_EVENT_NAME = "buildOutput";

lib/definitions/livesync.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This interface is a mashup of NodeJS' along with Chokidar's event watchers
12
interface IFSWatcher extends NodeJS.EventEmitter {
23
// from fs.FSWatcher
34
close(): void;
@@ -152,7 +153,6 @@ interface ILiveSyncWatchInfo {
152153
isRebuilt: boolean;
153154
syncAllFiles: boolean;
154155
useLiveEdit?: boolean;
155-
156156
}
157157

158158
interface ILiveSyncResultInfo {
@@ -190,12 +190,11 @@ interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase
190190

191191
/**
192192
* Removes specified files from a connected device
193-
* @param {string} appIdentifier Application identifier.
193+
* @param {Mobile.IDeviceAppData} deviceAppData Data about device and app.
194194
* @param {Mobile.ILocalToDevicePathData[]} localToDevicePaths Object containing a mapping of file paths from the system to the device.
195-
* @param {string} projectId Project identifier - for example org.nativescript.livesync.
196195
* @return {Promise<void>}
197196
*/
198-
removeFiles(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectId: string): Promise<void>;
197+
removeFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void>;
199198
}
200199

201200
interface IAndroidNativeScriptDeviceLiveSyncService {
@@ -209,12 +208,12 @@ interface IAndroidNativeScriptDeviceLiveSyncService {
209208

210209
interface IDeviceProjectRootOptions {
211210
appIdentifier: string;
211+
getDirname?: boolean;
212212
syncAllFiles?: boolean;
213213
watch?: boolean;
214214
}
215215

216216
interface IDevicePathProvider {
217-
getDeviceBuildInfoDirname(device: Mobile.IDevice, appIdentifier: string): Promise<string>;
218217
getDeviceProjectRootPath(device: Mobile.IDevice, options: IDeviceProjectRootOptions): Promise<string>;
219218
getDeviceSyncZipPath(device: Mobile.IDevice): string;
220219
}

lib/definitions/platform.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ interface IPlatformService extends NodeJS.EventEmitter {
5555
* - the .nsbuildinfo file in product folder points to an old prepare.
5656
* @param {string} platform The platform to build.
5757
* @param {IProjectData} projectData DTO with information about the project.
58-
* @param {IBuildConfig} buildConfig Indicates whether the build is for device or emulator.
58+
* @param {IBuildConfig} @optional buildConfig Indicates whether the build is for device or emulator.
59+
* @param {string} @optional outputPath Directory containing build information and artifacts.
5960
* @returns {boolean} true indicates that the platform should be build.
6061
*/
6162
shouldBuild(platform: string, projectData: IProjectData, buildConfig?: IBuildConfig, outputPath?: string): Promise<boolean>;
@@ -77,6 +78,7 @@ interface IPlatformService extends NodeJS.EventEmitter {
7778
* - the .nsbuildinfo file located in application root folder is different than the local .nsbuildinfo file
7879
* @param {Mobile.IDevice} device The device where the application should be installed.
7980
* @param {IProjectData} projectData DTO with information about the project.
81+
* @param {string} @optional outputPath Directory containing build information and artifacts.
8082
* @returns {Promise<boolean>} true indicates that the application should be installed.
8183
*/
8284
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean>;
@@ -87,6 +89,8 @@ interface IPlatformService extends NodeJS.EventEmitter {
8789
* * .nsbuildinfo is not persisted when building for release.
8890
* @param {Mobile.IDevice} device The device where the application should be installed.
8991
* @param {IRelease} options Whether the application was built in release configuration.
92+
* @param {string} @optional pathToBuiltApp Path to build artifact.
93+
* @param {string} @optional outputPath Directory containing build information and artifacts.
9094
* @param {IProjectData} projectData DTO with information about the project.
9195
* @returns {void}
9296
*/
@@ -129,7 +133,10 @@ interface IPlatformService extends NodeJS.EventEmitter {
129133
validatePlatform(platform: string, projectData: IProjectData): void;
130134

131135
/**
132-
* Ensures that passed platform can be built on the current OS
136+
* Checks whether passed platform can be built on the current OS
137+
* @param {string} platform The mobile platform.
138+
* @param {IProjectData} projectData DTO with information about the project.
139+
* @returns {boolean} Whether the platform is supported for current OS or not.
133140
*/
134141
isPlatformSupportedForOS(platform: string, projectData: IProjectData): boolean;
135142

lib/definitions/simple-plist.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "simple-plist" {
2+
export function readFile(filePath: string, callback?:(err: Error, obj: any) => void): void;
3+
export function readFileSync(filePath: string): any;
4+
}

lib/device-path-provider.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fromWindowsRelativePathToUnix } from "./common/helpers";
2-
import { IOS_DEVICE_SYNC_ZIP_PATH, IOS_DEVICE_PROJECT_ROOT_PATH, SYNC_DIR_NAME, FULLSYNC_DIR_NAME } from "./constants";
2+
import { APP_FOLDER_NAME, LiveSyncPaths } from "./constants";
33
import { AndroidDeviceLiveSyncService } from "./services/livesync/android-device-livesync-service";
44
import * as path from "path";
55

@@ -9,39 +9,35 @@ export class DevicePathProvider implements IDevicePathProvider {
99
private $iOSSimResolver: Mobile.IiOSSimResolver) {
1010
}
1111

12-
public async getDeviceBuildInfoDirname(device: Mobile.IDevice, appIdentifier: string): Promise<string> {
13-
let result = "";
14-
if (this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform)) {
15-
result = path.dirname(await this.getDeviceProjectRootPath(device, { appIdentifier }));
16-
} else if (this.$mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) {
17-
result = `/data/local/tmp/${appIdentifier}`;
18-
}
19-
20-
return result;
21-
}
22-
2312
public async getDeviceProjectRootPath(device: Mobile.IDevice, options: IDeviceProjectRootOptions): Promise<string> {
2413
let projectRoot = "";
2514
if (this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform)) {
2615
if (device.isEmulator) {
2716
let applicationPath = this.$iOSSimResolver.iOSSim.getApplicationPath(device.deviceInfo.identifier, options.appIdentifier);
28-
projectRoot = path.join(applicationPath, "app");
17+
projectRoot = path.join(applicationPath);
2918
} else {
30-
projectRoot = IOS_DEVICE_PROJECT_ROOT_PATH;
19+
projectRoot = LiveSyncPaths.IOS_DEVICE_PROJECT_ROOT_PATH;
20+
}
21+
22+
if (!options.getDirname) {
23+
projectRoot = path.join(projectRoot, APP_FOLDER_NAME);
3124
}
3225
} else if (this.$mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) {
33-
const deviceLiveSyncService = this.$injector.resolve<AndroidDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: device });
34-
const hashService = deviceLiveSyncService.getDeviceHashService(options.appIdentifier);
35-
const hashFile = options.syncAllFiles ? null : await hashService.doesShasumFileExistsOnDevice();
36-
const syncFolderName = options.watch || hashFile ? SYNC_DIR_NAME : FULLSYNC_DIR_NAME;
37-
projectRoot = `/data/local/tmp/${options.appIdentifier}/${syncFolderName}`;
26+
projectRoot = `/data/local/tmp/${options.appIdentifier}`;
27+
if (!options.getDirname) {
28+
const deviceLiveSyncService = this.$injector.resolve<AndroidDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: device });
29+
const hashService = deviceLiveSyncService.getDeviceHashService(options.appIdentifier);
30+
const hashFile = options.syncAllFiles ? null : await hashService.doesShasumFileExistsOnDevice();
31+
const syncFolderName = options.watch || hashFile ? LiveSyncPaths.SYNC_DIR_NAME : LiveSyncPaths.FULLSYNC_DIR_NAME;
32+
projectRoot = path.join(projectRoot, syncFolderName);
33+
}
3834
}
3935

4036
return fromWindowsRelativePathToUnix(projectRoot);
4137
}
4238

4339
public getDeviceSyncZipPath(device: Mobile.IDevice): string {
44-
return this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform) && !device.isEmulator ? IOS_DEVICE_SYNC_ZIP_PATH : undefined;
40+
return this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform) && !device.isEmulator ? LiveSyncPaths.IOS_DEVICE_SYNC_ZIP_PATH : undefined;
4541
}
4642
}
4743

0 commit comments

Comments
 (0)