@pega/custom-dx-components
Version:
Utility for building custom UI components
149 lines (113 loc) • 4.33 kB
JavaScript
import inquirer from 'inquirer';
import chalk from 'chalk';
import {showVersion, getLibraryBased, addDebugLog, checkLibraryAndArchives, getLibraryArchivesVersions, getConfigDefaults, getLocalArchivedLibrraryVersionData, getComponentsConfigs, cleanUpTemp } from '../../util.js';
import { getArchiveLibraryQuestions } 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();
await checkLibraryAndArchives();
addDebugLog("listLibrary", "", "+");
await cleanUpTemp();
let organization;
let library;
const compDef = getConfigDefaults();
organization = compDef.organization;
library = compDef.library;
let libraryName;
const currnetVersion = compDef.buildVersion;
let selectedVersion;
let libVersions = [];
let currentOrStore = "";
if (options.params.length >= 5) {
libraryName = options.params[3];
selectedVersion = options.params[4];
if (options.params.length >= 6) {
currentOrStore = options.params[5];
}
try {
libVersions = await getLibraryArchivesVersions(libraryName, "");
}
catch (ex) {}
}
else {
const questions = await getArchiveLibraryQuestions();
const answers = await inquirer.prompt(questions);
({ libraryName } = answers);
try {
libVersions = await getLibraryArchivesVersions(libraryName, "");
}
catch (ex) {}
if (libVersions.length > 0) {
if (selectedVersion === undefined) {
const libAnswers = await inquirer.prompt([
{
name: 'libVersion',
type: 'rawlist',
message: 'Enter version',
choices: libVersions
},
]);
selectedVersion = libAnswers.libVersion;
}
}
}
let data;
// get built on from first component if exists
let builtOn = "(date unavailable)";
if (libVersions.length > 0) {
if (libraryName === compDef.currentOrgLib && selectedVersion === compDef.buildVersion) {
console.log("\nYou've selected the current working library/version.");
console.log("You can list current components or the last store of this library/version.");
if (currentOrStore === "") {
const archAnswers = await inquirer.prompt([
{
name: 'currentOrStore',
type: 'rawlist',
message: 'Select current or store',
default: "Current",
choices: ["Current", "Store"]
},
]);
currentOrStore = archAnswers.currentOrStore;
}
if (currentOrStore === "Current") {
data = await getComponentsConfigs();
builtOn = "(no date - current)";
}
else {
data = await getLocalArchivedLibrraryVersionData(libraryName, selectedVersion);
data = JSON.parse(data);
if (data[0] && data[0].buildDate) {
builtOn = data[0].buildDate;
}
}
}
else {
data = await getLocalArchivedLibrraryVersionData(libraryName, selectedVersion);
data = JSON.parse(data);
if (data[0] && data[0].buildDate) {
builtOn = data[0].buildDate;
}
}
if (data.length === 0) {
console.log(chalk.bold.redBright(`No custom components in ${libraryName}/${selectedVersion}`));
process.exit();
}
let libData = data.map((component) => ( {'Component': component.name, 'Label': component.label, 'Version': component.version, 'Type': component.type, 'Sub Type' : component.subtype}));
console.log(chalk.bold.blueBright(`\nList of ${libraryName}:${selectedVersion} components built on ${builtOn}.`));
console.table(libData, ['Component', 'Label', 'Version', 'Type', 'Sub Type']);
}
else {
// No library with that name
console.log(chalk.redBright(`No other library versions for ${libraryName} exist other than current library version.`));
console.log(chalk.redBright(`To see contents for the currnet library version, enter 'npm run list'.`));
addDebugLog("listLibrary", "END", "-");
process.exit();
}
addDebugLog("listLibrary", "END", "-");
return true;
};