UNPKG

@pega/custom-dx-components

Version:

Utility for building custom UI components

59 lines (50 loc) 2.08 kB
import inquirer from 'inquirer'; import { showVersion, getLibraryBased, addDebugLog, checkLibraryAndArchives } from '../../util.js'; import { deleteLocalComponents, SOURCE_OF_COMPONENT_TYPES, deleteServerComponents, getDeleteComponentsQuestions } from './helper.js'; const deleteComponentsFn = async (sourceOfComponents, answers, options) => { addDebugLog('deleteComponentsFn', `sourceOfComponents: ${sourceOfComponents}`, ''); switch (sourceOfComponents) { case SOURCE_OF_COMPONENT_TYPES.LOCAL: { await deleteLocalComponents(sourceOfComponents, options); break; } case SOURCE_OF_COMPONENT_TYPES.SERVER: { await deleteServerComponents(sourceOfComponents, answers); break; } default: { console.log('Source of components needs to be either Local or Server'); break; } } }; export default async options => { await showVersion(); await checkLibraryAndArchives(); const isLibraryBased = getLibraryBased(); addDebugLog('deleteAll', '', '+'); let sourceOfComponentsOption = SOURCE_OF_COMPONENT_TYPES.LOCAL; if (isLibraryBased) { sourceOfComponentsOption = SOURCE_OF_COMPONENT_TYPES.LOCAL; await deleteComponentsFn(sourceOfComponentsOption, null, options); } else if (options.params[3] === SOURCE_OF_COMPONENT_TYPES.LOCAL) { sourceOfComponentsOption = options.params[3]; await deleteComponentsFn(sourceOfComponentsOption, null, options); } else if (options.params[3] === SOURCE_OF_COMPONENT_TYPES.SERVER) { sourceOfComponentsOption = options.params[3]; const questions = await getDeleteComponentsQuestions(options, sourceOfComponentsOption); const answers = await inquirer.prompt(questions); await deleteComponentsFn(sourceOfComponentsOption, answers, options); } else { const questions = await getDeleteComponentsQuestions(options); const answers = await inquirer.prompt(questions); const { sourceOfComponents } = answers; await deleteComponentsFn(sourceOfComponents, answers, options); } addDebugLog('deleteAll', 'END', '-'); };