From 814ff1d694155a8c252bb73a5cbcd4b2186e6125 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Fri, 3 Nov 2023 10:25:38 -0600 Subject: [PATCH] chore: switch to using prompter via sf-plugins-core --- package.json | 1 - src/shared/prompts/prompts.ts | 21 ++++---- src/shared/prompts/relationshipField.ts | 9 ++-- yarn.lock | 65 +------------------------ 4 files changed, 18 insertions(+), 78 deletions(-) diff --git a/package.json b/package.json index 37f12aa8..4e968498 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "change-case": "^4.1.2", "fast-glob": "^3.3.1", "fast-xml-parser": "^4.3.2", - "inquirer": "^9.2.11", "js2xmlparser": "^4.0.2" }, "devDependencies": { diff --git a/src/shared/prompts/prompts.ts b/src/shared/prompts/prompts.ts index a2f92ee6..5076d1e5 100644 --- a/src/shared/prompts/prompts.ts +++ b/src/shared/prompts/prompts.ts @@ -4,12 +4,12 @@ * 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 {dirname} from 'node:path'; -import {fileURLToPath} from 'node:url'; +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; import { NamedPackageDir } from '@salesforce/core'; import { ValueSet, CustomValue } from 'jsforce/api/metadata'; import { Messages } from '@salesforce/core'; -import {ListQuestion, prompt, Question} from 'inquirer'; +import { Prompter } from '@salesforce/sf-plugins-core'; import { getDirectoriesThatContainObjects, getObjectDirectories } from '../fs.js'; Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url))); @@ -28,21 +28,21 @@ const getSuffix = (objectType: ObjectType): string => { return '__e'; } }; -export const directoryPrompt = async (packageDirs: NamedPackageDir[]): Promise => ({ +export const directoryPrompt = async (packageDirs: NamedPackageDir[]): Promise => ({ type: 'list', message: messages.getMessage('directory'), name: 'directory', choices: await getDirectoriesThatContainObjects(packageDirs.map((pd) => pd.path)), }); -export const pluralPrompt = (label: string): Question => ({ +export const pluralPrompt = (label: string): Prompter.Answers => ({ type: 'input', message: messages.getMessage('pluralLabel'), name: 'pluralLabel', default: `${label}s`, }); -export const apiNamePrompt = (label: string, objectType: ObjectType): Question => ({ +export const apiNamePrompt = (label: string, objectType: ObjectType): Prompter.Answers => ({ type: 'input', message: messages.getMessage('apiName'), name: 'fullName', @@ -57,7 +57,7 @@ export const descriptionPrompt = { }; /** Ask about the name/type for the Name field, with a followup for AutoNumber format if AutoNumber is chosen */ -export const namePrompts = (label: string): Array => [ +export const namePrompts = (label: string): Prompter.Answers[] => [ { type: 'input', message: messages.getMessage('nameFieldPrompts.label'), @@ -73,7 +73,7 @@ export const namePrompts = (label: string): Array => [ }, { type: 'input', - when: (answers) => answers.nameFieldType === 'AutoNumber', + when: (answers: { nameFieldType: string }) => answers.nameFieldType === 'AutoNumber', message: messages.getMessage('nameFieldPrompts.autoNumberFormat'), name: 'autoNumberFormat', default: `${label}-{0}`, @@ -88,7 +88,7 @@ export const objectPrompt = async ( packageDirs: NamedPackageDir[], name: 'object' | 'referenceTo' = 'object', message = messages.getMessage('object') -): Promise => ({ +): Promise => ({ type: 'list', message, name, @@ -110,11 +110,12 @@ export const integerValidation = (value: number, min: number, max: number): true export const picklistPrompts = async (): Promise> => { const output: CustomValue[] = []; let keepAsking = true; + const prompter = new Prompter(); while (keepAsking) { // the very definition of needing a loop for an await // eslint-disable-next-line no-await-in-loop - const response = await prompt<{ picklistValue: string }>({ + const response = await prompter.prompt<{ picklistValue: string }>({ type: 'input', name: 'picklistValue', validate: (input: string) => (output.find((v) => v.fullName === input) ? `${input} already exists` : true), diff --git a/src/shared/prompts/relationshipField.ts b/src/shared/prompts/relationshipField.ts index 97688aab..c4f1f729 100644 --- a/src/shared/prompts/relationshipField.ts +++ b/src/shared/prompts/relationshipField.ts @@ -4,12 +4,12 @@ * 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 path, {dirname} from 'node:path'; -import {fileURLToPath} from 'node:url'; +import path, { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; import { NamedPackageDir } from '@salesforce/core'; -import { prompt } from 'inquirer'; import { CustomField } from 'jsforce/api/metadata'; import { Messages } from '@salesforce/core'; +import { Prompter } from '@salesforce/sf-plugins-core'; import { getObjectXmlByFolderAsJson } from '../fs.js'; import { objectPrompt, makeNameApiCompatible } from './prompts.js'; @@ -36,8 +36,9 @@ export const relationshipFieldPrompts = async ({ packageDirs: NamedPackageDir[]; childObjectFolderPath: string; }): Promise => { + const prompter = new Prompter(); const childObjectXml = await getObjectXmlByFolderAsJson(childObjectFolderPath); - const response = await prompt([ + const response = await prompter.prompt([ // prompt the user to select from objects in local source await objectPrompt(packageDirs, 'referenceTo', messages.getMessage('objectPrompt')), { diff --git a/yarn.lock b/yarn.lock index d446552c..bde5024c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -515,13 +515,6 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@ljharb/through@^2.3.9": - version "2.3.11" - resolved "https://registry.yarnpkg.com/@ljharb/through/-/through-2.3.11.tgz#783600ff12c06f21a76cc26e33abd0b1595092f9" - integrity sha512-ccfcIDlogiXNq5KcbAwbaO7lMh3Tm1i3khMPYpxlK8hH/W53zN81KM9coerRLOnTGu3nfXIniAmQbRI9OxbC0w== - dependencies: - call-bind "^1.0.2" - "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -2377,11 +2370,6 @@ cli-width@^3.0.0: resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6" integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw== -cli-width@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-4.1.0.tgz#42daac41d3c254ef38ad8ac037672130173691c5" - integrity sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ== - cliui@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1" @@ -3013,11 +3001,6 @@ escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg== -escape-string-regexp@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#4683126b500b61762f2dbebace1806e8be31b1c8" - integrity sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw== - eslint-config-prettier@^8.10.0: version "8.10.0" resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.10.0.tgz#3a06a662130807e2502fc3ff8b4143d8a0658e11" @@ -3308,7 +3291,7 @@ exponential-backoff@^3.1.1: resolved "https://registry.yarnpkg.com/exponential-backoff/-/exponential-backoff-3.1.1.tgz#64ac7526fe341ab18a39016cd22c787d01e00bf6" integrity sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw== -external-editor@^3.0.3, external-editor@^3.1.0: +external-editor@^3.0.3: version "3.1.0" resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495" integrity sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew== @@ -3425,14 +3408,6 @@ figures@^3.0.0: dependencies: escape-string-regexp "^1.0.5" -figures@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/figures/-/figures-5.0.0.tgz#126cd055052dea699f8a54e8c9450e6ecfc44d5f" - integrity sha512-ej8ksPF4x6e5wvK9yevct0UCXh8TTFlWGVLlgjZuoBH1HwjIfKE/IdL5mq89sFA7zELi1VhKpmtDnrs7zWyeyg== - dependencies: - escape-string-regexp "^5.0.0" - is-unicode-supported "^1.2.0" - file-entry-cache@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027" @@ -4191,27 +4166,6 @@ inquirer@^8.0.0, inquirer@^8.2.5: through "^2.3.6" wrap-ansi "^6.0.1" -inquirer@^9.2.11: - version "9.2.11" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-9.2.11.tgz#e9003755c233a414fceda1891c23bd622cad4a95" - integrity sha512-B2LafrnnhbRzCWfAdOXisUzL89Kg8cVJlYmhqoi3flSiV/TveO+nsXwgKr9h9PIo+J1hz7nBSk6gegRIMBBf7g== - dependencies: - "@ljharb/through" "^2.3.9" - ansi-escapes "^4.3.2" - chalk "^5.3.0" - cli-cursor "^3.1.0" - cli-width "^4.1.0" - external-editor "^3.1.0" - figures "^5.0.0" - lodash "^4.17.21" - mute-stream "1.0.0" - ora "^5.4.1" - run-async "^3.0.0" - rxjs "^7.8.1" - string-width "^4.2.3" - strip-ansi "^6.0.1" - wrap-ansi "^6.2.0" - internal-slot@^1.0.5: version "1.0.6" resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.6.tgz#37e756098c4911c5e912b8edbf71ed3aa116f930" @@ -4452,11 +4406,6 @@ is-unicode-supported@^0.1.0: resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7" integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== -is-unicode-supported@^1.2.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz#d824984b616c292a2e198207d4a609983842f714" - integrity sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ== - is-utf8@^0.2.0, is-utf8@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72" @@ -5494,11 +5443,6 @@ mute-stream@0.0.8: resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== -mute-stream@1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-1.0.0.tgz#e31bd9fe62f0aed23520aa4324ea6671531e013e" - integrity sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA== - nanoid@3.3.3: version "3.3.3" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25" @@ -6781,11 +6725,6 @@ run-async@^2.0.0, run-async@^2.4.0: resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455" integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ== -run-async@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/run-async/-/run-async-3.0.0.tgz#42a432f6d76c689522058984384df28be379daad" - integrity sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q== - run-parallel@^1.1.9: version "1.2.0" resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee" @@ -6800,7 +6739,7 @@ rxjs@^6.6.0: dependencies: tslib "^1.9.0" -rxjs@^7.2.0, rxjs@^7.5.5, rxjs@^7.8.1: +rxjs@^7.2.0, rxjs@^7.5.5: version "7.8.1" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543" integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==