1- import { PlaygroundStoreUrls } from "./preview-app-constants" ;
21import * as util from "util" ;
3- const chalk = require ( "chalk" ) ;
2+ import { EOL } from "os" ;
3+ import { PlaygroundStoreUrls } from "./preview-app-constants" ;
44
55export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
66 constructor ( private $previewSdkService : IPreviewSdkService ,
@@ -10,27 +10,8 @@ export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
1010 private $logger : ILogger ) {
1111 }
1212
13- public async generateQrCodeForiOS ( ) : Promise < void > {
14- const message = `Scan the QR code below to install ${ "NativeScript Playground app" . underline . bold } on your ${ "iOS" . underline . bold } device or get it from ${ PlaygroundStoreUrls . APP_STORE_URL . underline . bold } .` ;
15- await this . generateQrCode ( PlaygroundStoreUrls . APP_STORE_URL , message ) ;
16- }
17-
18- public async generateQrCodeForAndroid ( ) : Promise < void > {
19- const message = `Scan the QR code below to install ${ "NativeScript Playground app" . underline . bold } on your ${ "Android" . underline . bold } device or get it from ${ PlaygroundStoreUrls . GOOGLE_PLAY_URL . underline . bold } .` ;
20- await this . generateQrCode ( PlaygroundStoreUrls . GOOGLE_PLAY_URL , message ) ;
21- }
22-
23- public async generateQrCodeForCurrentApp ( options : IHasUseHotModuleReloadOption ) : Promise < void > {
24- const message = `Use ${ "NativeScript Playground app" . underline . bold } and scan the QR code below to preview the application on your device.` ;
25- await this . generateQrCode ( this . $previewSdkService . getQrCodeUrl ( options ) , message ) ;
26- }
27-
28- private async generateQrCode ( url : string , message : string ) : Promise < void > {
29- await this . generateQrCodeCore ( url , message ) ;
30- this . printUsage ( ) ;
31- }
32-
33- private async generateQrCodeCore ( url : string , message : string ) : Promise < void > {
13+ public async generateQrCode ( options : IGenerateQrCodeOptions ) : Promise < void > {
14+ let url = this . $previewSdkService . getQrCodeUrl ( options ) ;
3415 const shortenUrlEndpoint = util . format ( this . $config . SHORTEN_URL_ENDPOINT , encodeURIComponent ( url ) ) ;
3516 try {
3617 const response = await this . $httpClient . httpRequest ( shortenUrlEndpoint ) ;
@@ -40,20 +21,22 @@ export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
4021 // use the longUrl
4122 }
4223
43- this . $qrCodeTerminalService . generate ( url , message ) ;
44- }
45-
46- private printUsage ( ) : void {
47- this . $logger . info ( `
48- -> Press ${ this . underlineBoldCyan ( "a" ) } to get a link to NativeScript Playground app for ${ this . underlineBoldCyan ( "Android" ) } on Google Play
49- -> Press ${ this . underlineBoldCyan ( "i" ) } to get a link to NativeScript Playground app for ${ this . underlineBoldCyan ( "iOS" ) } on the App Store
50- -> Press ${ this . underlineBoldCyan ( "c" ) } to show the QR code of ${ this . underlineBoldCyan ( "your application" ) }
51- ` ) ;
52- }
53-
54- private underlineBoldCyan ( str : string ) {
55- const { bold, underline, cyan } = chalk ;
56- return underline ( bold ( cyan ( str ) ) ) ;
24+ this . $logger . info ( ) ;
25+ const message = `${ EOL } Generating qrcode for url ${ url } .` ;
26+ this . $logger . trace ( message ) ;
27+
28+ if ( options . link ) {
29+ this . $logger . printMarkdown ( message ) ;
30+ } else {
31+ this . $qrCodeTerminalService . generate ( url ) ;
32+
33+ this . $logger . info ( ) ;
34+ this . $logger . printMarkdown ( `# Use \`NativeScript Playground app\` and scan the \`QR code\` below to preview the application on your device.` ) ;
35+ this . $logger . printMarkdown ( `
36+ To scan the QR code and deploy your app on a device, you need to have the \`NativeScript Playground app\`:
37+ App Store (iOS): ${ PlaygroundStoreUrls . APP_STORE_URL }
38+ Google Play (Android): ${ PlaygroundStoreUrls . GOOGLE_PLAY_URL } ` ) ;
39+ }
5740 }
5841}
5942$injector . register ( "playgroundQrCodeGenerator" , PlaygroundQrCodeGenerator ) ;
0 commit comments