generated from salesforcecli/plugin-template-sf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nameField.ts
39 lines (33 loc) · 1.41 KB
/
nameField.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Copyright (c) 2020, 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 { Messages } from '@salesforce/core/messages';
import input from '@inquirer/input';
import select from '@inquirer/select';
import { FieldType } from '@salesforce/types/metadata';
import { NameField } from '../types.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
export const messages = Messages.loadMessages('@salesforce/plugin-sobject', 'prompts.shared');
/** Ask about the name/type for the Name field, with a followup for AutoNumber format if AutoNumber is chosen */
export const nameFieldPrompts = async (objectLabel: string): Promise<NameField> => {
const label = await input({
message: messages.getMessage('nameFieldPrompts.label'),
default: `${objectLabel} Name`,
});
const type = await select<FieldType>({
message: messages.getMessage('nameFieldPrompts.type'),
default: 'Text',
choices: [{ value: 'Text' }, { value: 'AutoNumber' }],
});
const displayFormat =
type === 'AutoNumber'
? await input({
message: messages.getMessage('nameFieldPrompts.autoNumberFormat'),
default: `${objectLabel}-{0}`,
})
: undefined;
return { label, type, ...(type === 'AutoNumber' ? { displayFormat } : {}) };
};