@pega/custom-dx-components 0.242.26 → 0.242.28

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 (46) hide show
  1. package/package.json +2 -1
  2. package/src/cli.js +44 -2
  3. package/src/constants.js +2 -0
  4. package/src/tasks/build-all/helper.js +1 -1
  5. package/src/tasks/build-all/index.js +17 -3
  6. package/src/tasks/build-comp/helper.js +7 -4
  7. package/src/tasks/build-comp/index.js +15 -2
  8. package/src/tasks/build-jest-assets/index.js +1 -1
  9. package/src/tasks/build-lib/helper.js +2 -34
  10. package/src/tasks/build-lib/index.js +36 -85
  11. package/src/tasks/create/index.js +31 -19
  12. package/src/tasks/create-all/index.js +31 -16
  13. package/src/tasks/create-lib/helper.js +80 -0
  14. package/src/tasks/create-lib/index.js +109 -0
  15. package/src/tasks/create-version/helper.js +81 -0
  16. package/src/tasks/create-version/index.js +108 -0
  17. package/src/tasks/delete/index.js +7 -4
  18. package/src/tasks/delete-all/index.js +14 -9
  19. package/src/tasks/delete-lib/helper.js +19 -46
  20. package/src/tasks/delete-lib/index.js +107 -49
  21. package/src/tasks/delete-pub/helper.js +35 -0
  22. package/src/tasks/delete-pub/index.js +105 -0
  23. package/src/tasks/index.js +7 -0
  24. package/src/tasks/init/helper.js +5 -5
  25. package/src/tasks/init/template/package.json.mustache +15 -7
  26. package/src/tasks/list/helper.js +29 -8
  27. package/src/tasks/list/index.js +4 -9
  28. package/src/tasks/list-lib/helper.js +18 -53
  29. package/src/tasks/list-lib/index.js +68 -110
  30. package/src/tasks/list-pub/helper.js +42 -0
  31. package/src/tasks/list-pub/index.js +170 -0
  32. package/src/tasks/promote-webpack/index.js +1 -1
  33. package/src/tasks/publish/helper.js +44 -44
  34. package/src/tasks/publish/index.js +70 -5
  35. package/src/tasks/publish-all/index.js +10 -2
  36. package/src/tasks/publish-lib/helper.js +0 -38
  37. package/src/tasks/publish-lib/index.js +39 -13
  38. package/src/tasks/rename/index.js +25 -10
  39. package/src/tasks/rename-lib/index.js +8 -41
  40. package/src/tasks/revert-webpack/index.js +1 -1
  41. package/src/tasks/show-status/index.js +41 -0
  42. package/src/tasks/switch-lib/helper.js +81 -0
  43. package/src/tasks/switch-lib/index.js +134 -0
  44. package/src/tasks/switch-version/helper.js +92 -0
  45. package/src/tasks/switch-version/index.js +142 -0
  46. package/src/util.js +730 -61
@@ -5,7 +5,7 @@ import chalk from 'chalk';
5
5
  import validate from '../validator/index.js';
6
6
  import bundleComponent from '../bundle/index.js';
7
7
  import { lintComponent } from '../linter/index.js';
8
- import { getComponents, getComponentDirectoryPath, showVersion, getLibraryBased, addDebugLog } from '../../util.js';
8
+ import { getComponents, getComponentDirectoryPath, showVersion, getLibraryBased, addDebugLog, getPegaServerConfig, updateServerConfigRuleSetAndVersion, checkLibraryAndArchives } from '../../util.js';
9
9
 
10
10
  import {
11
11
  getPublishComponentQuestions,
@@ -14,7 +14,7 @@ import {
14
14
  cleanUp
15
15
  } from './helper.js';
16
16
 
17
- const isLibraryBased = await getLibraryBased();
17
+ const isLibraryBased = getLibraryBased();
18
18
 
19
19
  export function getCustomTasks(componentKey, sourceMap, devBuild, content, options) {
20
20
  addDebugLog("getCustomTasks", `componentKey: ${componentKey}, sourceMap: ${sourceMap}, devBuild: ${devBuild}`, "");
@@ -70,10 +70,12 @@ export default async options => {
70
70
  }
71
71
 
72
72
  await showVersion();
73
+ await checkLibraryAndArchives();
73
74
 
74
75
  addDebugLog("publishAll", "", "+");
75
76
 
76
77
  const components = await getComponents();
78
+ const defaultPegaConfig = await getPegaServerConfig();
77
79
 
78
80
  if (components.length === 0) {
79
81
  console.log(chalk.redBright('No components to publish'));
@@ -102,6 +104,11 @@ addDebugLog("publishAll", "", "+");
102
104
  };
103
105
  }
104
106
 
107
+ // update ruleset and version config for future
108
+ if (defaultPegaConfig.serverType === "infinity") {
109
+ updateServerConfigRuleSetAndVersion(content.rulesetName, content.rulesetVersion);
110
+ }
111
+
105
112
  // eslint-disable-next-line no-shadow
106
113
  for await (const componentKey of components) {
107
114
  console.log(chalk.bold.green(`Publishing: ${componentKey}`));
@@ -119,6 +126,7 @@ addDebugLog("publishAll", "", "+");
119
126
  // once done, remove leftover directories
120
127
  await cleanUp();
121
128
 
129
+
122
130
  addDebugLog("publishAll", "END", "-");
123
131
 
124
132
  return true;
@@ -1,44 +1,6 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import chalk from 'chalk';
4
-
5
1
  import {
6
- getPegaServerConfig,
7
- checkPathAccess,
8
- getComponentDefaults,
9
2
  addDebugLog
10
3
  } from '../../util.js';
11
- import { TASKS_CONFIG_JSON_FILENAME, COMPONENTS_DIRECTORY_PATH, COMPONENTS_PATH } from '../../constants.js';
12
-
13
- const pegaConfigJsonPath = path.join(path.resolve(), TASKS_CONFIG_JSON_FILENAME);
14
-
15
- export const getOrgLib = async () => {
16
- addDebugLog("getOrgLib", "", "");
17
- const defaultPegaConfig = await getPegaServerConfig();
18
-
19
- await checkPathAccess(pegaConfigJsonPath);
20
-
21
- let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
22
- data = data && JSON.parse(data);
23
-
24
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
25
- console.error(`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`);
26
- process.exit(1);
27
- }
28
-
29
- const componentData = data[COMPONENTS_PATH];
30
-
31
- let library;
32
- ({ library } = componentData);
33
- let { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
34
-
35
- const componentDefaults = await getComponentDefaults();
36
- componentDefaults.library = library;
37
- componentDefaults.organization = organization;
38
-
39
- return componentDefaults;
40
- }
41
-
42
4
 
43
5
 
44
6
  export const getLibraryVersionQuestion = async(libVersions) => {
@@ -4,14 +4,14 @@ import chalk from 'chalk';
4
4
 
5
5
  import validate from '../validator/index.js';
6
6
  import { lintComponent } from '../linter/index.js';
7
- import { getComponentDirectoryPath, showVersion, getC11NB2STokenAndStaticServer, getLocalLibraryVersions, getLibraryBased, deletePublishExtras, addDebugLog } from '../../util.js';
7
+ import { getComponentDirectoryPath, showVersion, getC11NB2STokenAndStaticServer, getLocalLibraryVersions, getLibraryBased, deletePublishExtras, addDebugLog, checkLibraryAndArchives, checkJWTExpiration, getConfigDefaults } from '../../util.js';
8
8
 
9
9
  import { publishLib, listLibJSONResponse, deleteLibVersion } from '@pega/constellation-dx-components-build-utils/index.js';
10
10
 
11
- import { getLibraryVersionQuestion, getOrgLib } from './helper.js';
11
+ import { getLibraryVersionQuestion } from './helper.js';
12
12
 
13
13
 
14
- const isLibraryBased = await getLibraryBased();
14
+ const isLibraryBased = getLibraryBased();
15
15
 
16
16
  export function getCustomTasks(componentKey, sourceMap, devBuild, options) {
17
17
  addDebugLog("getCustomTasks", `componentKey: ${componentKey}, sourceMap: ${sourceMap}, devBuild: ${devBuild}`, "");
@@ -48,7 +48,6 @@ addDebugLog("doesLibraryExist", `libraryName: ${libraryName}, libraryVersion: ${
48
48
  const libList = await listLibJSONResponse(tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
49
49
 
50
50
  let libVersionExists = false;
51
- let overrideExisting = false;
52
51
  if (libList && libList[libraryName] && libList[libraryName][libraryVersion]) {
53
52
  libVersionExists = true;
54
53
  }
@@ -80,7 +79,7 @@ addDebugLog("publishNewLibraryAsync", `libraryName: ${libraryName}, version: ${v
80
79
  console.log(chalk.green(`Deleted..`));
81
80
  }
82
81
 
83
- console.log("\nPublishing Library " + chalk.bold.green(`${libraryName}:${version}`) + " to " + chalk.bold.green(`${tokenAndStaticServer.appStaticContentServer}`));
82
+ console.log("\nPublishing Library " + chalk.bold.green(`${libraryName}/${version}`) + " to " + chalk.bold.green(`${tokenAndStaticServer.appStaticContentServer}`));
84
83
  addDebugLog("publishLib", "services call", "");
85
84
  await publishLib(libraryName, version, tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
86
85
  addDebugLog("deleteLib", "services end", "");
@@ -94,7 +93,12 @@ export default async (options) => {
94
93
  process.exit();
95
94
  }
96
95
 
97
- await showVersion();
96
+ if (options.params.length != 4) {
97
+ // internal so already called
98
+ await showVersion();
99
+ await checkLibraryAndArchives();
100
+ await checkJWTExpiration();
101
+ }
98
102
 
99
103
  addDebugLog("publishLibrary", "", "+");
100
104
 
@@ -102,6 +106,7 @@ addDebugLog("publishLibrary", "", "+");
102
106
  let library;
103
107
  let version;
104
108
  let devBuild;
109
+ let internalPublish = false;
105
110
 
106
111
  let libraryName;
107
112
  let noRealPublish = false;
@@ -116,6 +121,25 @@ addDebugLog("publishLibrary", "", "+");
116
121
  version = options.params[4];
117
122
  noRealPublish = true;
118
123
  }
124
+ else if (options.params.length === 4) {
125
+ // internal call from publish
126
+ internalPublish = true;
127
+ const orgLib = getConfigDefaults();
128
+ library = orgLib.library;
129
+ organization = orgLib.organization;
130
+ // libraryName = `${organization}_${library}`;
131
+ libraryName = orgLib.currentOrgLib;
132
+
133
+ version = orgLib.buildVersion;
134
+
135
+ // check to see if devBuild
136
+ // const devBuild = await getConfigDevBuild();
137
+ // const devBuild = orgLib.devBuild;
138
+ // if (devBuild) {
139
+ // version = version.concat("-dev");
140
+ // }
141
+
142
+ }
119
143
 
120
144
  const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
121
145
 
@@ -126,14 +150,12 @@ addDebugLog("publishLibrary", "", "+");
126
150
 
127
151
  let libVersions = [];
128
152
  if (!libraryName) {
129
- const compDef = await getOrgLib();
153
+ const compDef = getConfigDefaults();
130
154
  organization = compDef.organization;
131
155
  library = compDef.library;
132
156
 
133
- libraryName = organization.concat("_").concat(library);
134
-
135
- console.log(`\nLibrary ${chalk.bold.green(libraryName)} `)
136
-
157
+ // libraryName = `${organization}_${library}`;
158
+ libraryName = compDef.currentOrgLib;
137
159
 
138
160
  try {
139
161
  libVersions = await getLocalLibraryVersions(libraryName);
@@ -141,6 +163,8 @@ addDebugLog("publishLibrary", "", "+");
141
163
  catch (ex) {}
142
164
  }
143
165
 
166
+ console.log(`\nPreparing to publish ${chalk.bold.green(`${libraryName}/${version}`)} `)
167
+
144
168
  if (libVersions.length > 0 || version) {
145
169
 
146
170
  if (!version) {
@@ -160,7 +184,7 @@ addDebugLog("publishLibrary", "", "+");
160
184
  return;
161
185
  }
162
186
 
163
- if (!version.includes("-dev")) {
187
+ if (!version.includes("-dev") && !internalPublish) {
164
188
  okToPublish = false;
165
189
  const publishAnswers = await inquirer.prompt([
166
190
 
@@ -192,7 +216,7 @@ addDebugLog("publishLibrary", "", "+");
192
216
 
193
217
 
194
218
  if (libVersionExists) {
195
- console.log("\nLibrary " + chalk.bold.yellow(`${libraryName}:${version}`) + " already exists.");
219
+ console.log("\nLibrary " + chalk.bold.yellow(`${libraryName}/${version}`) + " already exists.");
196
220
  const questions = [
197
221
  {
198
222
  name: 'override',
@@ -234,6 +258,8 @@ addDebugLog("publishLibrary", "END", "-");
234
258
  console.log(chalk.bold.redBright(`You need to build library ${libraryName} first.`));
235
259
  }
236
260
 
261
+
262
+
237
263
  addDebugLog("publishLibrary", "END", "-");
238
264
 
239
265
  return true;
@@ -7,7 +7,7 @@ import inquirer from 'inquirer';
7
7
  import ncp from 'ncp';
8
8
  import chalk from 'chalk';
9
9
 
10
- import { checkPathAccess, showVersion, getComponentsObj, getDirectoryFiles, addDebugLog } from '../../util.js';
10
+ import { checkPathAccess, showVersion, getComponentsObj, getDirectoryFiles, addDebugLog, checkLibraryAndArchives, getConfigDefaults, getLibraryBased } from '../../util.js';
11
11
  import { TASKS_CONFIG_JSON_FILENAME, COMPONENTS_DIRECTORY_PATH, COMPONENTS_PATH } from '../../constants.js';
12
12
 
13
13
 
@@ -21,7 +21,6 @@ import {
21
21
  convertIntoPascalCase,
22
22
  getComponentDirectoryPath,
23
23
  getPegaConfig,
24
- getComponentDefaults,
25
24
  sanitize,
26
25
  validateSemver
27
26
  } from '../../util.js';
@@ -180,10 +179,12 @@ addDebugLog("renameComponent", `library: ${library}, organization: ${organizatio
180
179
 
181
180
  export default async options => {
182
181
  await showVersion();
182
+ await checkLibraryAndArchives();
183
183
 
184
184
  addDebugLog("rename", "", "+");
185
185
 
186
186
  await checkPathAccess(pegaConfigJsonPath);
187
+ const isLibraryBased = getLibraryBased();
187
188
 
188
189
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
189
190
  data = data && JSON.parse(data);
@@ -200,7 +201,7 @@ addDebugLog("rename", "", "+");
200
201
  const { library } = componentData;
201
202
  const { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
202
203
 
203
- let componentDefaults = await getComponentDefaults();
204
+ let componentDefaults = getConfigDefaults();
204
205
  componentDefaults.library = library;
205
206
 
206
207
  const localComponents = await getComponentsObj();
@@ -282,7 +283,8 @@ addDebugLog("rename", "", "+");
282
283
  return true;
283
284
  }
284
285
  return 'Please provide value for organization';
285
- }
286
+ },
287
+ when: () => !isLibraryBased
286
288
  },
287
289
  {
288
290
  name: 'version',
@@ -293,7 +295,8 @@ addDebugLog("rename", "", "+");
293
295
  return true;
294
296
  }
295
297
  return 'Please provide semver compatible version e.g 0.0.1';
296
- }
298
+ },
299
+ when: () => !isLibraryBased
297
300
  },
298
301
  {
299
302
  name: 'library',
@@ -309,12 +312,14 @@ addDebugLog("rename", "", "+");
309
312
  return true;
310
313
  }
311
314
  return 'Only alphanumeric values are allowed, starting with alphabets';
312
- }
315
+ },
316
+ when: () => !isLibraryBased
313
317
  },
314
318
  {
315
319
  name: 'allowedApplications',
316
320
  message: 'Please enter the application names to be supported (comma-separated). ',
317
- suffix: 'Keep empty for all applications'
321
+ suffix: 'Keep empty for all applications',
322
+ when: () => !isLibraryBased
318
323
  },
319
324
  {
320
325
  name: 'description',
@@ -330,12 +335,22 @@ addDebugLog("rename", "", "+");
330
335
  componentKey = paramComponentKey,
331
336
  componentName,
332
337
  componentLabel,
338
+ description,
339
+ } = answers;
340
+ let {
333
341
  organization,
334
342
  library,
335
343
  version,
336
- description,
337
- allowedApplications
338
- } = answers;
344
+ allowedApplications } = answers;
345
+
346
+ if (isLibraryBased) {
347
+ // these answers come from defaults
348
+ const orgLib = getConfigDefaults();
349
+ library = orgLib.library;
350
+ version = orgLib.buildVersion;
351
+ organization = orgLib.organization;
352
+ allowedApplications = "";
353
+ }
339
354
 
340
355
  await renameComponent(
341
356
  {
@@ -18,7 +18,9 @@ import {
18
18
  getC11NB2STokenAndStaticServer,
19
19
  updateComponentDefaultLibrary,
20
20
  updateDefaultOrganization,
21
- addDebugLog
21
+ addDebugLog,
22
+ checkLibraryAndArchives,
23
+ getConfigDefaults
22
24
  } from '../../util.js';
23
25
  import {
24
26
  TASKS_CONFIG_JSON_FILENAME,
@@ -32,52 +34,17 @@ export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
32
34
  const currentDirectory = process.cwd();
33
35
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
34
36
 
35
- const isLibraryBased = await getLibraryBased();
37
+ const isLibraryBased = getLibraryBased();
36
38
 
37
39
  import {
38
40
  convertIntoPascalCase,
39
41
  getComponentDirectoryPath,
40
- getPegaConfig,
41
- getComponentDefaults,
42
42
  getComponents,
43
43
  sanitize
44
44
  } from '../../util.js';
45
45
 
46
46
  const copy = promisify(ncp);
47
47
 
48
- export const getOrgLib = async () => {
49
-
50
- addDebugLog("getOrgLib", "", "+");
51
-
52
- const defaultPegaConfig = await getPegaServerConfig();
53
-
54
- await checkPathAccess(pegaConfigJsonPath);
55
-
56
- let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
57
- data = data && JSON.parse(data);
58
-
59
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
60
- console.error(
61
- `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
62
- );
63
- process.exit(1);
64
- }
65
-
66
- const componentData = data[COMPONENTS_PATH];
67
-
68
- let library;
69
- ({ library } = componentData);
70
- let { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
71
-
72
- const componentDefaults = await getComponentDefaults();
73
- componentDefaults.library = library;
74
- componentDefaults.organization = organization;
75
-
76
- addDebugLog("getOrgLib", `componentsDefaults: ${JSON.stringify(componentDefaults)}`, "");
77
- addDebugLog("getOrgLib", "END", "-");
78
-
79
- return componentDefaults;
80
- };
81
48
 
82
49
  export const updateConfig = async (
83
50
  {
@@ -136,7 +103,7 @@ addDebugLog("updateFile", "", "");
136
103
 
137
104
  export const renameLibrary = async ({ library, organization }, options) => {
138
105
  addDebugLog("renameLibrary", `library: ${library}, organization: ${organization}`, "");
139
- const compDef = await getOrgLib();
106
+ const compDef = getConfigDefaults();
140
107
  const currentOrganization = compDef.organization;
141
108
  const currentLibrary = compDef.library;
142
109
  const currentVersion = compDef.version;
@@ -230,8 +197,6 @@ export const renameComponent = async (
230
197
 
231
198
  addDebugLog("renameComponent", `library: ${library}, organization: ${organization}, componentKey: ${componentKey}`, "");
232
199
 
233
- let pegaConfig = await getPegaConfig();
234
-
235
200
  const newComponentKey = `${organization}_${library}_${componentName}`;
236
201
 
237
202
  const oldComponentKey = componentKey;
@@ -284,6 +249,8 @@ export default async options => {
284
249
  }
285
250
 
286
251
  await showVersion();
252
+ await checkLibraryAndArchives();
253
+
287
254
  addDebugLog("renameLibrary", "", "+");
288
255
 
289
256
  await checkPathAccess(pegaConfigJsonPath);
@@ -303,7 +270,7 @@ addDebugLog("renameLibrary", "", "+");
303
270
  const { library } = componentData;
304
271
  const { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
305
272
 
306
- let componentDefaults = await getComponentDefaults();
273
+ let componentDefaults = getConfigDefaults();
307
274
  componentDefaults.library = library;
308
275
 
309
276
  const localComponents = await getComponentsObj();
@@ -6,7 +6,7 @@ import chalk from 'chalk';
6
6
  import { showVersion, updateUseWebPackPromotion, getLibraryBased, addDebugLog } from '../../util.js';
7
7
  import { WEBPACK_CONFIG_JS_FILENAME } from '../../constants.js';
8
8
 
9
- const isLibraryBased = await getLibraryBased();
9
+ const isLibraryBased = getLibraryBased();
10
10
 
11
11
  export const renamePromotedWebPack = async () => {
12
12
  addDebugLog("renamePromotedWebPack","", "");
@@ -0,0 +1,41 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ import chalk from 'chalk';
5
+
6
+ import { showVersion, getLibraryBased, addDebugLog, getConfigDefaults, getComponents, checkLibraryAndArchives } from '../../util.js';
7
+
8
+ const isLibraryBased = getLibraryBased();
9
+
10
+ export const showCurrentStatus = async () => {
11
+
12
+ const configDefaults = await getConfigDefaults();
13
+ const componentList = await getComponents();
14
+
15
+ console.log("");
16
+ console.log("\tCurrent status");
17
+ console.log("\t---------------------");
18
+ console.log(`\tOrganization:\t ${chalk.bold.green(`${configDefaults.organization}`)}`);
19
+ console.log(`\tLibrary:\t ${chalk.bold.green(`${configDefaults.library}`)}`);
20
+ console.log(`\tVersion:\t ${chalk.bold.green(`${configDefaults.buildVersion}`)}`);
21
+ console.log(`\tPermanent:\t ${chalk.bold.green(`${!configDefaults.devBuild}`)}`);
22
+ console.log(`\tComponent count: ${chalk.bold.green(`${componentList.length}`)}`);
23
+
24
+ console.log("");
25
+
26
+ }
27
+
28
+
29
+ export default async options => {
30
+ if (!isLibraryBased) {
31
+ console.log(`Command only supported for ${chalk.bold.green('library based')} components.`);
32
+ process.exit();
33
+ }
34
+
35
+ await showVersion();
36
+ await checkLibraryAndArchives();
37
+ await showCurrentStatus();
38
+
39
+
40
+
41
+ }
@@ -0,0 +1,81 @@
1
+
2
+ import chalk from 'chalk';
3
+ import { promisify } from 'util';
4
+ import { exec as LocalExec } from "child_process";
5
+
6
+
7
+ import {
8
+ getComponents,
9
+ getPegaServerConfig,
10
+ updateConfigVersion,
11
+ getLibraryArchiveDirectories,
12
+ getLibraryArchivesVersions,
13
+ addDebugLog,
14
+ getConfigDefaults
15
+ } from '../../util.js';
16
+
17
+
18
+ const exec = promisify(LocalExec);
19
+
20
+ export const updateAllComponentsConfig = async( newVersion ) => {
21
+ addDebugLog("updateAllComponentsConfig", `newVersion: ${newVersion}`, "");
22
+ const componentList = await getComponents();
23
+ const orgLib = getConfigDefaults();
24
+ const currentOrgLib = `${orgLib.organization}_${orgLib.library}`;
25
+
26
+ for (const index in componentList) {
27
+ const componentKey = componentList[index];
28
+ await updateConfigVersion(componentKey, newVersion, currentOrgLib);
29
+
30
+ }
31
+ };
32
+
33
+ export const getSwitchLibraryComponentQuestions = async () => {
34
+ addDebugLog("getSwitchLibraryComponentQuestions", "", "");
35
+ const defaultPegaConfig = await getPegaServerConfig();
36
+ const componentDefaults = getConfigDefaults();
37
+ const orgLib = getConfigDefaults();
38
+ const currentOrgLib = `${orgLib.organization}_${orgLib.library}`;
39
+
40
+
41
+ const archVersionList = await getLibraryArchiveDirectories(currentOrgLib);
42
+
43
+
44
+ console.log(chalk.bold.yellow('\nBe sure to SAVE all changes before switching versions, unsaved changes will be LOST.'))
45
+
46
+ return [
47
+ {
48
+ name: 'okToContinue',
49
+ type: 'confirm',
50
+ message: 'Ok to continue ?',
51
+ default: false
52
+ },
53
+ {
54
+ name: 'newOrgLib',
55
+ type: 'rawlist',
56
+ message: `Select a library (current library is ${chalk.bold.green(`${currentOrgLib}`)}) `,
57
+ choices: archVersionList
58
+ }
59
+ ];
60
+ };
61
+
62
+ export const getSwitchVersionComponentQuestions = async (newOrgLib) => {
63
+ addDebugLog("getSwitchVersionComponentQuestions", "", "");
64
+
65
+ const archVersionList = await getLibraryArchivesVersions(newOrgLib, "0.0.0");
66
+
67
+ return [
68
+ {
69
+ name: 'version',
70
+ type: 'rawlist',
71
+ message: `Select a version `,
72
+ choices: archVersionList
73
+ }
74
+ ];
75
+ };
76
+
77
+ export const runNpmUpdate = async () => {
78
+ const script = `npm update`;
79
+
80
+ const { stdout, stderr } = await exec(script);
81
+ }
@@ -0,0 +1,134 @@
1
+ import { join } from 'path';
2
+ import { Listr } from 'listr2';
3
+
4
+ import inquirer from 'inquirer';
5
+ import chalk from 'chalk';
6
+
7
+
8
+ // eslint-disable-next-line import/order
9
+ import {
10
+ showVersion,
11
+ getLibraryBased,
12
+ addDebugLog,
13
+ zipVersionAndArchive,
14
+ restoreFromArchive,
15
+ checkLibraryAndArchives,
16
+ getConfigDefaults,
17
+ forceDefaultsUpdate,
18
+ getHaveDependencyDifference
19
+ } from '../../util.js';
20
+
21
+ import { getSwitchLibraryComponentQuestions, getSwitchVersionComponentQuestions } from './helper.js';
22
+ import { showCurrentStatus } from '../show-status/index.js';
23
+
24
+ const isLibraryBased = getLibraryBased();
25
+
26
+ export default async options => {
27
+ if (!isLibraryBased) {
28
+ console.log(`Command only supported for ${chalk.bold.green('library based')} components.`);
29
+ process.exit();
30
+ }
31
+
32
+ await showVersion();
33
+ await checkLibraryAndArchives();
34
+
35
+ addDebugLog("switchLibrary", "", "+");
36
+ let libraryName;
37
+ let version;
38
+ let newOrgLib;
39
+ // permBuild is the opposite of devBuild
40
+
41
+ let okToContinue;
42
+
43
+ const currentDirectory = process.cwd();
44
+ const componentDirectory = join (currentDirectory, "src", "components");
45
+
46
+
47
+ if (options.params.length >= 6) {
48
+ const okToCont = options.params[3];
49
+ newOrgLib = options.params[4];
50
+ version = options.params[5];
51
+
52
+ okToContinue = !!(okToCont === 'Y' || okToCont === 'y' || okToCont === true || okToCont === 'true');
53
+
54
+ } else {
55
+ const questions = await getSwitchLibraryComponentQuestions();
56
+ const answers = await inquirer.prompt(questions);
57
+ ({ okToContinue, newOrgLib } = answers);
58
+
59
+ const nextQuestion = await getSwitchVersionComponentQuestions(newOrgLib);
60
+ const nextAnswers = await inquirer.prompt(nextQuestion);
61
+ ({ version } = nextAnswers);
62
+
63
+
64
+ }
65
+
66
+ // in this scenario, version contains "-dev", if appropriate
67
+
68
+ const orgLib = getConfigDefaults();
69
+ const newVersion = version;
70
+ const existingOrgLib = orgLib.currentOrgLib;
71
+ let oldVersion = orgLib.buildVersion;
72
+
73
+ const switchToFileName = `${newOrgLib}_${newVersion}.zip`;
74
+
75
+ console.log("");
76
+
77
+ const tasks = new Listr(
78
+ [
79
+ {
80
+ title: `Archive ${orgLib.displayLibVersion}`,
81
+ task: async () => {
82
+ await zipVersionAndArchive(existingOrgLib, oldVersion);
83
+ }
84
+ },
85
+ {
86
+ title: `Restore ${newOrgLib}/${newVersion}`,
87
+ task: async () => {
88
+ await restoreFromArchive(switchToFileName, newOrgLib, newVersion);
89
+ }
90
+ }
91
+ ],
92
+ { concurrent: false, exitOnError: true }
93
+ );
94
+
95
+ await tasks.run().catch(err => {
96
+ console.log(chalk.bold.red(err.toString()));
97
+ process.exit(1);
98
+ });
99
+
100
+ // archive existing
101
+ // await zipVersionAndArchive(existingOrgLib, oldVersion);
102
+
103
+ // restore from archive
104
+ // await restoreFromArchive(switchToFileName, newOrgLib, newVersion);
105
+
106
+ console.log(`${chalk.bold.green(`\nSwitched to ${newOrgLib}/${newVersion}!\n`)}`);
107
+
108
+ await forceDefaultsUpdate();
109
+ await showCurrentStatus();
110
+
111
+ if (getHaveDependencyDifference()) {
112
+
113
+ console.log('\n***************************************************************');
114
+ console.log(chalk.bold.yellow('Dependencies have changed between versions, recommend updating.'));
115
+ console.log(`PLEASE run ${chalk.bold.yellow("'npm update'")}.`);
116
+ console.log('****************************************************************\n');
117
+
118
+ // const upateQuestions = await getRunNpmQuestions();
119
+ // const answers = await inquirer.prompt(upateQuestions);
120
+ // const { updateNpm } = answers;
121
+
122
+ // if (updateNpm) {
123
+ // await anotherTask.run().catch(err => {
124
+ // console.log(chalk.bold.red(err.toString()));
125
+ // process.exit(1);
126
+ // });
127
+ // }
128
+ }
129
+
130
+
131
+ addDebugLog("switchLibrary", "END", "-");
132
+
133
+ return true;
134
+ };