Skip to content

Commit 518da37

Browse files
author
DimitarTachev
committed
feat: support hmr in preview
1 parent b5e0aa0 commit 518da37

File tree

7 files changed

+12
-10
lines changed

7 files changed

+12
-10
lines changed

lib/commands/preview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class PreviewCommand implements ICommand {
2222
timeout: this.$options.timeout
2323
});
2424

25-
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp();
25+
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp(this.$options.hmr);
2626
}
2727

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

lib/definitions/preview-app-livesync.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare global {
1010
interface IPreviewAppLiveSyncData extends IProjectDir, IAppFilesUpdaterOptionsComposition, IEnvOptions { }
1111

1212
interface IPreviewSdkService {
13-
qrCodeUrl: string;
13+
getQrCodeUrl(options: { useHmr: boolean }): string;
1414
connectedDevices: Device[];
1515
initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): void;
1616
applyChanges(filesPayload: FilesPayload): Promise<void>;
@@ -29,6 +29,6 @@ declare global {
2929
interface IPlaygroundQrCodeGenerator {
3030
generateQrCodeForiOS(): Promise<void>;
3131
generateQrCodeForAndroid(): Promise<void>;
32-
generateQrCodeForCurrentApp(): Promise<void>;
32+
generateQrCodeForCurrentApp(useHmr: boolean): Promise<void>;
3333
}
3434
}

lib/helpers/preview-command-helper.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper {
66
private ctrlcReader: readline.ReadLine;
77

88
constructor(private $playgroundQrCodeGenerator: IPlaygroundQrCodeGenerator,
9+
private $options: IOptions,
910
private $processService: IProcessService) {
1011
this.$processService.attachToProcessExitSignals(this, () => {
1112
this.stopWaitingForCommand();
@@ -49,7 +50,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper {
4950
await this.$playgroundQrCodeGenerator.generateQrCodeForiOS();
5051
return;
5152
case "c":
52-
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp();
53+
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp(this.$options.hmr);
5354
return;
5455
}
5556
}

lib/services/livesync/playground/preview-sdk-service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export class PreviewSdkService implements IPreviewSdkService {
1313
private $config: IConfiguration) {
1414
}
1515

16-
public get qrCodeUrl(): string {
17-
return `nsplay://boot?instanceId=${this.instanceId}&pKey=${PubnubKeys.PUBLISH_KEY}&sKey=${PubnubKeys.SUBSCRIBE_KEY}&template=play-ng`;
16+
public getQrCodeUrl(options: { useHmr: boolean }): string {
17+
const hmrValue = options.useHmr ? "1" : "0";
18+
return `nsplay://boot?instanceId=${this.instanceId}&pKey=${PubnubKeys.PUBLISH_KEY}&sKey=${PubnubKeys.SUBSCRIBE_KEY}&template=play-ng&hmr=${hmrValue}`;
1819
}
1920

2021
public initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): void {

lib/services/livesync/playground/qr-code-generator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
1818
await this.generateQrCode(PlaygroundStoreUrls.GOOGLE_PLAY_URL);
1919
}
2020

21-
public async generateQrCodeForCurrentApp(): Promise<void> {
22-
await this.generateQrCode(this.$previewSdkService.qrCodeUrl);
21+
public async generateQrCodeForCurrentApp(useHmr: boolean): Promise<void> {
22+
await this.generateQrCode(this.$previewSdkService.getQrCodeUrl(useHmr));
2323
}
2424

2525
private async generateQrCode(url: string): Promise<void> {

test/helpers/preview-command-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function createTestInjector() {
2626
generateQrCodeForiOS: async () => {
2727
qrCodesData.isGeneratedForiOS = true;
2828
},
29-
generateQrCodeForCurrentApp: async () => {
29+
generateQrCodeForCurrentApp: async (useHmr: boolean) => {
3030
qrCodesData.isGeneratedForCurrentApp = true;
3131
}
3232
});

test/services/playground/preview-app-livesync-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const syncFilesMockData = {
6565
class PreviewSdkServiceMock implements IPreviewSdkService {
6666
public getInitialFiles: (device: Device) => Promise<FilesPayload>;
6767

68-
public get qrCodeUrl() {
68+
public getQrCodeUrl(options: { useHmr: boolean }) {
6969
return "my_cool_qr_code_url";
7070
}
7171

0 commit comments

Comments
 (0)