@pega/custom-dx-components 2.0.16 → 2.0.17

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 (117) hide show
  1. package/package.json +2 -2
  2. package/src/cli.js +18 -0
  3. package/src/tasks/authenticate/index.js +3 -1
  4. package/src/tasks/build/helper.js +123 -0
  5. package/src/tasks/build/index.js +54 -0
  6. package/src/tasks/{publish/bundle → bundle}/builder/index.js +0 -0
  7. package/src/tasks/{publish/bundle → bundle}/builder/modules.js +0 -0
  8. package/src/tasks/{publish/bundle → bundle}/builder/paths.js +0 -0
  9. package/src/tasks/{publish/bundle → bundle}/builder/webpack.config.js +0 -2
  10. package/src/tasks/{publish/bundle → bundle}/index.js +2 -2
  11. package/src/tasks/create/index.js +6 -3
  12. package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +1 -1
  13. package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +29 -18
  14. package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +1 -2
  15. package/src/tasks/create/templates/Constellation/Field/Boolean/mock.stories.js.mustache +21 -0
  16. package/src/tasks/create/templates/Constellation/Field/Date/DateFormatter.js.mustache +61 -0
  17. package/src/tasks/create/templates/Constellation/Field/Date/FormattedText.jsx.mustache +41 -0
  18. package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +179 -67
  19. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +40 -16
  20. package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +3 -1
  21. package/src/tasks/create/templates/Constellation/Field/Date/mock.stories.js.mustache +23 -0
  22. package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +0 -1
  23. package/src/tasks/create/templates/Constellation/Field/DateTime/{date-utils.js → date-utils.js.mustache} +1 -0
  24. package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +1 -0
  25. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +40 -15
  26. package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +2 -0
  27. package/src/tasks/create/templates/Constellation/Field/DateTime/mock.stories.js.mustache +23 -0
  28. package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +22 -17
  29. package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +2 -1
  30. package/src/tasks/create/templates/Constellation/Field/Decimal/mock.stories.js.mustache +21 -0
  31. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +25 -17
  32. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +3 -4
  33. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/mock.stories.js.mustache +23 -0
  34. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +22 -17
  35. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +8 -2
  36. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/mock.stories.js.mustache +21 -0
  37. package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +22 -17
  38. package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +2 -1
  39. package/src/tasks/create/templates/Constellation/Field/Integer/mock.stories.js.mustache +21 -0
  40. package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +42 -14
  41. package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +44 -1
  42. package/src/tasks/create/templates/Constellation/Field/Picklist/mock.stories.js.mustache +67 -0
  43. package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +21 -16
  44. package/src/tasks/create/templates/Constellation/Field/Text/mock.stories.js.mustache +13 -0
  45. package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +20 -16
  46. package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +44 -2
  47. package/src/tasks/create/templates/Constellation/Field/Text-Email/mock.stories.js.mustache +22 -0
  48. package/src/tasks/create/templates/Constellation/Field/Text-Input/{StatusWork.js → StatusWork.jsx} +0 -1
  49. package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +21 -17
  50. package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +46 -3
  51. package/src/tasks/create/templates/Constellation/Field/Text-Input/mock.stories.js.mustache +21 -0
  52. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +21 -17
  53. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +44 -2
  54. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/mock.stories.js.mustache +20 -0
  55. package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +19 -17
  56. package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +46 -2
  57. package/src/tasks/create/templates/Constellation/Field/Text-Phone/mock.stories.js.mustache +37 -0
  58. package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +19 -17
  59. package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +174 -3
  60. package/src/tasks/create/templates/Constellation/Field/Text-URL/mock.stories.js.mustache +22 -0
  61. package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +24 -16
  62. package/src/tasks/create/templates/Constellation/Field/TimeofDay/mock.stories.js.mustache +20 -0
  63. package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +1 -0
  64. package/src/tasks/create/templates/Constellation/Template/DETAILS/StatusWork.jsx.mustache +26 -0
  65. package/src/tasks/create/templates/Constellation/Template/DETAILS/demo.stories.jsx.mustache +110 -0
  66. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +14 -29
  67. package/src/tasks/create/templates/Constellation/Template/DETAILS/mock.stories.js.mustache +179 -0
  68. package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +3 -77
  69. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/StatusWork.jsx.mustache +26 -0
  70. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/demo.stories.jsx.mustache +118 -0
  71. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +14 -29
  72. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/mock.stories.js.mustache +215 -0
  73. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +3 -74
  74. package/src/tasks/create/templates/Constellation/Template/FORM/demo.stories.jsx.mustache +89 -0
  75. package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +6 -10
  76. package/src/tasks/create/templates/Constellation/Template/FORM/mock.stories.js.mustache +125 -0
  77. package/src/tasks/create/templates/Constellation/Template/FORM-region/demo.stories.jsx.mustache +100 -0
  78. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +10 -8
  79. package/src/tasks/create/templates/Constellation/Template/FORM-region/mock.stories.js.mustache +131 -0
  80. package/src/tasks/create/templates/Constellation/Template/PAGE/{GetNextWork.js.mustache → GetNextWork.jsx.mustache} +6 -0
  81. package/src/tasks/create/templates/Constellation/Template/PAGE/demo.stories.jsx.mustache +102 -0
  82. package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +9 -7
  83. package/src/tasks/create/templates/Constellation/Template/PAGE/mock.stories.js.mustache +94 -0
  84. package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +4 -1
  85. package/src/tasks/create/templates/Constellation/Widget/CASE/demo.stories.jsx.mustache +78 -0
  86. package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +1 -0
  87. package/src/tasks/create/templates/Constellation/Widget/CASE/mock.stories.js.mustache +389 -0
  88. package/src/tasks/create/templates/Constellation/Widget/PAGE/demo.stories.jsx.mustache +30 -0
  89. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.jsx.mustache +8 -8
  90. package/src/tasks/create/templates/Constellation/Widget/PAGE/mock.stories.js.mustache +22 -0
  91. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Avatar.js.mustache → Avatar.jsx.mustache} +2 -0
  92. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Operator.js.mustache → Operator.jsx.mustache} +2 -1
  93. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/demo.stories.jsx.mustache +68 -0
  94. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +9 -9
  95. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/mock.stories.js.mustache +51 -0
  96. package/src/tasks/delete/helper.js +4 -0
  97. package/src/tasks/delete/index.js +4 -0
  98. package/src/tasks/delete-all/helper.js +175 -0
  99. package/src/tasks/delete-all/index.js +49 -0
  100. package/src/tasks/index.js +3 -0
  101. package/src/tasks/init/index.js +1 -1
  102. package/src/tasks/init/template/.eslintignore +8 -0
  103. package/src/tasks/init/template/.eslintrc.json +186 -5
  104. package/src/tasks/init/template/package.json.mustache +19 -4
  105. package/src/tasks/init/template/tasks.config.json +1 -0
  106. package/src/tasks/linter/index.js +46 -0
  107. package/src/tasks/list/index.js +4 -0
  108. package/src/tasks/publish/index.js +14 -1
  109. package/src/tasks/publish-all/helper.js +139 -0
  110. package/src/tasks/publish-all/index.js +84 -0
  111. package/src/util.js +10 -0
  112. package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +0 -43
  113. package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +0 -43
  114. package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +0 -43
  115. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +0 -43
  116. package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +0 -43
  117. package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.js.mustache +0 -172
@@ -10,12 +10,15 @@
10
10
  "lint": "run-p -cl lint:*",
11
11
  "fix": "run-p -cl fix:*",
12
12
  "authenticate": "custom-dx-components authenticate",
13
+ "buildComponent": "custom-dx-components buildComponent",
13
14
  "create": "custom-dx-components create",
14
15
  "publish": "custom-dx-components publish",
16
+ "publishAll": "custom-dx-components publishAll",
15
17
  "list": "custom-dx-components list",
16
18
  "validate-schema": "custom-dx-components validateSchema",
17
19
  "update": "custom-dx-components update",
18
20
  "delete": "custom-dx-components delete",
21
+ "deleteAll": "custom-dx-components deleteAll",
19
22
  "lint:types": "tsc --noEmit",
20
23
  "lint:es": "eslint .",
21
24
  "lint:styles": "stylelint \"./**/*.@(js|jsx|ts|tsx)\"",
@@ -35,8 +38,8 @@
35
38
  "license": "Enter License",
36
39
  "sideEffects": false,
37
40
  "dependencies": {
38
- "@pega/cosmos-react-core": "^3.0.0-rc.4",
39
- "@pega/cosmos-react-work": "3.0.0-rc.4",
41
+ "@pega/cosmos-react-core": "^3.0.1",
42
+ "@pega/cosmos-react-work": "3.0.1",
40
43
  "@storybook/addon-knobs": "^6.3.1",
41
44
  "dayjs": "^1.11.5",
42
45
  "jest": "^29.3.1",
@@ -52,7 +55,8 @@
52
55
  },
53
56
  "devDependencies": {
54
57
  "@pega/configs": "^0.3.4",
55
- "@pega/custom-dx-components": "^2.0.16",
58
+ "@pega/custom-dx-components": "^2.0.17",
59
+ "@pega/eslint-config": "^0.3.2",
56
60
  "@storybook/addon-actions": "^6.5.12",
57
61
  "@storybook/addon-essentials": "^6.5.12",
58
62
  "@storybook/addon-links": "^6.5.12",
@@ -65,7 +69,18 @@
65
69
  "@types/react-color": "^3.0.6",
66
70
  "@types/react-dom": "^17.0.11",
67
71
  "@types/styled-components": "^5.1.26",
68
- "eslint": "^8.23.1",
72
+ "@typescript-eslint/eslint-plugin": "^5.6.0",
73
+ "eslint": "^8.4.1",
74
+ "eslint-plugin-import": "^2.25.3",
75
+ "eslint-plugin-jest": "^25.3.0",
76
+ "eslint-plugin-jsx-a11y": "^6.5.1",
77
+ "eslint-plugin-mdx": "^2.0.5",
78
+ "eslint-plugin-prettier": "^4.0.0",
79
+ "eslint-plugin-react": "^7.27.1",
80
+ "eslint-plugin-react-hooks": "^4.3.0",
81
+ "eslint-plugin-sonarjs": "^0.11.0",
82
+ "jest": "^29.3.1",
83
+ "jest-environment-jsdom": "^29.3.1",
69
84
  "npm-run-all": "^4.1.5",
70
85
  "prettier": "2.7.1",
71
86
  "stylelint": "^14.11.0",
@@ -14,6 +14,7 @@
14
14
  "component": {
15
15
  "library": "",
16
16
  "type": "",
17
+ "version": "",
17
18
  "subtype": "",
18
19
  "description": "",
19
20
  "icon": ""
@@ -0,0 +1,46 @@
1
+ import { ESLint } from 'eslint';
2
+ import chalk from 'chalk';
3
+
4
+ export const lintComponent = async (dirToLint) => {
5
+ // console.log("in dx-component-builder-sdk: lintComponent - dirToLint: " + dirToLint);
6
+ console.log(chalk.green(` linting ${dirToLint}`));
7
+
8
+ // 1. Create an instance.
9
+ const eslint = new ESLint();
10
+
11
+ // 2. Lint files.
12
+ const results = await eslint.lintFiles([dirToLint]);
13
+
14
+ // 3. Format the results.
15
+ const formatter = await eslint.loadFormatter("stylish");
16
+ const resultText = formatter.format(results);
17
+
18
+ // 4. Output it.
19
+ // console.log(`lint resultText: ${resultText}`);
20
+ console.log(resultText);
21
+
22
+ // Indicate linting is complete
23
+ console.log(chalk.green(` linting complete...`));
24
+ };
25
+
26
+ // inpsired by https://eslint.org/docs/latest/developer-guide/nodejs-api
27
+
28
+ // (async function main() {
29
+ // // 1. Create an instance.
30
+ // const eslint = new ESLint();
31
+
32
+ // // 2. Lint files.
33
+ // const results = await eslint.lintFiles(["lib/**/*.js"]);
34
+
35
+ // // 3. Format the results.
36
+ // const formatter = await eslint.loadFormatter("stylish");
37
+ // const resultText = formatter.format(results);
38
+
39
+ // // 4. Output it.
40
+ // console.log(resultText);
41
+ // })().catch((error) => {
42
+ // process.exitCode = 1;
43
+ // console.error(error);
44
+ // });
45
+
46
+ export default lintComponent;
@@ -10,6 +10,8 @@ import {
10
10
  getListComponentsQuestions
11
11
  } from './helper.js';
12
12
 
13
+ import { showVersion } from '../../util.js';
14
+
13
15
  const getList = async (sourceOfComponents, answers) => {
14
16
  switch (sourceOfComponents) {
15
17
  case SOURCE_OF_COMPONENT_TYPES.LOCAL: {
@@ -32,6 +34,8 @@ const getList = async (sourceOfComponents, answers) => {
32
34
  };
33
35
 
34
36
  export default async options => {
37
+ showVersion();
38
+
35
39
  let sourceOfComponentsOption = SOURCE_OF_COMPONENT_TYPES.LOCAL;
36
40
 
37
41
  if (options.params[3] === SOURCE_OF_COMPONENT_TYPES.LOCAL) {
@@ -4,10 +4,15 @@ import chalk from 'chalk';
4
4
 
5
5
  import validate from '../validator/index.js';
6
6
 
7
- import bundleComponent from './bundle/index.js';
7
+ import bundleComponent from '../bundle/index.js';
8
+ import { lintComponent } from '../linter/index.js';
9
+
10
+ import { getComponentDirectoryPath, showVersion } from '../../util.js';
8
11
  import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
9
12
 
10
13
  export default async options => {
14
+ showVersion();
15
+
11
16
  const questions = await getPublishComponentQuestions();
12
17
  const answers = await inquirer.prompt(questions);
13
18
  const { componentKey, sourceMap, devBuild } = answers;
@@ -24,6 +29,14 @@ export default async options => {
24
29
  await validate(componentKey);
25
30
  }
26
31
  },
32
+ {
33
+ title: 'Lint component',
34
+ task: async () => {
35
+ const targetDirectory = await getComponentDirectoryPath(componentKey);
36
+ // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
37
+ await lintComponent(targetDirectory);
38
+ }
39
+ },
27
40
  {
28
41
  title: 'Bundle Component',
29
42
  task: async () => await bundleComponent(componentKey, sourceMap, devBuild),
@@ -0,0 +1,139 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import https from 'https';
4
+
5
+ import fetch from 'node-fetch';
6
+ import AdmZip from 'adm-zip';
7
+ import chalk from 'chalk';
8
+
9
+ import {
10
+ constructCompleteUrl,
11
+ getComponentDirectoryPath,
12
+ getComponents,
13
+ getPegaServerConfig,
14
+ validateRulesetVersion
15
+ } from '../../util.js';
16
+ import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
17
+
18
+ export const getPublishComponentQuestions = async () => {
19
+ const components = await getComponents();
20
+ const defaultPegaConfig = await getPegaServerConfig();
21
+
22
+ return [
23
+ {
24
+ name: 'rulesetName',
25
+ message: 'Enter ruleset name',
26
+ default: defaultPegaConfig.rulesetName,
27
+ validate: value => {
28
+ if (value.trim()) {
29
+ return true;
30
+ }
31
+ return 'Ruleset name cannot be empty';
32
+ }
33
+ },
34
+ {
35
+ name: 'rulesetVersion',
36
+ message: 'Enter ruleset version',
37
+ default: defaultPegaConfig.rulesetVersion,
38
+ validate: value => {
39
+ if (validateRulesetVersion(value)) {
40
+ return true;
41
+ }
42
+ return 'Please provide compatible version e.g 01-01-01';
43
+ }
44
+ },
45
+ {
46
+ name: 'sourceMap',
47
+ message: 'Generate source map ?',
48
+ default: defaultPegaConfig.sourceMap,
49
+ when: () => false && !process.env.SOURCE_MAP
50
+ },
51
+ {
52
+ name: 'devBuild',
53
+ message: 'Generate development build ?',
54
+ default: defaultPegaConfig.devBuild
55
+ }
56
+ ];
57
+ };
58
+
59
+ export const zipComponent = async componentKey => {
60
+ const srcDirectory = await getComponentDirectoryPath(componentKey);
61
+ const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
62
+ const configJson = `${srcDirectory}/config.json`;
63
+
64
+ const zip = new AdmZip();
65
+
66
+ zip.addLocalFolder(srcDirectory, 'src/');
67
+ zip.addLocalFile(configJson);
68
+ zip.addLocalFolder(buildDirectory);
69
+ const zipContent = zip.toBuffer().toString('base64');
70
+
71
+ const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
72
+ fs.rmdir('dist', { recursive: true }, err => {
73
+ if (err) {
74
+ throw err;
75
+ }
76
+ });
77
+ return { zipContent, configContent };
78
+ };
79
+
80
+ export const publishComponentToServer = async data => {
81
+ const { configContent, zipContent, componentKey, rulesetName, rulesetVersion } = data;
82
+
83
+ const apiBody = {
84
+ configContent,
85
+ zipContent,
86
+ componentKey: JSON.parse(configContent).componentKey,
87
+ publishFor: 'constellation',
88
+ rulesetName,
89
+ rulesetVersion,
90
+ category: ''
91
+ };
92
+ const defaultPegaConfig = await getPegaServerConfig();
93
+ const url = constructCompleteUrl(
94
+ defaultPegaConfig.server,
95
+ PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
96
+ );
97
+ try {
98
+ const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
99
+ if (OauthData) {
100
+ const {
101
+ access_token: accessToken,
102
+ token_type: tokenType,
103
+ refresh_token: refreshToken
104
+ } = JSON.parse(OauthData);
105
+ let status = 500;
106
+ fetch(url, {
107
+ method: 'POST',
108
+ agent: new https.Agent({ rejectUnauthorized: false }),
109
+ headers: {
110
+ Authorization: `${tokenType} ${accessToken}`
111
+ },
112
+ body: JSON.stringify(apiBody)
113
+ })
114
+ .then(response => {
115
+ status = response.status;
116
+ return response.text();
117
+ })
118
+ .then(resp => {
119
+ const respData = JSON.parse(resp);
120
+ if (status === 401) {
121
+ throw new Error(
122
+ 'Error occured in authentication. Please regenerate using authenticate'
123
+ );
124
+ // console.log(accessTokenUri, refreshToken);
125
+ /* TODO - Handle refresh_token */
126
+ } else if (status == 200) {
127
+ console.log(chalk.bold.green(`Success : ${respData.message}`));
128
+ } else {
129
+ throw new Error(`${respData.message}`);
130
+ }
131
+ })
132
+ .catch(e => Promise.reject(`${chalk.bold.red(e)}`));
133
+ } else {
134
+ throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
135
+ }
136
+ } catch (err) {
137
+ throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
138
+ }
139
+ };
@@ -0,0 +1,84 @@
1
+ import inquirer from 'inquirer';
2
+ import Listr from 'listr';
3
+ import chalk from 'chalk';
4
+
5
+ import validate from '../validator/index.js';
6
+
7
+ import bundleComponent from '../bundle/index.js';
8
+ import { lintComponent } from '../linter/index.js';
9
+
10
+
11
+ import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
12
+ import {
13
+ getComponents,
14
+ getComponentDirectoryPath,
15
+ showVersion
16
+ } from '../../util.js';
17
+
18
+ export default async options => {
19
+ showVersion();
20
+
21
+ const components = await getComponents();
22
+ const questions = await getPublishComponentQuestions();
23
+ const answers = await inquirer.prompt(questions);
24
+ const {sourceMap, devBuild } = answers;
25
+
26
+ let content = {
27
+ ...answers
28
+ };
29
+
30
+ var componentKey;
31
+
32
+ const tasks = new Listr(
33
+ [
34
+ {
35
+ title: 'Validate config schema',
36
+ task: async () => {
37
+ await validate(componentKey);
38
+ }
39
+ },
40
+ {
41
+ title: 'Bundle Component',
42
+ task: async () => await bundleComponent(componentKey, sourceMap, devBuild),
43
+ skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
44
+ },
45
+ {
46
+ title: 'Lint component',
47
+ task: async () => {
48
+ const targetDirectory = await getComponentDirectoryPath(componentKey);
49
+ // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
50
+ await lintComponent(targetDirectory);
51
+ }
52
+ },
53
+ {
54
+ title: 'Zip Component',
55
+ task: async () => {
56
+ const output = await zipComponent(componentKey);
57
+ content = { ...content, ...output };
58
+ }
59
+ },
60
+ {
61
+ title: 'Publish Component',
62
+ task: async () => {
63
+ await publishComponentToServer(content);
64
+ }
65
+ }
66
+ ],
67
+ {
68
+ exitOnError: true
69
+ }
70
+ );
71
+
72
+ for (var index in components) {
73
+ componentKey = components[index];
74
+ console.log(chalk.bold.green("Publishing: " + componentKey));
75
+ await tasks.run().catch(err => {
76
+ console.log(chalk.bold.red(err.toString()));
77
+ });
78
+ }
79
+
80
+ // await tasks.run().catch(err => {
81
+ // console.log(chalk.bold.red(err.toString()));
82
+ // });
83
+ return true;
84
+ };
package/src/util.js CHANGED
@@ -7,6 +7,8 @@ import chalk from 'chalk';
7
7
  import mustache from 'mustache';
8
8
  import pascalCase from 'pascalcase';
9
9
  import fetch from 'node-fetch';
10
+ import { createRequire } from 'module';
11
+
10
12
 
11
13
  import {
12
14
  COMPONENTS_DIRECTORY_PATH,
@@ -218,6 +220,14 @@ export const validateRulesetVersion = str => {
218
220
  return regex.test(str);
219
221
  };
220
222
 
223
+ export const showVersion = () => {
224
+ // get package version, so can display at start
225
+ const require = createRequire(import.meta.url);
226
+ const pData = require("@pega/custom-dx-components/package.json");
227
+
228
+ console.log(chalk.green("DX Component Builder v" + pData.version));
229
+ }
230
+
221
231
  export const getOOTBComponents = async () => {
222
232
  return new Promise((resolve, reject) => {
223
233
  fs.readFile(OOTB_COMPONENTS, 'utf-8', async (err, data) => {
@@ -1,43 +0,0 @@
1
- import {EmailDisplay, PhoneDisplay, URLDisplay } from "@pega/cosmos-react-core";
2
-
3
- export const formatExists = (formatterVal) => {
4
- const formatterValues = [
5
- "TextInput",
6
- "WorkStatus",
7
- "RichText",
8
- "Email",
9
- "Phone",
10
- "URL",
11
- "Operator"
12
- ];
13
- let isformatter = false;
14
- if (formatterValues.includes(formatterVal)) {
15
- isformatter = true;
16
- }
17
- return isformatter;
18
- };
19
-
20
-
21
- export const textFormatter = (formatter,value) => {
22
- let displayComponent = null;
23
- switch(formatter){
24
- case "TextInput" : {
25
- displayComponent = value;
26
- break;
27
- }
28
- case "Email" : {
29
- displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
30
- break;
31
- }
32
- case "Phone" : {
33
- displayComponent = (<PhoneDisplay value={value} variant="link" />);
34
- break;
35
- }
36
- case "URL" : {
37
- displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
38
- break;
39
- }
40
- // no default
41
- }
42
- return displayComponent;
43
- };
@@ -1,43 +0,0 @@
1
- import {EmailDisplay, PhoneDisplay, URLDisplay } from "@pega/cosmos-react-core";
2
-
3
- export const formatExists = (formatterVal) => {
4
- const formatterValues = [
5
- "TextInput",
6
- "WorkStatus",
7
- "RichText",
8
- "Email",
9
- "Phone",
10
- "URL",
11
- "Operator"
12
- ];
13
- let isformatter = false;
14
- if (formatterValues.includes(formatterVal)) {
15
- isformatter = true;
16
- }
17
- return isformatter;
18
- };
19
-
20
-
21
- export const textFormatter = (formatter,value) => {
22
- let displayComponent = null;
23
- switch(formatter){
24
- case "TextInput" : {
25
- displayComponent = value;
26
- break;
27
- }
28
- case "Email" : {
29
- displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
30
- break;
31
- }
32
- case "Phone" : {
33
- displayComponent = (<PhoneDisplay value={value} variant="link" />);
34
- break;
35
- }
36
- case "URL" : {
37
- displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
38
- break;
39
- }
40
- // no default
41
- }
42
- return displayComponent;
43
- };
@@ -1,43 +0,0 @@
1
- import {EmailDisplay, PhoneDisplay, URLDisplay } from "@pega/cosmos-react-core";
2
-
3
- export const formatExists = (formatterVal) => {
4
- const formatterValues = [
5
- "TextInput",
6
- "WorkStatus",
7
- "RichText",
8
- "Email",
9
- "Phone",
10
- "URL",
11
- "Operator"
12
- ];
13
- let isformatter = false;
14
- if (formatterValues.includes(formatterVal)) {
15
- isformatter = true;
16
- }
17
- return isformatter;
18
- };
19
-
20
-
21
- export const textFormatter = (formatter,value) => {
22
- let displayComponent = null;
23
- switch(formatter){
24
- case "TextInput" : {
25
- displayComponent = value;
26
- break;
27
- }
28
- case "Email" : {
29
- displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
30
- break;
31
- }
32
- case "Phone" : {
33
- displayComponent = (<PhoneDisplay value={value} variant="link" />);
34
- break;
35
- }
36
- case "URL" : {
37
- displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
38
- break;
39
- }
40
- // no default
41
- }
42
- return displayComponent;
43
- };
@@ -1,43 +0,0 @@
1
- import {EmailDisplay, PhoneDisplay, URLDisplay } from "@pega/cosmos-react-core";
2
-
3
- export const formatExists = (formatterVal) => {
4
- const formatterValues = [
5
- "TextInput",
6
- "WorkStatus",
7
- "RichText",
8
- "Email",
9
- "Phone",
10
- "URL",
11
- "Operator"
12
- ];
13
- let isformatter = false;
14
- if (formatterValues.includes(formatterVal)) {
15
- isformatter = true;
16
- }
17
- return isformatter;
18
- };
19
-
20
-
21
- export const textFormatter = (formatter,value) => {
22
- let displayComponent = null;
23
- switch(formatter){
24
- case "TextInput" : {
25
- displayComponent = value;
26
- break;
27
- }
28
- case "Email" : {
29
- displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
30
- break;
31
- }
32
- case "Phone" : {
33
- displayComponent = (<PhoneDisplay value={value} variant="link" />);
34
- break;
35
- }
36
- case "URL" : {
37
- displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
38
- break;
39
- }
40
- // no default
41
- }
42
- return displayComponent;
43
- };
@@ -1,43 +0,0 @@
1
- import {EmailDisplay, PhoneDisplay, URLDisplay } from "@pega/cosmos-react-core";
2
-
3
- export const formatExists = (formatterVal) => {
4
- const formatterValues = [
5
- "TextInput",
6
- "WorkStatus",
7
- "RichText",
8
- "Email",
9
- "Phone",
10
- "URL",
11
- "Operator"
12
- ];
13
- let isformatter = false;
14
- if (formatterValues.includes(formatterVal)) {
15
- isformatter = true;
16
- }
17
- return isformatter;
18
- };
19
-
20
-
21
- export const textFormatter = (formatter,value) => {
22
- let displayComponent = null;
23
- switch(formatter){
24
- case "TextInput" : {
25
- displayComponent = value;
26
- break;
27
- }
28
- case "Email" : {
29
- displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
30
- break;
31
- }
32
- case "Phone" : {
33
- displayComponent = (<PhoneDisplay value={value} variant="link" />);
34
- break;
35
- }
36
- case "URL" : {
37
- displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
38
- break;
39
- }
40
- // no default
41
- }
42
- return displayComponent;
43
- };