@pega/custom-dx-components 0.242.33 → 0.242.34

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "0.242.33",
3
+ "version": "0.242.34",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "@babel/plugin-transform-class-properties": "^7.23.3",
20
20
  "@babel/preset-react": "^7.23.3",
21
21
  "@pega/auth": "^0.1.6",
22
- "@pega/constellation-dx-components-build-utils": "^1.0.1-dev-0.16",
22
+ "@pega/constellation-dx-components-build-utils": "^1.0.1-dev-0.17",
23
23
  "ajv": "^8.12.0",
24
24
  "ajv-keywords": "^5.1.0",
25
25
  "archiver": "^7.0.1",
package/src/cli.js CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  revertWebPack,
33
33
  promoteWebPack,
34
34
  showStatus,
35
+ showHelp,
35
36
  setPermanent,
36
37
  storeComponents,
37
38
  updateComponent,
@@ -63,6 +64,7 @@ const TASKS = {
63
64
  LIST_LIB: 'listLibrary',
64
65
  LIST_PUB: 'listPublished',
65
66
  SHOW_STATUS: 'showStatus',
67
+ SHOW_HELP: 'showHelp',
66
68
  SET_PERM: 'setPermanent',
67
69
  STORE: 'storeComponents',
68
70
  VALIDATE_SCHEMA: 'validateSchema',
@@ -190,6 +192,10 @@ export default async (args = []) => {
190
192
  showStatus(options);
191
193
  break;
192
194
  }
195
+ case TASKS.SHOW_HELP: {
196
+ showHelp(options);
197
+ break;
198
+ }
193
199
  case TASKS.SET_PERM: {
194
200
  setPermanent(options);
195
201
  break;
@@ -67,7 +67,6 @@ addDebugLog("createLibrary", "", "+");
67
67
  // store it before clearing out /src/components
68
68
 
69
69
  if (hasArch) {
70
-
71
70
  const hasLib = await hasLibraryAndVersion(libraryName, version, !permBuild);
72
71
  if (hasLib) {
73
72
  console.log(`${chalk.bold.red(`Library ${orgLib.organization}_${libraryName} already exists.`)}`);
@@ -35,12 +35,12 @@ addDebugLog("deleteLibraryVersion", "", "+");
35
35
  process.exit();
36
36
  }
37
37
 
38
- if (version === "") {
39
- try {
40
- libVersions = await getLibraryArchivesVersions(libraryName, "");
41
- }
42
- catch (ex) {}
38
+ try {
39
+ libVersions = await getLibraryArchivesVersions(libraryName, "");
40
+ }
41
+ catch (ex) {}
43
42
 
43
+ if (version === "") {
44
44
 
45
45
  if (libVersions.length > 0) {
46
46
  // ALL option
@@ -148,6 +148,27 @@ addDebugLog("renameComponent", `library: ${library}, componentKey: ${componentKe
148
148
 
149
149
  };
150
150
 
151
+ export const getPackgeOrg = async(packagePath) => {
152
+ const sPackData = fs.readFileSync(packagePath, { encoding: 'utf8' });
153
+ const packData = sPackData && JSON.parse(sPackData);
154
+
155
+ return packData.organization;
156
+ }
157
+
158
+ export const getLocalConfigData = async(tasksPath) => {
159
+ let configData = { library: "", version: "", buildVersion: "", devBuild: false};
160
+ const sTaskData = fs.readFileSync(tasksPath, { encoding: 'utf8' });
161
+ const taskData = sTaskData && JSON.parse(sTaskData);
162
+
163
+ const devBuild = taskData["server-config"].devBuild;
164
+ configData.library = taskData["component"].library;
165
+ configData.version = taskData["component"].version;
166
+ configData.devBuild = devBuild;
167
+
168
+ configData.buildVersion = devBuild ? configData.version.concat("-dev") : configData.version;
169
+
170
+ return configData;
171
+ }
151
172
 
152
173
  export const moveComp = async(componentKey, orgLibName, version, copyShared, options) => {
153
174
 
@@ -203,7 +224,9 @@ addDebugLog("importArch", `filePath: ${filePath}, fileName: ${fileName}`, "");
203
224
 
204
225
  // check to see if have a tasks.config.json file, if not, archive not good
205
226
  const tempTasksConfig = join(tempDirectory, "tasks.config.json");
206
- if (!fs.existsSync(tempTasksConfig)) {
227
+ const tempPackage = join(tempDirectory, "package.json");
228
+
229
+ if (!fs.existsSync(tempTasksConfig) || !fs.existsSync(tempPackage)) {
207
230
  console.log(chalk.red.bold(`Zip file: ${fileName} not a compatible DX Component archive.`));
208
231
  console.log(chalk.red.bold("Cleaning up..."));
209
232
  fs.rmSync(tempDirectory, { recursive: true, force: true, maxRetries: 5 });
@@ -212,20 +235,23 @@ addDebugLog("importArch", `filePath: ${filePath}, fileName: ${fileName}`, "");
212
235
 
213
236
  }
214
237
 
238
+ // need to get info from tasks.config and package.json
239
+ // we won't rely on name of file, as owner can change it
240
+
241
+ let organization = await getPackgeOrg(tempPackage);
242
+ let localConfig = await getLocalConfigData(tempTasksConfig);
215
243
 
244
+ let orgLibName = `${organization}_${localConfig.library}`;
245
+ const version = localConfig.buildVersion;
246
+ const devBuild = localConfig.devBuild;
216
247
 
217
- const arFileData = fileName.split("_");
218
- let orgLibName = `${arFileData[0]}_${arFileData[1]}`;
219
- let libName = arFileData[1];
220
- const version = arFileData[2].replace(".zip", "");
221
- const devBuild = version.indexOf("-dev") > 0 ? true : false;
222
248
  const configDef = getConfigDefaults();
223
249
 
224
- if (arFileData[0] !== configDef.organization) {
250
+ if (organization !== configDef.organization) {
225
251
  console.log(`\nImported ${chalk.yellow(`${orgLibName}/${version}`)} is not the same organization as your current organization: ${chalk.yellow(`${configDef.organization}`)}.`);
226
252
  console.log(`\nTo import, the organization of the components will be changed to match your organization.`);
227
253
  console.log(`\n\t>>> If you don't want this to happen, then end and create a new project with an organization`);
228
- console.log(`\t of ${chalk.yellow(`${arFileData[0]}`)} and import there.\n`);
254
+ console.log(`\t of ${chalk.yellow(`${organization}`)} and import there.\n`);
229
255
 
230
256
  const proceedAnswers = await inquirer.prompt([
231
257
 
@@ -22,6 +22,7 @@ export { default as listComponents } from './list/index.js';
22
22
  export { default as listLibrary } from './list-lib/index.js';
23
23
  export { default as listPublished } from './list-pub/index.js';
24
24
  export { default as showStatus } from './show-status/index.js';
25
+ export { default as showHelp } from './show-help/index.js';
25
26
  export { default as setPermanent } from './set-perm/index.js';
26
27
  export { default as storeComponents } from './store/index.js';
27
28
  export { default as importArchive } from './import-archive/index.js';
@@ -43,6 +43,7 @@
43
43
  "exportLibVersion": "custom-dx-components exportArchive",
44
44
  "validate": "custom-dx-components buildComponent",
45
45
  "validateAll": "custom-dx-components buildAllComponents",
46
+ "help": "custom-dx-components showHelp",
46
47
  "_internal-test-coverage": "node --input-type=module --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand node_modules/@pega/custom-dx-component --ci --testResultsProcessor='jest-junit' --coverage",
47
48
  "_internal-test": "echo 'Running functional and unit tests will DELETE existing local components, proceed (y/n)?' && read proceed && if test \"$proceed\" = \"y\"; then npm run _internal-test-full; fi ",
48
49
  "_internal-test-full": "npm run _internal-test-functional && npm run _internal-test-unit",
@@ -97,7 +98,7 @@
97
98
  },
98
99
  "devDependencies": {
99
100
  "@pega/configs": "^0.6.0",
100
- "@pega/custom-dx-components": "0.242.33",
101
+ "@pega/custom-dx-components": "0.242.34",
101
102
  "@pega/pcore-pconnect-typedefs": "~3.0.0",
102
103
  "@storybook/addon-actions": "^7.6.7",
103
104
  "@storybook/addon-essentials": "^7.6.19",
@@ -0,0 +1,128 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ import chalk from 'chalk';
5
+
6
+ import { showVersion, getLibraryBased } from '../../util.js';
7
+
8
+ export const showCurrentStatus = async () => {
9
+
10
+ const configDefaults = await getConfigDefaults();
11
+ const componentList = await getComponents();
12
+
13
+ console.log("");
14
+ console.log("\tCurrent status");
15
+ console.log("\t---------------------");
16
+ console.log(`\tOrganization:\t ${chalk.bold.green(`${configDefaults.organization}`)}`);
17
+ console.log(`\tLibrary:\t ${chalk.bold.green(`${configDefaults.library}`)}`);
18
+ console.log(`\tVersion:\t ${chalk.bold.green(`${configDefaults.buildVersion}`)}`);
19
+ if (!configDefaults.devBuild) {
20
+ console.log(`\tPermanent:\t ${chalk.bold.magentaBright(`${!configDefaults.devBuild}`)}`);
21
+ }
22
+ else {
23
+ console.log(`\tPermanent:\t ${chalk.bold.green(`${!configDefaults.devBuild}`)}`);
24
+ }
25
+ console.log(`\tComponent count: ${chalk.bold.green(`${componentList.length}`)}`);
26
+
27
+ console.log("");
28
+
29
+ }
30
+
31
+ export const showHelpV1 = () => {
32
+ console.log("");
33
+ console.log(`\nnpm run <command>`);
34
+ console.log(`\nUsage:`);
35
+
36
+ console.log(`\n${chalk.underline(`Authenticate (for Server commands)`)}`);
37
+ console.log(`${chalk.cyan('npm run authenticate')}\t\tauthenticate to a server`);
38
+
39
+ console.log(`\n${chalk.underline(`Components`)}`);
40
+ console.log(`${chalk.cyan('npm run create ')}\tcreate a component`);
41
+ console.log(`${chalk.cyan('npm run createAll ')}\tcreate components of all different types`);
42
+ console.log(`${chalk.cyan('npm run buildComponent ')}\tvalidate a component before publishing, checking for errors`);
43
+ console.log(`${chalk.cyan('npm run buildAllComponents')}\tvalidate and build a component before publishing, checking for errors`);
44
+ console.log(`${chalk.cyan('npm run validateAll ')}\tvalidate and build ALL components before publishing, checking for errors`);
45
+ console.log(`${chalk.cyan('npm run rename ')}\trename a component`);
46
+ console.log(`${chalk.cyan('npm run startStorybook ')}\tstorybook components for testing`);
47
+
48
+ console.log(`\n${chalk.underline(`Local and Server`)}`);
49
+ console.log(`${chalk.cyan('npm run list ')}\tget list of components`);
50
+ console.log(`${chalk.cyan('npm run delete ')}\tdelete a component`);
51
+ console.log(`${chalk.cyan('npm run deleteAll ')}\tdelete ALL components`);
52
+
53
+ console.log(`\n${chalk.underline(`Server`)}`);
54
+ console.log(`${chalk.cyan('npm run publish ')}\tpublish a component to server`);
55
+ console.log(`${chalk.cyan('npm run publishAll ')}\tpublish ALL components to server`);
56
+
57
+ console.log("");
58
+
59
+ };
60
+
61
+ export const showHelpV2 = () => {
62
+ console.log("");
63
+ console.log(`All commands will not work until a library is created via ${chalk.cyan(`npm run createLib`)}.`);
64
+ console.log(`\nnpm run <command>`);
65
+ console.log(`\nUsage:`);
66
+
67
+
68
+ console.log(`\n${chalk.underline(`Authenticate`)}`);
69
+ console.log(`${chalk.cyan('npm run authenticate')}\t\tauthenticate to a server (required for publish commands)`);
70
+
71
+ console.log(`\n${chalk.underline(`Library`)}`);
72
+ console.log(`${chalk.cyan('npm run createLib' )}\t\tcreate a new library and version`);
73
+ console.log(`${chalk.cyan('npm run switchLib' )}\t\tswitch to different library and version`);
74
+ console.log(`${chalk.cyan('npm run listLib ')}\t\tget contents of library and version`);
75
+ console.log(`${chalk.cyan('npm run deleteLib ')}\t\tdelete library, version or ALL versions`);
76
+ console.log(`${chalk.cyan('npm run showStatus')}\t\tshow state of current library`);
77
+
78
+ console.log(`\n${chalk.underline(`Library Versions`)}`);
79
+ console.log(`${chalk.cyan('npm run createLibVersion')}\tcreate a new version within the current library`);
80
+ console.log(`${chalk.cyan('npm run switchLibVersion')}\tswitch to different version within the current library`);
81
+ console.log(`${chalk.cyan('npm run deleteLibVersion')}\tdelete current version, move to another version`);
82
+ console.log(`${chalk.cyan('npm run moveLibVersion ')}\tmove (or copy) single component or ALL in current version to another version or library`);
83
+ console.log(`${chalk.cyan('npm run storeLibVersion ')}\tstore current version to local storage`);
84
+ console.log(`${chalk.cyan('npm run exportLibVersion')}\texport currnet version as a zip file to a given local path`);
85
+ console.log(`${chalk.cyan('npm run importLibVersion')}\timport a zip file (created by export) from a given local path`);
86
+ console.log(`${chalk.cyan('npm run setPermanent ')}\tmake current version permanent or non permanent upon publish`);
87
+
88
+ console.log(`\n${chalk.underline(`Published Versions (needs authentication)`)}`);
89
+ console.log(`${chalk.cyan('npm run publishLibVersion')}\tpublish current library/version to server (creates a local published library as well)`);
90
+ console.log(`${chalk.cyan('npm run listPublishedLib')}\tget contents of published library/version (local or server)`);
91
+ console.log(`${chalk.cyan('npm run deletePublishedLib')}\tdelete ALL contents of published libary/version (local or server)`);
92
+
93
+ console.log(`\n${chalk.underline(`Components (in current library/version context)`)}`);
94
+ console.log(`${chalk.cyan('npm run create ')}\t\tcreate a component`);
95
+ console.log(`${chalk.cyan('npm run createAll ')}\t\tcreate components of all different types`);
96
+ console.log(`${chalk.cyan('npm run validate ')}\t\tvalidate a component before publishing, checking for errors`);
97
+ console.log(`${chalk.cyan('npm run validateAll')}\t\tvalidate ALL components before publishing, checking for errors`);
98
+ console.log(`${chalk.cyan('npm run rename ')}\t\trename a component`);
99
+ console.log(`${chalk.cyan('npm run list ')}\t\tget list of components`);
100
+ console.log(`${chalk.cyan('npm run delete ')}\t\tdelete a component`);
101
+ console.log(`${chalk.cyan('npm run deleteAll ')}\t\tdelete ALL components`);
102
+ console.log(`${chalk.cyan('npm run startStorybook')}\t\tstorybook components for testing`);
103
+ console.log("");
104
+
105
+ console.log(`\n${chalk.underline(`Notes`)}`);
106
+ console.log(`The following commands will store existing version in storage before executing the command:`);
107
+ console.log(`${chalk.cyan(`createLib, switchLib, createLibVersion, switchLibVersion, publishLibVersion, exportLibVersion`)}`);
108
+ console.log(`\nWhen in an IDE, always ${chalk.yellow("SAVE")} changes to components before doing a library/version context switch`);
109
+ console.log(`or changes will be lost.`);
110
+ console.log("");
111
+ }
112
+
113
+
114
+ export default async options => {
115
+ const isLibraryBased = getLibraryBased();
116
+
117
+ await showVersion();
118
+
119
+ if (isLibraryBased) {
120
+ await showHelpV2();
121
+ }
122
+ else {
123
+ await showHelpV1();
124
+ }
125
+
126
+
127
+
128
+ }