Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/onRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: salesforcecli/github-workflows/.github/workflows/npmPublish.yml@main
needs: [getDistTag, getMajorVersion]
with:
#ctc: true
ctc: true
sign: true
# At CLCO, the new patch branch's version will be released as 'prerelease'. After R2b, delete the logic below for 'latest' and update 'prerelease' candidate to 'latest'
tag: ${{ needs.getDistTag.outputs.tag || (needs.getMajorVersion.outputs.major == '4' && 'latest') || (needs.getMajorVersion.outputs.major == '5' && 'prerelease') || 'next' }}
Expand Down
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

#GUSINFO:Application Fabric Services, Application Fabric Services
* @salesforcecli/local-dev @salesforcecli/lex @salesforcecli/mobile-platform-experience

#ECCN:Open Source
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,14 @@ _See code: [src/commands/lightning/dev/component.ts](https://github.com/salesfor

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

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`
configuration variable is already set.
--api-version=<value> Override the api version used for api requests made by this command
--guest Preview the site as a guest user (rather than an authenticated user).
--ssr Preview the SSR bundle

GLOBAL FLAGS
--flags-dir=<value> Import flag values from a directory.
Expand Down Expand Up @@ -302,10 +298,6 @@ EXAMPLES
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/6.2.12/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 @@ -19,8 +19,8 @@
"alias": [],
"command": "lightning:dev:site",
"flagAliases": [],
"flagChars": ["l", "n", "o"],
"flags": ["api-version", "flags-dir", "get-latest", "guest", "name", "ssr", "target-org"],
"flagChars": ["n", "o"],
"flags": ["api-version", "flags-dir", "name", "target-org"],
"plugin": "@salesforce/plugin-lightning-dev"
}
]
14 changes: 0 additions & 14 deletions messages/lightning.dev.site.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,9 @@ 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.

# flags.guest.summary

Preview the site as a guest user (rather than an authenticated user).

# flags.ssr.summary

Preview the SSR bundle

# 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 src/commands/lightning/dev/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class LightningDevApp extends SfCommand<void> {
throw new Error(sharedMessages.getMessage('error.no-project', [(error as Error)?.message ?? '']));
}

logger.debug('Initalizing preview connection and configuring local web server identity');
logger.debug('Initializing preview connection and configuring local web server identity');

const connection = targetOrg.getConnection(apiVersion);

Expand Down
82 changes: 1 addition & 81 deletions src/commands/lightning/dev/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fs from 'node:fs';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Connection, Logger, Messages, SfProject } from '@salesforce/core';
import { Platform } from '@salesforce/lwc-dev-mobile-core';
import { expDev, SitesLocalDevOptions, setupDev } from '@lwrjs/api';
import open from 'open';
import { PromptUtils } from '../../../shared/promptUtils.js';
import { ExperienceSite } from '../../../shared/experience/expSite.js';
Expand All @@ -41,18 +39,6 @@ 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',
}),
guest: Flags.boolean({
summary: messages.getMessage('flags.guest.summary'),
default: false,
}),
ssr: Flags.boolean({
summary: messages.getMessage('flags.ssr.summary'),
default: false,
}),
'api-version': Flags.orgApiVersion(),
};

Expand All @@ -61,10 +47,7 @@ export default class LightningDevSite extends SfCommand<void> {

try {
const org = flags['target-org'];
const getLatest = flags['get-latest'];
const apiVersion = flags['api-version'];
const guest = flags.guest;
const ssr = flags.ssr;
let siteName = flags.name;

const connection = org.getConnection(apiVersion);
Expand All @@ -81,76 +64,13 @@ export default class LightningDevSite extends SfCommand<void> {

const selectedSite = new ExperienceSite(org, siteName);

if (!ssr) {
return await this.openPreviewUrl(selectedSite, connection);
}
await this.serveSSRSite(selectedSite, getLatest, siteName, guest);
return await this.openPreviewUrl(selectedSite, connection);
} catch (e) {
this.spinner.stop('failed.');
this.log('Local Development setup failed', e);
}
}

private async serveSSRSite(
selectedSite: ExperienceSite,
getLatest: boolean,
siteName: string,
guest: boolean,
): Promise<void> {
let siteZip: string | undefined;

// 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();

// 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 = guest ? '' : await selectedSite.setupAuth();

// Start the dev server
const port = parseInt(process.env.PORT ?? '3000', 10);

// Internal vs external mode
const internalProject = !fs.existsSync('sfdx-project.json') && fs.existsSync('lwr.config.json');
const logLevel = process.env.LOG_LEVEL ?? 'error';

const startupParams: SitesLocalDevOptions = {
sfCLI: !internalProject,
authToken,
open: process.env.OPEN_BROWSER === 'false' ? false : true,
port,
logLevel,
mode: 'dev',
siteZip,
siteDir: selectedSite.getSiteDirectory(),
};

// 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)');
}
}

private async openPreviewUrl(selectedSite: ExperienceSite, connection: Connection): Promise<void> {
let sfdxProjectRootPath = '';
try {
Expand Down