Skip to content
Closed
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
9 changes: 5 additions & 4 deletions messages/lightningCmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

<%= config.bin %> <%= command.id %> --name mycomponent --type lwc --output-dir force-app/main/default/lwc

- Generate a TypeScript Lightning Web Component:

<%= config.bin %> <%= command.id %> --name mycomponent --type lwc --template typescript

# summary

Generate a bundle for an Aura component or a Lightning web component.
Expand All @@ -33,3 +29,8 @@ To generate a Lightning web component, pass "--type lwc" to the command. If you
# flags.type.summary

Type of the component bundle.

<!-- TODO: Add back TypeScript example when support is GA:
- Generate a TypeScript Lightning Web Component:
<%= config.bin %> <%= command.id %> --name mycomponent --type lwc --template typescript
-->
10 changes: 6 additions & 4 deletions messages/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ By default, the generated sfdx-project.json file sets the sourceApiVersion prope

<%= config.bin %> <%= command.id %> --name mywork --template empty

- Generate a project in which the Lightning Web Components use TypeScript rather than the default JavaScript:

<%= config.bin %> <%= command.id %> --name mywork --lwc-language typescript

# flags.name.summary

Name of the generated project.
Expand Down Expand Up @@ -105,3 +101,9 @@ Language of the Lightning Web Components. If not specified, "javascript" is used
# flags.lwc-language.description

When set to `'typescript'`, generates TypeScript configuration files (tsconfig.json, package.json with TypeScript dependencies, and TypeScript-aware ESLint config). When you deploy the TypeScript-based Lightning Web Components, the TypeScript files are first compiled locally for validation and then the `.ts` files are deployed to your org for server-side type stripping.

<!-- TODO: Add back when TypeScript support is GA
Example to add back:
- Generate a project in which the Lightning Web Components use TypeScript rather than the default JavaScript:
<%= config.bin %> <%= command.id %> --name mywork --lwc-language typescript
-->
27 changes: 3 additions & 24 deletions src/commands/template/generate/lightning/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { CreateOutput, LightningComponentOptions, TemplateType } from '@salesforce/templates';
import { Messages, SfProject } from '@salesforce/core';
import { Messages } from '@salesforce/core';
import { getCustomTemplates, runGenerator } from '../../../../utils/templateCommand.js';
import { internalFlag, outputDirFlagLightning } from '../../../../utils/flags.js';
const BUNDLE_TYPE = 'Component';
Expand Down Expand Up @@ -39,7 +39,7 @@ export default class LightningComponent extends SfCommand<CreateOutput> {
default: 'default',
// Note: keep this list here and LightningComponentOptions#template in-sync with the
// templates/lightningcomponents/[aura|lwc]/* folders
options: ['default', 'analyticsDashboard', 'analyticsDashboardWithStep', 'typescript'] as const,
options: ['default', 'analyticsDashboard', 'analyticsDashboardWithStep'] as const,
})(),
'output-dir': outputDirFlagLightning,
'api-version': orgApiVersionFlagWithDeprecations,
Expand All @@ -55,30 +55,9 @@ export default class LightningComponent extends SfCommand<CreateOutput> {
public async run(): Promise<CreateOutput> {
const { flags } = await this.parse(LightningComponent);

// Determine if user explicitly set the template flag
const userExplicitlySetTemplate = this.argv.includes('--template') || this.argv.includes('-t');
let template = flags.template;

// If template not explicitly provided and generating LWC, check project preference
if (!userExplicitlySetTemplate && flags.type === 'lwc') {
try {
const projectPath = flags['output-dir'] || process.cwd();
const project = await SfProject.resolve(projectPath);
const projectJson = await project.resolveProjectConfig();
const defaultLwcLanguage = projectJson.defaultLwcLanguage as string | undefined;

if (defaultLwcLanguage === 'typescript') {
template = 'typescript';
}
} catch (error) {
this.debug('Could not resolve project config for intelligent defaulting:', error);
}
}

const flagsAsOptions: LightningComponentOptions = {
componentname: flags.name,
// Temp re-mapping to allow lowercase typescript flag
template: template === 'typescript' ? 'typeScript' : template,
template: flags.template,
outputdir: flags['output-dir'],
apiversion: flags['api-version'],
internal: flags.internal,
Expand Down
8 changes: 8 additions & 0 deletions src/commands/template/generate/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default class Project extends SfCommand<CreateOutput> {
summary: messages.getMessage('flags.lwc-language.summary'),
description: messages.getMessage('flags.lwc-language.description'),
options: ['javascript', 'typescript'] as const,
hidden: true, // Hide from external developers until GA
})(),
loglevel,
'api-version': Flags.orgApiVersion({
Expand All @@ -89,6 +90,13 @@ export default class Project extends SfCommand<CreateOutput> {
};
if (flags['lwc-language']) {
flagsAsOptions.lwcLanguage = flags['lwc-language'];

// Warn users about TypeScript deployment limitations
if (flags['lwc-language'] === 'typescript') {
this.warn(
'TypeScript support is in preview. Direct deployment of .ts files is not yet supported. You must compile TypeScript to JavaScript using "npm run build" before deploying to Salesforce.'
);
}
}

return runGenerator({
Expand Down
6 changes: 3 additions & 3 deletions test/commands/template/generate/lightning/component.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('template generate lightning component:', () => {
});
});

describe('TypeScript Lightning web component generation', () => {
describe.skip('TypeScript Lightning web component generation', () => {
it('should create TypeScript LWC with explicit template flag', () => {
execCmd(
'template generate lightning component --componentname tsComponent --outputdir lwc --type lwc --template typescript',
Expand Down Expand Up @@ -357,7 +357,7 @@ describe('template generate lightning component:', () => {
);
});

it('should throw error when using typescript template with aura type', () => {
it.skip('should throw error when using typescript template with aura type', () => {
const stderr = execCmd(
'template generate lightning component --outputdir aura --componentname foo --type aura --template typescript'
).shellOutput.stderr;
Expand All @@ -383,7 +383,7 @@ describe('template generate lightning component:', () => {
assert.noFile(path.join(session.project.dir, 'standalone', 'lwc', 'outsideComponent', 'outsideComponent.ts'));
});

it('should create TypeScript component outside project with explicit template flag', () => {
it.skip('should create TypeScript component outside project with explicit template flag', () => {
// Generate TypeScript component outside project
execCmd(
'template generate lightning component --componentname outsideTsComponent --outputdir standalone/lwc --type lwc --template typescript',
Expand Down
2 changes: 1 addition & 1 deletion test/commands/template/generate/project/index.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ describe('template generate project:', () => {
});
});

describe('TypeScript project creation', () => {
describe.skip('TypeScript project creation', () => {
it('should create TypeScript project with all required files', () => {
execCmd('template generate project --projectname tsproject --lwc-language typescript', { ensureExitCode: 0 });

Expand Down
Loading