@pega/custom-dx-components 0.8.1 → 0.8.3

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.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
@@ -24,23 +24,8 @@ export const SOURCE_OF_COMPONENT_TYPES = {
24
24
  LOCAL: 'Local'
25
25
  };
26
26
 
27
- const currentDirectory = process.cwd();
28
- const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
29
-
30
- let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
31
- data = data && JSON.parse(data);
32
-
33
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
34
- console.error(
35
- `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
36
- );
37
- process.exit(1);
38
- }
39
-
40
- const componentData = data[COMPONENTS_PATH];
41
-
42
- let { library } = componentData;
43
- let { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
27
+ let library;
28
+ let organization;
44
29
 
45
30
  export const getDeleteComponentsQuestions = async (options) => {
46
31
  const defaultPegaServerConfig = await getPegaServerConfig();
@@ -62,31 +47,47 @@ export const getDeleteComponentsQuestions = async (options) => {
62
47
  export const getLaunchPadFilterQuestions = async () => {
63
48
  const defaultPegaServerConfig = await getPegaServerConfig();
64
49
 
50
+ const currentDirectory = process.cwd();
51
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
52
+
53
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
54
+ data = data && JSON.parse(data);
55
+
56
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
57
+ console.error(`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`);
58
+ process.exit(1);
59
+ }
60
+
61
+ const componentData = data[COMPONENTS_PATH];
62
+
63
+ ({ library } = componentData);
64
+ ({ organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8')));
65
+
65
66
  return [
66
- {
67
- name: 'organization',
68
- message: 'Enter component organization (required)',
69
- default: organization,
70
- validate: value => {
71
- if (value) {
72
- return true;
67
+ {
68
+ name: 'organization',
69
+ message: 'Enter component organization (required)',
70
+ default: organization,
71
+ validate: (value) => {
72
+ if (value) {
73
+ return true;
74
+ }
75
+ return 'Please provide value for organization';
73
76
  }
74
- return 'Please provide value for organization';
75
- }
76
- },
77
- {
78
- name: 'library',
79
- message: 'Enter library name (required)',
80
- default: library,
81
- validate: value => {
82
- if (value) {
83
- return true;
77
+ },
78
+ {
79
+ name: 'library',
80
+ message: 'Enter library name (required)',
81
+ default: library,
82
+ validate: (value) => {
83
+ if (value) {
84
+ return true;
85
+ }
86
+ return 'Please provide value for library';
84
87
  }
85
- return 'Please provide value for library';
86
88
  }
87
- }
88
89
  ];
89
- }
90
+ };
90
91
 
91
92
  export const deleteLocalComponents = async (sourceOfComponents, options) => {
92
93
  const localComponents = await getComponents();
@@ -124,27 +125,23 @@ export const deleteLocalComponents = async (sourceOfComponents, options) => {
124
125
  };
125
126
 
126
127
  export const deleteServerComponents = async (sourceOfComponents, answers) => {
127
-
128
128
  const defaultPegaServerConfig = await getPegaServerConfig();
129
129
  const isLaunchpad = defaultPegaServerConfig.serverType === 'launchpad';
130
130
 
131
-
132
131
  if (isLaunchpad) {
133
132
  const questions = await getLaunchPadFilterQuestions();
134
133
  const lpAnswers = await inquirer.prompt(questions);
135
134
 
136
- ({library, organization} = lpAnswers);
135
+ ({ library, organization } = lpAnswers);
137
136
  }
138
137
 
139
138
  const spinner = ora('Fetching components from server').start();
140
139
  const data = await getComponentsFromServer(library, organization);
141
140
  spinner.stop();
142
141
 
143
-
144
142
  let serverComponents;
145
143
  if (isLaunchpad) {
146
144
  serverComponents = data;
147
-
148
145
  } else {
149
146
  try {
150
147
  if (typeof data === 'object') {
@@ -157,7 +154,6 @@ export const deleteServerComponents = async (sourceOfComponents, answers) => {
157
154
  }
158
155
  }
159
156
 
160
-
161
157
  if (serverComponents && serverComponents?.length > 0) {
162
158
  if (isLaunchpad) {
163
159
  const choicesArr = serverComponents.map(({ name: componentName, type, version }) => {
@@ -25,23 +25,8 @@ export const SOURCE_OF_COMPONENT_TYPES = {
25
25
  LOCAL: 'Local'
26
26
  };
27
27
 
28
- const currentDirectory = process.cwd();
29
- const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
30
-
31
- let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
32
- data = data && JSON.parse(data);
33
-
34
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
35
- console.error(
36
- `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
37
- );
38
- process.exit(1);
39
- }
40
-
41
- const componentData = data[COMPONENTS_PATH];
42
-
43
- let { library } = componentData;
44
- let { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
28
+ let library;
29
+ let organization;
45
30
 
46
31
  export const getDeleteComponentsQuestions = async (options) => {
47
32
  const defaultPegaServerConfig = await getPegaServerConfig();
@@ -62,13 +47,28 @@ export const getDeleteComponentsQuestions = async (options) => {
62
47
 
63
48
  export const getLaunchPadFilterQuestions = async () => {
64
49
  const defaultPegaServerConfig = await getPegaServerConfig();
50
+ const currentDirectory = process.cwd();
51
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
52
+
53
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
54
+ data = data && JSON.parse(data);
55
+
56
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
57
+ console.error(`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`);
58
+ process.exit(1);
59
+ }
60
+
61
+ const componentData = data[COMPONENTS_PATH];
62
+
63
+ ({ library } = componentData);
64
+ ({ organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8')));
65
65
 
66
66
  return [
67
67
  {
68
68
  name: 'organization',
69
69
  message: 'Enter component organization (required)',
70
70
  default: organization,
71
- validate: value => {
71
+ validate: (value) => {
72
72
  if (value) {
73
73
  return true;
74
74
  }
@@ -79,7 +79,7 @@ export const getLaunchPadFilterQuestions = async () => {
79
79
  name: 'library',
80
80
  message: 'Enter library name (required)',
81
81
  default: library,
82
- validate: value => {
82
+ validate: (value) => {
83
83
  if (value) {
84
84
  return true;
85
85
  }
@@ -87,7 +87,7 @@ export const getLaunchPadFilterQuestions = async () => {
87
87
  }
88
88
  }
89
89
  ];
90
- }
90
+ };
91
91
 
92
92
  export const deleteLocalComponents = async (sourceOfComponents, options) => {
93
93
  const localComponents = await getComponents();
@@ -133,7 +133,6 @@ export const deleteLocalComponents = async (sourceOfComponents, options) => {
133
133
  };
134
134
 
135
135
  export const deleteServerComponents = async (sourceOfComponents, answers) => {
136
-
137
136
  const defaultPegaServerConfig = await getPegaServerConfig();
138
137
  const isLaunchpad = defaultPegaServerConfig.serverType === 'launchpad';
139
138
 
@@ -141,14 +140,13 @@ export const deleteServerComponents = async (sourceOfComponents, answers) => {
141
140
  const questions = await getLaunchPadFilterQuestions();
142
141
  const lpAnswers = await inquirer.prompt(questions);
143
142
 
144
- ({library, organization} = lpAnswers);
143
+ ({ library, organization } = lpAnswers);
145
144
  }
146
145
 
147
146
  const spinner = ora('Fetching components from server').start();
148
147
  const data = await getComponentsFromServer(library, organization);
149
148
  spinner.stop();
150
149
 
151
-
152
150
  // const serverComponents = isLaunchpad ? data : data.pxResults;
153
151
  let serverComponents;
154
152
  if (isLaunchpad) {
@@ -165,8 +163,6 @@ export const deleteServerComponents = async (sourceOfComponents, answers) => {
165
163
  }
166
164
  }
167
165
 
168
-
169
-
170
166
  if (serverComponents && serverComponents?.length > 0) {
171
167
  if (isLaunchpad) {
172
168
  serverComponents.forEach((component) => {
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "devDependencies": {
68
68
  "@pega/configs": "^0.5.3",
69
- "@pega/custom-dx-components": "^0.8.1",
69
+ "@pega/custom-dx-components": "^0.8.3",
70
70
  "@pega/eslint-config": "^0.3.2",
71
71
  "@storybook/addon-actions": "^6.5.12",
72
72
  "@storybook/addon-essentials": "^6.5.12",
@@ -7,7 +7,15 @@ import ora from 'ora';
7
7
 
8
8
  import inquirer from 'inquirer';
9
9
 
10
- import { LIST_COMPONENT_SERVICE_REST_ENDPOINT, LP_LIST_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH, COMPONENT_SCHEMA, TASKS_CONFIG_JSON_FILENAME, COMPONENTS_DIRECTORY_PATH, COMPONENTS_PATH } from '../../constants.js';
10
+ import {
11
+ LIST_COMPONENT_SERVICE_REST_ENDPOINT,
12
+ LP_LIST_COMPONENT_SERVICE_REST_ENDPOINT,
13
+ TOKEN_PATH,
14
+ COMPONENT_SCHEMA,
15
+ TASKS_CONFIG_JSON_FILENAME,
16
+ COMPONENTS_DIRECTORY_PATH,
17
+ COMPONENTS_PATH
18
+ } from '../../constants.js';
11
19
  import { constructCompleteUrl, getComponents, getPegaServerConfig, getHttpsAgent, sanitize } from '../../util.js';
12
20
 
13
21
  export const SOURCE_OF_COMPONENT_TYPES = {
@@ -15,24 +23,6 @@ export const SOURCE_OF_COMPONENT_TYPES = {
15
23
  LOCAL: 'Local'
16
24
  };
17
25
 
18
- const currentDirectory = process.cwd();
19
- const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
20
-
21
- let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
22
- data = data && JSON.parse(data);
23
-
24
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
25
- console.error(
26
- `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
27
- );
28
- process.exit(1);
29
- }
30
-
31
- const componentData = data[COMPONENTS_PATH];
32
-
33
- let { library } = componentData;
34
- let { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
35
-
36
26
  export const getListComponentsQuestions = async (options) => {
37
27
  const defaultPegaServerConfig = await getPegaServerConfig();
38
28
 
@@ -52,13 +42,28 @@ export const getListComponentsQuestions = async (options) => {
52
42
 
53
43
  export const getLaunchPadFilterQuestions = async () => {
54
44
  const defaultPegaServerConfig = await getPegaServerConfig();
45
+ const currentDirectory = process.cwd();
46
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
47
+
48
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
49
+ data = data && JSON.parse(data);
50
+
51
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
52
+ console.error(`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`);
53
+ process.exit(1);
54
+ }
55
+
56
+ const componentData = data[COMPONENTS_PATH];
57
+
58
+ let { library } = componentData;
59
+ let { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
55
60
 
56
61
  return [
57
62
  {
58
63
  name: 'organization',
59
64
  message: 'Enter component organization (required)',
60
65
  default: organization,
61
- validate: value => {
66
+ validate: (value) => {
62
67
  if (value) {
63
68
  return true;
64
69
  }
@@ -69,7 +74,7 @@ export const getLaunchPadFilterQuestions = async () => {
69
74
  name: 'library',
70
75
  message: 'Enter library name (required)',
71
76
  default: library,
72
- validate: value => {
77
+ validate: (value) => {
73
78
  if (value) {
74
79
  return true;
75
80
  }
@@ -77,7 +82,7 @@ export const getLaunchPadFilterQuestions = async () => {
77
82
  }
78
83
  }
79
84
  ];
80
- }
85
+ };
81
86
 
82
87
  export const listLocalComponents = async (sourceOfComponents) => {
83
88
  let localComponents = await getComponents();
@@ -168,8 +173,6 @@ export const getComponentsFromServer = async (library, organization) => {
168
173
  isLaunchpad ? LP_LIST_COMPONENT_SERVICE_REST_ENDPOINT : LIST_COMPONENT_SERVICE_REST_ENDPOINT
169
174
  );
170
175
 
171
-
172
-
173
176
  return new Promise((resolve, reject) => {
174
177
  try {
175
178
  fs.readFile(TOKEN_PATH, 'utf8', (err, data) => {
@@ -187,9 +190,12 @@ export const getComponentsFromServer = async (library, organization) => {
187
190
 
188
191
  fetchComponentsFromLaunchpad(url, headers)
189
192
  .then((response) => {
190
- response = response.filter(component => (component.library === library || library === "*" ) && (component.organization === organization || organization === "*"));
191
- resolve(response); }
192
- )
193
+ response = response.filter(
194
+ (component) =>
195
+ (component.library === library || library === '*') && (component.organization === organization || organization === '*')
196
+ );
197
+ resolve(response);
198
+ })
193
199
  .catch((e) => reject(e));
194
200
  } else {
195
201
  headers.Authorization = `${tokenType} ${accessToken}`;