UNPKG

@pega/custom-dx-components

Version:

Utility for building custom UI components

113 lines (97 loc) 2.87 kB
import chalk from 'chalk'; import { sanitize, validateSemver, getLibraryArchiveDirectories, addDebugLog, getConfigDefaults, getComponents, updateConfigVersion } from '../../util.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 getCurrentOrOriginalQuestion = async () => { addDebugLog("getCurrentOrOriginal", "", ""); return [ { name: 'currentOrOriginal', type: 'rawlist', message: 'Current config changes or original defaults ?', default: 'Original', choices: ['Current', 'Original'] } ]; } export const getOkToProceedQuestion = async () => { addDebugLog("getCreateLibComponentQuestions", "", ""); return [ { name: 'okToContinue', type: 'confirm', message: 'Ok to continue ?', default: true } ]; } export const getCreateLibComponentQuestions = async (libraryName = "") => { addDebugLog("getCreateLibComponentQuestions", "", ""); const archDirectories = await getLibraryArchiveDirectories(); const orgLib = getConfigDefaults(); return [ { name: 'libraryName', message: 'Enter libray name', default: libraryName, validate: value => { /* value should not be empty It should not have spaces It should not start with a number Only case-insensitive alphanumeric values are allowed */ if (value && !/^\d/.test(value) && value === sanitize(value)) { if (archDirectories && archDirectories.length > 0) { const newOrgLib = `${orgLib.organization}_${value}`; if (archDirectories.includes(newOrgLib)) { return `Library ${value} already exists.`; } else { return true; } } else { return true; } } else { return 'Only alphanumeric values are allowed, starting with alphabets, no spaces.'; } } }, { name: 'version', message: 'Enter version ', default: '0.0.1', validate: value => { if (validateSemver(value)) { return true; } return 'Please provide semver compatible version e.g 0.0.1'; } }, { name: 'permBuild', type: 'confirm', message: `Version to be ${chalk.bold.yellow('PERMANENT')} upon publish `, default: false } ]; };