Skip to content

feat: scaffolding for single component preview command @W-17803218 #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"flags": ["device-id", "device-type", "flags-dir", "name", "target-org"],
"plugin": "@salesforce/plugin-lightning-dev"
},
{
"alias": [],
"command": "lightning:dev:component",
"flagAliases": [],
"flagChars": ["n", "o"],
"flags": ["flags-dir", "json", "name", "target-org"],
"plugin": "@salesforce/plugin-lightning-dev"
},
{
"alias": [],
"command": "lightning:dev:site",
Expand Down
19 changes: 19 additions & 0 deletions messages/lightning.dev.component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# summary

Preview LWC components in isolation.

# description

Preview LWC components in isolation. Replacement for: https://developer.salesforce.com/docs/platform/sfvscode-extensions/guide/lwclocaldev.html

# flags.name.summary

Description of a flag.

# flags.name.description

More information about a flag. Don't repeat the summary.

# examples

Comment on lines +9 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to be filled out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, will be done by doc team

- <%= config.bin %> <%= command.id %>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@inquirer/select": "^2.4.7",
"@lwc/lwc-dev-server": "~11.5.0",
"@lwc/sfdc-lwc-compiler": "~11.5.0",
"@lwrjs/api": "0.16.4",
"@lwrjs/api": "0.16.6",
"@oclif/core": "^4.1.0",
"@salesforce/core": "^8.6.2",
"@salesforce/kit": "^3.1.6",
Expand Down
52 changes: 52 additions & 0 deletions src/commands/lightning/dev/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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';
import { cmpDev } from '@lwrjs/api';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.dev.component');

export type LightningDevComponentResult = {
path: string;
};

export default class LightningDevComponent extends SfCommand<LightningDevComponentResult> {
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,
}),
// TODO should this be required or optional?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i vote optional

Copy link
Collaborator Author

@nrkruk nrkruk Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will let Brian decide based off what he has time to implement. If we don't make it required, will need to do some code scanning of the component u are attempting to preview, then error out if it needs data and you don't supply an authenticated org. Just added todo comment as a reminder

// We don't technically need this if your components are simple / don't need any data from your org
'target-org': Flags.requiredOrg(),
};

public async run(): Promise<LightningDevComponentResult> {
const { flags } = await this.parse(LightningDevComponent);

const name = flags.name ?? 'world';
this.log(`preview component: ${name}`);

// TODO implement me
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
await cmpDev({
componentName: name,
});

return {
path: '',
};
}
}
30 changes: 30 additions & 0 deletions test/commands/lightning/dev/component.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these test files necessary? they don't do anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brian will add these tests. Just created the initial file structure

* 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
*/
// TODO - add proper NUT tests
/*
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);
});
});
*/
24 changes: 24 additions & 0 deletions test/commands/lightning/dev/component.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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';

describe('lightning single component preview', () => {
const $$ = new TestContext();
// let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;

beforeEach(() => {
// sfCommandStubs = stubSfCommandUx($$.SANDBOX);
});

afterEach(() => {
$$.restore();
});

it('todo add unit tests', async () => {});
});
Loading