@pega/dx-component-builder-sdk 0.1.22 → 0.1.24

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 (25) hide show
  1. package/package.json +2 -2
  2. package/src/cli.js +8 -2
  3. package/src/tasks/create/templates/Constellation/field/Text/config.json.mustache +14 -0
  4. package/src/tasks/create/templates/SDK-React/field/Boolean/config.json.mustache +14 -0
  5. package/src/tasks/create/templates/SDK-React/field/Date/config.json.mustache +14 -0
  6. package/src/tasks/create/templates/SDK-React/field/DateTime/config.json.mustache +14 -0
  7. package/src/tasks/create/templates/SDK-React/field/Decimal/config.json.mustache +14 -0
  8. package/src/tasks/create/templates/SDK-React/field/Decimal-Currency/config.json.mustache +14 -0
  9. package/src/tasks/create/templates/SDK-React/field/Decimal-Percentage/config.json.mustache +14 -0
  10. package/src/tasks/create/templates/SDK-React/field/Integer/config.json.mustache +14 -0
  11. package/src/tasks/create/templates/SDK-React/field/Picklist/config.json.mustache +14 -0
  12. package/src/tasks/create/templates/SDK-React/field/Text/config.json.mustache +14 -0
  13. package/src/tasks/create/templates/SDK-React/field/Text-Email/config.json.mustache +14 -0
  14. package/src/tasks/create/templates/SDK-React/field/Text-Input/config.json.mustache +14 -0
  15. package/src/tasks/create/templates/SDK-React/field/Text-Paragraph/config.json.mustache +14 -0
  16. package/src/tasks/create/templates/SDK-React/field/Text-Phone/config.json.mustache +14 -0
  17. package/src/tasks/create/templates/SDK-React/field/TimeofDay/config.json.mustache +14 -0
  18. package/src/tasks/create/templates/SDK-React/template/DETAILS/demo.stories.jsx.mustache +509 -0
  19. package/src/tasks/create/templates/SDK-React/template/DETAILS/mock.stories.js.mustache +34 -0
  20. package/src/tasks/create/templates/SDK-React/template/DETAILS-region/demo.stories.jsx.mustache +1107 -0
  21. package/src/tasks/create/templates/SDK-React/template/DETAILS-region/mock.stories.js.mustache +34 -0
  22. package/src/tasks/create/templates/SDK-React/template/FORM/demo.stories.jsx.mustache +200 -0
  23. package/src/tasks/index.js +1 -0
  24. package/src/tasks/override/index.js +4 -2
  25. package/src/tasks/override-all/index.js +218 -0
@@ -0,0 +1,34 @@
1
+ const operatorDetails = {
2
+ data: {
3
+ "pzLoadTime": "March 13, 2023 10:58:15 AM EDT",
4
+ "pzPageNameHash": "_pa134221491644431pz",
5
+ "pyOperatorInfo": {
6
+ "pyUserName": "User DigV2",
7
+ "pyPosition": "",
8
+ "pyImageInsKey": "",
9
+ "pySkills": [
10
+ {
11
+ "pySkillName": "",
12
+ "pzIndexOwnerKey": "DATA-ADMIN-OPERATOR-ID USER.DIGV2",
13
+ "pySkillRating": 0
14
+ }
15
+ ],
16
+ "pyReportToUserName": "",
17
+ "pyReportTo": "",
18
+ "pyOrganization": "DXIL",
19
+ "pyTitle": "",
20
+ "pyLabel": "User.DigV2",
21
+ "pyEmailAddress": "User@DigV2",
22
+ "pyTelephone": ""
23
+ }
24
+ },
25
+ status: 200,
26
+ statusText: '',
27
+ headers: {
28
+ 'content-length': '435',
29
+ 'content-type': 'application/json;charset=UTF-8'
30
+ },
31
+ request: {}
32
+ };
33
+
34
+ export default operatorDetails;
@@ -0,0 +1,200 @@
1
+ import { useState } from 'react';
2
+
3
+ import { withKnobs } from '@storybook/addon-knobs';
4
+
5
+ import {{COMPONENT_CLASS_NAME}} from './index.tsx';
6
+
7
+ export default {
8
+ title: '{{COMPONENT_CLASS_NAME}}',
9
+ decorators: [withKnobs],
10
+ component: {{COMPONENT_CLASS_NAME}}
11
+ };
12
+
13
+ if (!window.PCore) {
14
+ window.PCore = {};
15
+ }
16
+
17
+ window.PCore = {
18
+ getErrorHandler() {
19
+ return {
20
+ getGenericFailedMessage() {
21
+ /* nothing */
22
+ }
23
+ };
24
+ }
25
+ };
26
+
27
+ export const Base{{COMPONENT_CLASS_NAME}} = () => {
28
+
29
+ const [firstName, setFirstName] = useState('John');
30
+ const [middleName, setMiddleName] = useState('');
31
+ const [lastName, setLastName] = useState('Joe');
32
+ const [phone, setPhone] = useState('+16397975093');
33
+ const [suffix, setSuffix] = useState('');
34
+ const [email, setEmail] = useState('john@doe.com');
35
+
36
+ const props = {
37
+ NumCols: "1",
38
+ template: 'DefaultForm',
39
+
40
+ getPConnect: () => {
41
+ return {
42
+ getChildren: () => {
43
+ return [
44
+ {
45
+ getPConnect: () => {
46
+ return {
47
+ getChildren: () => {
48
+ return [
49
+ {
50
+ readOnly: undefined,
51
+ placeholder: 'First Name',
52
+ value: firstName,
53
+ label: 'First Name',
54
+ hasSuggestions: false,
55
+ onChange: val => {
56
+ setFirstName(val.target.value);
57
+ }
58
+ },
59
+ {
60
+ readOnly: undefined,
61
+ placeholder: 'Middle Name',
62
+ value: middleName,
63
+ label: 'Middle Name',
64
+ hasSuggestions: false,
65
+ onChange: val => {
66
+ setMiddleName(val.target.value);
67
+ }
68
+ },
69
+
70
+ {
71
+ value: lastName,
72
+ label: 'Last Name',
73
+ required: true,
74
+ placeholder: 'Last Name',
75
+ testId: '77587239BF4C54EA493C7033E1DBF636',
76
+ hasSuggestions: false,
77
+ onChange: val => {
78
+ setLastName(val.target.value);
79
+ }
80
+ },
81
+
82
+ {
83
+ readOnly: undefined,
84
+ value: phone,
85
+ label: 'Phone Number',
86
+ datasource: {
87
+ fields: {
88
+ value: undefined
89
+ },
90
+ source: [
91
+ {
92
+ value: '+1'
93
+ },
94
+ {
95
+ value: '+91'
96
+ },
97
+ {
98
+ value: '+48'
99
+ },
100
+ {
101
+ value: '+44'
102
+ }
103
+ ]
104
+ },
105
+ hasSuggestions: false,
106
+ onChange: val => {
107
+ setPhone(val.value);
108
+ },
109
+ onBlur: () => {
110
+ /* nothing */
111
+ }
112
+ },
113
+
114
+ {
115
+ value: suffix,
116
+ label: 'Suffix',
117
+ placeholder: 'Select...',
118
+ listType: 'associated',
119
+ datasource: [
120
+ {
121
+ key: 'Sr',
122
+ value: 'Sr'
123
+ },
124
+ {
125
+ key: 'Jr',
126
+ value: 'Jr'
127
+ },
128
+ {
129
+ key: 'III',
130
+ value: 'III'
131
+ },
132
+ {
133
+ key: 'IV',
134
+ value: 'IV'
135
+ },
136
+ {
137
+ key: 'V',
138
+ value: 'V'
139
+ }
140
+ ],
141
+ testId: '56E6DDD1CB6CEC596B433440DFB21C17',
142
+ hasSuggestions: false,
143
+ deferDatasource: false,
144
+ getPConnect: () => {
145
+ return {
146
+ getContextName: () => {
147
+ return null;
148
+ },
149
+ getDataObject: () => {
150
+ return null;
151
+ },
152
+ getActionsApi: () => {
153
+ return {
154
+ updateFieldValue: (propName, value) => {
155
+ setSuffix(value);
156
+ },
157
+ triggerFieldChange: () => {
158
+ /* nothing */
159
+ }
160
+ };
161
+ },
162
+ getStateProps: () => {
163
+ return {
164
+ value: ''
165
+ };
166
+ }
167
+ };
168
+ },
169
+ onChange: val => {
170
+ setSuffix(val.target.value);
171
+ }
172
+ },
173
+
174
+ {
175
+ value: email,
176
+ label: 'Email',
177
+ required: true,
178
+ testId: 'CE8AE9DA5B7CD6C3DF2929543A9AF92D',
179
+ hasSuggestions: false,
180
+ onChange: val => {
181
+ setEmail(val.target.value);
182
+ }
183
+ }
184
+ ];
185
+ }
186
+ };
187
+ }
188
+ }
189
+ ];
190
+ }
191
+ };
192
+ }
193
+ };
194
+
195
+ return (
196
+ <>
197
+ <{{COMPONENT_CLASS_NAME}} {...props}></{{COMPONENT_CLASS_NAME}}>
198
+ </>
199
+ );
200
+ };
@@ -1,5 +1,6 @@
1
1
  export { default as createComponent } from './create/index.js';
2
2
  export { default as overrideComponent } from './override/index.js';
3
+ export { default as overrideAllComponents } from './override-all/index.js';
3
4
  export { default as deleteComponent } from './delete/index.js';
4
5
  export { default as deleteAllComponents } from './delete-all/index.js';
5
6
  export { default as mapAllComponents } from './map-all/index.js';
@@ -57,7 +57,7 @@ const checkAndCreateConfigComponentKey = async (targetDirectory) => {
57
57
  }
58
58
 
59
59
 
60
- // stringify "4", makes the json string look like JSON in the file
60
+ // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
61
61
  const configContent = JSON.stringify(configObj, null, 4);
62
62
 
63
63
  // update file
@@ -67,7 +67,9 @@ const checkAndCreateConfigComponentKey = async (targetDirectory) => {
67
67
  }
68
68
  catch (err) {
69
69
  // no config-ext.json file, so no update, which is ok
70
- console.log(chalk.yellow("Component has no config file for extension."));
70
+ const arPaths = targetDirectory.split("/");
71
+ const compName = arPaths[arPaths.length-1] ;
72
+ console.log(chalk.yellow(`Component ${compName} has no config file for extension.`));
71
73
  }
72
74
  }
73
75
 
@@ -0,0 +1,218 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { promisify } from 'util';
4
+ import { join } from 'path';
5
+
6
+ import inquirer from 'inquirer';
7
+ import ncp from 'ncp';
8
+ import chalk from 'chalk';
9
+ import { updateComponentMap } from '../map/map.js';
10
+
11
+ import { checkPathAccess, showVersion, getPegaConfig } from '../../util.js';
12
+ import {
13
+ getComponentDirectoryPath,
14
+ getComponents,
15
+ getComponentDefaults
16
+ } from '../../util.js';
17
+
18
+ import { COMPONENT_SCHEMA,
19
+ CATEGORY_OVERRIDE,
20
+ SDK_CONFIG_JSON_FILENAME,
21
+ DXCB_CONFIG,
22
+ DXCB_COMPONENT_DEFAULTS,
23
+ CUSTOM_TEMPLATES,
24
+ OVERRIDE_TEMPLATE_PATH,
25
+ OVERRIDE_LIB_PATH } from '../../constants.js';
26
+ import { compileMustacheTemplates } from '@pega/dx-component-builder-sdk/src/tasks/create/index.js';
27
+
28
+ const pegaConfigJsonPath = path.join(path.resolve(), SDK_CONFIG_JSON_FILENAME);
29
+
30
+ const copy = promisify(ncp);
31
+
32
+ const copyComponentTemplate = async options => {
33
+ return copy(options.overrideDirectory, options.targetDirectory, {
34
+ clobber: false
35
+ });
36
+ };
37
+
38
+
39
+ const checkAndCreateConfigComponentKey = async (targetDirectory) => {
40
+
41
+ const configFile = path.join(targetDirectory, "config-ext.json");
42
+ try {
43
+ const configData = fs.readFileSync(path.resolve(configFile), 'utf8');
44
+ let configObj = JSON.parse(configData);
45
+
46
+ let writeUpdate = false;
47
+ if (!configObj.componentKey || !configObj.label) {
48
+ const name = configObj.name;
49
+
50
+ if (!configObj.componentKey) {
51
+ const componentKey = name;
52
+ configObj = { componentKey, ...configObj };
53
+ }
54
+
55
+ if (!configObj.label) {
56
+ const label = name;
57
+ configObj = { label, ...configObj };
58
+ }
59
+
60
+
61
+ // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
62
+ const configContent = JSON.stringify(configObj, null, 4);
63
+
64
+ // update file
65
+ fs.writeFileSync(configFile, configContent, { encoding: 'utf8' });
66
+ }
67
+
68
+ }
69
+ catch (err) {
70
+ // no config-ext.json file, so no update, which is ok
71
+ const arPaths = targetDirectory.split("/");
72
+ const compName = arPaths[arPaths.length-1] ;
73
+ console.log(chalk.yellow(`Component ${compName} has no config file for extension.`));
74
+ }
75
+ }
76
+
77
+
78
+ const getListAvailableComponents = async (type) => {
79
+ const components = await getComponents(false, CATEGORY_OVERRIDE);
80
+ const fullList = COMPONENT_SCHEMA.overrideComponent[type];
81
+ let availList = [];
82
+ for (var el in fullList) {
83
+
84
+ let listEl = fullList[el].value;
85
+
86
+ if (listEl.indexOf("/") >=0) {
87
+ const arKey = listEl.split("/");
88
+ listEl = arKey[arKey.length - 1];
89
+ }
90
+
91
+ if (components.includes(listEl)) {
92
+ // currently don't show, because too many separators inquirer flaky
93
+ //availList.push(new inquirer.Separator("** " + fullList[el].name));
94
+ }
95
+ else {
96
+ availList.push(fullList[el]);
97
+ }
98
+ }
99
+
100
+ return availList;
101
+ }
102
+
103
+
104
+ const validateCompile = async (
105
+ {
106
+ componentName,
107
+ type
108
+ },
109
+ options
110
+ ) => {
111
+
112
+ let pegaConfig =
113
+ await getPegaConfig();
114
+ let templateParentDir = OVERRIDE_LIB_PATH;
115
+
116
+ if (pegaConfig[DXCB_CONFIG] &&
117
+ pegaConfig[DXCB_CONFIG][CUSTOM_TEMPLATES] &&
118
+ pegaConfig[DXCB_CONFIG][CUSTOM_TEMPLATES][OVERRIDE_TEMPLATE_PATH] &&
119
+ pegaConfig[DXCB_CONFIG][CUSTOM_TEMPLATES][OVERRIDE_TEMPLATE_PATH] != "") {
120
+ templateParentDir = pegaConfig[DXCB_CONFIG][CUSTOM_TEMPLATES][OVERRIDE_TEMPLATE_PATH];
121
+ }
122
+
123
+ // componentName has sub directory if components are in a sub directory of main "type"
124
+ const overrideDirectory = `${templateParentDir}/${type}/${componentName}`;
125
+
126
+ await checkPathAccess(overrideDirectory);
127
+
128
+ let componentKey = componentName;
129
+ if (componentKey.indexOf("/") >= 0) {
130
+ componentKey = componentKey.split("/")[1];
131
+ }
132
+ const typeLC = type.toLowerCase();
133
+ const targetDirectory = await getComponentDirectoryPath(join(typeLC, "/",componentKey), CATEGORY_OVERRIDE);
134
+
135
+ const components = await getComponents(false, CATEGORY_OVERRIDE);
136
+ if (components.includes(componentKey)) {
137
+ console.log(chalk.red(`${componentKey} component already exists in ${targetDirectory}`));
138
+ return;
139
+ }
140
+
141
+ await copyComponentTemplate({
142
+ ...options,
143
+ targetDirectory,
144
+ overrideDirectory
145
+ });
146
+
147
+ await checkAndCreateConfigComponentKey(targetDirectory);
148
+
149
+
150
+ console.log(chalk.green(`> Created ${componentKey} component in ${targetDirectory}`));
151
+
152
+ const componentKeyWithType = join(type, componentKey);
153
+ await updateComponentMap(componentKeyWithType, CATEGORY_OVERRIDE);
154
+
155
+ console.log(chalk.green(`> Added ${componentKeyWithType} to map`));
156
+
157
+ };
158
+
159
+ const buildOverridComponents = async (type, compList, options) => {
160
+ if (compList.length > 0) {
161
+ for (var index in compList) {
162
+ let componentName = compList[index].value;
163
+ await validateCompile(
164
+ {
165
+ componentName,
166
+ type
167
+ },
168
+ options
169
+ );
170
+ }
171
+ }
172
+ else {
173
+ console.log(chalk.green(`> All ${type} components have already been created.`));
174
+ }
175
+
176
+
177
+ }
178
+
179
+ export default async options => {
180
+ showVersion();
181
+
182
+ await checkPathAccess(pegaConfigJsonPath);
183
+
184
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
185
+ data = data && JSON.parse(data);
186
+
187
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][DXCB_COMPONENT_DEFAULTS]) {
188
+ console.error(
189
+ `${chalk.red.bold('ERROR')} Could not able find components defaults path in config.json`
190
+ );
191
+ process.exit(1);
192
+ }
193
+
194
+ const componentData = data[DXCB_CONFIG][DXCB_COMPONENT_DEFAULTS];
195
+
196
+ const { organization, library} = componentData;
197
+
198
+ let componentDefaults = await getComponentDefaults();
199
+ componentDefaults.library = library;
200
+
201
+ const fieldList = await getListAvailableComponents("field");
202
+ const desList = await getListAvailableComponents("designSystemExtension");
203
+ const templateList = await getListAvailableComponents("template");
204
+ const widgetList = await getListAvailableComponents("widget");
205
+ const infraList = await getListAvailableComponents("infra");
206
+
207
+
208
+ await buildOverridComponents("field", fieldList, options);
209
+ await buildOverridComponents("template", templateList, options);
210
+ await buildOverridComponents("widget", widgetList, options);
211
+ await buildOverridComponents("designSystemExtension", desList, options);
212
+ await buildOverridComponents("infra", infraList, options);
213
+
214
+
215
+
216
+ };
217
+
218
+