UNPKG

@salesforce/plugin-templates

Version:

Commands to create metadata from a default or custom template

88 lines 4.24 kB
/* * Copyright (c) 2019, 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 */ // tslint:disable:no-unused-expression import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand, Ux } from '@salesforce/sf-plugins-core'; import { TemplateType } from '@salesforce/templates'; import { Messages, SfProject } from '@salesforce/core'; import { getCustomTemplates, runGenerator } from '../../../../utils/templateCommand.js'; import { internalFlag, outputDirFlagLightning } from '../../../../utils/flags.js'; const BUNDLE_TYPE = 'Component'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-templates', 'lightningCmp'); const lightningCommon = Messages.loadMessages('@salesforce/plugin-templates', 'lightning'); export default class LightningComponent extends SfCommand { static summary = messages.getMessage('summary'); static description = messages.getMessage('description'); static examples = messages.getMessages('examples'); static aliases = ['force:lightning:component:create', 'lightning:generate:component']; static deprecateAliases = true; static flags = { name: Flags.string({ char: 'n', summary: lightningCommon.getMessage('flags.name.summary', [BUNDLE_TYPE]), description: lightningCommon.getMessage('flags.name.description'), required: true, aliases: ['componentname'], deprecateAliases: true, }), template: Flags.option({ char: 't', summary: lightningCommon.getMessage('flags.template.summary'), description: lightningCommon.getMessage('flags.template.description'), default: 'default', // Note: keep this list here and LightningComponentOptions#template in-sync with the // templates/lightningcomponents/[aura|lwc]/* folders options: ['default', 'analyticsDashboard', 'analyticsDashboardWithStep', 'typescript'], })(), 'output-dir': outputDirFlagLightning, 'api-version': orgApiVersionFlagWithDeprecations, type: Flags.option({ summary: messages.getMessage('flags.type.summary'), options: ['aura', 'lwc'], default: 'aura', })(), internal: internalFlag, loglevel, }; async run() { 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; if (defaultLwcLanguage === 'typescript') { template = 'typescript'; } } catch (error) { this.debug('Could not resolve project config for intelligent defaulting:', error); } } const flagsAsOptions = { componentname: flags.name, // Temp re-mapping to allow lowercase typescript flag template: template === 'typescript' ? 'typeScript' : template, outputdir: flags['output-dir'], apiversion: flags['api-version'], internal: flags.internal, type: flags.type, }; return runGenerator({ templateType: TemplateType.LightningComponent, opts: flagsAsOptions, ux: new Ux({ jsonEnabled: this.jsonEnabled() }), templates: getCustomTemplates(this.configAggregator), }); } } //# sourceMappingURL=component.js.map