feat: add microfrontend template generator command#943
Conversation
|
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.
3028578 to
0efa415
Compare
|
@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
c4b860a to
d72b7f5
Compare
| 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 |
There was a problem hiding this comment.
Why not export these from the library?
There was a problem hiding this comment.
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.
| componentname: flags.name, | ||
| src: flags.src, | ||
| sandbox: flags.sandbox.join(' '), | ||
| shellTitle: flags['shell-title'] ?? flags.name, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Please add tests for these templates. Lots of examples in |
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
Added in |
jshackell-sfdc
left a comment
There was a problem hiding this comment.
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!
|
|
||
| # 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). |
There was a problem hiding this comment.
| 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). |
|
|
||
| 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". |
There was a problem hiding this comment.
| 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". |
|
|
||
| # summary | ||
|
|
||
| Generate a Lightning Web Component that wraps the lightning-embedding base component. |
There was a problem hiding this comment.
| 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. |
|
|
||
| # flags.name.summary | ||
|
|
||
| PascalCase name of the generated component. |
There was a problem hiding this comment.
| PascalCase name of the generated component. | |
| Name of the generated component; must be in PascalCase format. |
|
|
||
| # flags.src.summary | ||
|
|
||
| Absolute https URL the iframe will load. |
There was a problem hiding this comment.
| Absolute https URL the iframe will load. | |
| Absolute HTTPS URL that the iframe will load. |
|
|
||
| # 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). |
There was a problem hiding this comment.
| 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). |
|
|
||
| # 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. |
There was a problem hiding this comment.
| 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. |
|
|
||
| # flags.sandbox.summary | ||
|
|
||
| Iframe sandbox token (specify the flag multiple times to set more than one token). |
There was a problem hiding this comment.
| 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. |
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).
…mplate # Conflicts: # yarn.lock
f6e04eb to
e9eef82
Compare
Summary
sf template generate lightning embeddingto scaffold a Lightning Web Component bundle that wraps<lightning-embedding>.lightningtopic as a peer ofapp,component,event,interface,test(per team alignment in #plugin-design-templates — avoids bothmfeandmicrofrontend).--name,--src,--sandbox(multi-value, validated against W3C sandbox tokens),--shell-title,--output-dir,--api-version,--internal.--srcvalidation: https only; plain http allowed only forlocalhost/127.0.0.1(local dev).static hidden = trueuntil rollout is finalized.LightningEmbeddingGeneratorin feat: add lightning embedding template generator forcedotcom/salesforcedx-templates#821.