Skip to content

Commit 94b1f9a

Browse files
Merge 'origin/release' into master
2 parents 11bb7b3 + c8f1ee9 commit 94b1f9a

16 files changed

+409
-42
lines changed

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
NativeScript CLI Changelog
22
================
3+
5.0.3 (2018, December 4)
4+
==
5+
### Fixed
6+
* [Fixed #4186](https://github.com/NativeScript/nativescript-cli/issues/4186): Fix stuck http requests/responses
7+
* [Fixed #4189](https://github.com/NativeScript/nativescript-cli/pull/4189): API: Fix "Cannot read property 'removeListener' of undefined" error on second stop of livesync to preview app
8+
9+
10+
5.0.2 (2018, November 29)
11+
==
12+
### Implemented
13+
* [Implemented #4167](https://github.com/NativeScript/nativescript-cli/pull/4167): API: Expose previewAppLiveSyncError event when some error is thrown while livesyncing to preview app
14+
15+
### Fixed
16+
* [Fixed #3962](https://github.com/NativeScript/nativescript-cli/issues/3962): If command 'tns plugin create .. ' failed , directory with plugin repository name must be deleted
17+
* [Fixed #4053](https://github.com/NativeScript/nativescript-cli/issues/4053): Update Nativescript cli setup scripts to use android sdk 28
18+
* [Fixed #4077](https://github.com/NativeScript/nativescript-cli/issues/4077): Platform add with framework path and custom version breaks run with "--bundle"
19+
* [Fixed #4129](https://github.com/NativeScript/nativescript-cli/issues/4129): tns preview doesn't sync changes when download 2 Playground projects
20+
* [Fixed #4135](https://github.com/NativeScript/nativescript-cli/issues/4135): Too many TypeScript "Watching for file changes" messages in console during build
21+
* [Fixed #4158](https://github.com/NativeScript/nativescript-cli/pull/4158): API: reset devices list when stopLiveSync method is called
22+
* [Fixed #4161](https://github.com/NativeScript/nativescript-cli/pull/4161): API: raise deviceLost event after timeout of 5 seconds
23+
324

425
5.0.1 (2018, November 14)
526
==

PublicAPI.md

+78
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const tns = require("nativescript");
3737
* [debug](#debug)
3838
* [liveSyncService](#livesyncservice)
3939
* [liveSync](#livesync)
40+
* [liveSyncToPreviewApp](#livesynctopreviewapp)
4041
* [stopLiveSync](#stopLiveSync)
4142
* [enableDebugging](#enableDebugging)
4243
* [attachDebugger](#attachDebugger)
@@ -59,6 +60,12 @@ const tns = require("nativescript");
5960
* [startEmulator](#startemulator)
6061
* [deviceEmitter](#deviceemitter)
6162
* [events](#deviceemitterevents)
63+
* [previewDevicesService](#previewdevicesservice)
64+
* [deviceFound](#devicefound)
65+
* [deviceLost](#devicelost)
66+
* [deviceLog](#devicelog)
67+
* [previewQrCodeService](#previewqrcodeservice)
68+
* [getPlaygroundAppQrCode](#getplaygroundappqrcode)
6269

6370
## Module projectService
6471

@@ -779,6 +786,33 @@ tns.liveSyncService.liveSync([ androidDeviceDescriptor, iOSDeviceDescriptor ], l
779786
});
780787
```
781788
789+
### liveSyncToPreviewApp
790+
Starts a LiveSync operation to the Preview app. After scanning the QR code with the scanner provided in the NativeScript Playground app, the app will be launched on a device through the Preview app. Additionally, any changes made to the project will be automatically synchronized with the deployed app.
791+
792+
* Definition
793+
```TypeScript
794+
/**
795+
* Starts LiveSync operation by producting a QR code and starting watcher.
796+
* @param {IPreviewAppLiveSyncData} liveSyncData Describes the LiveSync operation - for which project directory is the operation and other settings.
797+
* @returns {Promise<IQrCodeImageData>}
798+
*/
799+
liveSyncToPreviewApp(liveSyncData: IPreviewAppLiveSyncData): Promise<IQrCodeImageData>;
800+
```
801+
802+
* Usage:
803+
```JavaScript
804+
const liveSyncData = {
805+
projectDir,
806+
bundle: false,
807+
useHotModuleReload: false,
808+
env: { }
809+
};
810+
tns.liveSyncService.liveSyncToPreviewApp(liveSyncData)
811+
.then(qrCodeImageData => {
812+
console.log("The qrCodeImageData is: " + qrCodeImageData);
813+
});
814+
```
815+
782816
### stopLiveSync
783817
Stops LiveSync operation. In case deviceIdentifires are passed, the operation will be stopped only for these devices.
784818
@@ -1352,6 +1386,50 @@ tns.deviceEmitter.on("emulatorImageLost", (emulatorImageInfo) => {
13521386
```
13531387
`emulatorImageInfo` is of type [Moble.IDeviceInfo](https://github.com/telerik/mobile-cli-lib/blob/61cdaaaf7533394afbbe84dd4eee355072ade2de/definitions/mobile.d.ts#L9-L86).
13541388
1389+
## previewDevicesService
1390+
The `previewDevicesService` module allows interaction with preview devices. You can get a list of the connected preview devices and logs from specified device.
1391+
1392+
### previewDevicesEmitterEvents
1393+
1394+
* `deviceFound` - Raised when the QR code is scanned with any device. The callback function will receive one argument - `device`.
1395+
Sample usage:
1396+
```JavaScript
1397+
tns.previewDevicesService.on("deviceFound", device => {
1398+
console.log("Attached device with identifier: " + device.id);
1399+
});
1400+
```
1401+
1402+
* `deviceLost` - Raised when the Preview app is stopped on a specified device. The callback function will receive one argument - `device`.
1403+
Sample usage:
1404+
```JavaScript
1405+
tns.previewDevicesService.on("deviceLost", device => {
1406+
console.log("Detached device with identifier: " + device.id);
1407+
});
1408+
```
1409+
1410+
* `deviceLog` - Raised when the app deployed in Preview app reports any information. The event is raised for any device that reports data. The callback function has two arguments - `device` and `message`. <br/><br/>
1411+
Sample usage:
1412+
```JavaScript
1413+
tns.previewDevicesService.on("deviceLogData", (device, message) => {
1414+
console.log("Device " + device.id + " reports: " + message);
1415+
});
1416+
```
1417+
1418+
## previewQrCodeService
1419+
The `previewQrCodeService` exposes methods for getting information about the QR of the Playground app and deployed app in Preview app.
1420+
1421+
### getPlaygroundAppQrCode
1422+
Returns information used to generate the QR code of the Playground app.
1423+
1424+
* Usage:
1425+
```TypeScript
1426+
tns.previewQrCodeService.getPlaygroundAppQrCode()
1427+
.then(result => {
1428+
console.log("QR code data for iOS platform: " + result.ios);
1429+
console.log("QR code data for Android platform: " + result.android);
1430+
});
1431+
```
1432+
13551433
## How to add a new method to Public API
13561434
CLI is designed as command line tool and when it is used as a library, it does not give you access to all of the methods. This is mainly implementation detail. Most of the CLI's code is created to work in command line, not as a library, so before adding method to public API, most probably it will require some modification.
13571435
For example the `$options` injected module contains information about all `--` options passed on the terminal. When the CLI is used as a library, the options are not populated. Before adding method to public API, make sure its implementation does not rely on `$options`.

lib/commands/plugin/create-plugin.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export class CreatePluginCommand implements ICommand {
55
public allowedParameters: ICommandParameter[] = [];
66
public userMessage = "What is your GitHub username?\n(will be used to update the Github URLs in the plugin's package.json)";
77
public nameMessage = "What will be the name of your plugin?\n(use lowercase characters and dashes only)";
8+
public pathAlreadyExistsMessageTemplate = "Path already exists and is not empty %s";
89
constructor(private $options: IOptions,
910
private $errors: IErrors,
1011
private $terminalSpinnerService: ITerminalSpinnerService,
@@ -22,8 +23,17 @@ export class CreatePluginCommand implements ICommand {
2223
const selectedPath = path.resolve(pathToProject || ".");
2324
const projectDir = path.join(selectedPath, pluginRepoName);
2425

25-
await this.downloadPackage(selectedTemplate, projectDir);
26-
await this.setupSeed(projectDir, pluginRepoName);
26+
// Must be out of try catch block, because will throw error if folder alredy exists and we don't want to delete it.
27+
this.ensurePackageDir(projectDir);
28+
29+
try {
30+
await this.downloadPackage(selectedTemplate, projectDir);
31+
await this.setupSeed(projectDir, pluginRepoName);
32+
} catch (err) {
33+
// The call to this.ensurePackageDir() above will throw error if folder alredy exists, so it is safe to delete here.
34+
this.$fs.deleteDirectory(projectDir);
35+
throw err;
36+
}
2737

2838
this.$logger.printMarkdown("Solution for `%s` was successfully created.", pluginRepoName);
2939
}
@@ -66,13 +76,15 @@ export class CreatePluginCommand implements ICommand {
6676
}
6777
}
6878

69-
private async downloadPackage(selectedTemplate: string, projectDir: string): Promise<void> {
79+
private ensurePackageDir(projectDir: string): void {
7080
this.$fs.createDirectory(projectDir);
7181

7282
if (this.$fs.exists(projectDir) && !this.$fs.isEmptyDir(projectDir)) {
73-
this.$errors.fail("Path already exists and is not empty %s", projectDir);
83+
this.$errors.fail(this.pathAlreadyExistsMessageTemplate, projectDir);
7484
}
85+
}
7586

87+
private async downloadPackage(selectedTemplate: string, projectDir: string): Promise<void> {
7688
if (selectedTemplate) {
7789
this.$logger.printMarkdown("Make sure your custom template is compatible with the Plugin Seed at https://github.com/NativeScript/nativescript-plugin-seed/");
7890
} else {
@@ -84,9 +96,6 @@ export class CreatePluginCommand implements ICommand {
8496
try {
8597
spinner.start();
8698
await this.$pacoteService.extractPackage(packageToInstall, projectDir);
87-
} catch (err) {
88-
this.$fs.deleteDirectory(projectDir);
89-
throw err;
9099
} finally {
91100
spinner.stop();
92101
}

lib/common/declarations.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ declare module Server {
163163
interface IRequestResponseData {
164164
statusCode: number;
165165
headers: { [index: string]: any };
166+
complete: boolean;
166167
pipe(destination: any, options?: { end?: boolean; }): IRequestResponseData;
167168
on(event: string, listener: Function): void;
169+
destroy(error?: Error): void;
168170
}
169171
}
170172

@@ -744,7 +746,7 @@ interface IAnalyticsSettingsService {
744746
* Gets information for projects that are exported from playground
745747
* @param projectDir Project directory path
746748
*/
747-
getPlaygroundInfo(projectDir?: string): Promise<IPlaygroundInfo>;
749+
getPlaygroundInfo(projectDir?: string): Promise<IPlaygroundInfo>;
748750
}
749751

750752
/**

0 commit comments

Comments
 (0)