Skip to content

Commit f0e77df

Browse files
Fatmerosen-vladimirov
authored andcommitted
feat: add ability to pass schema and keys to preview app from public api and nsconfig
1 parent 8ed7b5b commit f0e77df

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

lib/commands/preview.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ export class PreviewCommand implements ICommand {
2929
env: this.$options.env
3030
});
3131

32-
await this.$previewQrCodeService.printLiveSyncQrCode({ useHotModuleReload: this.$options.hmr, link: this.$options.link });
32+
await this.$previewQrCodeService.printLiveSyncQrCode({
33+
nsConfigPreviewAppSchema: this.$projectData.previewAppSchema,
34+
useHotModuleReload: this.$options.hmr,
35+
link: this.$options.link
36+
});
3337
}
3438

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

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,28 @@ declare global {
1818
filesToRemove?: string[];
1919
}
2020

21-
interface IPreviewAppLiveSyncData extends IProjectDir, IHasUseHotModuleReloadOption, IBundle, IEnvOptions { }
21+
interface IPreviewAppLiveSyncData extends IProjectDir, IHasUseHotModuleReloadOption, IBundle, IEnvOptions {
22+
qrCodeData?: IPreviewAppQrCodeData;
23+
}
24+
25+
interface IPreviewAppQrCodeData {
26+
publishKey?: string;
27+
subscribeKey?: string;
28+
schemaName?: string;
29+
}
2230

2331
interface IPreviewSdkService extends EventEmitter {
24-
getQrCodeUrl(options: IHasUseHotModuleReloadOption): string;
32+
getQrCodeUrl(options: IGetQrCodeUrlOptions): string;
2533
initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): void;
2634
applyChanges(filesPayload: FilesPayload): Promise<void>;
2735
stop(): void;
2836
}
2937

38+
interface IGetQrCodeUrlOptions extends IHasUseHotModuleReloadOption {
39+
nsConfigPreviewAppSchema?: string;
40+
qrCodeData?: IPreviewAppQrCodeData;
41+
}
42+
3043
interface IPreviewAppPluginsService {
3144
getPluginsUsageWarnings(data: IPreviewAppLiveSyncData, device: Device): string[];
3245
comparePluginsOnDevice(data: IPreviewAppLiveSyncData, device: Device): Promise<void>;
@@ -48,6 +61,7 @@ declare global {
4861
}
4962

5063
interface IPrintLiveSyncOptions extends IHasUseHotModuleReloadOption {
64+
nsConfigPreviewAppSchema?: string;
5165
/**
5266
* If set to true, a link will be shown on console instead of QR code
5367
* Default value is false.

lib/definitions/project.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ interface INsConfig {
7575
appResourcesPath?: string;
7676
shared?: boolean;
7777
useLegacyWorkflow?: boolean;
78+
previewAppSchema?: string;
7879
}
7980

8081
interface IProjectData extends ICreateProjectData {
@@ -105,6 +106,11 @@ interface IProjectData extends ICreateProjectData {
105106
*/
106107
useLegacyWorkflow: boolean;
107108

109+
/**
110+
* Defines the schema for the preview app
111+
*/
112+
previewAppSchema: string;
113+
108114
/**
109115
* Initializes project data with the given project directory. If none supplied defaults to --path option or cwd.
110116
* @param {string} projectDir Project root directory.

lib/project-data.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class ProjectData implements IProjectData {
6262
public podfilePath: string;
6363
public isShared: boolean;
6464
public useLegacyWorkflow: boolean;
65+
public previewAppSchema: string;
6566

6667
constructor(private $fs: IFileSystem,
6768
private $errors: IErrors,
@@ -137,6 +138,7 @@ export class ProjectData implements IProjectData {
137138
this.podfilePath = path.join(this.appResourcesDirectoryPath, this.$devicePlatformsConstants.iOS, constants.PODFILE_NAME);
138139
this.isShared = !!(this.nsConfig && this.nsConfig.shared);
139140
this.useLegacyWorkflow = this.nsConfig && this.nsConfig.useLegacyWorkflow;
141+
this.previewAppSchema = this.nsConfig && this.nsConfig.previewAppSchema;
140142
return;
141143
}
142144

lib/services/livesync/livesync-service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
6666
env: data.env,
6767
});
6868

69-
const url = this.$previewSdkService.getQrCodeUrl({ useHotModuleReload: data.useHotModuleReload });
69+
const projectData = this.$projectDataService.getProjectData(data.projectDir);
70+
const url = this.$previewSdkService.getQrCodeUrl({
71+
nsConfigPreviewAppSchema: projectData.previewAppSchema,
72+
qrCodeData: data.qrCodeData,
73+
useHotModuleReload: data.useHotModuleReload
74+
});
7075
const result = await this.$previewQrCodeService.getLiveSyncQrCode(url);
7176
return result;
7277
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic
1616
super();
1717
}
1818

19-
public getQrCodeUrl(options: IHasUseHotModuleReloadOption): string {
20-
const hmrValue = options.useHotModuleReload ? "1" : "0";
21-
return `nsplay://boot?instanceId=${this.instanceId}&pKey=${PubnubKeys.PUBLISH_KEY}&sKey=${PubnubKeys.SUBSCRIBE_KEY}&template=play-ng&hmr=${hmrValue}`;
19+
public getQrCodeUrl(options: IGetQrCodeUrlOptions): string {
20+
const { nsConfigPreviewAppSchema, qrCodeData = { }, useHotModuleReload } = options;
21+
const schema = qrCodeData.schemaName || nsConfigPreviewAppSchema || "nsplay";
22+
const publishKey = qrCodeData.publishKey || PubnubKeys.PUBLISH_KEY;
23+
const subscribeKey = qrCodeData.subscribeKey || PubnubKeys.SUBSCRIBE_KEY;
24+
const hmrValue = useHotModuleReload ? "1" : "0";
25+
return `${schema}://boot?instanceId=${this.instanceId}&pKey=${publishKey}&sKey=${subscribeKey}&template=play-ng&hmr=${hmrValue}`;
2226
}
2327

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

0 commit comments

Comments
 (0)