@pega/custom-dx-components
Version:
Utility for building custom UI components
93 lines (72 loc) • 2.37 kB
JavaScript
import chalk from 'chalk';
import { promisify } from 'util';
import { exec as LocalExec } from "child_process";
import {
getComponents,
updateConfigVersion,
getLibraryArchivesVersions,
addDebugLog,
getConfigDefaults
} from '../../util.js';
const exec = promisify(LocalExec);
export const updateAllComponentsConfig = async( newVersion ) => {
addDebugLog("updateAllComponentsConfig", `newVersion: ${newVersion}`, "");
const componentList = await getComponents();
const orgLib = getConfigDefaults();
const currentOrgLib = `${orgLib.organization}_${orgLib.library}`;
for (const index in componentList) {
const componentKey = componentList[index];
await updateConfigVersion(componentKey, newVersion, currentOrgLib);
}
};
export const getSwitchVersionComponentQuestions = async () => {
addDebugLog("getSwitchVersionComponentQuestions", "", "");
const orgLib = getConfigDefaults();
const currentOrgLib = orgLib.currentOrgLib;
const currentVersion = orgLib.buildVersion;
const archVersionList = await getLibraryArchivesVersions(currentOrgLib, currentVersion);
if (archVersionList && archVersionList.length == 0) {
console.log(chalk.bold.redBright(`\nCurrently no other versions exist in library: ${currentOrgLib}`));
process.exit();
}
console.log(chalk.bold.yellow('\nBe sure to SAVE all changes before switching versions, unsaved changes will be LOST.'))
return [
{
name: 'okToContinue',
type: 'confirm',
message: 'Ok to continue ?',
default: true
},
{
name: 'version',
type: 'rawlist',
message: `Select a version (current version is ${chalk.bold.green(`${currentVersion}`)}) `,
choices: archVersionList,
when(answers) {
return answers.okToContinue;
}
}
];
};
export const getRunNpmQuestions = async () => {
addDebugLog("getSwitchVersionComponentQuestions", "", "");
console.log(chalk.bold.yellow('\nDependencies have changed between versions, recommend updating.'));
return [
{
name: 'updateNpm',
type: 'confirm',
message: 'Run npm update?',
default: true
}
];
};
export const runNpmUpdate = async () => {
const script = `npm update`;
const { stdout, stderr } = await exec(script);
if (stdout) {
console.log(stdout);
}
if (stderr) {
console.log(stderr);
}
}