@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
@@ -1,37 +1,11 @@
1
1
  import inquirer from 'inquirer';
2
2
  import chalk from 'chalk';
3
3
 
4
- import {showVersion, getC11NB2STokenAndStaticServer, getLocalLibraryVersions, getLocalLibraryVersionData, getLibraryBased, addDebugLog } from '../../util.js';
4
+ import {showVersion, getLibraryBased, addDebugLog, checkLibraryAndArchives, getLibraryArchivesVersions, getConfigDefaults, getLocalArchivedLibrraryVersionData, getComponentsConfigs } from '../../util.js';
5
+ import { getArchiveLibraryQuestions } from './helper.js';
5
6
 
6
- import { listLibJSONResponse } from '@pega/constellation-dx-components-build-utils/index.js';
7
+ const isLibraryBased = getLibraryBased();
7
8
 
8
- import { getListLibraryQuestions, getLibraryVersionQuestion, getOrgLib, SOURCE_OF_COMPONENT_TYPES } from './helper.js';
9
-
10
- const isLibraryBased = await getLibraryBased();
11
-
12
- export const getServerLibraryVersions = async(libraryName) => {
13
- addDebugLog("getServerLibraryVersions", `libraryName: ${libraryName}`, "");
14
-
15
- // server
16
- const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
17
-
18
- if (tokenAndStaticServer.C11NB2S === undefined) {
19
- console.log(chalk.redBright("Need to authenticate, missing services token.\nDeleting a library requires authentication to acquire a token to delete."));
20
- process.exit(1);
21
- }
22
-
23
- addDebugLog("listLibJSONResponse", "services call", "");
24
- const oLibList = await listLibJSONResponse(tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
25
- addDebugLog("listLibJSONResponse", "services end", "");
26
-
27
- let versionList = null;
28
- if (oLibList && oLibList[libraryName]) {
29
- versionList = oLibList[libraryName];
30
- }
31
-
32
- return versionList;
33
-
34
- }
35
9
 
36
10
  export default async (options) => {
37
11
 
@@ -41,128 +15,112 @@ export default async (options) => {
41
15
  }
42
16
 
43
17
  await showVersion();
18
+ await checkLibraryAndArchives();
44
19
  addDebugLog("listLibrary", "", "+");
45
20
 
46
21
  let sourceOfLibrary;
47
22
  let organization;
48
23
  let library;
49
24
 
50
- const compDef = await getOrgLib();
25
+ const compDef = getConfigDefaults();
51
26
  organization = compDef.organization;
52
27
  library = compDef.library;
53
- const libraryName = organization.concat("_").concat(library);
28
+ let libraryName;
29
+ const currnetVersion = compDef.buildVersion;
54
30
  let selectedVersion;
55
31
  let libVersions = [];
56
32
 
57
33
  if (options.params.length >= 5) {
58
- sourceOfLibrary = options.params[3];
59
- selectedVersion = options.params[4];
34
+ // sourceOfLibrary = options.params[3];
35
+ // selectedVersion = options.params[4];
60
36
 
61
- libVersions.push(selectedVersion);
37
+ // libVersions.push(selectedVersion);
62
38
 
63
39
  }
64
- else {
65
40
 
66
- const questions = await getListLibraryQuestions(libraryName);
67
- const answers = await inquirer.prompt(questions);
68
- ({ sourceOfLibrary } = answers);
41
+ const questions = await getArchiveLibraryQuestions();
42
+ const answers = await inquirer.prompt(questions);
43
+ ({ libraryName } = answers);
69
44
 
45
+ try {
46
+ libVersions = await getLibraryArchivesVersions(libraryName, "");
70
47
  }
48
+ catch (ex) {}
71
49
 
72
- if (sourceOfLibrary === SOURCE_OF_COMPONENT_TYPES.LOCAL ) {
73
- // local
74
50
 
75
- if (libVersions.length == 0) {
76
- try {
77
- libVersions = await getLocalLibraryVersions(libraryName);
78
- }
79
- catch (ex) {
80
- }
51
+ if (libVersions.length > 0) {
81
52
 
82
- }
53
+ if (selectedVersion === undefined) {
54
+ const libAnswers = await inquirer.prompt([
83
55
 
84
- if (libVersions.length > 0) {
56
+ {
57
+ name: 'libVersion',
58
+ type: 'rawlist',
59
+ message: 'Enter version',
60
+ choices: libVersions
61
+ },
62
+ ]);
85
63
 
86
- if (selectedVersion === undefined) {
87
- const libAnswers = await inquirer.prompt([
64
+ selectedVersion = libAnswers.libVersion;
65
+ }
88
66
 
89
- {
90
- name: 'libVersion',
91
- type: 'rawlist',
92
- message: 'Enter version',
93
- choices: libVersions
94
- },
95
- ]);
67
+ let data;
68
+ // get built on from first component if exists
69
+ let builtOn = "(date unavailable)";
96
70
 
97
- selectedVersion = libAnswers.libVersion;
71
+ if (libraryName === compDef.currentOrgLib && selectedVersion === compDef.buildVersion) {
72
+
73
+ console.log("\nYou've selected the current working library/version.");
74
+ console.log("You can list current components or the last archive of this library/version.");
75
+ const archAnswers = await inquirer.prompt([
76
+ {
77
+ name: 'currentOrArchive',
78
+ type: 'rawlist',
79
+ message: 'Select current or archive',
80
+ default: "Current",
81
+ choices: ["Current", "Archive"]
82
+ },
83
+ ]);
84
+
85
+ const currentOrArchive = archAnswers.currentOrArchive;
86
+
87
+ if (currentOrArchive === "Current") {
88
+ data = await getComponentsConfigs();
89
+ builtOn = "(no date - current)";
98
90
  }
91
+ else {
92
+ data = await getLocalArchivedLibrraryVersionData(libraryName, selectedVersion);
93
+ data = JSON.parse(data);
99
94
 
100
- let data = await getLocalLibraryVersionData(libraryName, selectedVersion);
95
+ if (data[0] && data[0].buildDate) {
96
+ builtOn = data[0].buildDate;
97
+ }
98
+ }
99
+
100
+ }
101
+ else {
102
+ data = await getLocalArchivedLibrraryVersionData(libraryName, selectedVersion);
101
103
  data = JSON.parse(data);
102
104
 
103
- // get built on from first component if exists
104
- let builtOn = "(date unavailable)";
105
105
  if (data[0] && data[0].buildDate) {
106
106
  builtOn = data[0].buildDate;
107
107
  }
108
-
109
- let libData = data.map((component) => ( {'Component': component.name, 'Label': component.label, 'Version': component.version, 'Type': component.type, 'Sub Type' : component.subtype}));
110
- console.log(chalk.bold.blueBright(`\nList of ${libraryName}:${selectedVersion} components built on ${builtOn}.`));
111
- console.table(libData, ['Component', 'Label', 'Version', 'Type', 'Sub Type']);
112
-
113
- }
114
- else {
115
- // No library with that name
116
- console.log(chalk.redBright(`No local library named: ${libraryName} exists.`));
117
- console.log(chalk.redBright(`You need to build library: ${libraryName} first.`));
118
- addDebugLog("listLibrary", "END", "-");
119
- process.exit(1);
120
-
121
- }
122
-
123
- }
124
- else {
125
- const libVersions = await getServerLibraryVersions(libraryName);
126
-
127
- if (libVersions) {
128
- const keys = Object.keys(libVersions);
129
- const libAnswers = await inquirer.prompt([
130
-
131
- {
132
- name: 'libVersion',
133
- type: 'rawlist',
134
- message: 'Enter version',
135
- choices: keys
136
- },
137
- ]);
138
-
139
- const selectedVersion = libAnswers.libVersion;
140
-
141
- const versionData = libVersions[selectedVersion];
142
- const data = JSON.parse(versionData);
143
-
144
- // get built on from first component if exists
145
- let builtOn = "(date unavailable)";
146
- if (data[0] && data[0].buildDate) {
147
- builtOn = data[0].buildDate;
148
108
  }
149
109
 
150
110
  let libData = data.map((component) => ( {'Component': component.name, 'Label': component.label, 'Version': component.version, 'Type': component.type, 'Sub Type' : component.subtype}));
151
111
  console.log(chalk.bold.blueBright(`\nList of ${libraryName}:${selectedVersion} components built on ${builtOn}.`));
152
112
  console.table(libData, ['Component', 'Label', 'Version', 'Type', 'Sub Type']);
153
113
 
154
- }
155
- else {
156
- // No library with that name
157
- console.log(chalk.redBright(`No server library named: ${libraryName} exists.`));
158
- console.log(chalk.redBright(`You need to build library: ${libraryName} and publish this library.`));
114
+ }
115
+ else {
116
+ // No library with that name
117
+ console.log(chalk.redBright(`No other library versions for ${libraryName} exist other than current library version.`));
118
+ console.log(chalk.redBright(`To see contents for the currnet library version, enter 'npm run list'.`));
159
119
  addDebugLog("listLibrary", "END", "-");
160
- process.exit(1);
161
-
162
- }
163
-
120
+ process.exit();
164
121
  }
165
122
 
123
+
166
124
  addDebugLog("listLibrary", "END", "-");
167
125
 
168
126
  return true;
@@ -0,0 +1,42 @@
1
+ import chalk from 'chalk';
2
+
3
+ import {
4
+ getPegaServerConfig,
5
+ addDebugLog
6
+ } from '../../util.js';
7
+
8
+ export const SOURCE_OF_COMPONENT_TYPES = {
9
+ SERVER: 'Server',
10
+ LOCAL: 'Local'
11
+ };
12
+
13
+
14
+ export const getListLibraryQuestions = async (libraryName) => {
15
+ addDebugLog("getListLibraryQuestions", `libraryName: ${libraryName}`, "");
16
+ const defaultPegaConfig = await getPegaServerConfig();
17
+
18
+
19
+ return [
20
+ {
21
+ name: 'sourceOfLibrary',
22
+ type: 'rawlist',
23
+ message: `List library ${chalk.bold.green(`${libraryName}`)} from Server or Local ?`,
24
+ choices: Object.values(SOURCE_OF_COMPONENT_TYPES),
25
+ default: defaultPegaConfig.sourceOfComponents,
26
+ }
27
+ ];
28
+ };
29
+
30
+
31
+ export const getLibraryVersionQuestion = async(libraryName, libVersions) => {
32
+ addDebugLog("getLibraryVersionQuestion", `libraryName: ${libraryName}, libVersions: ${libVersions}`, "");
33
+ return [
34
+ {
35
+ name: 'version',
36
+ type: 'rawlist',
37
+ message: `Select ${chalk.green.bold(`${libraryName}`)} library version (or ALL) to delete`,
38
+ choices: libVersions
39
+ }
40
+ ];
41
+
42
+ }
@@ -0,0 +1,170 @@
1
+ import inquirer from 'inquirer';
2
+ import chalk from 'chalk';
3
+
4
+ import {showVersion, getC11NB2STokenAndStaticServer, getLocalLibraryVersions, getLocalLibraryVersionData, getLibraryBased, addDebugLog, checkLibraryAndArchives, getConfigDefaults } from '../../util.js';
5
+
6
+ import { listLibJSONResponse } from '@pega/constellation-dx-components-build-utils/index.js';
7
+
8
+ import { getListLibraryQuestions, SOURCE_OF_COMPONENT_TYPES } from './helper.js';
9
+
10
+ const isLibraryBased = getLibraryBased();
11
+
12
+ export const getServerLibraryVersions = async(libraryName) => {
13
+ addDebugLog("getServerLibraryVersions", `libraryName: ${libraryName}`, "");
14
+
15
+ // server
16
+ const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
17
+
18
+ if (tokenAndStaticServer.C11NB2S === undefined) {
19
+ console.log(chalk.redBright("Need to authenticate, missing services token.\nDeleting a library requires authentication to acquire a token to delete."));
20
+ process.exit(1);
21
+ }
22
+
23
+ addDebugLog("listLibJSONResponse", "services call", "");
24
+ const oLibList = await listLibJSONResponse(tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
25
+ addDebugLog("listLibJSONResponse", "services end", "");
26
+
27
+ let versionList = null;
28
+ if (oLibList && oLibList[libraryName]) {
29
+ versionList = oLibList[libraryName];
30
+ }
31
+
32
+ return versionList;
33
+
34
+ }
35
+
36
+ export default async (options) => {
37
+
38
+ if (!isLibraryBased) {
39
+ console.log(`Command only supported for ${chalk.bold.green('library based')} components.`)
40
+ process.exit();
41
+ }
42
+
43
+ await showVersion();
44
+ await checkLibraryAndArchives();
45
+ addDebugLog("listPublished", "", "+");
46
+
47
+ let sourceOfLibrary;
48
+ let organization;
49
+ let library;
50
+
51
+ const compDef = getConfigDefaults();
52
+ organization = compDef.organization;
53
+ library = compDef.library;
54
+ const libraryName = compDef.currentOrgLib;
55
+ let selectedVersion;
56
+ let libVersions = [];
57
+
58
+ if (options.params.length >= 5) {
59
+ sourceOfLibrary = options.params[3];
60
+ selectedVersion = options.params[4];
61
+
62
+ libVersions.push(selectedVersion);
63
+
64
+ }
65
+ else {
66
+
67
+ const questions = await getListLibraryQuestions(libraryName);
68
+ const answers = await inquirer.prompt(questions);
69
+ ({ sourceOfLibrary } = answers);
70
+
71
+ }
72
+
73
+ if (sourceOfLibrary === SOURCE_OF_COMPONENT_TYPES.LOCAL ) {
74
+ // local
75
+
76
+ if (libVersions.length == 0) {
77
+ try {
78
+ libVersions = await getLocalLibraryVersions(libraryName);
79
+ }
80
+ catch (ex) {
81
+ }
82
+
83
+ }
84
+
85
+ if (libVersions.length > 0) {
86
+
87
+ if (selectedVersion === undefined) {
88
+ const libAnswers = await inquirer.prompt([
89
+
90
+ {
91
+ name: 'libVersion',
92
+ type: 'rawlist',
93
+ message: 'Enter version',
94
+ choices: libVersions
95
+ },
96
+ ]);
97
+
98
+ selectedVersion = libAnswers.libVersion;
99
+ }
100
+
101
+ let data = await getLocalLibraryVersionData(libraryName, selectedVersion);
102
+ data = JSON.parse(data);
103
+
104
+ // get built on from first component if exists
105
+ let builtOn = "(date unavailable)";
106
+ if (data[0] && data[0].buildDate) {
107
+ builtOn = data[0].buildDate;
108
+ }
109
+
110
+ let libData = data.map((component) => ( {'Component': component.name, 'Label': component.label, 'Version': component.version, 'Type': component.type, 'Sub Type' : component.subtype}));
111
+ console.log(chalk.bold.blueBright(`\nList of ${libraryName}:${selectedVersion} components built on ${builtOn}.`));
112
+ console.table(libData, ['Component', 'Label', 'Version', 'Type', 'Sub Type']);
113
+
114
+ }
115
+ else {
116
+ // No library with that name
117
+ console.log(chalk.redBright(`No local library named: ${libraryName} exists.`));
118
+ console.log(chalk.redBright(`You need to publish library: ${libraryName} first.`));
119
+ addDebugLog("listPublished", "END", "-");
120
+ process.exit(1);
121
+
122
+ }
123
+
124
+ }
125
+ else {
126
+ const libVersions = await getServerLibraryVersions(libraryName);
127
+
128
+ if (libVersions) {
129
+ const keys = Object.keys(libVersions);
130
+ const libAnswers = await inquirer.prompt([
131
+
132
+ {
133
+ name: 'libVersion',
134
+ type: 'rawlist',
135
+ message: 'Enter version',
136
+ choices: keys
137
+ },
138
+ ]);
139
+
140
+ const selectedVersion = libAnswers.libVersion;
141
+
142
+ const versionData = libVersions[selectedVersion];
143
+ const data = JSON.parse(versionData);
144
+
145
+ // get built on from first component if exists
146
+ let builtOn = "(date unavailable)";
147
+ if (data[0] && data[0].buildDate) {
148
+ builtOn = data[0].buildDate;
149
+ }
150
+
151
+ let libData = data.map((component) => ( {'Component': component.name, 'Label': component.label, 'Version': component.version, 'Type': component.type, 'Sub Type' : component.subtype}));
152
+ console.log(chalk.bold.blueBright(`\nList of ${libraryName}:${selectedVersion} components built on ${builtOn}.`));
153
+ console.table(libData, ['Component', 'Label', 'Version', 'Type', 'Sub Type']);
154
+
155
+ }
156
+ else {
157
+ // No library with that name
158
+ console.log(chalk.redBright(`No server library named: ${libraryName} exists.`));
159
+ console.log(chalk.redBright(`You need to publish library: ${libraryName} first.`));
160
+ addDebugLog("listPublished", "END", "-");
161
+ process.exit(1);
162
+
163
+ }
164
+
165
+ }
166
+
167
+ addDebugLog("listLibrary", "END", "-");
168
+
169
+ return true;
170
+ };
@@ -21,7 +21,7 @@ import {
21
21
  BUILDER_DIR_FILE_PATH
22
22
  } from '../../constants.js';
23
23
 
24
- const isLibraryBased = await getLibraryBased();
24
+ const isLibraryBased = getLibraryBased();
25
25
 
26
26
 
27
27
  export const copyWebPack = async () => {
@@ -177,64 +177,64 @@ addDebugLog("publishComponentToServer", `data: ${data}`, "");
177
177
  // refresh_token: refreshToken
178
178
  } = JSON.parse(OauthData);
179
179
  let status = 500;
180
- const headers = {
181
- Authorization: `${tokenType} ${accessToken}`
182
- };
180
+ let headers = {};
183
181
 
184
182
  if (isLaunchpad) {
185
183
  headers.cookie = `Pega-AAT=${accessToken}`;
186
184
  headers['Content-Type'] = 'application/json';
185
+ } else {
186
+ headers.Authorization = `${tokenType} ${accessToken}`;
187
187
  }
188
188
 
189
- fetch(url, {
189
+ const response = await fetch(url, {
190
190
  method: 'POST',
191
191
  agent: getHttpsAgent(defaultPegaConfig),
192
192
  headers,
193
193
  body: JSON.stringify(apiBody)
194
- })
195
- .then(response => {
196
- status = response.status;
197
- return response.text();
198
- })
199
- .then(resp => {
200
- const respData = isLaunchpad ? resp : JSON.parse(resp);
201
- if (status === 401) {
202
- throw new Error(
203
- 'Error occurred in authentication. Please regenerate using authenticate'
204
- );
205
- // console.log(accessTokenUri, refreshToken);
206
- /* TODO - Handle refresh_token */
207
- } else if (status === 200 || status === 201) {
208
- console.log(
209
- chalk.bold.green(`Success : ${isLaunchpad ? respData : respData.message}`)
210
- );
211
- } else {
212
- throw new Error(`${respData.message}`);
213
- }
214
- })
215
- .catch(e => {
216
- if (e.code === 'ECONNREFUSED' || status === 401) {
217
- // eslint-disable-next-line prefer-promise-reject-errors
218
- Promise.reject(
219
- `${chalk.bold.red(
220
- 'Error occurred in authentication. Please regenerate using authenticate'
221
- )}`
222
- );
223
- } else if (status === 403) {
224
- // eslint-disable-next-line prefer-promise-reject-errors
225
- Promise.reject(
226
- `${chalk.bold.red('Error forbidden: User does not have privileges to Publish.')}`
227
- );
228
- } else {
229
- // eslint-disable-next-line prefer-promise-reject-errors
230
- Promise.reject(`${chalk.bold.red(e)}`);
231
- }
232
- });
194
+ });
195
+
196
+ status = response.status;
197
+ if (!response.ok) {
198
+ if (status === 401) {
199
+ throw new Error(
200
+ 'Error occurred in authentication. Please regenerate using authenticate'
201
+ );
202
+ // console.log(accessTokenUri, refreshToken);
203
+ /* TODO - Handle refresh_token */
204
+ } else if (status === 404) {
205
+ throw new Error('404: Server resource not found');
206
+ } else if (status === 405) {
207
+ throw new Error('405: Server method not allowed');
208
+ } else if (status === 408) {
209
+ throw new Error('408: Server timed out');
210
+ } else if (response.status === 403) {
211
+ throw new Error('Error forbidden: User does not have privileges to Publish.');
212
+ }
213
+ }
214
+
215
+ try {
216
+ const respData = isLaunchpad ? await response.text() : await response.json();
217
+ console.log(chalk.bold.green(`Success : ${isLaunchpad ? respData : respData.message}`));
218
+
219
+ if (status === 500) {
220
+ status = 999;
221
+ throw new Error(respData.message);
222
+ }
223
+ } catch (err) {
224
+ if (status === 500) {
225
+ throw new Error(
226
+ `Error occurred in authentication. Please regenerate using authenticate`
227
+ );
228
+ } else if (status === 999) {
229
+ throw new Error(err);
230
+ }
231
+ }
233
232
  } else {
234
233
  throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
235
234
  }
236
235
  } catch (err) {
237
- throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
236
+ // throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
237
+ throw new Error(err);
238
238
  }
239
239
  }
240
240
  };
@@ -5,19 +5,74 @@ 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 { getComponentDirectoryPath, showVersion, getLibraryBased, addDebugLog } from '../../util.js';
8
+ import { getComponentDirectoryPath, showVersion, getLibraryBased, addDebugLog, getPegaServerConfig, updateServerConfigRuleSetAndVersion, checkLibraryAndArchives, getConfigDevBuild, checkJWTExpiration, getConfigDefaults } from '../../util.js';
9
9
 
10
10
  import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
11
+ import { default as buildLibrary } from '../build-lib/index.js';
12
+ import { default as publishLibrary } from '../publish-lib/index.js';
11
13
 
12
- const isLibraryBased = await getLibraryBased();
14
+ const isLibraryBased = getLibraryBased();
13
15
 
14
16
  export default async options => {
17
+
18
+ await showVersion();
19
+ await checkLibraryAndArchives();
20
+
15
21
  if (isLibraryBased) {
16
- console.log(`Command only supported for ${chalk.bold.green('non library based')} components.`)
17
- process.exit();
22
+
23
+ await checkJWTExpiration();
24
+
25
+ const devBuild = await getConfigDevBuild();
26
+ let okToPublish = false;
27
+
28
+ const orgLib = getConfigDefaults();
29
+ const currentOrgLib = orgLib.currentOrgLib;
30
+ // const currentVersion = devBuild ? `${orgLib.version}-dev`: orgLib.version;
31
+ const currentVersion = orgLib.buildVersion;
32
+
33
+
34
+
35
+ const publishThisVersion = await inquirer.prompt([
36
+ {
37
+ name: 'confirmPublish',
38
+ type: 'confirm',
39
+ message: `Publish ${chalk.bold.green(`${orgLib.displayLibVersion}`)}, proceed ?`,
40
+ default: true
41
+ }
42
+ ]);
43
+
44
+ if (publishThisVersion.confirmPublish) {
45
+ okToPublish = true;
46
+ }
47
+
48
+ if (okToPublish && !devBuild) {
49
+ okToPublish = false;
50
+ console.log("");
51
+ const publishAnswers = await inquirer.prompt([
52
+ {
53
+ name: 'confirmPublish',
54
+ type: 'confirm',
55
+ message: `You are about to publish a ${chalk.bold.yellow('PRODUCTION')} version which can ${chalk.bold.yellow('NOT')} be deleted, proceed ?`,
56
+ default: false
57
+ }
58
+ ]);
59
+ if (publishAnswers.confirmPublish) {
60
+ okToPublish = true;
61
+ }
62
+ }
63
+
64
+ if (okToPublish) {
65
+ // marking as intenral, so no questions will be ask
66
+ options.params.push("internal");
67
+
68
+ await buildLibrary(options);
69
+ await publishLibrary(options);
70
+ }
71
+
72
+ return true;
18
73
  }
19
74
 
20
- await showVersion();
75
+
21
76
 
22
77
  addDebugLog("publish", "", "+");
23
78
 
@@ -27,6 +82,8 @@ addDebugLog("publish", "", "+");
27
82
  let content;
28
83
 
29
84
  let doFetch = true;
85
+ // const defaultPegaConfig = await getPegaServerConfig();
86
+ const componentDefaults = getConfigDefaults();
30
87
 
31
88
  if (options.params.length >= 7) {
32
89
  componentKey = options.params[3];
@@ -55,6 +112,11 @@ addDebugLog("publish", "", "+");
55
112
  };
56
113
  }
57
114
 
115
+ // update ruleset and version config for future
116
+ if (componentDefaults.serverType === "infinity") {
117
+ updateServerConfigRuleSetAndVersion(content.rulesetName, content.rulesetVersion);
118
+ }
119
+
58
120
  const sDevBuild = devBuild ? '(dev build)' : '';
59
121
  const tasks = new Listr(
60
122
  [
@@ -100,6 +162,9 @@ addDebugLog("publish", "", "+");
100
162
  console.log(chalk.bold.red(err.toString()));
101
163
  });
102
164
 
165
+
103
166
  addDebugLog("publish", "END", "-");
167
+
168
+
104
169
  return true;
105
170
  };