Skip to content

Commit 80800c7

Browse files
authored
Merge pull request #852 from scottmo/t/experience-sites-runtime/w-21313610/updateparam
@W-21313610 feat: match template param to existing tool
2 parents c7d23aa + d32c3c3 commit 80800c7

5 files changed

Lines changed: 54 additions & 29 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Generate an Experience Cloud site.
313313

314314
```
315315
USAGE
316-
$ sf template generate digital-experience site -n <value> -t BuildYourOwnLWR [--json] [--flags-dir <value>] [-o <value>] [-p <value>] [-e
316+
$ sf template generate digital-experience site -n <value> -t "Build Your Own (LWR)" [--json] [--flags-dir <value>] [-o <value>] [-p <value>] [-e
317317
<value>] [-d <value>]
318318
319319
FLAGS
@@ -323,8 +323,8 @@ FLAGS
323323
-n, --name=<value> (required) Name of the Experience Cloud site to generate.
324324
-o, --target-org=<value> Username or alias of the target org.
325325
-p, --url-path-prefix=<value> URL path prefix for the site; must contain only alphanumeric characters.
326-
-t, --template=<option> (required) Template to use when generating the site.
327-
<options: BuildYourOwnLWR>
326+
-t, --template-name=<option> (required) Template to use when generating the site.
327+
<options: Build Your Own (LWR)>
328328
329329
GLOBAL FLAGS
330330
--flags-dir=<value> Import flag values from a directory.
@@ -337,14 +337,14 @@ DESCRIPTION
337337
necessary metadata files, including DigitalExperienceConfig, DigitalExperienceBundle, Network, and CustomSite.
338338
339339
EXAMPLES
340-
Generate an Experience Cloud site using the BuildYourOwnLWR template. The site is called "mysite" and has the URL
341-
path prefix "mysite":
340+
Generate an Experience Cloud site using the Build Your Own (LWR) template. The site is called "mysite" and has the
341+
URL path prefix "mysite":
342342
343-
$ sf template generate digital-experience site --template BuildYourOwnLWR --name mysite --url-path-prefix mysite
343+
$ sf template generate digital-experience site --template-name "Build Your Own (LWR)" --name mysite --url-path-prefix mysite
344344
345345
Generate an Experience Cloud site like the last example, but generate the files into the specified output directory:
346346
347-
$ sf template generate digital-experience site --template BuildYourOwnLWR --name mysite --url-path-prefix mysite \
347+
$ sf template generate digital-experience site --template-name "Build Your Own (LWR)" --name mysite --url-path-prefix mysite \
348348
--output-dir force-app/main/default
349349
350350
FLAG DESCRIPTIONS

command-snapshot.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@
2828
"command": "template:generate:digital-experience:site",
2929
"flagAliases": [],
3030
"flagChars": ["d", "e", "n", "o", "p", "t"],
31-
"flags": ["admin-email", "flags-dir", "json", "name", "output-dir", "target-org", "template", "url-path-prefix"],
31+
"flags": [
32+
"admin-email",
33+
"flags-dir",
34+
"json",
35+
"name",
36+
"output-dir",
37+
"target-org",
38+
"template-name",
39+
"url-path-prefix"
40+
],
3241
"plugin": "@salesforce/plugin-templates"
3342
},
3443
{

messages/digitalExperienceSite.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,32 @@ Generate an Experience Cloud site.
44

55
# description
66

7-
Creates an Experience Cloud site with the specified template, name, and URL path prefix. The site includes all necessary metadata files, including DigitalExperienceConfig, DigitalExperienceBundle, Network, and CustomSite.
7+
Creates the metadata of an Experience Cloud site with the specified template, name, and URL path prefix. The output includes all the necessary metadata files, including DigitalExperienceConfig, DigitalExperienceBundle, Network, and CustomSite.
8+
Unlike `sf community create`, which builds the site directly in the org, this command generates only the local metadata.
89

910
# examples
1011

11-
- Generate an Experience Cloud site using the BuildYourOwnLWR template. The site is called "mysite" and has the URL path prefix "mysite":
12+
- Generate an Experience Cloud site using the Build Your Own (LWR) template. The site is called "mysite" and has the URL path prefix "mysite":
1213

13-
<%= config.bin %> <%= command.id %> --template BuildYourOwnLWR --name mysite --url-path-prefix mysite
14+
<%= config.bin %> <%= command.id %> --template-name "Build Your Own (LWR)" --name mysite --url-path-prefix mysite
1415

1516
- Generate an Experience Cloud site like the last example, but generate the files into the specified output directory:
1617

17-
<%= config.bin %> <%= command.id %> --template BuildYourOwnLWR --name mysite --url-path-prefix mysite --output-dir force-app/main/default
18+
<%= config.bin %> <%= command.id %> --template-name "Build Your Own (LWR)" --name mysite --url-path-prefix mysite --output-dir force-app/main/default
1819

1920
# flags.name.summary
2021

2122
Name of the Experience Cloud site to generate.
2223

23-
# flags.template.summary
24+
# flags.template-name.summary
2425

2526
Template to use when generating the site.
2627

27-
# flags.template.description
28+
# flags.template-name.description
2829

2930
Supported templates:
3031

31-
- BuildYourOwnLWR - Creates blazing-fast digital experiences, such as websites, microsites, and portals, using the Lightning Web Components programming model. Powered by Lightning Web Runtime (LWR), this customizable template delivers unparalleled site performance. For additional details, see this Salesforce Help topic: https://help.salesforce.com/s/articleView?id=experience.rss_build_your_own_lwr.htm.
32+
- Build Your Own (LWR) - Creates blazing-fast digital experiences, such as websites, microsites, and portals, using the Lightning Web Components programming model. Powered by Lightning Web Runtime (LWR), this customizable template delivers unparalleled site performance. For additional details, see this Salesforce Help topic: https://help.salesforce.com/s/articleView?id=experience.rss_build_your_own_lwr.htm.
3233

3334
# flags.url-path-prefix.summary
3435

src/commands/template/generate/digital-experience/site.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import { getCustomTemplates, runGenerator } from '../../../../utils/templateComm
1414
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1515
const messages = Messages.loadMessages('@salesforce/plugin-templates', 'digitalExperienceSite');
1616

17+
/**
18+
* Strips spaces and non-alphanumeric characters so display names map to template directories
19+
* (e.g. "Build Your Own (LWR)" → "BuildYourOwnLWR").
20+
*/
21+
function normalizeTemplateName(name: string): string {
22+
return name.replace(/[^a-zA-Z0-9]/g, '');
23+
}
24+
1725
export default class GenerateSite extends SfCommand<CreateOutput> {
1826
public static readonly state = 'preview';
1927
public static readonly summary = messages.getMessage('summary');
@@ -26,10 +34,10 @@ export default class GenerateSite extends SfCommand<CreateOutput> {
2634
summary: messages.getMessage('flags.name.summary'),
2735
required: true,
2836
}),
29-
template: Flags.string({
37+
'template-name': Flags.string({
3038
char: 't',
31-
summary: messages.getMessage('flags.template.summary'),
32-
options: ['BuildYourOwnLWR'] as const,
39+
summary: messages.getMessage('flags.template-name.summary'),
40+
options: ['Build Your Own (LWR)'] as const,
3341
required: true,
3442
}),
3543
'url-path-prefix': Flags.string({
@@ -82,7 +90,7 @@ export default class GenerateSite extends SfCommand<CreateOutput> {
8290
sitename: flags.name,
8391
urlpathprefix: flags['url-path-prefix'],
8492
adminemail: adminEmail,
85-
template: flags.template,
93+
template: normalizeTemplateName(flags['template-name']),
8694
outputdir: outputDir,
8795
};
8896

test/commands/template/generate/digital-experience/site.nut.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ describe(COMMAND, () => {
2424
await session?.clean();
2525
});
2626

27-
describe('--template BuildYourOwnLWR', () => {
27+
describe('--template-name "Build Your Own (LWR)"', () => {
2828
it('should create with all required files', () => {
2929
const outputDir = path.join(session.project.dir, 'force-app', 'main', 'default');
3030
execCmd(
31-
`${COMMAND} --template BuildYourOwnLWR --name "123 @ Test Site" --url-path-prefix 123testsite --output-dir "${outputDir}"`,
31+
`${COMMAND} --template-name "Build Your Own (LWR)" --name "123 @ Test Site" --url-path-prefix 123testsite --output-dir "${outputDir}"`,
3232
{
3333
ensureExitCode: 0,
3434
}
@@ -111,20 +111,24 @@ describe(COMMAND, () => {
111111

112112
describe('parameter validation', () => {
113113
it('should throw error if missing site name', () => {
114-
const stderr = execCmd(`${COMMAND} --template BuildYourOwnLWR --url-path-prefix test`).shellOutput.stderr;
114+
const stderr = execCmd(`${COMMAND} --template-name "Build Your Own (LWR)" --url-path-prefix test`).shellOutput
115+
.stderr;
115116
expect(stderr).to.contain('Missing required flag');
116117
});
117118

118-
it('should throw error if missing template', () => {
119+
it('should throw error if missing template-name', () => {
119120
const stderr = execCmd(`${COMMAND} --name test --url-path-prefix test`).shellOutput.stderr;
120121
expect(stderr).to.contain('Missing required flag');
121122
});
122123

123124
it('should default to empty string if url-path-prefix is not provided', () => {
124125
const outputDir = path.join(session.project.dir, 'force-app', 'main', 'default');
125-
execCmd(`${COMMAND} --template BuildYourOwnLWR --name "DefaultPrefixSite" --output-dir "${outputDir}"`, {
126-
ensureExitCode: 0,
127-
});
126+
execCmd(
127+
`${COMMAND} --template-name "Build Your Own (LWR)" --name "DefaultPrefixSite" --output-dir "${outputDir}"`,
128+
{
129+
ensureExitCode: 0,
130+
}
131+
);
128132

129133
const networkPath = path.join(outputDir, 'networks', 'DefaultPrefixSite.network-meta.xml');
130134
const networkContent = fs.readFileSync(networkPath, 'utf8');
@@ -140,9 +144,12 @@ describe(COMMAND, () => {
140144
});
141145

142146
it('should default to force/main/default if output-dir is not provided', () => {
143-
execCmd(`${COMMAND} --template BuildYourOwnLWR --name "DefaultDirSite" --url-path-prefix defaultdir`, {
144-
ensureExitCode: 0,
145-
});
147+
execCmd(
148+
`${COMMAND} --template-name "Build Your Own (LWR)" --name "DefaultDirSite" --url-path-prefix defaultdir`,
149+
{
150+
ensureExitCode: 0,
151+
}
152+
);
146153
const defaultOutputDir = path.join(session.project.dir, 'force-app', 'main', 'default');
147154
assert.file(path.join(defaultOutputDir, 'networks', 'DefaultDirSite.network-meta.xml'));
148155
assert.file(path.join(defaultOutputDir, 'sites', 'DefaultDirSite.site-meta.xml'));

0 commit comments

Comments
 (0)