Skip to content

Commit 41155bf

Browse files
authored
feat: scaffolding for single component preview command @W-17803218 (#336)
1 parent dc22ea4 commit 41155bf

File tree

7 files changed

+365
-232
lines changed

7 files changed

+365
-232
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:dev:component",
13+
"flagAliases": [],
14+
"flagChars": ["n", "o"],
15+
"flags": ["flags-dir", "json", "name", "target-org"],
16+
"plugin": "@salesforce/plugin-lightning-dev"
17+
},
1018
{
1119
"alias": [],
1220
"command": "lightning:dev:site",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# summary
2+
3+
Preview LWC components in isolation.
4+
5+
# description
6+
7+
Preview LWC components in isolation. Replacement for: https://developer.salesforce.com/docs/platform/sfvscode-extensions/guide/lwclocaldev.html
8+
9+
# flags.name.summary
10+
11+
Description of a flag.
12+
13+
# flags.name.description
14+
15+
More information about a flag. Don't repeat the summary.
16+
17+
# examples
18+
19+
- <%= config.bin %> <%= command.id %>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@inquirer/select": "^2.4.7",
1010
"@lwc/lwc-dev-server": "~11.5.0",
1111
"@lwc/sfdc-lwc-compiler": "~11.5.0",
12-
"@lwrjs/api": "0.16.4",
12+
"@lwrjs/api": "0.16.6",
1313
"@oclif/core": "^4.1.0",
1414
"@salesforce/core": "^8.6.2",
1515
"@salesforce/kit": "^3.1.6",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
import { cmpDev } from '@lwrjs/api';
11+
12+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
13+
const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.dev.component');
14+
15+
export type LightningDevComponentResult = {
16+
path: string;
17+
};
18+
19+
export default class LightningDevComponent extends SfCommand<LightningDevComponentResult> {
20+
public static readonly summary = messages.getMessage('summary');
21+
public static readonly description = messages.getMessage('description');
22+
public static readonly examples = messages.getMessages('examples');
23+
24+
public static readonly flags = {
25+
name: Flags.string({
26+
summary: messages.getMessage('flags.name.summary'),
27+
description: messages.getMessage('flags.name.description'),
28+
char: 'n',
29+
required: false,
30+
}),
31+
// TODO should this be required or optional?
32+
// We don't technically need this if your components are simple / don't need any data from your org
33+
'target-org': Flags.requiredOrg(),
34+
};
35+
36+
public async run(): Promise<LightningDevComponentResult> {
37+
const { flags } = await this.parse(LightningDevComponent);
38+
39+
const name = flags.name ?? 'world';
40+
this.log(`preview component: ${name}`);
41+
42+
// TODO implement me
43+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
44+
await cmpDev({
45+
componentName: name,
46+
});
47+
48+
return {
49+
path: '',
50+
};
51+
}
52+
}
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)