@pega/custom-dx-components 0.24.16 → 0.242.2

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 (33) hide show
  1. package/package.json +2 -1
  2. package/src/cli.js +32 -2
  3. package/src/constants.js +9 -0
  4. package/src/tasks/authenticate/index.js +12 -1
  5. package/src/tasks/build-lib/helper.js +71 -0
  6. package/src/tasks/build-lib/index.js +165 -0
  7. package/src/tasks/create/index.js +59 -6
  8. package/src/tasks/create/templates/Constellation/Field/Icon-Button-URL/index.tsx.mustache +1 -0
  9. package/src/tasks/create/templates/Constellation/Template/DETAILS/HighlightRender.tsx.mustache +1 -1
  10. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/HighlightRender.tsx.mustache +1 -1
  11. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.tsx.mustache +1 -0
  12. package/src/tasks/create/templates/Launchpad/Field/Icon-Button-URL/index.tsx.mustache +1 -0
  13. package/src/tasks/create/templates/Launchpad/Widget/PAGE/index.tsx.mustache +1 -0
  14. package/src/tasks/create-all/index.js +57 -6
  15. package/src/tasks/delete/index.js +8 -2
  16. package/src/tasks/delete-all/index.js +8 -2
  17. package/src/tasks/delete-lib/helper.js +75 -0
  18. package/src/tasks/delete-lib/index.js +97 -0
  19. package/src/tasks/index.js +5 -0
  20. package/src/tasks/init/template/package.json.mustache +32 -9
  21. package/src/tasks/init/template/tasks.config.json +3 -2
  22. package/src/tasks/list/index.js +9 -3
  23. package/src/tasks/list-lib/helper.js +72 -0
  24. package/src/tasks/list-lib/index.js +75 -0
  25. package/src/tasks/promote-webpack/index.js +8 -1
  26. package/src/tasks/promote-webpack/webpack.config.js +26 -0
  27. package/src/tasks/publish/index.js +8 -1
  28. package/src/tasks/publish-all/index.js +8 -1
  29. package/src/tasks/publish-lib/helper.js +53 -0
  30. package/src/tasks/publish-lib/index.js +212 -0
  31. package/src/tasks/rename-lib/index.js +353 -0
  32. package/src/tasks/revert-webpack/index.js +8 -1
  33. package/src/util.js +201 -2
@@ -0,0 +1,53 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import chalk from 'chalk';
4
+
5
+ import {
6
+ getPegaServerConfig,
7
+ checkPathAccess,
8
+ getComponentDefaults
9
+ } from '../../util.js';
10
+ import { TASKS_CONFIG_JSON_FILENAME, COMPONENTS_DIRECTORY_PATH, COMPONENTS_PATH } from '../../constants.js';
11
+
12
+ const pegaConfigJsonPath = path.join(path.resolve(), TASKS_CONFIG_JSON_FILENAME);
13
+
14
+ export const getOrgLib = async () => {
15
+ const defaultPegaConfig = await getPegaServerConfig();
16
+
17
+ await checkPathAccess(pegaConfigJsonPath);
18
+
19
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
20
+ data = data && JSON.parse(data);
21
+
22
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
23
+ console.error(`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`);
24
+ process.exit(1);
25
+ }
26
+
27
+ const componentData = data[COMPONENTS_PATH];
28
+
29
+ let library;
30
+ ({ library } = componentData);
31
+ let { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
32
+
33
+ const componentDefaults = await getComponentDefaults();
34
+ componentDefaults.library = library;
35
+ componentDefaults.organization = organization;
36
+
37
+ return componentDefaults;
38
+ }
39
+
40
+
41
+
42
+ export const getLibraryVersionQuestion = async(libVersions) => {
43
+
44
+ return [
45
+ {
46
+ name: 'version',
47
+ type: 'rawlist',
48
+ message: 'Select library version to publish',
49
+ choices: libVersions
50
+ }
51
+ ];
52
+
53
+ }
@@ -0,0 +1,212 @@
1
+ import inquirer from 'inquirer';
2
+ import { Listr } from 'listr2';
3
+ import chalk from 'chalk';
4
+
5
+ import validate from '../validator/index.js';
6
+ import { lintComponent } from '../linter/index.js';
7
+ import { getComponentDirectoryPath, showVersion, getC11NB2STokenAndStaticServer, getLibraryVersions, getLibraryBased } from '../../util.js';
8
+
9
+ import { publishLib, listLibJSONResponse, deleteLibVersion } from '@pega/constellation-dx-components-build-utils/index.js';
10
+
11
+ import { getLibraryVersionQuestion, getOrgLib } from './helper.js';
12
+ ;
13
+
14
+ const isLibraryBased = await getLibraryBased();
15
+
16
+ export function getCustomTasks(componentKey, sourceMap, devBuild, options) {
17
+
18
+ const sDevBuild = devBuild ? '(dev build)' : '';
19
+ return new Listr(
20
+ [
21
+ {
22
+ title: 'Validate config schema',
23
+ task: async () => {
24
+ await validate(componentKey);
25
+ }
26
+ },
27
+ {
28
+ title: 'Lint component',
29
+ task: async () => {
30
+ const targetDirectory = await getComponentDirectoryPath(componentKey);
31
+ // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
32
+ await lintComponent(targetDirectory);
33
+ }
34
+ }
35
+
36
+ ],
37
+ { concurrent: false, exitOnError: true }
38
+ );
39
+
40
+
41
+ }
42
+
43
+ export const doesLibraryExist = async (libraryName, libraryVersion) => {
44
+
45
+ const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
46
+ const libList = await listLibJSONResponse(tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
47
+ const oList = JSON.parse(libList);
48
+
49
+ let libVersionExists = false;
50
+ let overrideExisting = false;
51
+ if (oList && Object.keys(oList).length !== 0 ) {
52
+ // need to parse data to find versions
53
+ let versionList = oList[libraryName];
54
+
55
+ if (versionList && versionList.includes(libraryVersion)) {
56
+ libVersionExists = true;
57
+ }
58
+ }
59
+
60
+ return libVersionExists;
61
+ }
62
+
63
+
64
+ export const publishNewLibraryAsync = async (libraryName, version, checkDeleted = false) => {
65
+
66
+ const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
67
+
68
+ if (checkDeleted ) {
69
+ console.log(chalk.yellow(`Verifying library has been deleted..`));
70
+ let libExists = await doesLibraryExist(libraryName, version);
71
+ let count = 0;
72
+ while (libExists) {
73
+ // keep checking until no longer exists
74
+ libExists = await doesLibraryExist(libraryName, version);
75
+ count ++;
76
+
77
+ if (count > 100) {
78
+ console.log(chalk.red.bold(`Library hasn't been deleted, can't proceed.`));
79
+ process.exit(1);
80
+ }
81
+ }
82
+
83
+ console.log(chalk.green(`Deleted..`));
84
+ }
85
+
86
+
87
+
88
+ console.log(chalk.green.bold(`Publishing Library ${libraryName}:${version} ... `));
89
+ publishLib(libraryName, version, tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
90
+
91
+ }
92
+
93
+
94
+ export default async (options) => {
95
+ if (!isLibraryBased) {
96
+ console.log(`Command only supported for ${chalk.bold.green('library based')} components.`)
97
+ process.exit();
98
+ }
99
+
100
+ showVersion();
101
+
102
+ let organization;
103
+ let library;
104
+ let version;
105
+ let devBuild;
106
+
107
+ let libraryName;
108
+
109
+
110
+ if (options.params.length >= 6) {
111
+ organization = options.params[3];
112
+ library = options.params[4];
113
+ version = options.params[5];
114
+ libraryName = organization.concat("_").concat(library);
115
+ }
116
+ else {
117
+
118
+ const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
119
+
120
+ if (tokenAndStaticServer.C11NB2S === undefined) {
121
+ console.log(chalk.redBright("Need to authenticate, missing services token.\nPublishing a library requires authentication to acquire a token to publish."));
122
+ process.exit(1);
123
+ }
124
+
125
+ const compDef = await getOrgLib();
126
+ organization = compDef.organization;
127
+ library = compDef.library;
128
+
129
+ libraryName = organization.concat("_").concat(library);
130
+
131
+ console.log(`\nLibrary ${chalk.bold.green(libraryName)} `)
132
+
133
+ const libVersions = await getLibraryVersions(libraryName);
134
+
135
+ if (libVersions.length > 0) {
136
+ const versionQuestions = await getLibraryVersionQuestion(libVersions);
137
+ const versionAnswers = await inquirer.prompt(versionQuestions);
138
+
139
+ ({version} = versionAnswers);
140
+
141
+ let okToPublish = true;
142
+ if (!version.includes("-dev")) {
143
+ okToPublish = false;
144
+ const publishAnswers = await inquirer.prompt([
145
+
146
+ {
147
+ name: 'confirmPublish',
148
+ type: 'confirm',
149
+ message: 'You are about to publish a PRODUCTION version which can NOT be deleted, proceed ?',
150
+ default: false
151
+ }
152
+ ]);
153
+ if (publishAnswers.confirmPublish) {
154
+ okToPublish = true;
155
+ }
156
+ }
157
+
158
+ if (okToPublish) {
159
+
160
+ let libVersionExists = await doesLibraryExist(libraryName, version);
161
+ let overrideExisting = false;
162
+ let checkDeleted = false;
163
+
164
+ if (libVersionExists) {
165
+ console.log("\nLibrary " + chalk.bold.yellow(`${libraryName}:${version}`) + " already exists.");
166
+ const questions = [
167
+ {
168
+ name: 'override',
169
+ type: 'confirm',
170
+ message: `Do you wish to overrite it`,
171
+ default: false
172
+ }
173
+ ];
174
+
175
+ await inquirer.prompt(questions).then(async answers => {
176
+ overrideExisting = answers.override;
177
+ });
178
+ }
179
+
180
+
181
+
182
+ if (libVersionExists) {
183
+ if (overrideExisting) {
184
+ console.log("\nDeleting existing library " + chalk.bold.yellow(`${libraryName}:${version}`) + " ...");
185
+ await deleteLibVersion(libraryName, version, tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
186
+
187
+ checkDeleted = true;
188
+ }
189
+ else {
190
+ // don't override, so end
191
+ console.log(chalk.yellow(`You will need to increment your library version to publish`));
192
+ return;
193
+ }
194
+ }
195
+
196
+ // need a timeout to give services time to delete the library
197
+ setTimeout( function(){ publishNewLibraryAsync(libraryName, version, checkDeleted)}, 700 );
198
+
199
+
200
+ }
201
+
202
+
203
+
204
+ }
205
+ else {
206
+ console.log(chalk.bold.redBright(`No library versions in ${libraryName}`));
207
+ }
208
+
209
+ }
210
+
211
+ return true;
212
+ };
@@ -0,0 +1,353 @@
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
+
10
+ import { checkPathAccess, showVersion, getComponentsObj, getDirectoryFiles, getPegaServerConfig, getLibraryBased, deleteLocalLibrary, getC11NB2STokenAndStaticServer, updateComponentDefaultLibrary, updateDefaultOrganization } from '../../util.js';
11
+ import { TASKS_CONFIG_JSON_FILENAME, COMPONENTS_DIRECTORY_PATH, COMPONENTS_PATH } from '../../constants.js';
12
+
13
+ import { buildLib } from '@pega/constellation-dx-components-build-utils/index.js';
14
+
15
+ export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
16
+ const currentDirectory = process.cwd();
17
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
18
+
19
+ const isLibraryBased = await getLibraryBased();
20
+
21
+
22
+ import {
23
+ convertIntoPascalCase,
24
+ getComponentDirectoryPath,
25
+ getPegaConfig,
26
+ getComponentDefaults,
27
+ getComponents,
28
+ sanitize
29
+ } from '../../util.js';
30
+ import { deleteLocalComponents } from '@pega/custom-dx-components/src/tasks/delete/helper.js';
31
+
32
+ const copy = promisify(ncp);
33
+
34
+
35
+ export const getOrgLib = async () => {
36
+ const defaultPegaConfig = await getPegaServerConfig();
37
+
38
+ await checkPathAccess(pegaConfigJsonPath);
39
+
40
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
41
+ data = data && JSON.parse(data);
42
+
43
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
44
+ console.error(`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`);
45
+ process.exit(1);
46
+ }
47
+
48
+ const componentData = data[COMPONENTS_PATH];
49
+
50
+ let library;
51
+ ({ library } = componentData);
52
+ let { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
53
+
54
+ const componentDefaults = await getComponentDefaults();
55
+ componentDefaults.library = library;
56
+ componentDefaults.organization = organization;
57
+
58
+ return componentDefaults;
59
+ }
60
+
61
+ export const updateConfig = async (
62
+ {
63
+ oldComponentKey,
64
+ newComponentKey,
65
+ library,
66
+ organization,
67
+ componentName,
68
+ componentLabel,
69
+ version,
70
+ description,
71
+ allowedApplications,
72
+ targetDirectory,
73
+ },
74
+ options,
75
+ onlyCompanion = false
76
+ ) => {
77
+
78
+ let configData = fs.readFileSync(join(targetDirectory, "/config.json"), { encoding: 'utf8' });
79
+ configData = configData && JSON.parse(configData);
80
+
81
+ configData.name = newComponentKey;
82
+ configData.label = componentLabel;
83
+ configData.organization = organization;
84
+ if (configData.componentKey) configData.componentKey = newComponentKey;
85
+ configData.library = library;
86
+ configData.version = version;
87
+ configData.description = (description != '') ? description : componentLabel;
88
+
89
+ configData.allowedApplications = allowedApplications;
90
+
91
+ // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
92
+ fs.writeFileSync(join(targetDirectory, "/config.json"), JSON.stringify(configData, null, 4), { encoding: 'utf8' });
93
+
94
+ };
95
+
96
+ export const updateFile = async (
97
+ fileName,
98
+ oldComponentKeyPC,
99
+ newComponentKeyPC,
100
+ targetDirectory,
101
+ ) => {
102
+
103
+ let fileData = fs.readFileSync(join(targetDirectory, "/", fileName), { encoding: 'utf8' });
104
+
105
+ if (fileData.indexOf(oldComponentKeyPC) >= 0) {
106
+ fileData = fileData.replaceAll(oldComponentKeyPC, newComponentKeyPC);
107
+
108
+ fs.writeFileSync(join(targetDirectory, "/", fileName), fileData, { encoding: 'utf8' });
109
+ }
110
+
111
+ };
112
+
113
+ export const renameLibrary = async ({library, organization}, options) => {
114
+
115
+ const compDef = await getOrgLib();
116
+ const currentOrganization = compDef.organization;
117
+ const currentLibrary = compDef.library;
118
+ const currentVersion = compDef.version;
119
+
120
+ let compVersion;
121
+
122
+ const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
123
+
124
+ if (tokenAndStaticServer.C11NB2S === undefined) {
125
+ console.log(chalk.redBright("Need to authenticate, missing services token.\nBuilding a library requires authentication to acquire a token to build."));
126
+ process.exit(1);
127
+
128
+ }
129
+
130
+ const currentOrgLib = currentOrganization.concat("_").concat(currentLibrary);
131
+ const newOrgLib = organization.concat("_").concat(library);
132
+
133
+ // reaname all the components
134
+ const components = await getComponents();
135
+ for (const index in components) {
136
+ const componentKey = components[index];
137
+ const componentName = componentKey.split('_')[2];
138
+ const currentDirectory = await getComponentDirectoryPath(componentKey);
139
+
140
+ let configData = fs.readFileSync(join(currentDirectory, "/config.json"), { encoding: 'utf8' });
141
+ configData = configData && JSON.parse(configData);
142
+
143
+ const componentLabel = configData.label.substring(0, configData.label.indexOf("(")).concat(`(${newOrgLib})`);
144
+ const description = configData.description.substring(0, configData.description.indexOf("(")).concat(`(${newOrgLib})`);
145
+ const version = configData.version;
146
+ compVersion = version;
147
+ const allowedApplications = configData.allowedApplications;
148
+
149
+ await renameComponent({library, organization, componentKey, componentName, componentLabel,
150
+ version, description, allowedApplications}, options);
151
+
152
+
153
+
154
+ }
155
+
156
+
157
+ // delete and rebuild library
158
+ try {
159
+ await deleteLocalLibrary(currentOrgLib);
160
+ }
161
+ catch (ex) {}
162
+
163
+
164
+ // update config
165
+ await updateComponentDefaultLibrary(library);
166
+ await updateDefaultOrganization(organization);
167
+
168
+ // call constellation-dx-components-build-utils build library, which will create a directory of the "buildLibName"
169
+ // with subdirectories for each version.
170
+ // If "buildDev", we append to version "-dev". Currently, only "-dev" versions, when published, can be deleted.
171
+ buildLib(newOrgLib, compVersion, tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
172
+
173
+
174
+
175
+
176
+ }
177
+
178
+
179
+ export const renameComponent = async (
180
+ {
181
+ library,
182
+ organization,
183
+ componentKey,
184
+ componentName,
185
+ componentLabel,
186
+ version,
187
+ description,
188
+ allowedApplications
189
+ },
190
+ options,
191
+ onlyCompanion = false
192
+ ) => {
193
+
194
+
195
+ let pegaConfig = await getPegaConfig();
196
+
197
+ const newComponentKey = `${organization}_${library}_${componentName}`;
198
+
199
+ const oldComponentKey = componentKey;
200
+ const newComponentKeyPC = convertIntoPascalCase(newComponentKey);
201
+ const oldComponentKeyPC = convertIntoPascalCase(oldComponentKey);
202
+
203
+ const currentDirectory = await getComponentDirectoryPath(componentKey);
204
+ const targetDirectory = await getComponentDirectoryPath(newComponentKey);
205
+
206
+
207
+
208
+
209
+ // custom component
210
+ try {
211
+ fs.renameSync(currentDirectory, targetDirectory);
212
+ } catch(err) {
213
+ console.log(err)
214
+ }
215
+
216
+ const targetFileList = await getDirectoryFiles(targetDirectory);
217
+
218
+ for (var fileIndex in targetFileList) {
219
+ const fileName = targetFileList[fileIndex];
220
+
221
+ if (fileName === "config.json") {
222
+ await updateConfig(
223
+ {
224
+ oldComponentKey,
225
+ newComponentKey,
226
+ componentName,
227
+ componentLabel,
228
+ library,
229
+ version,
230
+ description,
231
+ allowedApplications,
232
+ organization,
233
+ targetDirectory,
234
+ },
235
+ options
236
+ );
237
+ }
238
+ else {
239
+ await updateFile(
240
+ fileName,
241
+ oldComponentKeyPC,
242
+ newComponentKeyPC,
243
+ targetDirectory );
244
+
245
+ }
246
+
247
+ } // for
248
+
249
+
250
+ console.log(chalk.green(`Component ${oldComponentKey} renamed to ${newComponentKey}`));
251
+
252
+ };
253
+
254
+
255
+
256
+
257
+
258
+ export default async options => {
259
+ if (!isLibraryBased) {
260
+ console.log(`Command only supported for ${chalk.bold.green('library based')} components.`)
261
+ process.exit();
262
+ }
263
+
264
+ showVersion();
265
+
266
+ await checkPathAccess(pegaConfigJsonPath);
267
+
268
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
269
+ data = data && JSON.parse(data);
270
+
271
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
272
+ console.error(
273
+ `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
274
+ );
275
+ process.exit(1);
276
+ }
277
+
278
+ const componentData = data[COMPONENTS_PATH];
279
+
280
+ const { library } = componentData;
281
+ const { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
282
+
283
+ let componentDefaults = await getComponentDefaults();
284
+ componentDefaults.library = library;
285
+
286
+ const localComponents = await getComponentsObj();
287
+
288
+
289
+ if (options.params.length >= 11) {
290
+ const organization = options.params[6];
291
+ const library = options.params[8];
292
+
293
+
294
+ await renameLibrary(
295
+ {
296
+ library,
297
+ organization
298
+ },
299
+ options
300
+ );
301
+
302
+ }
303
+ else {
304
+ const questions = [
305
+ {
306
+ name: 'organization',
307
+ message: 'Enter new component organization',
308
+ default: organization,
309
+ validate: value => {
310
+ if (value) {
311
+ return true;
312
+ }
313
+ return 'Please provide value for organization';
314
+ }
315
+ },
316
+ {
317
+ name: 'library',
318
+ message: 'Enter new library name',
319
+ default: componentDefaults.library,
320
+ validate: value => {
321
+ /* value should not be empty
322
+ It should not have spaces
323
+ It should not start with a number
324
+ Only case-insensitive alphanumeric values are allowed
325
+ */
326
+ if (value && !/^\d/.test(value) && value === sanitize(value)) {
327
+ return true;
328
+ }
329
+ return 'Only alphanumeric values are allowed, starting with alphabets';
330
+ }
331
+ }
332
+ ];
333
+
334
+ await inquirer.prompt(questions).then(async answers => {
335
+ const {
336
+ organization,
337
+ library
338
+ } = answers;
339
+
340
+ await renameLibrary(
341
+ {
342
+ library,
343
+ organization
344
+ },
345
+ options
346
+ );
347
+
348
+ });
349
+ }
350
+
351
+
352
+
353
+ };
@@ -9,13 +9,15 @@ import { up } from 'inquirer/lib/utils/readline.js';
9
9
  import {
10
10
  convertIntoPascalCase,
11
11
  showVersion,
12
- updateUseWebPackPromotion
12
+ updateUseWebPackPromotion,
13
+ getLibraryBased
13
14
  } from '../../util.js';
14
15
  import {
15
16
  WEBPACK_CONFIG_JS_FILENAME,
16
17
  BUILDER_INDEX_FILE_PATH
17
18
  } from '../../constants.js';
18
19
 
20
+ const isLibraryBased = await getLibraryBased();
19
21
 
20
22
 
21
23
  export const renamePromotedWebPack = async () => {
@@ -42,6 +44,11 @@ export const renamePromotedWebPack = async () => {
42
44
 
43
45
 
44
46
  export default async options => {
47
+ if (isLibraryBased) {
48
+ console.log(`Command only supported for ${chalk.bold.green('non library based')} components.`)
49
+ process.exit();
50
+ }
51
+
45
52
  showVersion();
46
53
 
47
54
  await renamePromotedWebPack();