Skip to content

Commit 5111e3b

Browse files
committed
feat: enhance component preview functionality by generating and logging the full preview URL
1 parent 33fff08 commit 5111e3b

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/commands/lightning/dev/component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,23 @@ export default class LightningDevComponent extends SfCommand<void> {
129129
targetOrgArg
130130
);
131131

132-
// Open the browser and navigate to the right page
133-
await this.config.runCommand('org:open', launchArguments);
132+
// Construct and log the full URL that will be opened
133+
const connection = targetOrg.getConnection();
134+
135+
const decodedFullUrl = PreviewUtils.generateComponentPreviewUrl(
136+
connection.instanceUrl,
137+
ldpServerUrl,
138+
ldpServerId,
139+
componentName,
140+
false
141+
);
142+
143+
// Open the browser and navigate to the right page (unless OPEN_BROWSER is set to true)
144+
if (process.env.OPEN_BROWSER !== 'false') {
145+
await this.config.runCommand('org:open', launchArguments);
146+
} else {
147+
// Otherwise, log the URL to the console
148+
this.log(`PreviewURL: ${decodedFullUrl}`);
149+
}
134150
}
135151
}

src/shared/previewUtils.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,34 @@ export class PreviewUtils {
246246
return launchArguments;
247247
}
248248

249+
/**
250+
* Generates the full URL for a component preview.
251+
*
252+
* @param instanceUrl The URL of the Salesforce instance
253+
* @param ldpServerUrl The URL for the local dev server
254+
* @param ldpServerId Record ID for the identity token
255+
* @param componentName The name of the component to preview
256+
* @param encodePath Whether to encode the path
257+
* @returns The full URL for the component preview
258+
*/
259+
public static generateComponentPreviewUrl(
260+
instanceUrl: string,
261+
ldpServerUrl: string,
262+
ldpServerId: string,
263+
componentName?: string,
264+
encodePath = false
265+
): string {
266+
let url = `${instanceUrl}/lwr/application/e/devpreview/ai/${
267+
encodePath ? encodeURIComponent('localdev%2Fpreview') : 'localdev%2Fpreview'
268+
}?ldpServerUrl=${ldpServerUrl}&ldpServerId=${ldpServerId}`;
269+
if (componentName) {
270+
// TODO: support other namespaces
271+
url += `&specifier=c/${componentName}`;
272+
}
273+
274+
return url;
275+
}
276+
249277
/**
250278
* Generates the proper set of arguments to be used for launching a mobile app with custom launch arguments.
251279
*

0 commit comments

Comments
 (0)