@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
package/src/util.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import fs from 'fs';
2
+ import path from 'path';
2
3
  import { join } from 'path';
3
4
  import { promisify } from 'util';
4
5
  import https from 'https';
@@ -20,7 +21,10 @@ import {
20
21
  DELETE_COMPONENT_SERVICE_REST_ENDPOINT,
21
22
  LP_DELETE_COMPONENT_SERVICE_REST_ENDPOINT,
22
23
  OOTB_COMPONENTS,
23
- USE_PROMOTED_WEB_PACK
24
+ USE_PROMOTED_WEB_PACK,
25
+ BOOTSTRAP_CONFIG,
26
+ LIBRARY_BASED,
27
+ SHARED_DIRECTORY
24
28
  } from './constants.js';
25
29
 
26
30
  const access = promisify(fs.access);
@@ -100,6 +104,21 @@ export const updateUseWebPackPromotion = async ( useValue = false ) => {
100
104
 
101
105
  }
102
106
 
107
+ export const getLibraryBased = async () => {
108
+ const currentDirectory = process.cwd();
109
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
110
+
111
+ await checkPathAccess(pegaConfigJsonPath);
112
+
113
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
114
+ data = JSON.parse(data);
115
+
116
+ if (data[LIBRARY_BASED]) {
117
+ return data[LIBRARY_BASED];
118
+ }
119
+ else return false;
120
+ }
121
+
103
122
  export const deleteLocalComponent = async componentKey => {
104
123
  const currentDirectory = process.cwd();
105
124
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
@@ -180,6 +199,39 @@ export const deleteServerComponent = async componentKey => {
180
199
  }
181
200
  };
182
201
 
202
+ export const copyFileToShared = async ( fileName, fileContents) => {
203
+ const currentDirectory = process.cwd();
204
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
205
+
206
+ await checkPathAccess(pegaConfigJsonPath);
207
+
208
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
209
+
210
+ data = JSON.parse(data);
211
+
212
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
213
+ console.error(
214
+ `${chalk.red.bold('ERROR')} Could not find components directory path in config.json`
215
+ );
216
+ process.exit(1);
217
+ }
218
+
219
+ const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH]);
220
+ const sharedDirectory = join(directory, SHARED_DIRECTORY);
221
+
222
+ // if shared doesn't exist, create it
223
+ if (!fs.existsSync(sharedDirectory)) {
224
+ fs.mkdirSync(sharedDirectory, { recursive: true });
225
+ }
226
+
227
+ const filePath = join(sharedDirectory, fileName);
228
+ if (!fs.existsSync(filePath)) {
229
+ fs.writeFileSync(filePath, fileContents);
230
+ }
231
+
232
+
233
+ };
234
+
183
235
  export const getComponents = async () => {
184
236
  const currentDirectory = process.cwd();
185
237
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
@@ -200,7 +252,7 @@ export const getComponents = async () => {
200
252
  const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH]);
201
253
  return fs
202
254
  .readdirSync(directory, { withFileTypes: true })
203
- .filter(dirent => dirent.isDirectory())
255
+ .filter(dirent => dirent.isDirectory() && dirent.name !== SHARED_DIRECTORY)
204
256
  .map(dirent => dirent.name);
205
257
  };
206
258
 
@@ -262,6 +314,45 @@ export const getComponentDefaults = async () => {
262
314
  return config.component;
263
315
  };
264
316
 
317
+ export const updateComponentDefaultLibrary = async (library) => {
318
+ const currentDirectory = process.cwd();
319
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
320
+
321
+ await checkPathAccess(pegaConfigJsonPath);
322
+
323
+ let config = await getPegaConfig();
324
+ let componentsDefault = config.component;
325
+ componentsDefault.library = library;
326
+
327
+
328
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(config, null, 4), { encoding: 'utf8' });
329
+
330
+ }
331
+
332
+ export const updateComponentDefaultVersion = async (version) => {
333
+ const currentDirectory = process.cwd();
334
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
335
+
336
+ await checkPathAccess(pegaConfigJsonPath);
337
+
338
+ let config = await getPegaConfig();
339
+ let componentsDefault = config.component;
340
+ componentsDefault.version = version;
341
+
342
+
343
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(config, null, 4), { encoding: 'utf8' });
344
+
345
+ }
346
+
347
+ export const updateDefaultOrganization = async (organization) => {
348
+ let packageData = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf-8'));
349
+
350
+ packageData.organization = organization;
351
+
352
+ fs.writeFileSync(path.resolve('package.json'), JSON.stringify(packageData, null, 4), { encoding: 'utf8' });
353
+
354
+ }
355
+
265
356
  export const getServerType = async () => {
266
357
  const defaultPegaServerConfig = await getPegaServerConfig();
267
358
  return defaultPegaServerConfig.serverType;
@@ -592,3 +683,111 @@ export const deleteLaunchpadServerComponent = async componentKey => {
592
683
  throw new Error(error);
593
684
  }
594
685
  };
686
+
687
+ export const getBootstrapConfig = async (restServerUrl, authorizationHeader) => {
688
+
689
+ const serverConfig = await getPegaServerConfig();
690
+
691
+ return fetch(`${restServerUrl}/${BOOTSTRAP_CONFIG}`, {
692
+ method: 'GET',
693
+ agent: getHttpsAgent(serverConfig),
694
+ headers: new Headers({
695
+ Authorization: authorizationHeader
696
+ })
697
+ }).then((response) => {
698
+ if (response.ok) {
699
+ return response.json();
700
+ }
701
+ throw Error('D_pxBootstrapConfig load failed.', { cause: response.status });
702
+ });
703
+ };
704
+
705
+ export const updateC11NB2SForInfinity = async () => {
706
+ const serverConfig = await getPegaServerConfig();
707
+ const { server } = serverConfig;
708
+ const OAuthData = fs.readFileSync(TOKEN_PATH, 'utf8');
709
+
710
+ if (OAuthData) {
711
+ const { access_token: accessToken, token_type: tokenType } = JSON.parse(OAuthData);
712
+
713
+ const bootstrapJSON = await getBootstrapConfig(server, `${tokenType} ${accessToken}`);
714
+
715
+ if (bootstrapJSON) {
716
+ const bootstrap = JSON.parse(bootstrapJSON.pyConfigJSON);
717
+
718
+ const objOauthData = JSON.parse(OAuthData);
719
+ objOauthData["C11NB2S"] = bootstrap.tokens.C11NB2S;
720
+ objOauthData["appStaticContentServer"] = bootstrap.serviceConfig.appStaticContentServer;
721
+
722
+ // write out file
723
+ fs.writeFileSync(TOKEN_PATH, JSON.stringify(objOauthData), { encoding: 'utf8' });
724
+ }
725
+
726
+ }
727
+ };
728
+
729
+ export const updateC11NB2SForLaunchpad = async () => {
730
+
731
+
732
+
733
+ };
734
+
735
+ export const getC11NB2STokenAndStaticServer = async () => {
736
+ const serverConfig = await getPegaServerConfig();
737
+ const { server } = serverConfig;
738
+ let OAuthData;
739
+ try {
740
+ OAuthData = fs.readFileSync(TOKEN_PATH, 'utf8');
741
+ }
742
+ catch (ex) {
743
+ return ({});
744
+ }
745
+
746
+ if (OAuthData) {
747
+ const { C11NB2S, appStaticContentServer } = JSON.parse(OAuthData)
748
+
749
+ if (C11NB2S) {
750
+ return ({ C11NB2S, appStaticContentServer});
751
+ }
752
+
753
+ }
754
+ return ({});
755
+ }
756
+
757
+ export const getLibraryVersions = async (libraryName) => {
758
+ const currentDirectory = process.cwd();
759
+
760
+ const directory = join(currentDirectory, libraryName);
761
+ return fs
762
+ .readdirSync(directory, { withFileTypes: true })
763
+ .filter(dirent => dirent.isDirectory())
764
+ .map(dirent => dirent.name);
765
+ };
766
+
767
+ export const deleteLocalLibrary = async (libraryName) => {
768
+ const currentDirectory = process.cwd();
769
+
770
+ const directory = join(currentDirectory, libraryName);
771
+ fs.rmSync(directory, { recursive: true }, err => {
772
+ if (err) {
773
+ throw err;
774
+ }
775
+ else {
776
+ console.log(`Library:${chalk.green.bold(libraryName)} is deleted from Local`);
777
+ }
778
+ });
779
+ }
780
+
781
+ export const deleteLocalLibraryVersion = async (libraryName, libraryVersion) => {
782
+ const currentDirectory = process.cwd();
783
+
784
+ const directory = join(currentDirectory, libraryName, libraryVersion);
785
+ fs.rmSync(directory, { recursive: true }, err => {
786
+ if (err) {
787
+ throw err;
788
+ }
789
+ else {
790
+ console.log(`Library version:${chalk.green.bold(libraryName)}:${chalk.green.bold(libraryVersion)} is deleted from Local`);
791
+ }
792
+ });
793
+ }