Skip to content

Commit 81f5465

Browse files
committed
feat: single component preview
1 parent dc22ea4 commit 81f5465

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

command-snapshot.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
"flags": ["device-id", "device-type", "flags-dir", "name", "target-org"],
88
"plugin": "@salesforce/plugin-lightning-dev"
99
},
10+
{
11+
"alias": [],
12+
"command": "lightning:preview:component",
13+
"flagAliases": [],
14+
"flagChars": ["n"],
15+
"flags": ["flags-dir", "json", "name"],
16+
"plugin": "@salesforce/plugin-lightning-dev"
17+
},
1018
{
1119
"alias": [],
1220
"command": "lightning:dev:site",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# summary
2+
3+
Preview LWC component in insolation.
4+
5+
# description
6+
7+
Preview components, apps, and sites. If no topic is specified, the default action is to preview the org.
8+
9+
In dev preview mode, you can edit local files and see these changes to your Lightning Web Components (LWC) within your {org name} org:
10+
11+
- Basic HTML and CSS edits
12+
- Importing new CSS-only LWC
13+
- JS edits in-service component library
14+
- JS method changes in the LWC component that don't alter its public API.
15+
16+
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.
17+
18+
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.
19+
20+
Use the appropriate topic to preview specific aspects of the development environment.
21+
22+
# flags.name.summary
23+
24+
Description of a flag.
25+
26+
# flags.name.description
27+
28+
More information about a flag. Don't repeat the summary.
29+
30+
# examples
31+
32+
- <%= config.bin %> <%= command.id %>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/LightningPreviewComponentResult",
4+
"definitions": {
5+
"LightningPreviewComponentResult": {
6+
"type": "object",
7+
"properties": {
8+
"path": {
9+
"type": "string"
10+
}
11+
},
12+
"required": ["path"],
13+
"additionalProperties": false
14+
}
15+
}
16+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
9+
import { Messages } from '@salesforce/core';
10+
11+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
12+
const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.preview.component');
13+
14+
export type LightningPreviewComponentResult = {
15+
path: string;
16+
};
17+
18+
export default class LightningPreviewComponent extends SfCommand<LightningPreviewComponentResult> {
19+
public static readonly summary = messages.getMessage('summary');
20+
public static readonly description = messages.getMessage('description');
21+
public static readonly examples = messages.getMessages('examples');
22+
23+
public static readonly flags = {
24+
name: Flags.string({
25+
summary: messages.getMessage('flags.name.summary'),
26+
description: messages.getMessage('flags.name.description'),
27+
char: 'n',
28+
required: false,
29+
}),
30+
};
31+
32+
public async run(): Promise<LightningPreviewComponentResult> {
33+
const { flags } = await this.parse(LightningPreviewComponent);
34+
35+
const name = flags.name ?? 'world';
36+
this.log(`hello ${name} from /Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/component.ts`);
37+
return {
38+
path: '/Users/nkruk/git/plugin-lightning-dev/src/commands/lightning/preview/component.ts',
39+
};
40+
}
41+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
// TODO - add proper NUT tests
8+
/*
9+
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
10+
import { expect } from 'chai';
11+
12+
describe('lightning preview component NUTs', () => {
13+
let session: TestSession;
14+
15+
before(async () => {
16+
session = await TestSession.create({ devhubAuthStrategy: 'NONE' });
17+
});
18+
19+
after(async () => {
20+
await session?.clean();
21+
});
22+
23+
it('should display provided name', () => {
24+
const name = 'World';
25+
const command = `lightning preview component --name ${name}`;
26+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;
27+
expect(output).to.contain(name);
28+
});
29+
});
30+
*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import { TestContext } from '@salesforce/core/testSetup';
8+
// import { expect } from 'chai';
9+
// import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
10+
11+
describe('lightning single component preview', () => {
12+
const $$ = new TestContext();
13+
// let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;
14+
15+
beforeEach(() => {
16+
// sfCommandStubs = stubSfCommandUx($$.SANDBOX);
17+
});
18+
19+
afterEach(() => {
20+
$$.restore();
21+
});
22+
23+
it('todo add unit tests', async () => {});
24+
});

0 commit comments

Comments
 (0)