From 67ced757ebe32e7349946f6c0fe031f546061a9b Mon Sep 17 00:00:00 2001 From: Nicolas Kruk Date: Tue, 30 Apr 2024 01:10:56 -0400 Subject: [PATCH 1/4] feat: generate stubs --- messages/lightning.preview.component.md | 32 +++++++++++++ messages/lightning.preview.org.md | 32 +++++++++++++ messages/lightning.preview.site.md | 32 +++++++++++++ package.json | 10 +++- src/commands/lightning/preview/component.ts | 41 +++++++++++++++++ src/commands/lightning/preview/org.ts | 41 +++++++++++++++++ src/commands/lightning/preview/site.ts | 41 +++++++++++++++++ .../lightning/preview/component.nut.ts | 27 +++++++++++ .../lightning/preview/component.test.ts | 46 +++++++++++++++++++ test/commands/lightning/preview/org.nut.ts | 27 +++++++++++ test/commands/lightning/preview/org.test.ts | 46 +++++++++++++++++++ test/commands/lightning/preview/site.nut.ts | 27 +++++++++++ test/commands/lightning/preview/site.test.ts | 46 +++++++++++++++++++ 13 files changed, 447 insertions(+), 1 deletion(-) create mode 100644 messages/lightning.preview.component.md create mode 100644 messages/lightning.preview.org.md create mode 100644 messages/lightning.preview.site.md create mode 100644 src/commands/lightning/preview/component.ts create mode 100644 src/commands/lightning/preview/org.ts create mode 100644 src/commands/lightning/preview/site.ts create mode 100644 test/commands/lightning/preview/component.nut.ts create mode 100644 test/commands/lightning/preview/component.test.ts create mode 100644 test/commands/lightning/preview/org.nut.ts create mode 100644 test/commands/lightning/preview/org.test.ts create mode 100644 test/commands/lightning/preview/site.nut.ts create mode 100644 test/commands/lightning/preview/site.test.ts diff --git a/messages/lightning.preview.component.md b/messages/lightning.preview.component.md new file mode 100644 index 0000000..8b16fd8 --- /dev/null +++ b/messages/lightning.preview.component.md @@ -0,0 +1,32 @@ +# summary + +Preview LWC component in insolation. + +# description + +Preview components, org, and sites. If no topic is specified, the default action is to preview the org. + +In dev preview mode, you can edit local files and see these changes to your Lightning Web Components (LWC) within your {org name} org: + +- Basic HTML and CSS edits +- Importing new CSS-only LWC +- JS edits in-service component library +- JS method changes in the LWC component that don't alter its public API. + +Other local changes require deployment to your org. However, changes made directly in your org (like modifying component properties and saving) are immediately live and won't show in your local files until you retrieve them from the org. + +This feature enables developers to quickly iterate on their components and pages, seeing the impact of changes in real-time without needing to deploy or refresh manually. Live reload is enabled by default to automatically refresh the preview when source code changes are detected. + +Use the appropriate topic to preview specific aspects of the development environment. + +# flags.name.summary + +Description of a flag. + +# flags.name.description + +More information about a flag. Don't repeat the summary. + +# examples + +- <%= config.bin %> <%= command.id %> diff --git a/messages/lightning.preview.org.md b/messages/lightning.preview.org.md new file mode 100644 index 0000000..7f227ef --- /dev/null +++ b/messages/lightning.preview.org.md @@ -0,0 +1,32 @@ +# summary + +Preview LWC components in context of your Salesforce Org. + +# description + +Preview components, org, and sites. If no topic is specified, the default action is to preview the org. + +In dev preview mode, you can edit local files and see these changes to your Lightning Web Components (LWC) within your {org name} org: + +- Basic HTML and CSS edits +- Importing new CSS-only LWC +- JS edits in-service component library +- JS method changes in the LWC component that don't alter its public API. + +Other local changes require deployment to your org. However, changes made directly in your org (like modifying component properties and saving) are immediately live and won't show in your local files until you retrieve them from the org. + +This feature enables developers to quickly iterate on their components and pages, seeing the impact of changes in real-time without needing to deploy or refresh manually. Live reload is enabled by default to automatically refresh the preview when source code changes are detected. + +Use the appropriate topic to preview specific aspects of the development environment. + +# flags.name.summary + +Description of a flag. + +# flags.name.description + +More information about a flag. Don't repeat the summary. + +# examples + +- <%= config.bin %> <%= command.id %> diff --git a/messages/lightning.preview.site.md b/messages/lightning.preview.site.md new file mode 100644 index 0000000..5ed3f39 --- /dev/null +++ b/messages/lightning.preview.site.md @@ -0,0 +1,32 @@ +# summary + +Preview LWC components in context of Experience Cloud on Experience Delivery site. + +# description + +Preview components, org, and sites. If no topic is specified, the default action is to preview the org. + +In dev preview mode, you can edit local files and see these changes to your Lightning Web Components (LWC) within your {org name} org: + +- Basic HTML and CSS edits +- Importing new CSS-only LWC +- JS edits in-service component library +- JS method changes in the LWC component that don't alter its public API. + +Other local changes require deployment to your org. However, changes made directly in your org (like modifying component properties and saving) are immediately live and won't show in your local files until you retrieve them from the org. + +This feature enables developers to quickly iterate on their components and pages, seeing the impact of changes in real-time without needing to deploy or refresh manually. Live reload is enabled by default to automatically refresh the preview when source code changes are detected. + +Use the appropriate topic to preview specific aspects of the development environment. + +# flags.name.summary + +Description of a flag. + +# flags.name.description + +More information about a flag. Don't repeat the summary. + +# examples + +- <%= config.bin %> <%= command.id %> diff --git a/package.json b/package.json index f08bd6f..7876d33 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,14 @@ "topics": { "hello": { "description": "Commands to say hello." + }, + "lightning": { + "external": true, + "subtopics": { + "preview": { + "description": "Preview components, org, and, sites in real-time." + } + } } }, "flexibleTaxonomy": true @@ -187,7 +195,7 @@ "output": [] }, "link-check": { - "command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|world.ts|my.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error", + "command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|my.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error", "files": [ "./*.md", "./!(CHANGELOG).md", diff --git a/src/commands/lightning/preview/component.ts b/src/commands/lightning/preview/component.ts new file mode 100644 index 0000000..d3dab81 --- /dev/null +++ b/src/commands/lightning/preview/component.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; +import { Messages } from '@salesforce/core'; + +Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); +const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.preview.component'); + +export type LightningPreviewComponentResult = { + path: string; +}; + +export default class LightningPreviewComponent extends SfCommand { + public static readonly summary = messages.getMessage('summary'); + public static readonly description = messages.getMessage('description'); + public static readonly examples = messages.getMessages('examples'); + + public static readonly flags = { + name: Flags.string({ + summary: messages.getMessage('flags.name.summary'), + description: messages.getMessage('flags.name.description'), + char: 'n', + required: false, + }), + }; + + public async run(): Promise { + const { flags } = await this.parse(LightningPreviewComponent); + + const name = flags.name ?? 'world'; + this.log(`hello ${name} from /Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/component.ts`); + return { + path: '/Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/component.ts', + }; + } +} diff --git a/src/commands/lightning/preview/org.ts b/src/commands/lightning/preview/org.ts new file mode 100644 index 0000000..4ee33ad --- /dev/null +++ b/src/commands/lightning/preview/org.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; +import { Messages } from '@salesforce/core'; + +Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); +const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.preview.org'); + +export type LightningPreviewOrgResult = { + path: string; +}; + +export default class LightningPreviewOrg extends SfCommand { + public static readonly summary = messages.getMessage('summary'); + public static readonly description = messages.getMessage('description'); + public static readonly examples = messages.getMessages('examples'); + + public static readonly flags = { + name: Flags.string({ + summary: messages.getMessage('flags.name.summary'), + description: messages.getMessage('flags.name.description'), + char: 'n', + required: false, + }), + }; + + public async run(): Promise { + const { flags } = await this.parse(LightningPreviewOrg); + + const name = flags.name ?? 'world'; + this.log(`hello ${name} from /Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/org.ts`); + return { + path: '/Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/org.ts', + }; + } +} diff --git a/src/commands/lightning/preview/site.ts b/src/commands/lightning/preview/site.ts new file mode 100644 index 0000000..c86beaa --- /dev/null +++ b/src/commands/lightning/preview/site.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; +import { Messages } from '@salesforce/core'; + +Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); +const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.preview.site'); + +export type LightningPreviewSiteResult = { + path: string; +}; + +export default class LightningPreviewSite extends SfCommand { + public static readonly summary = messages.getMessage('summary'); + public static readonly description = messages.getMessage('description'); + public static readonly examples = messages.getMessages('examples'); + + public static readonly flags = { + name: Flags.string({ + summary: messages.getMessage('flags.name.summary'), + description: messages.getMessage('flags.name.description'), + char: 'n', + required: false, + }), + }; + + public async run(): Promise { + const { flags } = await this.parse(LightningPreviewSite); + + const name = flags.name ?? 'world'; + this.log(`hello ${name} from /Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/site.ts`); + return { + path: '/Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/site.ts', + }; + } +} diff --git a/test/commands/lightning/preview/component.nut.ts b/test/commands/lightning/preview/component.nut.ts new file mode 100644 index 0000000..f205258 --- /dev/null +++ b/test/commands/lightning/preview/component.nut.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; +import { expect } from 'chai'; + +describe('lightning preview component NUTs', () => { + let session: TestSession; + + before(async () => { + session = await TestSession.create({ devhubAuthStrategy: 'NONE' }); + }); + + after(async () => { + await session?.clean(); + }); + + it('should display provided name', () => { + const name = 'World'; + const command = `lightning preview component --name ${name}`; + const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout; + expect(output).to.contain(name); + }); +}); diff --git a/test/commands/lightning/preview/component.test.ts b/test/commands/lightning/preview/component.test.ts new file mode 100644 index 0000000..aa7a75c --- /dev/null +++ b/test/commands/lightning/preview/component.test.ts @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { TestContext } from '@salesforce/core/testSetup'; +import { expect } from 'chai'; +import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; +import LightningPreviewComponent from '../../../../src/commands/lightning/preview/component.js'; + +describe('lightning preview component', () => { + const $$ = new TestContext(); + let sfCommandStubs: ReturnType; + + beforeEach(() => { + sfCommandStubs = stubSfCommandUx($$.SANDBOX); + }); + + afterEach(() => { + $$.restore(); + }); + + it('runs hello', async () => { + await LightningPreviewComponent.run([]); + const output = sfCommandStubs.log + .getCalls() + .flatMap((c) => c.args) + .join('\n'); + expect(output).to.include('hello world'); + }); + + it('runs hello with --json and no provided name', async () => { + const result = await LightningPreviewComponent.run([]); + expect(result.path).to.equal('/Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/component.ts'); + }); + + it('runs hello world --name Astro', async () => { + await LightningPreviewComponent.run(['--name', 'Astro']); + const output = sfCommandStubs.log + .getCalls() + .flatMap((c) => c.args) + .join('\n'); + expect(output).to.include('hello Astro'); + }); +}); diff --git a/test/commands/lightning/preview/org.nut.ts b/test/commands/lightning/preview/org.nut.ts new file mode 100644 index 0000000..a969dd4 --- /dev/null +++ b/test/commands/lightning/preview/org.nut.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; +import { expect } from 'chai'; + +describe('lightning preview org NUTs', () => { + let session: TestSession; + + before(async () => { + session = await TestSession.create({ devhubAuthStrategy: 'NONE' }); + }); + + after(async () => { + await session?.clean(); + }); + + it('should display provided name', () => { + const name = 'World'; + const command = `lightning preview org --name ${name}`; + const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout; + expect(output).to.contain(name); + }); +}); diff --git a/test/commands/lightning/preview/org.test.ts b/test/commands/lightning/preview/org.test.ts new file mode 100644 index 0000000..8000adf --- /dev/null +++ b/test/commands/lightning/preview/org.test.ts @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { TestContext } from '@salesforce/core/testSetup'; +import { expect } from 'chai'; +import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; +import LightningPreviewOrg from '../../../../src/commands/lightning/preview/org.js'; + +describe('lightning preview org', () => { + const $$ = new TestContext(); + let sfCommandStubs: ReturnType; + + beforeEach(() => { + sfCommandStubs = stubSfCommandUx($$.SANDBOX); + }); + + afterEach(() => { + $$.restore(); + }); + + it('runs hello', async () => { + await LightningPreviewOrg.run([]); + const output = sfCommandStubs.log + .getCalls() + .flatMap((c) => c.args) + .join('\n'); + expect(output).to.include('hello world'); + }); + + it('runs hello with --json and no provided name', async () => { + const result = await LightningPreviewOrg.run([]); + expect(result.path).to.equal('/Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/org.ts'); + }); + + it('runs hello world --name Astro', async () => { + await LightningPreviewOrg.run(['--name', 'Astro']); + const output = sfCommandStubs.log + .getCalls() + .flatMap((c) => c.args) + .join('\n'); + expect(output).to.include('hello Astro'); + }); +}); diff --git a/test/commands/lightning/preview/site.nut.ts b/test/commands/lightning/preview/site.nut.ts new file mode 100644 index 0000000..1010bf6 --- /dev/null +++ b/test/commands/lightning/preview/site.nut.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; +import { expect } from 'chai'; + +describe('lightning preview site NUTs', () => { + let session: TestSession; + + before(async () => { + session = await TestSession.create({ devhubAuthStrategy: 'NONE' }); + }); + + after(async () => { + await session?.clean(); + }); + + it('should display provided name', () => { + const name = 'World'; + const command = `lightning preview site --name ${name}`; + const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout; + expect(output).to.contain(name); + }); +}); diff --git a/test/commands/lightning/preview/site.test.ts b/test/commands/lightning/preview/site.test.ts new file mode 100644 index 0000000..d46bd8b --- /dev/null +++ b/test/commands/lightning/preview/site.test.ts @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { TestContext } from '@salesforce/core/testSetup'; +import { expect } from 'chai'; +import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; +import LightningPreviewSite from '../../../../src/commands/lightning/preview/site.js'; + +describe('lightning preview site', () => { + const $$ = new TestContext(); + let sfCommandStubs: ReturnType; + + beforeEach(() => { + sfCommandStubs = stubSfCommandUx($$.SANDBOX); + }); + + afterEach(() => { + $$.restore(); + }); + + it('runs hello', async () => { + await LightningPreviewSite.run([]); + const output = sfCommandStubs.log + .getCalls() + .flatMap((c) => c.args) + .join('\n'); + expect(output).to.include('hello world'); + }); + + it('runs hello with --json and no provided name', async () => { + const result = await LightningPreviewSite.run([]); + expect(result.path).to.equal('/Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/site.ts'); + }); + + it('runs hello world --name Astro', async () => { + await LightningPreviewSite.run(['--name', 'Astro']); + const output = sfCommandStubs.log + .getCalls() + .flatMap((c) => c.args) + .join('\n'); + expect(output).to.include('hello Astro'); + }); +}); From 20cea6af9bebb82c6dc22260197b4af0d861a259 Mon Sep 17 00:00:00 2001 From: Nicolas Kruk Date: Tue, 30 Apr 2024 01:13:29 -0400 Subject: [PATCH 2/4] fix: package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7876d33..2481324 100644 --- a/package.json +++ b/package.json @@ -195,7 +195,7 @@ "output": [] }, "link-check": { - "command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|my.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error", + "command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|world.ts|my.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error", "files": [ "./*.md", "./!(CHANGELOG).md", From dbf091255c85518bdfb14edbaa7fe3015799b683 Mon Sep 17 00:00:00 2001 From: Nicolas Kruk Date: Tue, 30 Apr 2024 01:22:20 -0400 Subject: [PATCH 3/4] chore: update snapshots --- command-snapshot.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/command-snapshot.json b/command-snapshot.json index 7788549..849ff47 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -6,5 +6,29 @@ "flagChars": ["n"], "flags": ["flags-dir", "json", "name"], "plugin": "@salesforce/plugin-lightning-dev" + }, + { + "alias": [], + "command": "lightning:preview:component", + "flagAliases": [], + "flagChars": ["n"], + "flags": ["flags-dir", "json", "name"], + "plugin": "@salesforce/plugin-lightning-dev" + }, + { + "alias": [], + "command": "lightning:preview:org", + "flagAliases": [], + "flagChars": ["n"], + "flags": ["flags-dir", "json", "name"], + "plugin": "@salesforce/plugin-lightning-dev" + }, + { + "alias": [], + "command": "lightning:preview:site", + "flagAliases": [], + "flagChars": ["n"], + "flags": ["flags-dir", "json", "name"], + "plugin": "@salesforce/plugin-lightning-dev" } ] From 72fa88691fe6c44216d88ab3c4e2e970177a7fc1 Mon Sep 17 00:00:00 2001 From: Nicolas Kruk Date: Tue, 30 Apr 2024 01:23:39 -0400 Subject: [PATCH 4/4] chore: update schemas --- schemas/lightning-preview-component.json | 16 ++++++++++++++++ schemas/lightning-preview-org.json | 16 ++++++++++++++++ schemas/lightning-preview-site.json | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 schemas/lightning-preview-component.json create mode 100644 schemas/lightning-preview-org.json create mode 100644 schemas/lightning-preview-site.json diff --git a/schemas/lightning-preview-component.json b/schemas/lightning-preview-component.json new file mode 100644 index 0000000..a8a2392 --- /dev/null +++ b/schemas/lightning-preview-component.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/LightningPreviewComponentResult", + "definitions": { + "LightningPreviewComponentResult": { + "type": "object", + "properties": { + "path": { + "type": "string" + } + }, + "required": ["path"], + "additionalProperties": false + } + } +} diff --git a/schemas/lightning-preview-org.json b/schemas/lightning-preview-org.json new file mode 100644 index 0000000..8b95ac0 --- /dev/null +++ b/schemas/lightning-preview-org.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/LightningPreviewOrgResult", + "definitions": { + "LightningPreviewOrgResult": { + "type": "object", + "properties": { + "path": { + "type": "string" + } + }, + "required": ["path"], + "additionalProperties": false + } + } +} diff --git a/schemas/lightning-preview-site.json b/schemas/lightning-preview-site.json new file mode 100644 index 0000000..c7c523d --- /dev/null +++ b/schemas/lightning-preview-site.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$ref": "#/definitions/LightningPreviewSiteResult", + "definitions": { + "LightningPreviewSiteResult": { + "type": "object", + "properties": { + "path": { + "type": "string" + } + }, + "required": ["path"], + "additionalProperties": false + } + } +}