@pega/custom-dx-components
Version:
Utility for building custom UI components
99 lines (76 loc) • 2.48 kB
JavaScript
import { Listr } from 'listr2';
import chalk from 'chalk';
import inquirer from 'inquirer';
import {
showVersion,
addDebugLog,
checkLibraryAndArchives,
getConfigDefaults,
getLibraryBased,
zipVersionAndArchive,
cleanUpTemp,
getUseInputConfig,
getInputConfigForCommand,
convertYNToBoolean
} from '../../util.js';
export default async options => {
await showVersion();
await checkLibraryAndArchives();
const useInputConfig = getUseInputConfig();
addDebugLog("storeComponents", "", "+");
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 answers = {};
if (useInputConfig) {
const inputConfig = await getInputConfigForCommand("storeLibVersion");
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 okToStore = convertYNToBoolean(inputConfig.okToStore);
answers.confirmStore = okToStore;
}
else {
console.log(chalk.bold.yellow('\nBe sure to SAVE all changes before storing, or changes will NOT be stored.'));
if (options.params.length === 4) {
const optConfirm = options.params[3];
answers["confirmStore"] = optConfirm === 'Y' || optConfirm === 'y' || optConfirm === true || optConfirm === 'true' ? true : false;
}
else {
answers = await inquirer.prompt([
{
name: 'confirmStore',
type: 'confirm',
message: `Storing ${chalk.green(`${confDef.currentOrgLib}/${confDef.buildVersion}`)} to local storage, proceed ?`,
default: true
}
]);
}
}
if (answers.confirmStore) {
console.log("");
const tasks = new Listr(
[
{
title: `Store ${confDef.displayLibVersion}`,
task: async () => {
await zipVersionAndArchive(confDef.currentOrgLib, confDef.buildVersion);
}
}
],
{ concurrent: false, exitOnError: true }
);
await tasks.run().catch(err => {
console.log(chalk.bold.red(err.toString()));
addDebugLog("storeComponents", "", "-");
process.exit(1);
});
console.log(chalk.greenBright('\nComponents Stored'));
}
addDebugLog("storeComponents", "", "-");
};