contensis-cli 1.0.0-beta.53 → 1.0.0-beta.55

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 (68) hide show
  1. package/.vscode/launch.json +15 -15
  2. package/README.md +1226 -1226
  3. package/dist/commands/connect.js.map +1 -1
  4. package/dist/commands/create.js.map +1 -1
  5. package/dist/commands/diff.js.map +1 -1
  6. package/dist/commands/get.js.map +1 -1
  7. package/dist/commands/globalOptions.js.map +1 -1
  8. package/dist/commands/import.js.map +1 -1
  9. package/dist/commands/index.js.map +1 -1
  10. package/dist/commands/list.js.map +1 -1
  11. package/dist/commands/login.js.map +1 -1
  12. package/dist/commands/push.js.map +1 -1
  13. package/dist/commands/release.js.map +1 -1
  14. package/dist/commands/remove.js.map +1 -1
  15. package/dist/commands/set.js.map +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/localisation/en-GB.js.map +1 -1
  18. package/dist/providers/CredentialProvider.js.map +1 -1
  19. package/dist/providers/SessionCacheProvider.js.map +1 -1
  20. package/dist/providers/file-provider.js.map +1 -1
  21. package/dist/services/ContensisAuthService.js.map +1 -1
  22. package/dist/services/ContensisCliService.js +4 -0
  23. package/dist/services/ContensisCliService.js.map +2 -2
  24. package/dist/shell.js.map +1 -1
  25. package/dist/util/console.printer.js +5 -5
  26. package/dist/util/console.printer.js.map +2 -2
  27. package/dist/util/csv.formatter.js.map +1 -1
  28. package/dist/util/index.js.map +1 -1
  29. package/dist/util/json.formatter.js.map +1 -1
  30. package/dist/util/logger.js.map +1 -1
  31. package/dist/util/xml.formatter.js.map +1 -1
  32. package/dist/version.js +1 -1
  33. package/dist/version.js.map +1 -1
  34. package/esbuild.config.js +49 -49
  35. package/headless-setup.sh +6 -6
  36. package/package.json +59 -59
  37. package/src/commands/connect.ts +24 -24
  38. package/src/commands/create.ts +70 -70
  39. package/src/commands/diff.ts +41 -41
  40. package/src/commands/get.ts +214 -214
  41. package/src/commands/globalOptions.ts +127 -127
  42. package/src/commands/import.ts +128 -128
  43. package/src/commands/index.ts +80 -80
  44. package/src/commands/list.ts +116 -116
  45. package/src/commands/login.ts +34 -34
  46. package/src/commands/push.ts +127 -127
  47. package/src/commands/release.ts +32 -32
  48. package/src/commands/remove.ts +85 -85
  49. package/src/commands/set.ts +96 -96
  50. package/src/index.ts +19 -19
  51. package/src/localisation/en-GB.ts +289 -289
  52. package/src/models/AppError.d.ts +40 -40
  53. package/src/models/Cache.d.ts +25 -25
  54. package/src/models/JsModules.d.ts +1 -1
  55. package/src/providers/CredentialProvider.ts +121 -121
  56. package/src/providers/SessionCacheProvider.ts +101 -101
  57. package/src/providers/file-provider.ts +76 -76
  58. package/src/services/ContensisAuthService.ts +70 -70
  59. package/src/services/ContensisCliService.ts +1749 -1745
  60. package/src/shell.ts +270 -270
  61. package/src/util/console.printer.ts +371 -371
  62. package/src/util/csv.formatter.ts +21 -21
  63. package/src/util/index.ts +73 -73
  64. package/src/util/json.formatter.ts +1 -1
  65. package/src/util/logger.ts +234 -234
  66. package/src/util/xml.formatter.ts +20 -20
  67. package/src/version.ts +1 -1
  68. package/tsconfig.json +22 -22
@@ -1,371 +1,371 @@
1
- import dayjs from 'dayjs';
2
- import { BlockVersion, MigrateModelsResult, MigrateStatus } from 'migratortron';
3
- import ContensisCli from '~/services/ContensisCliService';
4
- import { Logger } from './logger';
5
-
6
- const formatDate = (date: Date | string, format = 'DD/MM/YYYY HH:mm') =>
7
- dayjs(date).format(format);
8
-
9
- export const printBlockVersion = (
10
- { log, messages }: ContensisCli,
11
- block: BlockVersion,
12
- printOptions = {
13
- showSource: true,
14
- showStatus: true,
15
- showStaticPaths: true,
16
- showImage: true,
17
- }
18
- ) => {
19
- console.log(
20
- ` ${log.standardText(`v${block.version.versionNo}`)} ${block.id}`
21
- );
22
- console.log(
23
- ` state: ${messages.blocks.runningStatus(
24
- block.status.broken ? 'broken' : block.status.running.global
25
- )}`
26
- );
27
- console.log(
28
- ` released: ${log.infoText(
29
- block.version.released
30
- ? `[${formatDate(block.version.released)}] ${block.version.releasedBy}`
31
- : 'no'
32
- )}`
33
- );
34
- if (block.version.madeLive)
35
- console.log(
36
- ` live: ${log.infoText(
37
- `[${formatDate(block.version.madeLive)}] ${block.version.madeLiveBy}`
38
- )}`
39
- );
40
- if (printOptions.showStatus) {
41
- console.log(` status:`);
42
- console.log(` deployment: ${log.infoText(block.status.deployment)}`);
43
- console.log(` workflow: ${log.infoText(block.status.workflow)}`);
44
- console.log(
45
- ` running status: ${messages.blocks.runningStatus(
46
- block.status.running.global
47
- )}`
48
- );
49
- console.log(` datacentres:`);
50
- console.log(
51
- ` hq: ${messages.blocks.runningStatus(
52
- block.status.running.dataCenters.hq
53
- )}`
54
- );
55
- console.log(
56
- ` london: ${messages.blocks.runningStatus(
57
- block.status.running.dataCenters.london
58
- )}`
59
- );
60
- console.log(
61
- ` manchester: ${messages.blocks.runningStatus(
62
- block.status.running.dataCenters.manchester
63
- )}`
64
- );
65
- }
66
- if (printOptions.showSource) {
67
- console.log(` source:`);
68
- console.log(` commit: ${log.helpText(block.source.commit.id)}`);
69
- console.log(
70
- ` message: ${log.infoText(
71
- block.source.commit.message
72
- ?.replaceAll('\n', '\\n')
73
- .replaceAll('\\n\\n', '\\n')
74
- .replaceAll('\\n', '; ')
75
- )}`
76
- );
77
- console.log(
78
- ` committed: ${log.infoText(
79
- `[${formatDate(block.source.commit.dateTime)}] ${
80
- block.source.commit.authorEmail
81
- }`
82
- )}`
83
- );
84
- console.log(
85
- ` pushed: ${log.infoText(
86
- `[${formatDate(block.version.pushed)}] ${block.version.pushedBy}`
87
- )}`
88
- );
89
- console.log(` ${log.infoText(block.source.commit.commitUrl)}`);
90
- }
91
- if (printOptions.showImage) {
92
- console.log(` image:`);
93
- console.log(` uri: ${log.infoText(block.image.uri)}`);
94
- console.log(` tag: ${log.helpText(block.image.tag)}`);
95
- }
96
- if (printOptions.showStaticPaths) {
97
- if (block.staticPaths?.length) {
98
- console.log(` static paths:`);
99
- for (const path of block.staticPaths) console.log(` - ${path}`);
100
- }
101
- }
102
- if (block.stagingUrl)
103
- console.log(` staging url: ${log.infoText(block.stagingUrl)}`);
104
- console.log('');
105
- };
106
-
107
- export const printMigrateResult = (
108
- { log, messages, contensis, currentProject }: ContensisCli,
109
- migrateResult: any,
110
- {
111
- action = 'import',
112
- showDiff = false,
113
- showAllEntries = false,
114
- showChangedEntries = false,
115
- }: {
116
- action?: 'import' | 'delete';
117
- showDiff?: boolean;
118
- showAllEntries?: boolean;
119
- showChangedEntries?: boolean;
120
- } = {}
121
- ) => {
122
- if (Object.keys(migrateResult.entriesToMigrate.entryIds).length)
123
- console.log(``);
124
-
125
- for (const [contentTypeId, entryRes] of Object.entries(
126
- migrateResult.entriesToMigrate.entryIds
127
- ) as [string, any]) {
128
- for (const [originalId, entryStatus] of Object.entries(entryRes) as [
129
- string,
130
- any
131
- ][]) {
132
- // console.log(`${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`);
133
- if (
134
- showAllEntries ||
135
- (showChangedEntries &&
136
- (
137
- Object.entries(
138
- Object.entries(entryStatus[currentProject])[0]
139
- )[1][1] as any
140
- ).status !== 'no change')
141
- ) {
142
- console.log(
143
- log.infoText(
144
- `${originalId} ${Object.entries(entryStatus || {})
145
- .filter(x => x[0] !== 'entryTitle')
146
- .map(([projectId, projectStatus]) => {
147
- const [targetGuid, { status }] = (Object.entries(
148
- projectStatus || {}
149
- )?.[0] as [string, { status: MigrateStatus }]) || [
150
- '',
151
- { x: { status: undefined } },
152
- ];
153
- return `${messages.migrate.status(status)(`${status}`)}${
154
- targetGuid !== originalId ? `-> ${targetGuid}` : ''
155
- }`;
156
- })}`
157
- ) + ` ${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`
158
- );
159
-
160
- for (const [projectId, projectStatus] of Object.entries(
161
- entryStatus
162
- ).filter(([key]) => key !== 'entryTitle') as [string, any][]) {
163
- const [targetGuid, { error, diff, status }] = Object.entries(
164
- projectStatus
165
- )[0] as [string, any];
166
- if (error) log.error(error);
167
- if (diff && showDiff) {
168
- console.log(
169
- ` ${log.highlightText(`diff:`)} ${log.infoText(
170
- highlightDiffText(diff)
171
- )}\n`
172
- );
173
- }
174
- }
175
- }
176
- }
177
- }
178
- console.log(``);
179
- if (
180
- contensis?.isPreview &&
181
- migrateResult.entriesToMigrate?.[currentProject]?.totalCount > 0 &&
182
- !migrateResult.errors
183
- ) {
184
- log.help(messages.entries.commitTip());
185
- }
186
-
187
- if (action === 'import') {
188
- for (const [projectId, contentTypeCounts] of Object.entries(
189
- migrateResult.entries || {}
190
- ) as [string, any][]) {
191
- log.help(
192
- `import from project ${log.highlightText(projectId)} to ${log.boldText(
193
- log.warningText(currentProject)
194
- )}`
195
- );
196
- for (const [contentTypeId, count] of Object.entries(
197
- contentTypeCounts
198
- ) as [string, number][]) {
199
- const entriesToMigrate =
200
- migrateResult.entriesToMigrate?.[projectId]?.[contentTypeId];
201
- const existingCount =
202
- migrateResult.existing?.[projectId]?.[contentTypeId] || 0;
203
- const existingPercent = ((existingCount / count) * 100).toFixed(0);
204
- const noChangeOrTotalEntriesCount =
205
- typeof entriesToMigrate !== 'number'
206
- ? entriesToMigrate?.['no change'] || 0
207
- : entriesToMigrate;
208
-
209
- const isTotalCountRow = contentTypeId === 'totalCount';
210
-
211
- const changedPercentage = (
212
- (noChangeOrTotalEntriesCount / count) *
213
- 100
214
- ).toFixed(0);
215
-
216
- const existingColor =
217
- existingPercent === '0' ? log.warningText : log.infoText;
218
- const changedColor = isTotalCountRow
219
- ? log.helpText
220
- : changedPercentage === '100'
221
- ? log.successText
222
- : log.warningText;
223
-
224
- console.log(
225
- ` - ${
226
- isTotalCountRow
227
- ? log.highlightText(`${contentTypeId}: ${count}`)
228
- : `${contentTypeId}: ${log.helpText(count)}`
229
- }${
230
- changedPercentage === '100'
231
- ? ''
232
- : existingColor(
233
- ` [existing: ${
234
- isTotalCountRow ? existingCount : `${existingPercent}%`
235
- }]`
236
- )
237
- }${
238
- existingPercent === '0'
239
- ? ''
240
- : changedColor(
241
- ` ${
242
- isTotalCountRow
243
- ? `[to change: ${noChangeOrTotalEntriesCount}]`
244
- : changedPercentage === '100'
245
- ? 'up to date'
246
- : `[needs update: ${100 - Number(changedPercentage)}%]`
247
- }`
248
- )
249
- }`
250
- );
251
- }
252
- }
253
- if (migrateResult.errors?.length) {
254
- console.log(
255
- ` - ${log.errorText(`errors: ${migrateResult.errors.length}`)}\n`
256
- );
257
- for (const error of migrateResult.errors)
258
- log.error(error.message || error);
259
- }
260
- }
261
- };
262
-
263
- const highlightDiffText = (str: string) => {
264
- const addedRegex = new RegExp(/<<\+>>(.*?)<<\/\+>>/, 'g');
265
- const removedRegex = new RegExp(/<<->>(.*?)<<\/->>/, 'g');
266
- return str
267
- .replace(addedRegex, match => {
268
- return Logger.successText(
269
- match.replace(/<<\+>>/g, '<+>').replace(/<<\/\+>>/g, '</+>')
270
- );
271
- })
272
- .replace(removedRegex, match => {
273
- return Logger.errorText(
274
- match.replace(/<<->>/g, '<->').replace(/<<\/->>/g, '</->')
275
- );
276
- });
277
- };
278
-
279
- export const printModelMigrationAnalysis = (
280
- { log, messages }: ContensisCli,
281
- result: any = {}
282
- ) => {
283
- for (const [contentTypeId, model] of Object.entries(result) as [
284
- string,
285
- any
286
- ][]) {
287
- let mainOutput = log.standardText(` - ${contentTypeId}`);
288
- let extraOutput = '';
289
- let errorOutput = '';
290
- let diffOutput = '';
291
- for (const [key, details] of Object.entries(model) as [string, any][]) {
292
- if (key === 'dependencies') {
293
- extraOutput += log.infoText(
294
- ` references: [${details?.join(', ')}]\n`
295
- );
296
- }
297
- if (key === 'dependencyOf') {
298
- extraOutput += log.infoText(
299
- ` required by: [${details?.join(', ')}]\n`
300
- );
301
- }
302
- if (key === 'projects') {
303
- for (const [projectId, projectDetails] of Object.entries(details) as [
304
- string,
305
- any
306
- ][]) {
307
- mainOutput += log.infoText(
308
- ` [${messages.migrate.status(projectDetails.status)(
309
- `${projectId}: ${projectDetails.status}`
310
- )}] v${projectDetails.versionNo}`
311
- );
312
- if (projectDetails.diff)
313
- diffOutput += ` ${log.highlightText(`diff:`)} ${log.infoText(
314
- highlightDiffText(projectDetails.diff)
315
- )}\n`;
316
- if (projectDetails.error)
317
- errorOutput += ` ${log.highlightText(
318
- `error::`
319
- )} ${log.errorText(projectDetails.error)}`;
320
- }
321
- }
322
- }
323
- console.log(mainOutput);
324
- if (extraOutput) {
325
- const search = '\n';
326
- const replace = '';
327
- console.log(
328
- extraOutput.replace(
329
- new RegExp(search + '([^' + search + ']*)$'),
330
- replace + '$1'
331
- )
332
- );
333
- }
334
- if (diffOutput) console.log(diffOutput);
335
- if (errorOutput) console.log(errorOutput);
336
- }
337
- };
338
-
339
- type MigrateResultSummary = MigrateModelsResult['']['contentTypes'];
340
- type MigrateResultStatus = keyof MigrateResultSummary;
341
-
342
- export const printModelMigrationResult = (
343
- { log, messages }: ContensisCli,
344
- result: MigrateResultSummary
345
- ) => {
346
- for (const [status, ids] of Object.entries(result) as [
347
- MigrateResultStatus,
348
- string[]
349
- ][]) {
350
- if (ids?.length) {
351
- if (status === 'errors') {
352
- const errors: [string, MappedError][] = ids as any;
353
- log.raw(
354
- ` - ${status}: [ ${messages.migrate.models.result(status)(
355
- ids.map(id => id[0]).join(', ')
356
- )} ]\n`
357
- );
358
- for (const [contentTypeId, error] of errors)
359
- log.error(
360
- `${log.highlightText(contentTypeId)}: ${error.message}`,
361
- error
362
- );
363
- } else
364
- log.raw(
365
- ` - ${status}: [ ${messages.migrate.models.result(status)(
366
- ids.join(', ')
367
- )} ]`
368
- );
369
- }
370
- }
371
- };
1
+ import dayjs from 'dayjs';
2
+ import { BlockVersion, MigrateModelsResult, MigrateStatus } from 'migratortron';
3
+ import ContensisCli from '~/services/ContensisCliService';
4
+ import { Logger } from './logger';
5
+
6
+ const formatDate = (date: Date | string, format = 'DD/MM/YYYY HH:mm') =>
7
+ dayjs(date).format(format);
8
+
9
+ export const printBlockVersion = (
10
+ { log, messages }: ContensisCli,
11
+ block: BlockVersion,
12
+ printOptions = {
13
+ showSource: true,
14
+ showStatus: true,
15
+ showStaticPaths: true,
16
+ showImage: true,
17
+ }
18
+ ) => {
19
+ console.log(
20
+ ` ${log.standardText(`v${block.version.versionNo}`)} ${block.id}`
21
+ );
22
+ console.log(
23
+ ` state: ${messages.blocks.runningStatus(
24
+ block.status.broken ? 'broken' : block.status.running.global
25
+ )}`
26
+ );
27
+ console.log(
28
+ ` released: ${log.infoText(
29
+ block.version.released
30
+ ? `[${formatDate(block.version.released)}] ${block.version.releasedBy}`
31
+ : 'no'
32
+ )}`
33
+ );
34
+ if (block.version.madeLive)
35
+ console.log(
36
+ ` live: ${log.infoText(
37
+ `[${formatDate(block.version.madeLive)}] ${block.version.madeLiveBy}`
38
+ )}`
39
+ );
40
+ if (printOptions.showStatus) {
41
+ console.log(` status:`);
42
+ console.log(` deployment: ${log.infoText(block.status.deployment)}`);
43
+ console.log(` workflow: ${log.infoText(block.status.workflow)}`);
44
+ console.log(
45
+ ` running status: ${messages.blocks.runningStatus(
46
+ block.status.running.global
47
+ )}`
48
+ );
49
+ console.log(` datacentres:`);
50
+ console.log(
51
+ ` hq: ${messages.blocks.runningStatus(
52
+ block.status.running.dataCenters.hq
53
+ )}`
54
+ );
55
+ console.log(
56
+ ` london: ${messages.blocks.runningStatus(
57
+ block.status.running.dataCenters.london
58
+ )}`
59
+ );
60
+ console.log(
61
+ ` manchester: ${messages.blocks.runningStatus(
62
+ block.status.running.dataCenters.manchester
63
+ )}`
64
+ );
65
+ }
66
+ if (printOptions.showSource) {
67
+ console.log(` source:`);
68
+ console.log(` commit: ${log.helpText(block.source.commit.id)}`);
69
+ console.log(
70
+ ` message: ${log.infoText(
71
+ block.source.commit.message
72
+ ?.replaceAll('\n', '\\n')
73
+ .replaceAll('\\n\\n', '\\n')
74
+ .replaceAll('\\n', '; ')
75
+ )}`
76
+ );
77
+ console.log(
78
+ ` committed: ${log.infoText(
79
+ `[${formatDate(block.source.commit.dateTime)}] ${
80
+ block.source.commit.authorEmail
81
+ }`
82
+ )}`
83
+ );
84
+ console.log(
85
+ ` pushed: ${log.infoText(
86
+ `[${formatDate(block.version.pushed)}] ${block.version.pushedBy}`
87
+ )}`
88
+ );
89
+ console.log(` ${log.infoText(block.source.commit.commitUrl)}`);
90
+ }
91
+ if (printOptions.showImage) {
92
+ console.log(` image:`);
93
+ console.log(` uri: ${log.infoText(block.image.uri)}`);
94
+ console.log(` tag: ${log.helpText(block.image.tag)}`);
95
+ }
96
+ if (printOptions.showStaticPaths) {
97
+ if (block.staticPaths?.length) {
98
+ console.log(` static paths:`);
99
+ for (const path of block.staticPaths) console.log(` - ${path}`);
100
+ }
101
+ }
102
+ if (block.stagingUrl)
103
+ console.log(` staging url: ${log.infoText(block.stagingUrl)}`);
104
+ console.log('');
105
+ };
106
+
107
+ export const printMigrateResult = (
108
+ { log, messages, contensis, currentProject }: ContensisCli,
109
+ migrateResult: any,
110
+ {
111
+ action = 'import',
112
+ showDiff = false,
113
+ showAllEntries = false,
114
+ showChangedEntries = false,
115
+ }: {
116
+ action?: 'import' | 'delete';
117
+ showDiff?: boolean;
118
+ showAllEntries?: boolean;
119
+ showChangedEntries?: boolean;
120
+ } = {}
121
+ ) => {
122
+ if (Object.keys(migrateResult.entriesToMigrate.entryIds).length)
123
+ console.log(``);
124
+
125
+ for (const [contentTypeId, entryRes] of Object.entries(
126
+ migrateResult.entriesToMigrate.entryIds
127
+ ) as [string, any]) {
128
+ for (const [originalId, entryStatus] of Object.entries(entryRes) as [
129
+ string,
130
+ any
131
+ ][]) {
132
+ // console.log(`${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`);
133
+ if (
134
+ showAllEntries ||
135
+ (showChangedEntries &&
136
+ (
137
+ Object.entries(
138
+ Object.entries(entryStatus[currentProject])[0]
139
+ )[1][1] as any
140
+ ).status !== 'no change')
141
+ ) {
142
+ console.log(
143
+ log.infoText(
144
+ `${originalId} ${Object.entries(entryStatus || {})
145
+ .filter(x => x[0] !== 'entryTitle')
146
+ .map(([projectId, projectStatus]) => {
147
+ const [targetGuid, { status }] = (Object.entries(
148
+ projectStatus || {}
149
+ )?.[0] as [string, { status: MigrateStatus }]) || [
150
+ '',
151
+ { x: { status: undefined } },
152
+ ];
153
+ return `${messages.migrate.status(status)(`${status}`)}${
154
+ targetGuid !== originalId ? `-> ${targetGuid}` : ''
155
+ }`;
156
+ })}`
157
+ ) + ` ${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`
158
+ );
159
+
160
+ for (const [projectId, projectStatus] of Object.entries(
161
+ entryStatus
162
+ ).filter(([key]) => key !== 'entryTitle') as [string, any][]) {
163
+ const [targetGuid, { error, diff, status }] = Object.entries(
164
+ projectStatus
165
+ )[0] as [string, any];
166
+ if (error) log.error(error);
167
+ if (diff && showDiff) {
168
+ console.log(
169
+ ` ${log.highlightText(`diff:`)} ${log.infoText(
170
+ highlightDiffText(diff)
171
+ )}\n`
172
+ );
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+ console.log(``);
179
+ if (
180
+ contensis?.isPreview &&
181
+ migrateResult.entriesToMigrate?.[currentProject]?.totalCount > 0 &&
182
+ !migrateResult.errors
183
+ ) {
184
+ log.help(messages.entries.commitTip());
185
+ }
186
+
187
+ if (action === 'import') {
188
+ for (const [projectId, contentTypeCounts] of Object.entries(
189
+ migrateResult.entries || {}
190
+ ) as [string, any][]) {
191
+ log.help(
192
+ `import from project ${log.highlightText(projectId)} to ${log.boldText(
193
+ log.warningText(currentProject)
194
+ )}`
195
+ );
196
+ for (const [contentTypeId, count] of Object.entries(
197
+ contentTypeCounts
198
+ ) as [string, number][]) {
199
+ const migrateStatusAndCount =
200
+ migrateResult.entriesToMigrate[currentProject][contentTypeId];
201
+ const existingCount =
202
+ migrateResult.existing?.[currentProject]?.[contentTypeId] || 0;
203
+ const existingPercent = ((existingCount / count) * 100).toFixed(0);
204
+ const noChangeOrTotalEntriesCount =
205
+ typeof migrateStatusAndCount !== 'number'
206
+ ? migrateStatusAndCount?.['no change'] || 0
207
+ : migrateStatusAndCount;
208
+
209
+ const isTotalCountRow = contentTypeId === 'totalCount';
210
+
211
+ const changedPercentage = (
212
+ (noChangeOrTotalEntriesCount / count) *
213
+ 100
214
+ ).toFixed(0);
215
+
216
+ const existingColor =
217
+ existingPercent === '0' ? log.warningText : log.infoText;
218
+ const changedColor = isTotalCountRow
219
+ ? log.helpText
220
+ : changedPercentage === '100'
221
+ ? log.successText
222
+ : log.warningText;
223
+
224
+ console.log(
225
+ ` - ${
226
+ isTotalCountRow
227
+ ? log.highlightText(`${contentTypeId}: ${count}`)
228
+ : `${contentTypeId}: ${log.helpText(count)}`
229
+ }${
230
+ changedPercentage === '100'
231
+ ? ''
232
+ : existingColor(
233
+ ` [existing: ${
234
+ isTotalCountRow ? existingCount : `${existingPercent}%`
235
+ }]`
236
+ )
237
+ }${
238
+ existingPercent === '0'
239
+ ? ''
240
+ : changedColor(
241
+ ` ${
242
+ isTotalCountRow
243
+ ? `[to change: ${noChangeOrTotalEntriesCount}]`
244
+ : changedPercentage === '100'
245
+ ? 'up to date'
246
+ : `[needs update: ${100 - Number(changedPercentage)}%]`
247
+ }`
248
+ )
249
+ }`
250
+ );
251
+ }
252
+ }
253
+ if (migrateResult.errors?.length) {
254
+ console.log(
255
+ ` - ${log.errorText(`errors: ${migrateResult.errors.length}`)}\n`
256
+ );
257
+ for (const error of migrateResult.errors)
258
+ log.error(error.message || error);
259
+ }
260
+ }
261
+ };
262
+
263
+ const highlightDiffText = (str: string) => {
264
+ const addedRegex = new RegExp(/<<\+>>(.*?)<<\/\+>>/, 'g');
265
+ const removedRegex = new RegExp(/<<->>(.*?)<<\/->>/, 'g');
266
+ return str
267
+ .replace(addedRegex, match => {
268
+ return Logger.successText(
269
+ match.replace(/<<\+>>/g, '<+>').replace(/<<\/\+>>/g, '</+>')
270
+ );
271
+ })
272
+ .replace(removedRegex, match => {
273
+ return Logger.errorText(
274
+ match.replace(/<<->>/g, '<->').replace(/<<\/->>/g, '</->')
275
+ );
276
+ });
277
+ };
278
+
279
+ export const printModelMigrationAnalysis = (
280
+ { log, messages }: ContensisCli,
281
+ result: any = {}
282
+ ) => {
283
+ for (const [contentTypeId, model] of Object.entries(result) as [
284
+ string,
285
+ any
286
+ ][]) {
287
+ let mainOutput = log.standardText(` - ${contentTypeId}`);
288
+ let extraOutput = '';
289
+ let errorOutput = '';
290
+ let diffOutput = '';
291
+ for (const [key, details] of Object.entries(model) as [string, any][]) {
292
+ if (key === 'dependencies') {
293
+ extraOutput += log.infoText(
294
+ ` references: [${details?.join(', ')}]\n`
295
+ );
296
+ }
297
+ if (key === 'dependencyOf') {
298
+ extraOutput += log.infoText(
299
+ ` required by: [${details?.join(', ')}]\n`
300
+ );
301
+ }
302
+ if (key === 'projects') {
303
+ for (const [projectId, projectDetails] of Object.entries(details) as [
304
+ string,
305
+ any
306
+ ][]) {
307
+ mainOutput += log.infoText(
308
+ ` [${messages.migrate.status(projectDetails.status)(
309
+ `${projectId}: ${projectDetails.status}`
310
+ )}] v${projectDetails.versionNo}`
311
+ );
312
+ if (projectDetails.diff)
313
+ diffOutput += ` ${log.highlightText(`diff:`)} ${log.infoText(
314
+ highlightDiffText(projectDetails.diff)
315
+ )}\n`;
316
+ if (projectDetails.error)
317
+ errorOutput += ` ${log.highlightText(
318
+ `error::`
319
+ )} ${log.errorText(projectDetails.error)}`;
320
+ }
321
+ }
322
+ }
323
+ console.log(mainOutput);
324
+ if (extraOutput) {
325
+ const search = '\n';
326
+ const replace = '';
327
+ console.log(
328
+ extraOutput.replace(
329
+ new RegExp(search + '([^' + search + ']*)$'),
330
+ replace + '$1'
331
+ )
332
+ );
333
+ }
334
+ if (diffOutput) console.log(diffOutput);
335
+ if (errorOutput) console.log(errorOutput);
336
+ }
337
+ };
338
+
339
+ type MigrateResultSummary = MigrateModelsResult['']['contentTypes'];
340
+ type MigrateResultStatus = keyof MigrateResultSummary;
341
+
342
+ export const printModelMigrationResult = (
343
+ { log, messages }: ContensisCli,
344
+ result: MigrateResultSummary
345
+ ) => {
346
+ for (const [status, ids] of Object.entries(result) as [
347
+ MigrateResultStatus,
348
+ string[]
349
+ ][]) {
350
+ if (ids?.length) {
351
+ if (status === 'errors') {
352
+ const errors: [string, MappedError][] = ids as any;
353
+ log.raw(
354
+ ` - ${status}: [ ${messages.migrate.models.result(status)(
355
+ ids.map(id => id[0]).join(', ')
356
+ )} ]\n`
357
+ );
358
+ for (const [contentTypeId, error] of errors)
359
+ log.error(
360
+ `${log.highlightText(contentTypeId)}: ${error.message}`,
361
+ error
362
+ );
363
+ } else
364
+ log.raw(
365
+ ` - ${status}: [ ${messages.migrate.models.result(status)(
366
+ ids.join(', ')
367
+ )} ]`
368
+ );
369
+ }
370
+ }
371
+ };