UNPKG

@pega/custom-dx-components

Version:

Utility for building custom UI components

97 lines (79 loc) 2.96 kB
import inquirer from 'inquirer'; import ora from 'ora'; import chalk from 'chalk'; import { showVersion, getPegaServerConfig, getLibraryBased, addDebugLog, checkLibraryAndArchives } from '../../util.js'; import { listLocalComponents, SOURCE_OF_COMPONENT_TYPES, getComponentsFromServer, getLaunchPadFilterQuestions, displayServerComponents, getListComponentsQuestions } from './helper.js'; const getList = async (sourceOfComponents, answers) => { addDebugLog("getList", `sourceOfComponents: ${sourceOfComponents}`, ""); const defaultPegaServerConfig = await getPegaServerConfig(); const isLaunchpad = defaultPegaServerConfig.serverType === 'launchpad'; switch (sourceOfComponents) { case SOURCE_OF_COMPONENT_TYPES.LOCAL: { await listLocalComponents(sourceOfComponents); break; } case SOURCE_OF_COMPONENT_TYPES.SERVER: { let library; let organization; if (isLaunchpad) { const questions = await getLaunchPadFilterQuestions(); const lpAnswers = await inquirer.prompt(questions); ({library, organization} = lpAnswers); } const spinner = ora('Fetching components from server\n').start(); try { const data = await getComponentsFromServer(library, organization); spinner.stop(); await displayServerComponents(data, answers); } catch (error) { if (error.indexOf("ECONNREFUSED") >= 0) { console.log(`\n${chalk.bold.red('Error occurred in authentication. Please regenerate using authenticate')}`); } else { console.log(`${chalk.bold.red(error)}`); } // spinner.stop(); process.exit(1); } 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("list", "", "+"); let sourceOfComponentsOption = SOURCE_OF_COMPONENT_TYPES.LOCAL; if (isLibraryBased) { sourceOfComponentsOption = SOURCE_OF_COMPONENT_TYPES.LOCAL; await getList(sourceOfComponentsOption); } else if (options.params[3] === SOURCE_OF_COMPONENT_TYPES.LOCAL) { sourceOfComponentsOption = options.params[3]; await getList(sourceOfComponentsOption); } else if (options.params[3] === SOURCE_OF_COMPONENT_TYPES.SERVER) { sourceOfComponentsOption = options.params[3]; const questions = await getListComponentsQuestions(options, sourceOfComponentsOption); const answers = await inquirer.prompt(questions); await getList(sourceOfComponentsOption, answers); } else { const questions = await getListComponentsQuestions(options); const answers = await inquirer.prompt(questions); const { sourceOfComponents } = answers; await getList(sourceOfComponents, answers); } addDebugLog("list", "END", "-"); };