Skip to content

feat: add microfrontend template generator command#943

Open
aman06it wants to merge 7 commits into
salesforcecli:mainfrom
aman06it:feat/microfrontend-template
Open

feat: add microfrontend template generator command#943
aman06it wants to merge 7 commits into
salesforcecli:mainfrom
aman06it:feat/microfrontend-template

Conversation

@aman06it
Copy link
Copy Markdown

@aman06it aman06it commented May 22, 2026

Summary

  • Adds sf template generate lightning embedding to scaffold a Lightning Web Component bundle that wraps <lightning-embedding>.
  • Command is added under the existing lightning topic as a peer of app, component, event, interface, test (per team alignment in #plugin-design-templates — avoids both mfe and microfrontend).
  • Flags: --name, --src, --sandbox (multi-value, validated against W3C sandbox tokens), --shell-title, --output-dir, --api-version, --internal.
  • --src validation: https only; plain http allowed only for localhost / 127.0.0.1 (local dev).
  • Command is hidden via static hidden = true until rollout is finalized.
  • Naming and flag conventions audited against the topics and flags developer guides.
  • Depends on the new LightningEmbeddingGenerator in feat: add lightning embedding template generator forcedotcom/salesforcedx-templates#821.

@aman06it aman06it requested a review from a team as a code owner May 22, 2026 10:25
@salesforce-cla
Copy link
Copy Markdown

Thanks for the contribution! Unfortunately we can't verify the commit author(s): Aman Singh <a***@A***.i***.s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce Inc. Contributor License Agreement and this Pull Request will be revalidated.

Exposes `sf template generate microfrontend` to scaffold a microfrontend
LWC bundle, paired with the new generator in salesforcedx-templates.
@aman06it aman06it force-pushed the feat/microfrontend-template branch from 3028578 to 0efa415 Compare May 22, 2026 10:39
@aman06it
Copy link
Copy Markdown
Author

@salesforce-cla check

Per team alignment in #plugin-design-templates, rename the command to
align with the <lightning-embedding> base component name.

- Command: sf template generate microfrontend → sf template generate lightning embedding
- Move src/commands/template/generate/microfrontend.ts under
  lightning/ as a peer of app, component, event, interface, test
- messages/microfrontend.md → messages/lightningEmbedding.md
- Class Microfrontend → LightningEmbedding
- Imports updated: MicrofrontendOptions → LightningEmbeddingOptions,
  TemplateType.Microfrontend → TemplateType.LightningEmbedding
@aman06it aman06it force-pushed the feat/microfrontend-template branch from c4b860a to d72b7f5 Compare May 27, 2026 16:40
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-templates', 'lightningEmbedding');

// Keep in-sync with VALID_SANDBOX_TOKENS in salesforcedx-templates/src/generators/lightningEmbeddingGenerator.ts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not export these from the library?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — done in 3bf0f40 (library) and 6c7d94f (plugin). The token list now lives in salesforcedx-templates/src/utils/lightningEmbedding.ts and is exported from @salesforce/templates as LIGHTNING_EMBEDDING_SANDBOX_TOKENS. The CLI imports it for the --sandbox flag's options, so there's a single source of truth.

Comment thread src/commands/template/generate/lightning/embedding.ts
componentname: flags.name,
src: flags.src,
sandbox: flags.sandbox.join(' '),
shellTitle: flags['shell-title'] ?? flags.name,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If --shell-title is for screen reader accessibility, a PascalCase fallback is less than ideal. Just make --shell-title required and don't have a fallback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — fixed in 6c7d94f. --shell-title is now required: true with no fallback. Users will get a clear "Missing required flag shell-title" error if they omit it, which steers them toward providing a meaningful screen-reader name instead of inheriting a developer identifier.

@iowillhoit
Copy link
Copy Markdown
Contributor

Please add tests for these templates. Lots of examples in tests/

Copy link
Copy Markdown
Contributor

@iowillhoit iowillhoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

aman06it added 2 commits May 28, 2026 13:30
Per Eric's review (salesforcecli#943):
- Import sandbox token list and src URL validator from @salesforce/templates
  instead of duplicating them locally; single source of truth.
- Validate --src at the CLI parse layer (custom parse method) for faster
  user feedback on bad URLs.
- Make --shell-title required; drop the PascalCase fallback to --name
  since the iframe accessible name should be human-friendly, not a
  developer identifier.
- Add `state = 'beta'` alongside `hidden = true` so the command shows
  the beta-warning banner once it's unhidden.
Per Eric's review feedback on salesforcecli#943: cover the CLI surface end-to-end.

Happy paths:
- bundle scaffolding (4 files)
- <lightning-embedding> emitted in html
- multiple --sandbox tokens joined into one space-separated attribute
- --src URL bound into the generated js
- http://localhost accepted for local development

Failure paths:
- missing --name / --src / --sandbox / --shell-title (no fallback to --name)
- http src on non-localhost rejected at parse layer
- non-http(s) protocols rejected
- malformed URL rejected
- unknown sandbox token rejected
- output-dir without lwc/ parent rejected
@aman06it
Copy link
Copy Markdown
Author

Please add tests for these templates. Lots of examples in tests/

Added in e0ed7f3 — see test/commands/template/generate/lightning/embedding.nut.ts. 14 nut tests covering both happy paths (bundle scaffolding, <lightning-embedding> emission, multi-sandbox joining, src binding, localhost http acceptance) and failures (missing required flags, non-localhost http rejected at parse layer, malformed URLs, unknown sandbox tokens, missing lwc parent folder). All green locally.

Copy link
Copy Markdown
Contributor

@jshackell-sfdc jshackell-sfdc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my small suggestions. Note that this is a pretty cursory review, because I don't know anything about the feature itself, so I couldn't suggest additional useful content, which I like to do if possible. If your team has a CX writer I suggest you ask them to take a look too!

Comment thread messages/lightningEmbedding.md Outdated

# description

Generates a Lightning Web Component bundle that consumes the first-party <lightning-embedding> component, pre-wired with the three required attributes: the widget URL (src), iframe sandbox tokens, and an accessible iframe title (shell-title).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Generates a Lightning Web Component bundle that consumes the first-party <lightning-embedding> component, pre-wired with the three required attributes: the widget URL (src), iframe sandbox tokens, and an accessible iframe title (shell-title).
The generated LWC bundle consumes the first-party <lightning-embedding> component, which is pre-wired with the three required attributes: the widget URL (src), iframe sandbox tokens, and an accessible iframe title (shell-title).

Comment thread messages/lightningEmbedding.md Outdated

Generates a Lightning Web Component bundle that consumes the first-party <lightning-embedding> component, pre-wired with the three required attributes: the widget URL (src), iframe sandbox tokens, and an accessible iframe title (shell-title).

The generated bundle contains four files (.html, .js, .js-meta.xml, .css) in a directory named with the camelCased component name. The bundle must live under a parent folder named "lwc".
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The generated bundle contains four files (.html, .js, .js-meta.xml, .css) in a directory named with the camelCased component name. The bundle must live under a parent folder named "lwc".
The generated LWC bundle contains four files (.html, .js, .js-meta.xml, .css) in a directory named with the camelCased component name. The bundle must live under a parent folder named "lwc".

Comment thread messages/lightningEmbedding.md Outdated

# summary

Generate a Lightning Web Component that wraps the lightning-embedding base component.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Generate a Lightning Web Component that wraps the lightning-embedding base component.
Generate a Lightning Web Component (LWC) bundle that wraps the lightning-embedding base component.

Comment thread messages/lightningEmbedding.md Outdated

# flags.name.summary

PascalCase name of the generated component.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PascalCase name of the generated component.
Name of the generated component; must be in PascalCase format.

Comment thread messages/lightningEmbedding.md Outdated

# flags.src.summary

Absolute https URL the iframe will load.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Absolute https URL the iframe will load.
Absolute HTTPS URL that the iframe will load.

Comment thread messages/lightningEmbedding.md Outdated

# flags.src.description

The URL is bound to the <lightning-embedding> "src" attribute as a reactive property in the generated LWC. Must use https; plain http is only allowed for localhost or 127.0.0.1 (for local development).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The URL is bound to the <lightning-embedding> "src" attribute as a reactive property in the generated LWC. Must use https; plain http is only allowed for localhost or 127.0.0.1 (for local development).
The URL is bound to the <lightning-embedding> "src" attribute as a reactive property in the generated LWC. Must use HTTPS; plain HTTP is allowed only for localhost or 127.0.0.1 (for local development).

Comment thread messages/lightningEmbedding.md Outdated

# flags.src.error

The --src flag must be an absolute https URL (e.g., https://app.example.com). Plain http is only allowed for localhost or 127.0.0.1.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The --src flag must be an absolute https URL (e.g., https://app.example.com). Plain http is only allowed for localhost or 127.0.0.1.
The --src flag must be an absolute HTTPS URL, such as https://app.example.com. Plain HTTP is allowed only for localhost or 127.0.0.1.

Comment thread messages/lightningEmbedding.md Outdated

# flags.sandbox.summary

Iframe sandbox token (specify the flag multiple times to set more than one token).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Iframe sandbox token (specify the flag multiple times to set more than one token).
Iframe sandbox token. Specify this flag multiple times to set more than one token.

aman06it added 3 commits May 29, 2026 11:35
Apply all 8 suggestions from @jshackell-sfdc on salesforcecli#943:
- Add LWC abbreviation in summary
- Restructure description for clarity
- Tighten flags.name.summary wording
- Normalize "https" to "HTTPS" in user-facing strings
- Replace "e.g." with "such as" in flags.src.error
- Split flags.sandbox.summary into two sentences
The lightning embedding generator was merged in
forcedotcom/salesforcedx-templates#821 and published as 66.9.0. Bump
the dependency here so CI builds against the published library
instead of the yarn-linked local copy.

Also updates nut test assertions to match the user-facing wording
landed by tech-writer review (https → HTTPS in --src error message).
@aman06it aman06it force-pushed the feat/microfrontend-template branch from f6e04eb to e9eef82 Compare May 30, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants