@pega/custom-dx-components
Version:
Utility for building custom UI components
163 lines (120 loc) • 4.44 kB
JavaScript
import fs from 'fs';
import path from 'path';
import inquirer from 'inquirer';
import chalk from 'chalk';
import {
showVersion,
getLibraryBased,
addDebugLog,
getComponents,
getConfigDefaults,
setConfigDevBuild,
updateConfigVersion,
checkLibraryAndArchives,
getUseInputConfig,
getInputConfigForCommand,
forceDefaultsUpdate } from '../../util.js';
import { showCurrentStatus } from '../show-status/index.js';
export const updateAllComponentsConfig = async( newVersion ) => {
addDebugLog("updateAllComponentsConfig", `newVersion: ${newVersion}`, "");
const componentList = await getComponents();
const orgLib = getConfigDefaults();
// const currentOrgLib = `${orgLib.organization}_${orgLib.library}`;
const currentOrgLib = orgLib.currentOrgLib;
for (const index in componentList) {
const componentKey = componentList[index];
await updateConfigVersion(componentKey, newVersion, currentOrgLib);
}
};
export const setPermVersion = async (isPerm) => {
addDebugLog("setPermVersion", `isPerm: ${isPerm}`, "");
const configDefaults = await getConfigDefaults();
const devBuild = !isPerm;
let version = configDefaults.version;
if (devBuild) {
version = version.concat("-dev");
}
await updateAllComponentsConfig(version);
await setConfigDevBuild(devBuild);
}
export const setPermanent = async ( inputYN = "" ) => {
addDebugLog("setPermanent", "", "");
const configDefaults = await getConfigDefaults();
if (inputYN != "") {
const makePerm = (inputYN === 'Y' || inputYN === 'y' || inputYN === true || inputYN === 'true');
await setPermVersion(makePerm);
await forceDefaultsUpdate();
await showCurrentStatus();
process.exit();
}
const isOrNot = configDefaults.devBuild ? "NOT PERMANENT" : "PERMANENT";
console.log(`Currently ${chalk.green(`${configDefaults.displayLibVersion}`)} is ${chalk.yellow(`${isOrNot}`)}.`);
if (configDefaults.devBuild) {
console.log(`You can switch ${chalk.green(`${configDefaults.displayLibVersion}`)} to be ${chalk.yellow('PERMANENT')}.`);
console.log(`\nNotes after change:`);
console.log(`\tUpon publish you will ${chalk.yellow('NOT')} be able to delete the published version from the server.`);
console.log(`\tYou CAN delete the local copies, etc. and you can revert local copies to NON permanent.\n`)
const makePermAnswer = await inquirer.prompt([
{
name: 'makePerm',
type: 'confirm',
message: `Make ${chalk.green(`${configDefaults.displayLibVersion}`)} ${chalk.yellow('PERMANENT')} ?`,
default: false
}
]);
if (makePermAnswer.makePerm) {
await setPermVersion(makePermAnswer.makePerm);
await forceDefaultsUpdate();
await showCurrentStatus();
}
else {
console.log(chalk.green("No changes made."));
}
}
else {
console.log(`\nYou can switch ${chalk.green(`${configDefaults.displayLibVersion}`)} to be ${chalk.yellow('NON PERMANENT')}.`);
console.log(`\nNotes after change:`);
console.log(`\tIf ${chalk.green(`${configDefaults.displayLibVersion}`)} has been published, it can not deleted.`);
console.log(`\tIf not published, then a future publish can be deleted.\n`);
const makeNonPermAnswer = await inquirer.prompt([
{
name: 'makeNonPerm',
type: 'confirm',
message: `Make this library/version ${chalk.yellow('NON PERMANENT')} ?`,
default: true
}
]);
if (makeNonPermAnswer.makeNonPerm) {
await setPermVersion(!makeNonPermAnswer.makeNonPerm);
await forceDefaultsUpdate();
await showCurrentStatus();
}
else {
console.log(chalk.green("No changes made."));
}
}
}
export default async options => {
const isLibraryBased = getLibraryBased();
const useInputConfig = getUseInputConfig();
if (!isLibraryBased) {
console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`);
process.exit();
}
addDebugLog("setPerm", "", "+");
await showVersion();
await checkLibraryAndArchives();
let inputYN = "";
if (useInputConfig) {
const inputConfig = await getInputConfigForCommand("setPermanent");
inputYN = inputConfig.makePermanent;
}
else {
if (options.params.length >= 4) {
inputYN = options.params[3];
}
}
// await showCurrentStatus();
await setPermanent(inputYN);
addDebugLog("setPerm", "END", "-");
}