@pega/custom-dx-components
Version:
Utility for building custom UI components
147 lines (115 loc) • 3.73 kB
JavaScript
import chalk from 'chalk';
import path from 'path';
import { join } from 'path';
import { addDebugLog, getConfigDefaults, getLibraryArchiveDirectories, getLibraryArchivesVersions, setConfigExportRelativePath, forceDefaultsUpdate } from '../../util.js';
export const SOURCE_OF_COMPONENT_TYPES = {
SERVER: 'Server',
LOCAL: 'Local'
};
export const getFilePathQuestions = async () => {
addDebugLog("getFilePathQuestions", "", "");
console.log("\nFile path examples:");
if (path.sep === "/") {
console.log("\tMac OS/Unix:\t/Users/name/...");
}
else {
console.log("\tWindows:\tC:\\Users\\name\\...\n");
}
const configDef = getConfigDefaults();
const currentDirectory = process.cwd();
const arPathParts = currentDirectory.split(path.sep);
let defaultPath = join(arPathParts[0], arPathParts[1], arPathParts[2], configDef.exportRelativePath);
if (path.sep === "/") {
defaultPath = "/".concat(defaultPath);
}
return [
{
name: 'filePath',
message: 'Enter full file path of directory to export zip file:',
default: defaultPath
}
];
};
export const getFileNameQuestions = async (zipFileList) => {
addDebugLog("getFileNameQuestions", "", "");
return [
{
name: 'fileName',
type: 'rawlist',
message: `Select zip file`,
choices: zipFileList
},
];
};
export const getLibraryQuestion = async () => {
addDebugLog("getLibraryQuestion", "", "");
const componentDefaults = getConfigDefaults();
const orgLib = getConfigDefaults();
const currentOrgLib = `${orgLib.organization}_${orgLib.library}`;
const archVersionList = await getLibraryArchiveDirectories("");
return [
{
name: 'orgLibName',
type: 'rawlist',
message: `Select a library (current library is ${chalk.bold.green(`${currentOrgLib}`)}) `,
choices: archVersionList
}
];
};
export const getLibraryVersionQuestion = async (newOrgLib) => {
addDebugLog("getLibraryVersionQuestion", "", "");
const archVersionList = await getLibraryArchivesVersions(newOrgLib, "0.0.0");
return [
{
name: 'selectedVersion',
type: 'rawlist',
message: `Select a version `,
choices: archVersionList
}
];
};
export const getFullArchiveQuestions = async () => {
return [
{
name: 'fullArchive',
type: 'rawlist',
message: 'Type of export',
choices: [{name: 'Full Archive (code)', value: 'Full'}, {name: 'CL Binary (runtime only)', value: 'Binary'}],
default: 'Full'
}
];
}
export const updateSavedExportFilePath = async(filePath) => {
const currentDirectory = process.cwd();
const arPathParts = currentDirectory.split(path.sep);
const configDef = getConfigDefaults();
let defaultPath = join(path.sep, arPathParts[0], arPathParts[1], arPathParts[2]);
if (path.sep != "/") {
// windows
if (defaultPath.indexOf(path.sep) === 0) {
// if start with \\, then remove
defaultPath = defaultPath.substring(1);
}
if (filePath.indexOf(defaultPath) === 0) {
let relativePath = "";
if (filePath !== defaultPath) {
// same starting path, so we can save the relative
relativePath = filePath.replace(defaultPath.concat("/"), "");
}
await setConfigExportRelativePath(relativePath);
await forceDefaultsUpdate();
}
}
else {
// mac
if (filePath.indexOf(defaultPath) === 0) {
let relativePath = "";
if (filePath !== defaultPath) {
// same starting path, so we can save the relative
relativePath = filePath.replace(defaultPath.concat("/"), "");
}
await setConfigExportRelativePath(relativePath);
await forceDefaultsUpdate();
}
}
}