@pega/dx-component-builder-sdk 0.1.6 → 0.1.7

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.
@@ -10,7 +10,8 @@ import {
10
10
 
11
11
  import {
12
12
  COMPONENTS_DIRECTORY_PATH,
13
- DXCB_CONFIG_JSON_FILENAME
13
+ DXCB_CONFIG_JSON_FILENAME,
14
+ CATEGORY_CUSTOM
14
15
  } from '../../constants.js';
15
16
 
16
17
  export const SDK_LOCAL_COMPONENT_MAP_FILENAME = "sdk-local-component-map.js";
@@ -18,7 +19,7 @@ export const COMPONENT_PATH = "./src/components";
18
19
  export const IMPORT_END_TAG = "/*import end";
19
20
  export const MAP_END_TAG = "/*map end";
20
21
 
21
- export const updateComponentMap = async (componentKey, category = "custom") => {
22
+ export const updateComponentMap = async (componentKey, category = CATEGORY_CUSTOM) => {
22
23
 
23
24
  const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
24
25
  const pegaLocalComponentMapPath = path.join(path.resolve(), SDK_LOCAL_COMPONENT_MAP_FILENAME);
@@ -77,7 +78,7 @@ export const updateComponentMap = async (componentKey, category = "custom") => {
77
78
 
78
79
  };
79
80
 
80
- export const deleteFromComponentMap = async (componentKey, category = "custom") => {
81
+ export const deleteFromComponentMap = async (componentKey, category = CATEGORY_CUSTOM) => {
81
82
  const pegaLocalComponentMapPath = path.join(path.resolve(), SDK_LOCAL_COMPONENT_MAP_FILENAME);
82
83
  const categoryDirectory = join("/", category.toLowerCase());
83
84
  const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
@@ -10,15 +10,7 @@ import ncp from 'ncp';
10
10
  import chalk from 'chalk';
11
11
  import { updateComponentMap } from '../map/map.js';
12
12
 
13
- import { checkPathAccess, getTokenUrl, showVersion } from '../../util.js';
14
-
15
-
16
- export const DXCB_CONFIG_JSON_FILENAME = 'dxcb.config.json';
17
- export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
18
-
19
- const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
20
- const pegaConfigInternalJsonPath = path.join(path.resolve(), DXCB_CONFIG_INTERNAL_JSON_FILENAME);
21
-
13
+ import { checkPathAccess, getTokenUrl, showVersion, getDirectoryFiles } from '../../util.js';
22
14
  import {
23
15
  convertIntoPascalCase,
24
16
  compileMustacheTemplate,
@@ -28,7 +20,15 @@ import {
28
20
  sanitize,
29
21
  validateSemver
30
22
  } from '@pega/dx-component-builder-sdk/src/util.js';
31
- import { COMPONENT_SCHEMA } from '../../constants.js';
23
+ import { COMPONENT_SCHEMA, CATEGORY_OVERRIDE } from '../../constants.js';
24
+
25
+ export const DXCB_CONFIG_JSON_FILENAME = 'dxcb.config.json';
26
+ export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
27
+
28
+ const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
29
+ const pegaConfigInternalJsonPath = path.join(path.resolve(), DXCB_CONFIG_INTERNAL_JSON_FILENAME);
30
+
31
+
32
32
 
33
33
  const copy = promisify(ncp);
34
34
 
@@ -62,9 +62,9 @@ const validateCompile = async (
62
62
  componentKey = componentKey.split("/")[1];
63
63
  }
64
64
  const typeLC = type.toLowerCase();
65
- const targetDirectory = await getComponentDirectoryPath(join(typeLC, "/",componentKey), "override");
65
+ const targetDirectory = await getComponentDirectoryPath(join(typeLC, "/",componentKey), CATEGORY_OVERRIDE);
66
66
 
67
- const components = await getComponents(false, "override");
67
+ const components = await getComponents(false, CATEGORY_OVERRIDE);
68
68
  if (components.includes(componentKey)) {
69
69
  console.log(chalk.red(`${componentKey} component already exists in ${targetDirectory}`));
70
70
  return;
@@ -80,7 +80,7 @@ const validateCompile = async (
80
80
  console.log(chalk.green(`> Created ${componentKey} component in ${targetDirectory}`));
81
81
 
82
82
  const componentKeyWithType = join(type, componentKey);
83
- await updateComponentMap(componentKeyWithType, "override");
83
+ await updateComponentMap(componentKeyWithType, CATEGORY_OVERRIDE);
84
84
 
85
85
  console.log(chalk.green(`> Added ${componentKeyWithType} to map`));
86
86
 
@@ -13,12 +13,39 @@ import {
13
13
  getComponentsObj,
14
14
  getComponentsAndSubDirectory,
15
15
  getPegaServerConfig,
16
- validateRulesetVersion
16
+ validateRulesetVersion,
17
+ getOptionsCategory
17
18
  } from '../../util.js';
18
- import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
19
+ import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH, COMPONENT_SCHEMA, CATEGORY_CONSTELLATION, CATEGORY_CUSTOM } from '../../constants.js';
19
20
 
20
- export const getPublishComponentQuestions = async () => {
21
- const components = await getComponentsObj(true);
21
+
22
+ export const mapConfigJsonToCompanion = async ( componentKey ) => {
23
+ const srcDirectory = await getComponentDirectoryPath(componentKey, CATEGORY_CUSTOM);
24
+ const companionDirectory = await getComponentDirectoryPath(componentKey, CATEGORY_CONSTELLATION);
25
+ let configContent = fs.readFileSync(`${srcDirectory}/config.json`, { encoding: 'utf8' });
26
+
27
+ fs.writeFileSync(`${companionDirectory}/config.json`, configContent, { encoding: 'utf8' });
28
+
29
+ }
30
+
31
+ export const getBuildCategory = async (options) => {
32
+ const categoryType = getOptionsCategory(options);
33
+
34
+ return [
35
+ {
36
+ name: 'category',
37
+ type: 'rawlist',
38
+ message: 'Category of components ?',
39
+ choices: COMPONENT_SCHEMA.category,
40
+ when() {
41
+ return !options.params[4] && categoryType == null;
42
+ }
43
+ }
44
+ ];
45
+ };
46
+
47
+ export const getPublishComponentQuestions = async (category) => {
48
+ const components = await getComponentsObj(true, category);
22
49
  const defaultPegaConfig = await getPegaServerConfig();
23
50
 
24
51
  return [
@@ -64,24 +91,59 @@ export const getPublishComponentQuestions = async () => {
64
91
  ];
65
92
  };
66
93
 
67
- export const zipComponent = async componentKey => {
68
- const srcDirectory = await getComponentDirectoryPath(componentKey);
94
+ export const zipComponent = async (componentKey, category = CATEGORY_CUSTOM) => {
95
+ const srcDirectory = await getComponentDirectoryPath(componentKey, category);
69
96
  const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
70
97
  const configJson = `${srcDirectory}/config.json`;
98
+ const configExtJson = `${srcDirectory}/config-ext.json`;
71
99
 
72
100
  const zip = new AdmZip();
73
101
 
74
102
  zip.addLocalFolder(srcDirectory, 'src/');
75
- zip.addLocalFile(configJson);
103
+ if (category === CATEGORY_CUSTOM || category == CATEGORY_CONSTELLATION) {
104
+ zip.addLocalFile(configJson);
105
+ }
106
+ else {
107
+ // check to see if have file
108
+ if (fs.existsSync(configExtJson)) {
109
+ zip.addLocalFile(configExtJson);
110
+ }
111
+
112
+ }
113
+
76
114
  zip.addLocalFolder(buildDirectory);
77
115
  const zipContent = zip.toBuffer().toString('base64');
78
116
 
79
- const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
80
- fs.rmdir('dist', { recursive: true }, err => {
81
- if (err) {
82
- throw err;
117
+ let configContent = "{ }";
118
+ if (category === CATEGORY_CUSTOM || category === CATEGORY_CONSTELLATION) {
119
+ configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
120
+ fs.rmdir('dist', { recursive: true }, err => {
121
+ if (err) {
122
+ throw err;
123
+ }
124
+ });
125
+ }
126
+ else {
127
+ if (fs.existsSync(configExtJson)) {
128
+ configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config-ext.json`)).toString();
129
+ fs.rmdir('dist', { recursive: true }, err => {
130
+ if (err) {
131
+ throw err;
132
+ }
133
+ });
83
134
  }
84
- });
135
+ else {
136
+ const tempConfig = { "componentKey" : ""};
137
+ if (componentKey.indexOf("/") >= 0) {
138
+ componentKey = componentKey.split("/")[1];
139
+ }
140
+ tempConfig.componentKey = `${componentKey}`;
141
+
142
+ configContent = JSON.stringify(tempConfig);
143
+ }
144
+
145
+ }
146
+
85
147
  return { zipContent, configContent };
86
148
  };
87
149
 
@@ -127,7 +189,7 @@ export const publishComponentToServer = async data => {
127
189
  const respData = JSON.parse(resp);
128
190
  if (status === 401) {
129
191
  throw new Error(
130
- 'Error occured in authentication. Please regenerate using authenticate'
192
+ 'Error occurred in authentication. Please regenerate using authenticate'
131
193
  );
132
194
  // console.log(accessTokenUri, refreshToken);
133
195
  /* TODO - Handle refresh_token */
@@ -139,9 +201,9 @@ export const publishComponentToServer = async data => {
139
201
  })
140
202
  .catch(e => Promise.reject(`${chalk.bold.red(e)}`));
141
203
  } else {
142
- throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
204
+ throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
143
205
  }
144
206
  } catch (err) {
145
- throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
207
+ throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
146
208
  }
147
209
  };
@@ -3,17 +3,28 @@ import Listr from 'listr';
3
3
  import chalk from 'chalk';
4
4
 
5
5
  import validate from '../validator/index.js';
6
- import { getComponentDirectoryPath, showVersion } from '../../util.js';
6
+ import { getComponentDirectoryPath, showVersion, getOptionsCategory } from '../../util.js';
7
7
  import bundleComponent from '../bundle/index.js';
8
8
  import { updateComponentMap } from '../map/map.js';
9
9
  import { lintComponent } from '../linter/index.js';
10
+ import { CATEGORY_CONSTELLATION, CATEGORY_CUSTOM } from '../../constants.js';
11
+
12
+
13
+ import { getPublishComponentQuestions, publishComponentToServer, zipComponent, getBuildCategory, mapConfigJsonToCompanion } from './helper.js';
10
14
 
11
- import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
12
15
 
13
16
  export default async options => {
14
17
  showVersion();
15
18
 
16
- const questions = await getPublishComponentQuestions();
19
+ const catQuestion = await getBuildCategory(options);
20
+ const catAnwers = await inquirer.prompt(catQuestion);
21
+
22
+ let category = catAnwers.category;
23
+ if (category == null) {
24
+ category = getOptionsCategory(options);
25
+ }
26
+
27
+ const questions = await getPublishComponentQuestions(category);
17
28
  const answers = await inquirer.prompt(questions);
18
29
  const { componentKey, sourceMap, devBuild } = answers;
19
30
 
@@ -21,54 +32,131 @@ export default async options => {
21
32
  ...answers
22
33
  };
23
34
 
24
- const tasks = new Listr(
35
+ const customTasks = new Listr(
25
36
  [
37
+
26
38
  {
27
39
  title: 'Validate config schema',
28
40
  task: async () => {
29
- await validate(componentKey);
41
+ await validate(componentKey, category);
30
42
  }
31
43
  },
32
44
  {
33
45
  title: 'Lint component',
34
46
  task: async () => {
35
- const targetDirectory = await getComponentDirectoryPath(componentKey);
47
+ const targetDirectory = await getComponentDirectoryPath(componentKey, category);
36
48
  // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
37
49
  await lintComponent(targetDirectory);
38
50
  }
39
51
  },
40
52
  {
41
- title: 'Bundle Component',
42
- task: async () => await bundleComponent(componentKey, sourceMap, devBuild),
53
+ title: 'Bundle component',
54
+ task: async () => await bundleComponent(componentKey, sourceMap, devBuild, category),
43
55
  skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
44
56
  },
45
57
  {
46
- title: 'Update Component Map',
58
+ title: 'Update component map',
47
59
  task: async () => {
48
60
  await updateComponentMap(componentKey);
49
61
  }
50
62
  },
51
63
  {
52
- title: 'Zip Component',
64
+ title: 'Lint companion component',
65
+ task: async () => {
66
+ const targetDirectory = await getComponentDirectoryPath(componentKey, CATEGORY_CONSTELLATION);
67
+ // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
68
+ await lintComponent(targetDirectory);
69
+ }
70
+ },
71
+ {
72
+ title: 'Map config to companion component',
73
+ task: async () => {
74
+ mapConfigJsonToCompanion(componentKey);
75
+ }
76
+ },
77
+ {
78
+ title: 'Bundle companion component',
79
+ task: async () => await bundleComponent(componentKey, sourceMap, devBuild, CATEGORY_CONSTELLATION),
80
+ skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
81
+ },
82
+ {
83
+ title: 'Zip companion component',
84
+ task: async () => {
85
+ const output = await zipComponent(componentKey, CATEGORY_CONSTELLATION);
86
+ content = { ...content, ...output };
87
+ }
88
+ },
89
+ {
90
+ title: 'Publish companion component',
91
+ task: async () => {
92
+ await publishComponentToServer(content);
93
+ }
94
+ }
95
+ ],
96
+ {
97
+ exitOnError: true
98
+ }
99
+ );
100
+
101
+ const overrideTasks = new Listr(
102
+ [
103
+ {
104
+ title: 'Validate config schema',
105
+ task: async () => {
106
+ await validate(componentKey, category);
107
+ }
108
+ },
109
+ {
110
+ title: 'Lint component',
111
+ task: async () => {
112
+ const targetDirectory = await getComponentDirectoryPath(componentKey, category);
113
+ // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
114
+ await lintComponent(targetDirectory);
115
+ }
116
+ },
117
+ {
118
+ title: 'Bundle component',
119
+ task: async () => await bundleComponent(componentKey, sourceMap, devBuild, category),
120
+ skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
121
+ },
122
+ {
123
+ title: 'Update component map',
53
124
  task: async () => {
54
- const output = await zipComponent(componentKey);
125
+ await updateComponentMap(componentKey, category);
126
+ }
127
+ },
128
+ {
129
+ title: 'Zip component',
130
+ task: async () => {
131
+ const output = await zipComponent(componentKey, category);
55
132
  content = { ...content, ...output };
56
133
  }
57
134
  },
135
+ /*
58
136
  {
59
- title: 'Publish Component',
137
+ title: 'Publish component',
60
138
  task: async () => {
61
139
  await publishComponentToServer(content);
62
140
  }
63
141
  }
142
+ */
64
143
  ],
65
144
  {
66
145
  exitOnError: true
67
146
  }
68
147
  );
69
148
 
70
- await tasks.run().catch(err => {
71
- console.log(chalk.bold.red(err.toString()));
72
- });
149
+ if (category === CATEGORY_CUSTOM) {
150
+ await customTasks.run().catch(err => {
151
+ console.log(chalk.bold.red(err.toString()));
152
+ });
153
+ }
154
+ else {
155
+ await overrideTasks.run().catch(err => {
156
+ console.log(chalk.bold.red(err.toString()));
157
+ });
158
+
159
+ }
160
+
73
161
  return true;
74
162
  };
@@ -9,11 +9,40 @@ import chalk from 'chalk';
9
9
  import {
10
10
  constructCompleteUrl,
11
11
  getComponentDirectoryPath,
12
+ getComponents,
12
13
  getComponentsObj,
14
+ getComponentsAndSubDirectory,
13
15
  getPegaServerConfig,
14
- validateRulesetVersion
16
+ validateRulesetVersion,
17
+ getOptionsCategory
15
18
  } from '../../util.js';
16
- import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
19
+ import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH, COMPONENT_SCHEMA, CATEGORY_CONSTELLATION, CATEGORY_CUSTOM } from '../../constants.js';
20
+
21
+
22
+ export const mapConfigJsonToCompanion = async ( componentKey ) => {
23
+ const srcDirectory = await getComponentDirectoryPath(componentKey, CATEGORY_CUSTOM);
24
+ const companionDirectory = await getComponentDirectoryPath(componentKey, CATEGORY_CONSTELLATION);
25
+ let configContent = fs.readFileSync(`${srcDirectory}/config.json`, { encoding: 'utf8' });
26
+
27
+ fs.writeFileSync(`${companionDirectory}/config.json`, configContent, { encoding: 'utf8' });
28
+
29
+ }
30
+
31
+ export const getBuildCategory = async (options) => {
32
+ const categoryType = getOptionsCategory(options);
33
+
34
+ return [
35
+ {
36
+ name: 'category',
37
+ type: 'rawlist',
38
+ message: 'Category of components ?',
39
+ choices: COMPONENT_SCHEMA.category,
40
+ when() {
41
+ return !options.params[4] && categoryType == null;
42
+ }
43
+ }
44
+ ];
45
+ };
17
46
 
18
47
  export const getPublishComponentQuestions = async () => {
19
48
  const components = await getComponentsObj();
@@ -56,24 +85,59 @@ export const getPublishComponentQuestions = async () => {
56
85
  ];
57
86
  };
58
87
 
59
- export const zipComponent = async componentKey => {
60
- const srcDirectory = await getComponentDirectoryPath(componentKey);
88
+ export const zipComponent = async (componentKey, category = CATEGORY_CUSTOM) => {
89
+ const srcDirectory = await getComponentDirectoryPath(componentKey, category);
61
90
  const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
62
91
  const configJson = `${srcDirectory}/config.json`;
92
+ const configExtJson = `${srcDirectory}/config-ext.json`;
63
93
 
64
94
  const zip = new AdmZip();
65
95
 
66
96
  zip.addLocalFolder(srcDirectory, 'src/');
67
- zip.addLocalFile(configJson);
97
+ if (category === CATEGORY_CUSTOM || category == CATEGORY_CONSTELLATION) {
98
+ zip.addLocalFile(configJson);
99
+ }
100
+ else {
101
+ // check to see if have file
102
+ if (fs.existsSync(configExtJson)) {
103
+ zip.addLocalFile(configExtJson);
104
+ }
105
+
106
+ }
107
+
68
108
  zip.addLocalFolder(buildDirectory);
69
109
  const zipContent = zip.toBuffer().toString('base64');
70
110
 
71
- const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
72
- fs.rmdir('dist', { recursive: true }, err => {
73
- if (err) {
74
- throw err;
111
+ let configContent = "{ }";
112
+ if (category === CATEGORY_CUSTOM || category === CATEGORY_CONSTELLATION) {
113
+ configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
114
+ fs.rm('dist', { recursive: true }, err => {
115
+ if (err) {
116
+ throw err;
117
+ }
118
+ });
119
+ }
120
+ else {
121
+ if (fs.existsSync(configExtJson)) {
122
+ configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config-ext.json`)).toString();
123
+ fs.rm('dist', { recursive: true }, err => {
124
+ if (err) {
125
+ throw err;
126
+ }
127
+ });
75
128
  }
76
- });
129
+ else {
130
+ const tempConfig = { "componentKey" : ""};
131
+ if (componentKey.indexOf("/") >= 0) {
132
+ componentKey = componentKey.split("/")[1];
133
+ }
134
+ tempConfig.componentKey = `${componentKey}`;
135
+
136
+ configContent = JSON.stringify(tempConfig);
137
+ }
138
+
139
+ }
140
+
77
141
  return { zipContent, configContent };
78
142
  };
79
143
 
@@ -119,7 +183,7 @@ export const publishComponentToServer = async data => {
119
183
  const respData = JSON.parse(resp);
120
184
  if (status === 401) {
121
185
  throw new Error(
122
- 'Error occured in authentication. Please regenerate using authenticate'
186
+ 'Error occurred in authentication. Please regenerate using authenticate'
123
187
  );
124
188
  // console.log(accessTokenUri, refreshToken);
125
189
  /* TODO - Handle refresh_token */
@@ -131,9 +195,9 @@ export const publishComponentToServer = async data => {
131
195
  })
132
196
  .catch(e => Promise.reject(`${chalk.bold.red(e)}`));
133
197
  } else {
134
- throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
198
+ throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
135
199
  }
136
200
  } catch (err) {
137
- throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
201
+ throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
138
202
  }
139
203
  };