diff --git a/command-snapshot.json b/command-snapshot.json index fa7af857..4d758847 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -79,25 +79,6 @@ "flags": ["api-version", "flags-dir", "internal", "json", "loglevel", "name", "output-dir", "template", "type"], "plugin": "@salesforce/plugin-templates" }, - { - "alias": [], - "command": "template:generate:lightning:embedding", - "flagAliases": ["apiversion", "outputdir"], - "flagChars": ["d", "i", "n", "s"], - "flags": [ - "api-version", - "flags-dir", - "internal", - "json", - "loglevel", - "name", - "output-dir", - "sandbox", - "shell-title", - "src" - ], - "plugin": "@salesforce/plugin-templates" - }, { "alias": ["force:lightning:event:create", "lightning:generate:event"], "command": "template:generate:lightning:event", @@ -159,6 +140,25 @@ "flags": ["api-version", "flags-dir", "json", "label", "name", "output-dir", "template"], "plugin": "@salesforce/plugin-templates" }, + { + "alias": [], + "command": "template:generate:ui-embedding", + "flagAliases": ["apiversion", "outputdir"], + "flagChars": ["d", "i", "n", "s"], + "flags": [ + "api-version", + "flags-dir", + "internal", + "json", + "loglevel", + "name", + "output-dir", + "sandbox", + "shell-title", + "src" + ], + "plugin": "@salesforce/plugin-templates" + }, { "alias": ["force:visualforce:component:create", "visualforce:generate:component"], "command": "template:generate:visualforce:component", diff --git a/messages/lightningEmbedding.md b/messages/uiEmbedding.md similarity index 62% rename from messages/lightningEmbedding.md rename to messages/uiEmbedding.md index e549668b..7a149025 100644 --- a/messages/lightningEmbedding.md +++ b/messages/uiEmbedding.md @@ -2,19 +2,19 @@ - Generate an embedding wrapper LWC in the current directory: - <%= config.bin %> <%= command.id %> --name MyEmbeddingWrapper --src https://app.example.com --sandbox allow-forms --shell-title "Expense Report Widget" + <%= config.bin %> <%= command.id %> --name MyEmbeddingWrapper --src https://app.example.com --sandbox allow-forms --shell-title "Expense Report Embedding" - Generate an embedding wrapper LWC in the "force-app/main/default/lwc" directory with multiple sandbox tokens: - <%= config.bin %> <%= command.id %> --name MyEmbeddingWrapper --src https://app.example.com --sandbox allow-forms --sandbox allow-scripts --shell-title "Expense Report Widget" --output-dir force-app/main/default/lwc + <%= config.bin %> <%= command.id %> --name MyEmbeddingWrapper --src https://app.example.com --sandbox allow-forms --sandbox allow-scripts --shell-title "Expense Report Embedding" --output-dir force-app/main/default/lwc # summary -Generate a Lightning Web Component (LWC) bundle that wraps the lightning-embedding base component. +Generate a Lightning Web Component (LWC) bundle that wraps the base component. # description -The generated LWC bundle consumes the first-party component, which is 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 component, which is pre-wired with the three required attributes: the embedding URL (src), iframe sandbox tokens, and an accessible iframe title (shell-title). 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". @@ -32,7 +32,7 @@ Absolute HTTPS URL that the iframe will load. # flags.src.description -The URL is bound to the "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). +The URL is bound to the "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 @@ -44,7 +44,7 @@ Iframe sandbox token. Specify this flag multiple times to set more than one toke # flags.sandbox.description -Each token is written into the space-separated "sandbox" attribute on . Only W3C-defined sandbox tokens are accepted. +Each token is written into the space-separated "sandbox" attribute on . Only W3C-defined sandbox tokens are accepted. # flags.shell-title.summary @@ -52,4 +52,4 @@ Accessible title for the embedded iframe. # flags.shell-title.description -Written to the "shell-title" attribute on and used as the iframe's accessible name (announced by screen readers). +Written to the "shell-title" attribute on and used as the iframe's accessible name (announced by screen readers). diff --git a/package.json b/package.json index d6ba8a94..ea9c8857 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,9 @@ }, "ui-bundle": { "description": "Generate a UI bundle." + }, + "ui-embedding": { + "description": "Generate a UI embedding wrapper LWC." } } } diff --git a/schemas/template-generate-lightning-embedding.json b/schemas/template-generate-ui__embedding.json similarity index 100% rename from schemas/template-generate-lightning-embedding.json rename to schemas/template-generate-ui__embedding.json diff --git a/src/commands/template/generate/lightning/embedding.ts b/src/commands/template/generate/ui-embedding/index.ts similarity index 94% rename from src/commands/template/generate/lightning/embedding.ts rename to src/commands/template/generate/ui-embedding/index.ts index d1e68cb4..811d72c5 100644 --- a/src/commands/template/generate/lightning/embedding.ts +++ b/src/commands/template/generate/ui-embedding/index.ts @@ -18,9 +18,9 @@ import { getCustomTemplates, runGenerator } from '../../../../utils/templateComm import { internalFlag, outputDirFlagLightning } from '../../../../utils/flags.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); -const messages = Messages.loadMessages('@salesforce/plugin-templates', 'lightningEmbedding'); +const messages = Messages.loadMessages('@salesforce/plugin-templates', 'uiEmbedding'); -export default class LightningEmbedding extends SfCommand { +export default class UIEmbedding extends SfCommand { public static readonly summary = messages.getMessage('summary'); public static readonly description = messages.getMessage('description'); public static readonly examples = messages.getMessages('examples'); @@ -65,7 +65,7 @@ export default class LightningEmbedding extends SfCommand { }; public async run(): Promise { - const { flags } = await this.parse(LightningEmbedding); + const { flags } = await this.parse(UIEmbedding); const flagsAsOptions: UIEmbeddingOptions = { componentname: flags.name, diff --git a/test/commands/template/generate/lightning/embedding.nut.ts b/test/commands/template/generate/ui-embedding/index.nut.ts similarity index 63% rename from test/commands/template/generate/lightning/embedding.nut.ts rename to test/commands/template/generate/ui-embedding/index.nut.ts index f811aa1a..0fd969f4 100644 --- a/test/commands/template/generate/lightning/embedding.nut.ts +++ b/test/commands/template/generate/ui-embedding/index.nut.ts @@ -11,7 +11,7 @@ import assert from 'yeoman-assert'; config.truncateThreshold = 0; -describe('template generate lightning embedding:', () => { +describe('template generate ui-embedding:', () => { let session: TestSession; before(async () => { session = await TestSession.create({ @@ -29,22 +29,22 @@ describe('template generate lightning embedding:', () => { return ['.html', '.js', '.css', '.js-meta.xml'].map((suffix) => path.join(lwcDir(), camel, camel + suffix)); }; - describe('Check lightning embedding creation', () => { + describe('Check ui-embedding creation', () => { const name = 'MyEmbedding'; const src = 'https://app.example.com'; const shellTitle = 'Demo Embedding'; it('should scaffold an embedding LWC bundle with all four files', () => { execCmd( - `template generate lightning embedding --name ${name} --src ${src} --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, + `template generate ui-embedding --name ${name} --src ${src} --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, { ensureExitCode: 0 } ); assert.file(bundleFiles(name)); }); - it('should emit a element in the generated html', () => { + it('should emit a element in the generated html', () => { execCmd( - `template generate lightning embedding --name ${name} --src ${src} --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, + `template generate ui-embedding --name ${name} --src ${src} --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, { ensureExitCode: 0 } ); const camel = name.charAt(0).toLowerCase() + name.slice(1); @@ -53,7 +53,7 @@ describe('template generate lightning embedding:', () => { it('should join multiple --sandbox tokens into a single space-separated attribute', () => { execCmd( - `template generate lightning embedding --name MultiSandbox --src ${src} --sandbox allow-forms --sandbox allow-scripts --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, + `template generate ui-embedding --name MultiSandbox --src ${src} --sandbox allow-forms --sandbox allow-scripts --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, { ensureExitCode: 0 } ); assert.fileContent( @@ -64,7 +64,7 @@ describe('template generate lightning embedding:', () => { it('should bind the src URL into the generated js as a reactive property', () => { execCmd( - `template generate lightning embedding --name SrcBinding --src ${src} --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, + `template generate ui-embedding --name SrcBinding --src ${src} --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, { ensureExitCode: 0 } ); assert.fileContent(path.join(lwcDir(), 'srcBinding', 'srcBinding.js'), src); @@ -72,68 +72,67 @@ describe('template generate lightning embedding:', () => { it('should accept http URLs on localhost for local development', () => { execCmd( - `template generate lightning embedding --name LocalDev --src http://localhost:3000 --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, + `template generate ui-embedding --name LocalDev --src http://localhost:3000 --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`, { ensureExitCode: 0 } ); assert.fileContent(path.join(lwcDir(), 'localDev', 'localDev.js'), 'http://localhost:3000'); }); }); - describe('lightning embedding failures', () => { + describe('ui-embedding failures', () => { const baseFlags = '--name Foo --sandbox allow-forms --shell-title "Demo"'; it('should throw missing --name error', () => { const stderr = execCmd( - 'template generate lightning embedding --src https://app.example.com --sandbox allow-forms --shell-title "Demo"' + 'template generate ui-embedding --src https://app.example.com --sandbox allow-forms --shell-title "Demo"' ).shellOutput.stderr; expect(stderr).to.contain('Missing required flag'); }); it('should throw missing --src error', () => { - const stderr = execCmd( - 'template generate lightning embedding --name Foo --sandbox allow-forms --shell-title "Demo"' - ).shellOutput.stderr; + const stderr = execCmd('template generate ui-embedding --name Foo --sandbox allow-forms --shell-title "Demo"') + .shellOutput.stderr; expect(stderr).to.contain('Missing required flag'); }); it('should throw missing --sandbox error', () => { const stderr = execCmd( - 'template generate lightning embedding --name Foo --src https://app.example.com --shell-title "Demo"' + 'template generate ui-embedding --name Foo --src https://app.example.com --shell-title "Demo"' ).shellOutput.stderr; expect(stderr).to.contain('Missing required flag'); }); it('should throw missing --shell-title error (no fallback to --name)', () => { const stderr = execCmd( - 'template generate lightning embedding --name Foo --src https://app.example.com --sandbox allow-forms' + 'template generate ui-embedding --name Foo --src https://app.example.com --sandbox allow-forms' ).shellOutput.stderr; expect(stderr).to.contain('Missing required flag'); }); it('should reject http src on a non-localhost host', () => { const stderr = execCmd( - `template generate lightning embedding --name Foo --src http://attacker.com --sandbox allow-forms --shell-title "Demo" --output-dir ${lwcDir()}` + `template generate ui-embedding --name Foo --src http://attacker.com --sandbox allow-forms --shell-title "Demo" --output-dir ${lwcDir()}` ).shellOutput.stderr; expect(stderr).to.contain('HTTPS URL'); }); it('should reject non-http(s) protocols', () => { const stderr = execCmd( - `template generate lightning embedding --name Foo --src ftp://example.com --sandbox allow-forms --shell-title "Demo" --output-dir ${lwcDir()}` + `template generate ui-embedding --name Foo --src ftp://example.com --sandbox allow-forms --shell-title "Demo" --output-dir ${lwcDir()}` ).shellOutput.stderr; expect(stderr).to.contain('HTTPS URL'); }); it('should reject malformed --src input', () => { const stderr = execCmd( - `template generate lightning embedding --name Foo --src not-a-url --sandbox allow-forms --shell-title "Demo" --output-dir ${lwcDir()}` + `template generate ui-embedding --name Foo --src not-a-url --sandbox allow-forms --shell-title "Demo" --output-dir ${lwcDir()}` ).shellOutput.stderr; expect(stderr).to.contain('HTTPS URL'); }); it('should reject an unknown sandbox token', () => { const stderr = execCmd( - `template generate lightning embedding ${baseFlags} --src https://app.example.com --sandbox allow-everything --output-dir ${lwcDir()}`, + `template generate ui-embedding ${baseFlags} --src https://app.example.com --sandbox allow-everything --output-dir ${lwcDir()}`, { ensureExitCode: 'nonZero' } ).shellOutput.stderr; expect(stderr).to.contain('Expected --sandbox'); @@ -141,7 +140,7 @@ describe('template generate lightning embedding:', () => { it('should throw missing lwc parent folder error when output-dir is not under lwc/', () => { const stderr = execCmd( - `template generate lightning embedding --name Foo --src https://app.example.com --sandbox allow-forms --shell-title "Demo" --output-dir ${path.join( + `template generate ui-embedding --name Foo --src https://app.example.com --sandbox allow-forms --shell-title "Demo" --output-dir ${path.join( session.project.dir, 'somewhere-else' )}`