Skip to content

feat: pull forward 254-patch fixes @W-17682405 #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,15 @@ _See code: [src/commands/lightning/dev/app.ts](https://github.com/salesforcecli/

## `sf lightning dev site`

Preview an Experience Builder site locally and in real-time, without deploying it.
[Beta] Preview an Experience Builder site locally and in real-time, without deploying it.

```
USAGE
$ sf lightning dev site -o <value> [--flags-dir <value>] [-n <value>]
$ sf lightning dev site -o <value> [--flags-dir <value>] [-n <value>] [-l]

FLAGS
-l, --get-latest Download the latest version of the specified site from your org, instead of using any local
cache.
-n, --name=<value> Name of the Experience Builder site to preview. It has to match a site name from the current
org.
-o, --target-org=<value> (required) Username or alias of the target org. Not required if the `target-org`
Expand All @@ -220,7 +222,7 @@ GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.

DESCRIPTION
Preview an Experience Builder site locally and in real-time, without deploying it.
[Beta] Preview an Experience Builder site locally and in real-time, without deploying it.

Enable Local Dev to see local changes to your site in a real-time preview that you don't have to deploy or manually
refresh. To let you quickly iterate on your Lightning web components (LWCs) and pages, your site preview automatically
Expand All @@ -239,9 +241,17 @@ DESCRIPTION
For more considerations and limitations, see the Lightning Web Components Developer Guide.

EXAMPLES
Select a site to preview from the org "myOrg":

$ sf lightning dev site --target-org myOrg

Preview the site "Partner Central" from the org "myOrg":

$ sf lightning dev site --name "Partner Central" --target-org myOrg

Get and preview the latest version of the "Partner Central" site from the org "myOrg"

$ sf lightning dev site --name "Partner Central" --target-org myOrg --get-latest
```

_See code: [src/commands/lightning/dev/site.ts](https://github.com/salesforcecli/plugin-lightning-dev/blob/3.0.0/src/commands/lightning/dev/site.ts)_
Expand Down
4 changes: 2 additions & 2 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"alias": [],
"command": "lightning:dev:site",
"flagAliases": [],
"flagChars": ["n", "o"],
"flags": ["flags-dir", "name", "target-org"],
"flagChars": ["l", "n", "o"],
"flags": ["flags-dir", "get-latest", "name", "target-org"],
"plugin": "@salesforce/plugin-lightning-dev"
}
]
10 changes: 9 additions & 1 deletion messages/lightning.dev.site.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# summary

Preview an Experience Builder site locally and in real-time, without deploying it.
[Beta] Preview an Experience Builder site locally and in real-time, without deploying it.

# description

Expand All @@ -21,7 +21,15 @@ For more considerations and limitations, see the Lightning Web Components Develo

Name of the Experience Builder site to preview. It has to match a site name from the current org.

# flags.get-latest.summary

Download the latest version of the specified site from your org, instead of using any local cache.

# examples

- Select a site to preview from the org "myOrg":
<%= config.bin %> <%= command.id %> --target-org myOrg
- Preview the site "Partner Central" from the org "myOrg":
<%= config.bin %> <%= command.id %> --name "Partner Central" --target-org myOrg
- Get and preview the latest version of the "Partner Central" site from the org "myOrg"
<%= config.bin %> <%= command.id %> --name "Partner Central" --target-org myOrg --get-latest
2 changes: 1 addition & 1 deletion messages/prompts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# site.select

Select a site
Which Experience Cloud Site would you like to preview (Use arrow keys)

# site.confirm-update

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@inquirer/select": "^2.4.7",
"@lwc/lwc-dev-server": "~11.5.0",
"@lwc/sfdc-lwc-compiler": "~11.5.0",
"@lwrjs/api": "0.15.6",
"@lwrjs/api": "0.16.3",
"@oclif/core": "^4.1.0",
"@salesforce/core": "^8.6.2",
"@salesforce/kit": "^3.1.6",
Expand Down
41 changes: 25 additions & 16 deletions src/commands/lightning/dev/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ export default class LightningDevSite extends SfCommand<void> {
char: 'n',
}),
'target-org': Flags.requiredOrg(),
'get-latest': Flags.boolean({
summary: messages.getMessage('flags.get-latest.summary'),
char: 'l',
}),
};

public async run(): Promise<void> {
const { flags } = await this.parse(LightningDevSite);

try {
const org = flags['target-org'];
const getLatest = flags['get-latest'];
let siteName = flags.name;

const connection = org.getConnection(undefined);
Expand All @@ -55,26 +60,27 @@ export default class LightningDevSite extends SfCommand<void> {
const selectedSite = new ExperienceSite(org, siteName);
let siteZip: string | undefined;

if (!selectedSite.isSiteSetup()) {
this.log(`[local-dev] initializing: ${siteName}`);
// If the site is not setup / is not based on the current release / or get-latest is requested ->
// generate and download a new site bundle from the org based on latest builder metadata
if (!selectedSite.isSiteSetup() || getLatest) {
const startTime = Date.now();
this.log(`[local-dev] Initializing: ${siteName}`);
this.spinner.start('[local-dev] Downloading site (this may take a few minutes)');
siteZip = await selectedSite.downloadSite();
} else {
// If local-dev is already setup, check if an updated site has been published to download
const updateAvailable = await selectedSite.isUpdateAvailable();
if (updateAvailable) {
const shouldUpdate = await PromptUtils.promptUserToConfirmUpdate(siteName);
if (shouldUpdate) {
this.log(`[local-dev] updating: ${siteName}`);
siteZip = await selectedSite.downloadSite();
// delete oldSitePath recursive
const oldSitePath = selectedSite.getExtractDirectory();
if (fs.existsSync(oldSitePath)) {
fs.rmdirSync(oldSitePath, { recursive: true });
}
}

// delete oldSitePath recursive
const oldSitePath = selectedSite.getExtractDirectory();
if (fs.existsSync(oldSitePath)) {
fs.rmSync(oldSitePath, { recursive: true });
}
const endTime = Date.now();
const duration = (endTime - startTime) / 1000; // Convert to seconds
this.spinner.stop('done.');
this.log(`[local-dev] Site setup completed in ${duration.toFixed(2)} seconds.`);
}

this.log(`[local-dev] launching browser preview for: ${siteName}`);

// Establish a valid access token for this site
const authToken = await selectedSite.setupAuth();

Expand All @@ -94,10 +100,13 @@ export default class LightningDevSite extends SfCommand<void> {
// Environment variable used to setup the site rather than setup & start server
if (process.env.SETUP_ONLY === 'true') {
await setupDev(startupParams);
this.log('[local-dev] setup complete!');
} else {
await expDev(startupParams);
this.log('[local-dev] watching for file changes... (CTRL-C to stop)');
}
} catch (e) {
this.spinner.stop('failed.');
this.log('Local Development setup failed', e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lwc-dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function createLWCServerConfig(
const { namespace } = projectJson;

// e.g. lwc folders in force-app/main/default/lwc, package-dir/lwc
const namespacePaths = (await Promise.all(packageDirs.map((dir) => glob(`${dir.fullPath}/**/lwc`)))).flat();
const namespacePaths = (await Promise.all(packageDirs.map((dir) => glob(`${dir.fullPath}/**/lwc`, { absolute: true })))).flat();

const ports = serverPorts ??
(await ConfigUtils.getLocalDevServerPorts()) ?? {
Expand Down
Loading
Loading