@pega/custom-dx-components 0.242.66 → 0.242.68

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.
Files changed (62) hide show
  1. package/package.json +1 -1
  2. package/src/constants.js +3 -0
  3. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.tsx.mustache +2 -2
  4. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.tsx.mustache +2 -2
  5. package/src/tasks/create/templates/Constellation/Field/Icon-Button-URL/demo.stories.tsx.mustache +2 -2
  6. package/src/tasks/create/templates/Constellation/Template/DETAILS/demo.stories.tsx.mustache +3 -3
  7. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/demo.stories.tsx.mustache +3 -3
  8. package/src/tasks/create/templates/Constellation/Template/PAGE/demo.stories.tsx.mustache +2 -2
  9. package/src/tasks/create/templates/Constellation/Widget/CASE/demo.stories.tsx.mustache +4 -4
  10. package/src/tasks/create/templates/Constellation/Widget/PAGE/demo.stories.tsx.mustache +2 -2
  11. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/demo.stories.tsx.mustache +3 -3
  12. package/src/tasks/create/templates/Launchpad/Field/Icon-Button-URL/demo.stories.tsx.mustache +2 -2
  13. package/src/tasks/create/templates/Launchpad/Widget/CASE/demo.stories.tsx.mustache +4 -4
  14. package/src/tasks/create/templates/Launchpad/Widget/PAGE/demo.stories.tsx.mustache +2 -2
  15. package/src/tasks/create/templates/Launchpad/Widget/PAGE-CASE/demo.stories.tsx.mustache +3 -3
  16. package/src/tasks/create-lib/index.js +85 -1
  17. package/src/tasks/create-version/index.js +60 -16
  18. package/src/tasks/delete-lib/index.js +43 -14
  19. package/src/tasks/delete-version/index.js +30 -9
  20. package/src/tasks/export-archive/helper.js +14 -0
  21. package/src/tasks/export-archive/index.js +151 -28
  22. package/src/tasks/import-archive/index.js +27 -14
  23. package/src/tasks/import-comp/index.js +144 -82
  24. package/src/tasks/init/template/package.json.mustache +5 -4
  25. package/src/tasks/publish/index.js +34 -18
  26. package/src/tasks/publish-lib/index.js +19 -2
  27. package/src/tasks/set-perm/index.js +14 -2
  28. package/src/tasks/switch-lib/index.js +83 -34
  29. package/src/tasks/switch-version/index.js +69 -14
  30. package/src/util.js +144 -16
  31. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyCaseWidget/demo.stories.tsx +4 -4
  32. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDate/demo.stories.tsx +2 -2
  33. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDateTime/demo.stories.tsx +2 -2
  34. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDetails/demo.stories.tsx +3 -3
  35. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/demo.stories.tsx +2 -2
  36. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPage/demo.stories.tsx +2 -2
  37. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageCaseWidget/demo.stories.tsx +3 -3
  38. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageWidget/demo.stories.tsx +2 -2
  39. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/demo.stories.tsx +3 -3
  40. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyCaseWidget/demo.stories.tsx +4 -4
  41. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyDate/demo.stories.tsx +2 -2
  42. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyDateTime/demo.stories.tsx +2 -2
  43. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyDetails/demo.stories.tsx +3 -3
  44. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/demo.stories.tsx +2 -2
  45. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyPage/demo.stories.tsx +2 -2
  46. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyPageCaseWidget/demo.stories.tsx +3 -3
  47. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyPageWidget/demo.stories.tsx +2 -2
  48. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/demo.stories.tsx +3 -3
  49. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyCaseWidget/demo.stories.tsx +4 -4
  50. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyDate/demo.stories.tsx +2 -2
  51. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyDateTime/demo.stories.tsx +2 -2
  52. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyDetails/demo.stories.tsx +3 -3
  53. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyIconButtonURL/demo.stories.tsx +2 -2
  54. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyPage/demo.stories.tsx +2 -2
  55. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyPageCaseWidget/demo.stories.tsx +3 -3
  56. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyPageWidget/demo.stories.tsx +2 -2
  57. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnDetails/demo.stories.tsx +3 -3
  58. package/tests/functional/localLibCreateLibBuildLibDeleteLib.test.js +1 -1
  59. package/tests/functional/localLibCreateLibBuildLibListPubDeleteLib.test.js +1 -1
  60. package/tests/functional/localLibCreateLibExportImportLib.test.js +1 -1
  61. package/tests/functional/localLibCreateLibExportLib.test.js +1 -1
  62. package/tests/functional/localLibCreateLibValidateDeleteLib.test.js +1 -1
@@ -7,7 +7,10 @@ import {
7
7
  checkLibraryAndArchives,
8
8
  getConfigDefaults,
9
9
  addDebugLog,
10
- cleanUpTemp
10
+ cleanUpTemp,
11
+ getUseInputConfig,
12
+ getInputConfigForCommand,
13
+ convertYNToBoolean
11
14
  } from '../../util.js';
12
15
 
13
16
  import { deleteLibraryVersion } from '../delete-lib/index.js';
@@ -15,6 +18,8 @@ import { deleteLibraryVersion } from '../delete-lib/index.js';
15
18
 
16
19
  export default async (options) => {
17
20
  const isLibraryBased = getLibraryBased();
21
+ const useInputConfig = getUseInputConfig();
22
+
18
23
  if (!isLibraryBased) {
19
24
  console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`)
20
25
  process.exit();
@@ -33,19 +38,35 @@ addDebugLog("deleteVersion", "", "+");
33
38
  const configDef = getConfigDefaults();
34
39
  let libraryName = configDef.currentOrgLib;
35
40
 
36
- if (options.params.length >= 5) {
37
- libraryName = options.params[3]
38
- version = options.params[4];
41
+ if (useInputConfig) {
42
+ const inputConfig = await getInputConfigForCommand("deleteLibVersion");
43
+ version = inputConfig.libraryVersion;
44
+ const isPermanent = inputConfig.isPermanent;
45
+ const permBuild = convertYNToBoolean(isPermanent);
39
46
 
40
- if (options.params.length >=6 ) {
41
- const okToDel = options.params[5];
42
- okToDelete = !!(okToDel === 'Y' || okToDel === 'y' || okToDel === true || okToDel === 'true');
47
+ if (!permBuild && version != "ALL") {
48
+ version = version.concat("-dev");
43
49
  }
50
+
51
+ okToDelete = convertYNToBoolean(inputConfig.confirmDelete);
44
52
  }
45
- else if (options.params.length >= 4) {
46
- libraryName = options.params[3];
53
+ else {
54
+ if (options.params.length >= 5) {
55
+ libraryName = options.params[3]
56
+ version = options.params[4];
57
+
58
+ if (options.params.length >=6 ) {
59
+ const okToDel = options.params[5];
60
+ okToDelete = !!(okToDel === 'Y' || okToDel === 'y' || okToDel === true || okToDel === 'true');
61
+ }
62
+ }
63
+ else if (options.params.length >= 4) {
64
+ libraryName = options.params[3];
65
+ }
47
66
  }
48
67
 
68
+
69
+
49
70
  await deleteLibraryVersion(libraryName, version, okToDelete);
50
71
 
51
72
 
@@ -86,6 +86,20 @@ addDebugLog("getLibraryVersionQuestion", "", "");
86
86
  ];
87
87
  };
88
88
 
89
+ export const getFullArchiveQuestions = async () => {
90
+
91
+ return [
92
+ {
93
+ name: 'fullArchive',
94
+ type: 'rawlist',
95
+ message: 'Type of export',
96
+ choices: [{name: 'Full Archive (code)', value: 'Full'}, {name: 'CL Binary (runtime only)', value: 'Binary'}],
97
+ default: 'Full'
98
+ }
99
+
100
+ ];
101
+ }
102
+
89
103
  export const updateSavedExportFilePath = async(filePath) => {
90
104
  const currentDirectory = process.cwd();
91
105
  const arPathParts = currentDirectory.split(path.sep);
@@ -15,11 +15,12 @@ import {
15
15
  getConfigDefaults,
16
16
  getLibraryBased,
17
17
  zipVersionAndArchive,
18
+ zipVersionAndArchiveCL,
18
19
  cleanUpTemp
19
20
  } from '../../util.js';
20
- import { TASKS_CONFIG_JSON_FILENAME, ARCHIVES_PATH } from '../../constants.js';
21
- import { getFilePathQuestions, getLibraryQuestion, getLibraryVersionQuestion, updateSavedExportFilePath } from './helper.js';
22
- import { or } from 'ajv/dist/compile/codegen/index.js';
21
+ import { TASKS_CONFIG_JSON_FILENAME, ARCHIVES_PATH, BIN_ARCHIVES_PATH } from '../../constants.js';
22
+ import { getFilePathQuestions, getLibraryQuestion, getLibraryVersionQuestion, updateSavedExportFilePath, getFullArchiveQuestions } from './helper.js';
23
+ import { localBuildLibrary } from '../build-lib/index.js';
23
24
 
24
25
  export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
25
26
  const currentDirectory = process.cwd();
@@ -75,9 +76,95 @@ addDebugLog("updateFile", `fileName: ${fileName}, oldComponentKeyPC: ${oldCompon
75
76
  };
76
77
 
77
78
 
79
+ export const exportCLArch = async(exportPath, orgLibName, selectedVersion) => {
80
+ addDebugLog("exportCLArch", `exportPath: ${exportPath}, orgLibName: ${orgLibName}, selectedVersion: ${selectedVersion}`, "");
81
+ const currentDirectory = process.cwd();
82
+ const archiveDirectory = join (currentDirectory, BIN_ARCHIVES_PATH);
83
+ const fileName = `${orgLibName}_${selectedVersion}.zip`;
84
+ const archFileName = join(archiveDirectory, fileName);
85
+ const configDef = await getConfigDefaults();
86
+
87
+ const exportFile = join(exportPath, fileName);
88
+ let output;
89
+
90
+ // need to build the libary
91
+ console.log(chalk.green(`\nBuilding binaries...\n`));
92
+ const arOrgLib = orgLibName.split("_")
93
+ const arVersion = selectedVersion.split("-");
94
+ const devBuild = arVersion.length > 1 ? true : false;
95
+
96
+ await localBuildLibrary(arOrgLib[0], arOrgLib[1], arVersion[0], devBuild);
97
+
98
+ const libraryDir = join(currentDirectory, orgLibName, selectedVersion );
99
+ if (fs.existsSync(libraryDir)) {
100
+ console.log(chalk.green(`\nExporting binaries...\n`));
101
+
102
+ if (!fs.existsSync(exportPath)) {
103
+ console.log(`\Path: ${chalk.yellow(`${exportPath}`)} doesn't exist.`);
104
+ const newPathAnswer = await inquirer.prompt([
105
+ {
106
+ name: 'createNewPath',
107
+ type: 'confirm',
108
+ message: 'Create path',
109
+ default: true
110
+ },
111
+ ]);
112
+ const createNewPath = newPathAnswer.createNewPath;
113
+ if (createNewPath) {
114
+ fs.mkdirSync(exportPath, { recursive: true });
115
+
116
+ await updateSavedExportFilePath(exportPath);
117
+ }
118
+ else {
119
+ console.log(chalk.green("Store not exported."));
120
+ process.exit();
121
+ }
122
+ }
123
+
124
+ if (fs.existsSync(exportFile)) {
125
+ console.log(`\nFile: ${chalk.yellow(`${fileName}`)} already exists in ${chalk.yellow(`${exportPath}`)}.`);
126
+ const overwriteQuestion = await inquirer.prompt([
127
+ {
128
+ name: 'overWriteFile',
129
+ type: 'confirm',
130
+ message: 'Overrwrite',
131
+ default: true
132
+ },
133
+ ]);
134
+
135
+ if (!overwriteQuestion.overWriteFile) {
136
+ console.log(chalk.green("Store not exported."));
137
+ process.exit();
138
+ }
139
+ }
140
+
141
+
142
+
143
+ // archive it
144
+ output = await zipVersionAndArchiveCL(configDef.currentOrgLib, configDef.buildVersion);
145
+
146
+ // if archiving, need to wait before copying
147
+ output.on('close', function() {
148
+ fs.copyFileSync(archFileName, exportFile );
149
+
150
+ console.log(`\n${chalk.green(`${fileName}`)} has been exported to ${chalk.green(`${exportPath}`)}`);
151
+
152
+ });
153
+
154
+ }
155
+ else {
156
+ console.log.chalk.green(`\nBinary does not exist.`);
157
+ }
158
+
78
159
 
79
160
 
80
- export const exportArch = async(exportPath, orgLibName, selectedVersion, currentOrArchive = "") => {
161
+
162
+
163
+
164
+ }
165
+
166
+
167
+ export const exportArch = async(exportPath, orgLibName, selectedVersion, fullArchive = "Full", currentOrArchive = "" ) => {
81
168
  addDebugLog("exportArch", `exportPath: ${exportPath}, orgLibName: ${orgLibName}, selectedVersion: ${selectedVersion}`, "");
82
169
  const currentDirectory = process.cwd();
83
170
  const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${orgLibName}`, `${selectedVersion}`);
@@ -91,6 +178,11 @@ addDebugLog("exportArch", `exportPath: ${exportPath}, orgLibName: ${orgLibName},
91
178
 
92
179
  let archiveBeforeStore = false;
93
180
 
181
+ if (fullArchive != "Full") {
182
+ await exportCLArch(exportPath, orgLibName, selectedVersion);
183
+ return;
184
+ }
185
+
94
186
 
95
187
  if (orgLibName === configDef.currentOrgLib && selectedVersion === configDef.buildVersion) {
96
188
 
@@ -210,46 +302,77 @@ export default async options => {
210
302
  addDebugLog("exportArchive", "", "+");
211
303
 
212
304
 
213
- if (options.params.length >= 7) {
214
- const libraryName = options.params[3];
215
- const libraryVersion = options.params[4];
216
- const filePath = options.params[5];
217
- const currentOrArchive = options.params[6];
305
+ if (options.params.length >= 8) {
306
+ let fullArchive = options.params[3];
307
+ const libraryName = options.params[4];
308
+ const libraryVersion = options.params[5];
309
+ const filePath = options.params[6];
310
+
218
311
 
219
- await exportArch(filePath, libraryName, libraryVersion, currentOrArchive );
312
+ const currentOrArchive = options.params[7];
313
+
314
+ await exportArch(filePath, libraryName, libraryVersion, fullArchive, currentOrArchive );
220
315
 
221
316
  }
222
317
  else {
223
318
  let orgLibName = "";
224
319
  let selectedVersion = "";
320
+ let fullArchive = "";
225
321
 
226
- if (options.params.length >= 4) {
227
- orgLibName = options.params[3];
228
- if (options.params.length >= 5) {
229
- selectedVersion = options.params[4];
322
+ if (options.params.length >= 5) {
323
+ fullArchive = options.params[3];
324
+ orgLibName = options.params[4];
325
+ if (options.params.length >= 6) {
326
+ selectedVersion = options.params[5];
230
327
  }
231
328
  }
232
329
 
233
-
234
- if (orgLibName === "") {
235
- const libraryQuestion = await getLibraryQuestion();
236
- const libraryAnswers = await inquirer.prompt(libraryQuestion);
237
- ({ orgLibName } = libraryAnswers);
330
+ if (fullArchive === "" ) {
331
+ const fullArchiveQuestions = await getFullArchiveQuestions();
332
+ const fullArchiveAnswers = await inquirer.prompt(fullArchiveQuestions);
333
+ ({ fullArchive } = fullArchiveAnswers);
238
334
  }
239
335
 
240
- if (selectedVersion === "") {
241
- const libraryVersionQuestion = await getLibraryVersionQuestion(orgLibName);
242
- const libraryVersionAnswer = await inquirer.prompt(libraryVersionQuestion);
243
- ({ selectedVersion } = libraryVersionAnswer);
336
+ let filePathQuestions;
337
+ let filePathAnswers;
338
+ let filePath;
339
+
340
+ // if Binary, then we need to just build the current library, get the results and
341
+ // and export an archive as zip
342
+ if (fullArchive === "Binary") {
343
+ filePathQuestions = await getFilePathQuestions();
344
+ filePathAnswers = await inquirer.prompt(filePathQuestions);
345
+ ({ filePath } = filePathAnswers);
346
+
347
+ await updateSavedExportFilePath(filePath);
348
+
349
+ const configDef = getConfigDefaults();
350
+ orgLibName = configDef.currentOrgLib;
351
+ selectedVersion = configDef.buildVersion;
352
+
353
+
244
354
  }
355
+ else {
356
+ if (orgLibName === "") {
357
+ const libraryQuestion = await getLibraryQuestion();
358
+ const libraryAnswers = await inquirer.prompt(libraryQuestion);
359
+ ({ orgLibName } = libraryAnswers);
360
+ }
245
361
 
362
+ if (selectedVersion === "") {
363
+ const libraryVersionQuestion = await getLibraryVersionQuestion(orgLibName);
364
+ const libraryVersionAnswer = await inquirer.prompt(libraryVersionQuestion);
365
+ ({ selectedVersion } = libraryVersionAnswer);
366
+ }
246
367
 
247
- const filePathQuestions = await getFilePathQuestions();
248
- const filePathAnswers = await inquirer.prompt(filePathQuestions);
249
- let { filePath } = filePathAnswers;
250
368
 
251
- await updateSavedExportFilePath(filePath);
369
+ filePathQuestions = await getFilePathQuestions();
370
+ filePathAnswers = await inquirer.prompt(filePathQuestions);
371
+ ({ filePath } = filePathAnswers);
252
372
 
373
+ await updateSavedExportFilePath(filePath);
374
+
375
+ }
253
376
 
254
377
  // if (path.sep === "/") {
255
378
  // if (filePath.lastIndexOf(path.sep) != filePath.length - 1) {
@@ -257,7 +380,7 @@ export default async options => {
257
380
  // }
258
381
  // }
259
382
 
260
- await exportArch( filePath, orgLibName, selectedVersion);
383
+ await exportArch( filePath, orgLibName, selectedVersion, fullArchive);
261
384
 
262
385
  }
263
386
 
@@ -23,7 +23,9 @@ import {
23
23
  cleanUpTemp,
24
24
  hasArchives,
25
25
  restoreFromArchive,
26
- forceDefaultsUpdate
26
+ forceDefaultsUpdate,
27
+ getUseInputConfig,
28
+ getInputConfigForCommand
27
29
  } from '../../util.js';
28
30
  import { TASKS_CONFIG_JSON_FILENAME, ARCHIVES_PATH, TEMP_PATH } from '../../constants.js';
29
31
  import { getFilePathQuestions, getFileNameQuestions, updateTempArchive, updateSavedFilePath } from './helper.js';
@@ -395,6 +397,8 @@ export default async options => {
395
397
 
396
398
  await checkPathAccess(pegaConfigJsonPath);
397
399
  const isLibraryBased = getLibraryBased();
400
+ const useInputConfig = getUseInputConfig();
401
+
398
402
  if (!isLibraryBased) {
399
403
  console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`)
400
404
  process.exit();
@@ -415,22 +419,33 @@ export default async options => {
415
419
  }
416
420
  else {
417
421
 
418
- const filePathQuestions = await getFilePathQuestions();
419
- const filePathAnswers = await inquirer.prompt(filePathQuestions);
420
- const { filePath } = filePathAnswers;
421
- const zipFileList = await getZipFileList(filePath);
422
+ let filePath;
423
+ let fileName;
424
+
425
+ if (useInputConfig) {
426
+ const inputConfig = await getInputConfigForCommand("importLibVersion");
427
+ filePath = inputConfig.fileLocation;
428
+ fileName = inputConfig.fileName;
422
429
 
423
- if (!zipFileList || zipFileList.length === 0) {
424
- console.log(chalk.red.bold(`No zip files exist at path: ${filePath}`));
425
- process.exit();
426
430
  }
431
+ else {
432
+ const filePathQuestions = await getFilePathQuestions();
433
+ const filePathAnswers = await inquirer.prompt(filePathQuestions);
434
+ ({ filePath } = filePathAnswers);
435
+ const zipFileList = await getZipFileList(filePath);
436
+
437
+ if (!zipFileList || zipFileList.length === 0) {
438
+ console.log(chalk.red.bold(`No zip files exist at path: ${filePath}`));
439
+ process.exit();
440
+ }
427
441
 
428
- await updateSavedFilePath(filePath);
442
+ await updateSavedFilePath(filePath);
429
443
 
430
- const fileNameQuestions = await getFileNameQuestions(zipFileList);
431
- const fileNameAnswers = await inquirer.prompt(fileNameQuestions);
432
- const {fileName} = fileNameAnswers;
444
+ const fileNameQuestions = await getFileNameQuestions(zipFileList);
445
+ const fileNameAnswers = await inquirer.prompt(fileNameQuestions);
446
+ ({fileName} = fileNameAnswers);
433
447
 
448
+ }
434
449
 
435
450
  await importArch( filePath, fileName, hasArch);
436
451
 
@@ -438,8 +453,6 @@ export default async options => {
438
453
  // to keep what was entered as the latest
439
454
  await updateSavedFilePath(filePath);
440
455
 
441
-
442
-
443
456
  }
444
457
 
445
458
  addDebugLog("importArchive", "END", "-");
@@ -14,7 +14,10 @@ import {
14
14
  addDebugLog,
15
15
  checkLibraryAndArchives,
16
16
  getConfigDefaults,
17
- getComponents
17
+ getComponents,
18
+ getUseInputConfig,
19
+ getInputConfigForCommand,
20
+ convertYNToBoolean
18
21
  } from '../../util.js';
19
22
  import { TASKS_CONFIG_JSON_FILENAME } from '../../constants.js';
20
23
  import { getFilePathQuestions, getFileNameQuestions, updateSavedFilePath } from './helper.js';
@@ -156,6 +159,8 @@ addDebugLog("renameComponent", `library: ${library}, componentKey: ${componentKe
156
159
  export const importComp = async(filePath, fileName, askValidate) => {
157
160
  addDebugLog("importComp", `filePath: ${filePath}, fileName: ${fileName}`, "");
158
161
 
162
+ const useInputConfig = getUseInputConfig();
163
+
159
164
  const currentDirectory = process.cwd();
160
165
  // const compDirectory = join(currentDirectory, "src", "components");
161
166
 
@@ -166,6 +171,8 @@ addDebugLog("importComp", `filePath: ${filePath}, fileName: ${fileName}`, "");
166
171
  let configData;
167
172
  let newName = "";
168
173
  let newLabel = "";
174
+ let proceedAs;
175
+
169
176
 
170
177
  if (fs.existsSync(copyDir)) {
171
178
  configData = fs.readFileSync(join(copyDir, "/config.json"), { encoding: 'utf8' });
@@ -178,66 +185,96 @@ addDebugLog("importComp", `filePath: ${filePath}, fileName: ${fileName}`, "");
178
185
 
179
186
  if (currentCompList && currentCompList.includes(potentialCompKey)) {
180
187
  console.log(`\nComponent ${chalk.yellow(`${potentialCompKey}`)} already exists.`);
181
- const proceedAnswers = await inquirer.prompt([
182
188
 
183
- {
184
- name: 'proceedAs',
185
- type: 'rawlist',
186
- message: `Proceed as ?`,
187
- default: 'No import',
188
- choices: ['No import', 'Overwrite', 'New name']
189
- },
190
- {
191
- name: 'componentName',
192
- message: 'Enter component name (required)',
193
- when(answers) {
194
- return answers.proceedAs === 'New name';
189
+
190
+
191
+ if (useInputConfig) {
192
+ const inputConfig = await getInputConfigForCommand("importComponent");
193
+ proceedAs = inputConfig.proceedIfExists;
194
+
195
+ newName = inputConfig?.newComponentName;
196
+ newLabel = inputConfig?.newComponentLabel;
197
+
198
+
199
+ switch (proceedAs) {
200
+ case 'No import':
201
+ // removed copied
202
+ // fs.rmSync(copyDir, { recursive: true, force: true, maxRetries: 2 });
203
+ process.exit();
204
+ break;
205
+ case 'Overwrite':
206
+ // remove existing
207
+ const existingComp = await getComponentDirectoryPath(potentialCompKey);
208
+ fs.rmSync(existingComp, { recursive: true, force: true, maxRetries: 2 });
209
+ break;
210
+ }
211
+
212
+ }
213
+ else {
214
+ const proceedAnswers = await inquirer.prompt([
215
+
216
+ {
217
+ name: 'proceedAs',
218
+ type: 'rawlist',
219
+ message: `Proceed as ?`,
220
+ default: 'No import',
221
+ choices: ['No import', 'Overwrite', 'New name']
195
222
  },
196
- validate: value => {
197
- /* value should not be empty
198
- It should not have spaces
199
- It should not start with a number
200
- Only case-insensitive alphanumeric values are allowed
201
- */
202
- if (value && !/^\d/.test(value) && value === sanitize(value)) {
203
- return true;
223
+ {
224
+ name: 'componentName',
225
+ message: 'Enter component name (required)',
226
+ when(answers) {
227
+ return answers.proceedAs === 'New name';
228
+ },
229
+ validate: value => {
230
+ /* value should not be empty
231
+ It should not have spaces
232
+ It should not start with a number
233
+ Only case-insensitive alphanumeric values are allowed
234
+ */
235
+ if (value && !/^\d/.test(value) && value === sanitize(value)) {
236
+ return true;
237
+ }
238
+ return 'Only alphanumeric values are allowed, starting with alphabets, no spaces.';
204
239
  }
205
- return 'Only alphanumeric values are allowed, starting with alphabets, no spaces.';
206
- }
207
- },
208
- {
209
- name: 'componentLabel',
210
- message: 'Enter component label for display (required)',
211
- when(answers) {
212
- return answers.proceedAs === 'New name';
213
240
  },
214
- validate: value => {
215
- if (value) {
216
- return true;
241
+ {
242
+ name: 'componentLabel',
243
+ message: 'Enter component label for display (required)',
244
+ when(answers) {
245
+ return answers.proceedAs === 'New name';
246
+ },
247
+ validate: value => {
248
+ if (value) {
249
+ return true;
250
+ }
251
+ return 'Please provide value for label';
217
252
  }
218
- return 'Please provide value for label';
219
253
  }
254
+ ]);
255
+
256
+ proceedAs = proceedAnswers.proceedAs;
257
+
258
+ switch (proceedAs) {
259
+ case 'No import':
260
+ // removed copied
261
+ // fs.rmSync(copyDir, { recursive: true, force: true, maxRetries: 2 });
262
+ process.exit();
263
+ break;
264
+ case 'Overwrite':
265
+ // remove existing
266
+ const existingComp = await getComponentDirectoryPath(potentialCompKey);
267
+ fs.rmSync(existingComp, { recursive: true, force: true, maxRetries: 2 });
268
+ break;
269
+ case 'New name':
270
+ newName = proceedAnswers.componentName;
271
+ newLabel = proceedAnswers.componentLabel;
272
+ break;
220
273
  }
221
- ]);
222
-
223
-
224
- switch (proceedAnswers.proceedAs) {
225
- case 'No import':
226
- // removed copied
227
- // fs.rmSync(copyDir, { recursive: true, force: true, maxRetries: 2 });
228
- process.exit();
229
- break;
230
- case 'Overwrite':
231
- // remove existing
232
- const existingComp = await getComponentDirectoryPath(potentialCompKey);
233
- fs.rmSync(existingComp, { recursive: true, force: true, maxRetries: 2 });
234
- break;
235
- case 'New name':
236
- newName = proceedAnswers.componentName;
237
- newLabel = proceedAnswers.componentLabel;
238
- break;
239
274
  }
240
275
 
276
+
277
+
241
278
  }
242
279
  }
243
280
 
@@ -251,30 +288,39 @@ addDebugLog("importComp", `filePath: ${filePath}, fileName: ${fileName}`, "");
251
288
  console.log(`\n${chalk.green(`${fileName}`)} has been imported as ${chalk.green(`${newCompKey}`)}\n`);
252
289
 
253
290
  if (askValidate) {
254
- const validateAnswers = await inquirer.prompt([
255
- {
256
- name: 'doValidate',
257
- type: 'confirm',
258
- message: `Validate ${chalk.yellow(`${newCompKey}`)}`,
259
- default: true
260
- }]);
261
-
262
- if (validateAnswers.doValidate) {
263
- const args = [ '','', '', `${newCompKey}`];
264
- let myOptions = {};
265
- myOptions["params"] = args;
266
-
267
- await buildComponent(myOptions);
268
- }
269
- }
270
-
271
-
272
291
 
292
+ if (useInputConfig) {
293
+ const inputConfig = await getInputConfigForCommand("importComponent");
294
+ if (convertYNToBoolean(inputConfig.doValidation)) {
295
+ const args = [ '','', '', `${newCompKey}`];
296
+ let myOptions = {};
297
+ myOptions["params"] = args;
273
298
 
274
- }
299
+ await buildComponent(myOptions);
300
+ }
275
301
 
302
+ }
303
+ else {
304
+ const validateAnswers = await inquirer.prompt([
305
+ {
306
+ name: 'doValidate',
307
+ type: 'confirm',
308
+ message: `Validate ${chalk.yellow(`${newCompKey}`)}`,
309
+ default: true
310
+ }]);
311
+
312
+ if (validateAnswers.doValidate) {
313
+ const args = [ '','', '', `${newCompKey}`];
314
+ let myOptions = {};
315
+ myOptions["params"] = args;
316
+
317
+ await buildComponent(myOptions);
318
+ }
319
+ }
276
320
 
321
+ }
277
322
 
323
+ }
278
324
 
279
325
  }
280
326
 
@@ -321,6 +367,8 @@ export default async options => {
321
367
  await checkLibraryAndArchives();
322
368
  await checkPathAccess(pegaConfigJsonPath);
323
369
 
370
+ const useInputConfig = getUseInputConfig();
371
+
324
372
  addDebugLog("importComponent", "", "+");
325
373
 
326
374
  if (options.params.length >= 5) {
@@ -340,22 +388,36 @@ addDebugLog("importComponent", "", "+");
340
388
  }
341
389
  else {
342
390
 
343
- const filePathQuestions = await getFilePathQuestions();
344
- const filePathAnswers = await inquirer.prompt(filePathQuestions);
345
- const { filePath } = filePathAnswers;
391
+ let filePath;
392
+ let fileName;
393
+
394
+ if (useInputConfig) {
395
+ const inputConfig = await getInputConfigForCommand("importComponent");
396
+ filePath = inputConfig.fileLocation;
397
+ fileName = inputConfig.fileName;
398
+
399
+ }
400
+ else {
401
+ const filePathQuestions = await getFilePathQuestions();
402
+ const filePathAnswers = await inquirer.prompt(filePathQuestions);
403
+ ({ filePath } = filePathAnswers);
404
+
405
+ const compFileList = await getComponentList(filePath);
406
+
407
+ if (!compFileList || compFileList.length === 0) {
408
+ console.log(chalk.red.bold(`No component files exist at path: ${filePath}`));
409
+ process.exit();
410
+ }
411
+
412
+ await updateSavedFilePath(filePath);
346
413
 
347
- const compFileList = await getComponentList(filePath);
414
+ const fileNameQuestions = await getFileNameQuestions(compFileList);
415
+ const fileNameAnswers = await inquirer.prompt(fileNameQuestions);
416
+ ({fileName} = fileNameAnswers);
348
417
 
349
- if (!compFileList || compFileList.length === 0) {
350
- console.log(chalk.red.bold(`No component files exist at path: ${filePath}`));
351
- process.exit();
352
418
  }
353
419
 
354
- await updateSavedFilePath(filePath);
355
420
 
356
- const fileNameQuestions = await getFileNameQuestions(compFileList);
357
- const fileNameAnswers = await inquirer.prompt(fileNameQuestions);
358
- const {fileName} = fileNameAnswers;
359
421
 
360
422
  await importComp( filePath, fileName, true);
361
423