UNPKG

@salesforce/plugin-sobject

Version:
102 lines 4.62 kB
/* * Copyright 2025, Salesforce, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { dirname } from 'node:path'; import select from '@inquirer/select'; import confirm from '@inquirer/confirm'; import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; import { Messages } from '@salesforce/core/messages'; import { nameFieldPrompts } from '../../../shared/prompts/nameField.js'; import { apiNamePrompt } from '../../../shared/prompts/apiName.js'; import { pluralPrompt } from '../../../shared/prompts/plural.js'; import { directoryPrompt } from '../../../shared/prompts/directory.js'; import { descriptionPrompt } from '../../../shared/prompts/description.js'; import { writeObjectFile } from '../../../shared/fs.js'; import { labelValidation } from '../../../shared/flags.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-sobject', 'generate.object'); const defaultFeatures = { enableHistory: true, enableActivities: true, enableSearch: true, enableFeeds: true, enableReports: true, enableBulkApi: true, enableSharing: true, enableStreamingApi: true, }; export default class ObjectGenerate extends SfCommand { static summary = messages.getMessage('summary'); static description = messages.getMessage('description'); static examples = messages.getMessages('examples'); static requiresProject = true; static enableJsonFlag = false; static aliases = ['generate:metadata:sobject']; static deprecateAliases = true; static flags = { label: Flags.string({ char: 'l', summary: messages.getMessage('flags.label.summary'), required: true, parse: async (label) => labelValidation(label), }), 'use-default-features': Flags.boolean({ char: 'f', summary: messages.getMessage('flags.use-default-features.summary'), description: messages.getMessage('flags.use-default-features.description'), }), }; async run() { const { flags } = await this.parse(ObjectGenerate); const directory = await directoryPrompt(this.project.getPackageDirectories()); const resultsObject = { pluralLabel: await pluralPrompt(flags.label), fullName: await apiNamePrompt(flags.label, 'CustomObject'), description: await descriptionPrompt(), nameField: await nameFieldPrompts(flags.label), ...(flags['use-default-features'] ? defaultFeatures : await promptForDefaultFeatures()), sharingModel: await select({ message: messages.getMessage('prompts.sharingModel'), choices: [{ value: 'ReadWrite' }, { value: 'Read' }, { value: 'Private' }], }), label: flags.label, deploymentStatus: 'Deployed', }; this.styledJSON(resultsObject); const writePath = await writeObjectFile(directory, resultsObject); this.logSuccess(messages.getMessage('success', [writePath])); this.info(messages.getMessage('success.field', [dirname(writePath)])); this.log(); this.info(messages.getMessage('success.advice')); return { object: resultsObject, path: writePath }; } } const promptForDefaultFeatures = async () => { const enterprise = await confirm({ message: 'Enable Enterprise Features (Sharing, Bulk API, and Streaming API)', default: true, }); return { enableBulkApi: enterprise, enableSharing: enterprise, enableStreamingApi: enterprise, enableHistory: await confirm({ message: 'Enable History', default: true }), enableActivities: await confirm({ message: 'Enable Activities', default: true }), enableSearch: await confirm({ message: 'Enable Search', default: true }), enableFeeds: await confirm({ message: 'Enable Feeds', default: true }), enableReports: await confirm({ message: 'Enable Reports', default: true }), }; }; //# sourceMappingURL=sobject.js.map