Skip to content
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

feat: add initial command stubs #18

Merged
merged 4 commits into from
Apr 30, 2024
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
24 changes: 24 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
32 changes: 32 additions & 0 deletions messages/lightning.preview.component.md
Original file line number Diff line number Diff line change
@@ -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 %>
32 changes: 32 additions & 0 deletions messages/lightning.preview.org.md
Original file line number Diff line number Diff line change
@@ -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 %>
32 changes: 32 additions & 0 deletions messages/lightning.preview.site.md
Original file line number Diff line number Diff line change
@@ -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 %>
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions schemas/lightning-preview-component.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
16 changes: 16 additions & 0 deletions schemas/lightning-preview-org.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
16 changes: 16 additions & 0 deletions schemas/lightning-preview-site.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
41 changes: 41 additions & 0 deletions src/commands/lightning/preview/component.ts
Original file line number Diff line number Diff line change
@@ -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<LightningPreviewComponentResult> {
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<LightningPreviewComponentResult> {
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',
};
}
}
41 changes: 41 additions & 0 deletions src/commands/lightning/preview/org.ts
Original file line number Diff line number Diff line change
@@ -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<LightningPreviewOrgResult> {
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<LightningPreviewOrgResult> {
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',
};
}
}
41 changes: 41 additions & 0 deletions src/commands/lightning/preview/site.ts
Original file line number Diff line number Diff line change
@@ -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<LightningPreviewSiteResult> {
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<LightningPreviewSiteResult> {
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',
};
}
}
27 changes: 27 additions & 0 deletions test/commands/lightning/preview/component.nut.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
46 changes: 46 additions & 0 deletions test/commands/lightning/preview/component.test.ts
Original file line number Diff line number Diff line change
@@ -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<typeof stubSfCommandUx>;

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');
});
});
Loading
Loading