UNPKG

@pega/custom-dx-components

Version:

Utility for building custom UI components

103 lines (81 loc) 2.8 kB
import { Listr } from 'listr2'; import chalk from 'chalk'; import inquirer from 'inquirer'; import { showVersion, addDebugLog, checkLibraryAndArchives, getConfigDefaults, getLibraryBased, restoreFromArchive, cleanUpTemp, forceDefaultsUpdate, getUseInputConfig, getInputConfigForCommand, convertYNToBoolean } from '../../util.js'; import { showCurrentStatus } from '../show-status/index.js'; export default async options => { await showVersion(); await checkLibraryAndArchives(); const useInputConfig = getUseInputConfig(); addDebugLog("restoreComponent", "", "+"); await cleanUpTemp(); const isLibraryBased = getLibraryBased(); if (!isLibraryBased) { console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`) process.exit(); } const confDef = getConfigDefaults(); let restoreFromStore = {}; if (useInputConfig) { const inputConfig = await getInputConfigForCommand("restoreLibVersion"); if (!inputConfig || Object.keys(inputConfig).length === 0) { console.log(chalk.redBright("Configured for input config, but no input.config.json file found.")); process.exit(1); } const okToRestore = convertYNToBoolean(inputConfig.okToRestore); restoreFromStore.confirmRestore = okToRestore; } else { console.log(chalk.bold.yellow('\nChanges not saved to local storage will be LOST, code will be restored from local storage.')); console.log(""); if (options.params.length === 4) { const optConfirm = options.params[3]; restoreFromStore["confirmRestore"] = optConfirm === 'Y' || optConfirm === 'y' || optConfirm === true || optConfirm === 'true' ? true : false; } else { restoreFromStore = await inquirer.prompt([ { name: 'confirmRestore', type: 'confirm', message: `Restoring ${chalk.bold.green(`${confDef.displayLibVersion}`)} from local storage, proceed ?`, default: true } ]); } } if (restoreFromStore.confirmRestore) { const switchToFileName = `${confDef.currentOrgLib}_${confDef.version}.arch.zip`; const tasks = new Listr( [ { title: `Restoring ${confDef.displayLibVersion}`, task: async () => { await restoreFromArchive(switchToFileName, confDef.currentOrgLib, confDef.version); } } ], { concurrent: false, exitOnError: true } ); await tasks.run().catch(err => { console.log(chalk.bold.red(err.toString())); addDebugLog("restoreComponent", "", "-"); process.exit(1); }); console.log(chalk.greenBright('\nComponents restored')); await forceDefaultsUpdate(); await showCurrentStatus(); } addDebugLog("restoreComponent", "", "-"); };