-
Notifications
You must be signed in to change notification settings - Fork 13
W-21523405 feat: Add TypeScript component generation with intelligent defaulting #877
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
base: main
Are you sure you want to change the base?
Changes from all commits
7e6076b
887abda
d779bfc
0a1cf97
c908750
c3dc1b4
f09a0e9
622770a
2d96212
aad95cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,6 +115,7 @@ | |
| "json", | ||
| "login-url", | ||
| "loglevel", | ||
| "lwc-language", | ||
| "manifest", | ||
| "name", | ||
| "namespace", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
|
|
||
| import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand, Ux } from '@salesforce/sf-plugins-core'; | ||
| import { CreateOutput, LightningComponentOptions, TemplateType } from '@salesforce/templates'; | ||
| import { Messages } from '@salesforce/core'; | ||
| import { Messages, SfProject } from '@salesforce/core'; | ||
| import { getCustomTemplates, runGenerator } from '../../../../utils/templateCommand.js'; | ||
| import { internalFlag, outputDirFlagLightning } from '../../../../utils/flags.js'; | ||
| const BUNDLE_TYPE = 'Component'; | ||
|
|
@@ -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'] as const, | ||
| options: ['default', 'analyticsDashboard', 'analyticsDashboardWithStep', 'typeScript'] as const, | ||
| })(), | ||
| 'output-dir': outputDirFlagLightning, | ||
| 'api-version': orgApiVersionFlagWithDeprecations, | ||
|
|
@@ -54,9 +54,35 @@ 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 { | ||
| // Try to resolve project from output directory if provided, otherwise use cwd | ||
| 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'; | ||
| } else if (defaultLwcLanguage === 'javascript') { | ||
| template = 'default'; // Explicit JavaScript template | ||
| } | ||
| // If defaultLwcLanguage is undefined or other value, template remains 'default' | ||
| } catch (error) { | ||
| // Not in a project context or project config not available, use default | ||
| this.debug('Could not resolve project config for intelligent defaulting:', error); | ||
| } | ||
| } | ||
|
|
||
| const flagsAsOptions: LightningComponentOptions = { | ||
| componentname: flags.name, | ||
| template: flags.template, | ||
| template, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we removing flag, |
||
| outputdir: flags['output-dir'], | ||
| apiversion: flags['api-version'], | ||
| internal: flags.internal, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,11 @@ export default class Project extends SfCommand<CreateOutput> { | |
| aliases: ['loginurl'], | ||
| deprecateAliases: true, | ||
| }), | ||
| 'lwc-language': Flags.option({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is duplicate from other PR, one need to be remove: |
||
| summary: messages.getMessage('flags.lwc-language.summary'), | ||
| description: messages.getMessage('flags.lwc-language.description'), | ||
| options: ['javascript', 'typescript'] as const, | ||
| })(), | ||
| loglevel, | ||
| 'api-version': Flags.orgApiVersion({ | ||
| summary: messages.getMessage('flags.api-version.summary'), | ||
|
|
@@ -81,6 +86,7 @@ export default class Project extends SfCommand<CreateOutput> { | |
| ns: flags.namespace, | ||
| defaultpackagedir: flags['default-package-dir'], | ||
| apiversion: flags['api-version'], | ||
| lwcLanguage: flags['lwc-language'], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate. |
||
| }; | ||
| return runGenerator({ | ||
| templateType: TemplateType.Project, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate.