@pega/custom-dx-components 24.2.12 → 24.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,12 @@ import {
18
18
  getHaveDependencyDifference,
19
19
  forceDefaultsUpdate,
20
20
  modAddAboutData,
21
- cleanUpTemp
21
+ cleanUpTemp,
22
+ getUseInputConfig,
23
+ getInputConfigForCommand,
24
+ convertYNToBoolean,
25
+ hasArchives,
26
+ hasLibraryAndVersion
22
27
  } from '../../util.js';
23
28
 
24
29
  import { getSwitchVersionComponentQuestions } from './helper.js';
@@ -27,6 +32,8 @@ import { showCurrentStatus } from '../show-status/index.js';
27
32
 
28
33
  export default async options => {
29
34
  const isLibraryBased = getLibraryBased();
35
+ const useInputConfig = getUseInputConfig();
36
+
30
37
  if (!isLibraryBased) {
31
38
  console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`);
32
39
  process.exit();
@@ -46,31 +53,79 @@ addDebugLog("switchVersion", "", "+");
46
53
  const serverConfig = await getPegaServerConfig();
47
54
  const currentDirectory = process.cwd();
48
55
  const componentDirectory = join (currentDirectory, "src", "components");
56
+ const orgLib = getConfigDefaults();
57
+
58
+ // if we have choosen to use INPUT CONFIG FILE
59
+ // process and no inputs
60
+ if (useInputConfig) {
61
+ const inputConfig = await getInputConfigForCommand("switchLibVersion");
62
+
63
+ okToContinue = convertYNToBoolean(inputConfig.okToContinue);
64
+ if (okToContinue) {
65
+ version = inputConfig.libraryVersion;
66
+ const isPermanent = inputConfig.isPermanent;
67
+ const permBuild = convertYNToBoolean(isPermanent);
68
+
69
+
49
70
 
71
+ const hasArch = await hasArchives();
72
+ const orgLib = getConfigDefaults();
73
+ const hasLib = await hasLibraryAndVersion(orgLib.library, version, !permBuild);
50
74
 
51
- if (options.params.length >= 5) {
52
- const okToCont = options.params[3];
53
- version = options.params[4];
75
+ // version here includes -dev if appropriate
76
+ if (!permBuild) {
77
+ version = version.concat("-dev");
78
+ }
54
79
 
55
- // if have [5] will be "NoAbout" from Jest, to turn off build date
56
- if (options.params.length >= 6 ) {
57
- if (options.params[5] === "NoAbout") {
58
- modAddAboutData(false);
80
+ if (hasArch) {
81
+ if (orgLib.buildVersion == version ) {
82
+ console.log(`${chalk.bold.red(`Your current library/version is already ${orgLib.displayLibVersion}.`)}`);
83
+ process.exit();
84
+ }
85
+ if (!hasLib) {
86
+ console.log(`${chalk.bold.red(`${orgLib.library}/${version} does not exist.`)}`);
87
+ process.exit();
88
+ }
59
89
  }
90
+ else {
91
+ console.log(`${chalk.bold.red(`No libraries exist.`)}`);
92
+ console.log("You need to create a library first via 'npm run createLib'.\n")
93
+ process.exit();
94
+ }
95
+
60
96
  }
97
+ else {
98
+ process.exit();
99
+ }
100
+
101
+ }
102
+ else {
103
+ if (options.params.length >= 5) {
104
+ const okToCont = options.params[3];
105
+ version = options.params[4];
106
+
107
+ // if have [5] will be "NoAbout" from Jest, to turn off build date
108
+ if (options.params.length >= 6 ) {
109
+ if (options.params[5] === "NoAbout") {
110
+ modAddAboutData(false);
111
+ }
112
+ }
61
113
 
62
- okToContinue = !!(okToCont === 'Y' || okToCont === 'y' || okToCont === true || okToCont === 'true');
114
+ okToContinue = !!(okToCont === 'Y' || okToCont === 'y' || okToCont === true || okToCont === 'true');
63
115
 
64
- } else {
65
- const questions = await getSwitchVersionComponentQuestions();
66
- const answers = await inquirer.prompt(questions);
67
- ({ okToContinue, version } = answers);
116
+ } else {
117
+ const questions = await getSwitchVersionComponentQuestions();
118
+ const answers = await inquirer.prompt(questions);
119
+ ({ okToContinue, version } = answers);
120
+ }
68
121
  }
69
122
 
123
+
124
+
70
125
  if (okToContinue) {
71
126
  // in this scenario, version contains "-dev", if appropriate
72
127
 
73
- const orgLib = getConfigDefaults();
128
+
74
129
  const newVersion = version;
75
130
  const existingOrgLib = orgLib.currentOrgLib;
76
131
  const oldVersion = orgLib.buildVersion;
@@ -315,11 +315,13 @@ const validateOverideSchema = ajv.compile(overrideSchema);
315
315
 
316
316
 
317
317
  export default async (option) => {
318
- // addDebugLog("validate","", "");
318
+ // addDebugLog("validate","", "");
319
319
 
320
320
  let componentToValidate = null;
321
+ let throwTheError = false;
321
322
  if (option.params && option.params[3]) {
322
323
  componentToValidate = option.params[3];
324
+ throwTheError = true;
323
325
  } else if (option && option.task === 'validateSchema') {
324
326
  const localComponents = await getComponents();
325
327
  const answer = await inquirer.prompt({
@@ -332,8 +334,10 @@ export default async (option) => {
332
334
  componentToValidate = answer.component;
333
335
  } else if (option.name) {
334
336
  componentToValidate = option.value;
337
+ throwTheError = true;
335
338
  } else {
336
339
  componentToValidate = option;
340
+ throwTheError = true;
337
341
  }
338
342
 
339
343
  const componentDirectory = await getComponentDirectoryPath(componentToValidate);
@@ -369,13 +373,14 @@ export default async (option) => {
369
373
  componentToValidate &&
370
374
  !/^[A-Za-z0-9]+_[A-Za-z0-9]+_[A-Za-z0-9]+$/.test(componentToValidate)
371
375
  ) {
372
- const ootbComponents = await getOOTBComponents();
373
- if (ootbComponents.includes(componentToValidate)) {
374
- throw new Error(`Invalid: Error occurred in validating ${componentToValidate}`);
375
- }
376
- }
377
376
 
377
+ if (throwTheError) {
378
+ throw new Error (`${chalk.redBright(`Error: Invalid name of component '${componentToValidate}' .\n Component name (and component folder) MUST be of the form: 'Org_Lib_ComponentName'.`)}`);
378
379
 
380
+ }
381
+ console.log(`${chalk.redBright(`Error: Invalid name of component '${componentToValidate}' .\n Component name (and component folder) MUST be of the form: 'Org_Lib_ComponentName'.`)}`);
382
+ process.exit(1);
383
+ }
379
384
 
380
385
  console.log(`${chalk.bold.green(componentToValidate)} schema is valid`);
381
386
  } else {
package/src/util.js CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  COMPONENTS_DIRECTORY_PATH,
21
21
  COMPONENTS_CONFIG_FILE_NAME,
22
22
  TASKS_CONFIG_JSON_FILENAME,
23
+ INPUT_CONFIG_JSON_FILENAME,
23
24
  PACKAGE_JSON_FILENAME,
24
25
  TOKEN_PATH,
25
26
  OOTB_COMPONENT_SERVICE_REST_ENDPOINT,
@@ -29,6 +30,7 @@ import {
29
30
  USE_PROMOTED_WEB_PACK,
30
31
  BOOTSTRAP_CONFIG,
31
32
  LIBRARY_BASED,
33
+ USE_INPUT_CONFIG,
32
34
  SHARED_DIRECTORY,
33
35
  SHOW_DEBUG,
34
36
  COMPONENTS_PATH,
@@ -62,7 +64,8 @@ let defaultConfigs = {
62
64
  displayLibVersion: "",
63
65
  showDebug: false,
64
66
  importRelativePath: "",
65
- exportRelativePath: ""
67
+ exportRelativePath: "",
68
+ useInputConfig: false
66
69
  };
67
70
 
68
71
  let pegaConfig = null;
@@ -117,7 +120,8 @@ export const setUpDefaults = async () => {
117
120
  displayLibVersion: "",
118
121
  showDebug: false,
119
122
  importRelativePath: "",
120
- exportRelativePath: ""
123
+ exportRelativePath: "",
124
+ useInputConfig: false
121
125
  };
122
126
 
123
127
  // retrievedConfigData
@@ -143,6 +147,11 @@ export const setUpDefaults = async () => {
143
147
  if (data[LIBRARY_BASED]) {
144
148
  retrievedConfigData.isLibraryBased = data[LIBRARY_BASED];
145
149
  }
150
+
151
+ if (data[USE_INPUT_CONFIG]) {
152
+ retrievedConfigData.useInputConfig = data[USE_INPUT_CONFIG];
153
+ }
154
+
146
155
  retrievedConfigData.library = data.component.library;
147
156
  retrievedConfigData.version = data.component.version;
148
157
 
@@ -172,6 +181,65 @@ export const setUpDefaults = async () => {
172
181
  return JSON.parse(JSON.stringify(retrievedConfigData));
173
182
  }
174
183
 
184
+
185
+ export const convertYNToBoolean = (inputYN) => {
186
+ switch (inputYN) {
187
+ case 'Y':
188
+ case 'y':
189
+ case 'Yes':
190
+ case 'YES':
191
+ case 't':
192
+ case 'true':
193
+ case 'True':
194
+ case 'TRUE':
195
+ return true;
196
+ }
197
+
198
+ return false;
199
+ }
200
+
201
+ export const getInputConfigForCommand = async (commandName) => {
202
+ // retrievedConfigData
203
+ const currentDirectory = process.cwd();
204
+ const inputConfigJsonPath = join(currentDirectory, INPUT_CONFIG_JSON_FILENAME);
205
+ const isLibraryBased = getLibraryBased();
206
+
207
+ try {
208
+ // force to throw error and not console log
209
+ await checkPathAccess(inputConfigJsonPath, {}, true);
210
+
211
+ let data = fs.readFileSync(inputConfigJsonPath, { encoding: 'utf8' });
212
+ data = JSON.parse(data);
213
+
214
+ if (isLibraryBased) {
215
+ const libraryCommands = data["libraryMode"];
216
+
217
+ if (libraryCommands[commandName]) {
218
+ return libraryCommands[commandName];
219
+
220
+ }
221
+ }
222
+ else {
223
+ const standardCommands = data["standard"];
224
+
225
+ if (standardCommands[commandName]) {
226
+ return standardCommands[commandName];
227
+
228
+ }
229
+
230
+ }
231
+ }
232
+ catch (ex) {
233
+ // when can't find it, always be false, assume no library based.
234
+ // This is IMPORTANT for init (npx install)
235
+ return {};
236
+ }
237
+
238
+ return {};
239
+
240
+ }
241
+
242
+
175
243
  // initialize
176
244
  // await setUpDefaults();
177
245
 
@@ -332,6 +400,15 @@ if (showDebug) addDebugLog("getLibraryBased", "", "");
332
400
  return defaultConfigs.isLibraryBased;
333
401
  }
334
402
 
403
+ export const getUseInputConfig = () => {
404
+ if (showDebug) addDebugLog("getUseInputConfig", "", "");
405
+
406
+
407
+ return defaultConfigs.useInputConfig;
408
+ }
409
+
410
+
411
+
335
412
  export const setLibraryBased = async (isLibraryBased) => {
336
413
  if (showDebug) addDebugLog("setLibraryBased", "", "");
337
414
  const currentDirectory = process.cwd();
@@ -563,6 +640,7 @@ if (showDebug) addDebugLog("removeTopLevelConfigFiles", `directory: ${directory}
563
640
  if (configF !== "package-lock.json" &&
564
641
  configF !== "package.json" &&
565
642
  configF !== "tasks.config.json" &&
643
+ configF !== "input.config.json" &&
566
644
  configF !== ".gitignore" &&
567
645
  configF !== ".npmrc" &&
568
646
  configF !== ".prettierignore") {
@@ -758,6 +836,25 @@ export const getPegaServerConfig = async () => {
758
836
  if (showDebug) addDebugLog("getPegaServerConfig", "", "+");
759
837
  if (!pegaConfig) {
760
838
  pegaConfig = await getPegaConfig();
839
+
840
+ if (getServerType() === "launchpad") {
841
+
842
+ // need to append isolation id for now
843
+ let OAuthData;
844
+ try {
845
+ OAuthData = fs.readFileSync(TOKEN_PATH, 'utf8');
846
+ }
847
+ catch (ex) {
848
+ return ({});
849
+ }
850
+
851
+ if (OAuthData) {
852
+ const oOAuthData = JSON.parse(OAuthData);
853
+ const isolationId = oOAuthData["isolation-ids"].write;
854
+ pegaConfig['server-config'].isolationId = isolationId[0];
855
+ }
856
+
857
+ }
761
858
  sPegaServerConfig = JSON.stringify(pegaConfig['server-config']);
762
859
  }
763
860