UNPKG

@pega/custom-dx-components

Version:

Utility for building custom UI components

107 lines (74 loc) 2.87 kB
import inquirer from 'inquirer'; import chalk from 'chalk'; import { showVersion, getC11NB2STokenAndStaticServer, getLocalLibraryVersions, getLibraryBased, deleteLocalLibrary, deleteLocalLibraryVersion, addDebugLog, getConfigDefaults } from '../../util.js'; import { deleteLib } from '@pega/constellation-dx-components-build-utils/index.js'; import { getDeleteLibraryQuestions, getLibraryVersionQuestion, SOURCE_OF_COMPONENT_TYPES } from './helper.js'; export default async (options) => { const isLibraryBased = getLibraryBased(); if (!isLibraryBased) { console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`) process.exit(); } await showVersion(); addDebugLog("deletePublished", "", "+"); let sourceOfLibrary; let organization; let library; let version; const compDef = getConfigDefaults(); organization = compDef.organization; library = compDef.library; const libraryName = compDef.currentOrgLib; if (options.params.length >= 5) { sourceOfLibrary = options.params[3]; version = options.params[4]; } else { const questions = await getDeleteLibraryQuestions(); const answers = await inquirer.prompt(questions); ({ sourceOfLibrary } = answers); if (sourceOfLibrary === SOURCE_OF_COMPONENT_TYPES.LOCAL ) { // local let libVersions = []; try { libVersions = await getLocalLibraryVersions(libraryName); } catch (ex) {} if (libVersions.length > 0) { // ALL option libVersions.unshift('ALL'); const versionQuestions = await getLibraryVersionQuestion(libraryName, libVersions); const versionAnswers = await inquirer.prompt(versionQuestions); ({version} = versionAnswers); } else { // No library with that name console.log(chalk.redBright(`No local library named: ${libraryName} exists.`)); addDebugLog("deletePublished", "END", "-"); process.exit(1); } } } if (sourceOfLibrary === SOURCE_OF_COMPONENT_TYPES.LOCAL ) { if (version === 'ALL') { await deleteLocalLibrary(libraryName); } else { await deleteLocalLibraryVersion(libraryName, version); } } else { // server const tokenAndStaticServer = await getC11NB2STokenAndStaticServer(); if (tokenAndStaticServer.C11NB2S === undefined) { console.log(chalk.redBright("Need to authenticate, missing services token.\nDeleting a library requires authentication to acquire a token to delete.")); addDebugLog("deletePublished", "END", "-"); process.exit(1); } addDebugLog("deleteLib", "services call", ""); await deleteLib(tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer); addDebugLog("deleteLib", "services end", ""); } addDebugLog("deletePublished", "END", "-"); return true; };