contensis-cli 1.0.12-beta.1 → 1.0.12-beta.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.
@@ -1,5 +1,12 @@
1
+ import { Node } from 'contensis-delivery-api/lib/models';
1
2
  import dayjs from 'dayjs';
2
- import { BlockVersion, MigrateModelsResult, MigrateStatus } from 'migratortron';
3
+ import {
4
+ BlockVersion,
5
+ EntriesResult,
6
+ MigrateModelsResult,
7
+ MigrateStatus,
8
+ NodesResult,
9
+ } from 'migratortron';
3
10
  import ContensisCli from '~/services/ContensisCliService';
4
11
  import { Logger } from './logger';
5
12
 
@@ -104,19 +111,19 @@ export const printBlockVersion = (
104
111
  console.log('');
105
112
  };
106
113
 
107
- export const printMigrateResult = (
114
+ export const printEntriesMigrateResult = (
108
115
  { log, messages, currentProject }: ContensisCli,
109
- migrateResult: any,
116
+ migrateResult: EntriesResult,
110
117
  {
111
118
  action = 'import',
112
119
  showDiff = false,
113
- showAllEntries = false,
114
- showChangedEntries = false,
120
+ showAll = false,
121
+ showChanged = false,
115
122
  }: {
116
123
  action?: 'import' | 'delete';
117
124
  showDiff?: boolean;
118
- showAllEntries?: boolean;
119
- showChangedEntries?: boolean;
125
+ showAll?: boolean;
126
+ showChanged?: boolean;
120
127
  } = {}
121
128
  ) => {
122
129
  console.log(``);
@@ -129,8 +136,8 @@ export const printMigrateResult = (
129
136
  any
130
137
  ][]) {
131
138
  if (
132
- showAllEntries ||
133
- (showChangedEntries &&
139
+ showAll ||
140
+ (showChanged &&
134
141
  (
135
142
  Object.entries(
136
143
  Object.entries(entryStatus[currentProject])[0]
@@ -173,7 +180,7 @@ export const printMigrateResult = (
173
180
  }
174
181
  }
175
182
  }
176
- if (showAllEntries || showChangedEntries) console.log(``);
183
+ if (showAll || showChanged) console.log(``);
177
184
 
178
185
  for (const [projectId, contentTypeCounts] of Object.entries(
179
186
  migrateResult.entries || {}
@@ -254,6 +261,106 @@ export const printMigrateResult = (
254
261
  }
255
262
  };
256
263
 
264
+ export const printNodesMigrateResult = (
265
+ { log, messages, currentProject }: ContensisCli,
266
+ migrateResult: NodesResult,
267
+ {
268
+ action = 'import',
269
+ showDiff = false,
270
+ showAll = false,
271
+ showChanged = false,
272
+ }: {
273
+ action?: 'import' | 'delete';
274
+ showDiff?: boolean;
275
+ showAll?: boolean;
276
+ showChanged?: boolean;
277
+ } = {}
278
+ ) => {
279
+ console.log(``);
280
+
281
+ for (const [originalId, migrateNodeId] of Object.entries(
282
+ migrateResult.nodesToMigrate.nodeIds
283
+ )) {
284
+ if (showAll || (showChanged && migrateNodeId.status !== 'no change')) {
285
+ console.log(
286
+ log.infoText(
287
+ `${originalId} ${`${messages.migrate.status(migrateNodeId.status)(
288
+ `${migrateNodeId.status}`
289
+ )}${
290
+ migrateNodeId.id !== originalId ? `-> ${migrateNodeId.id}` : ''
291
+ }`}`
292
+ ) + ` ${log.helpText(migrateNodeId.path)} ${migrateNodeId.displayName}`
293
+ );
294
+
295
+ if (migrateNodeId.diff && showDiff)
296
+ console.log(
297
+ ` ${log.highlightText(`diff:`)} ${log.infoText(
298
+ highlightDiffText(migrateNodeId.diff)
299
+ )}\n`
300
+ );
301
+ }
302
+ }
303
+ if (showAll || showChanged) console.log(``);
304
+
305
+ for (const [projectId, counts] of Object.entries(migrateResult.nodes || {})) {
306
+ log.help(
307
+ `${action} from project ${
308
+ action === 'delete'
309
+ ? log.warningText(currentProject)
310
+ : `${log.highlightText(projectId)} to ${log.boldText(
311
+ log.warningText(currentProject)
312
+ )}`
313
+ }`
314
+ );
315
+ counts.totalCount;
316
+ const migrateStatusAndCount = migrateResult.nodesToMigrate[currentProject];
317
+ const existingCount =
318
+ migrateResult.existing?.[currentProject]?.totalCount || 0;
319
+ const existingPercent = ((existingCount / counts.totalCount) * 100).toFixed(
320
+ 0
321
+ );
322
+ const noChangeOrTotalEntriesCount =
323
+ typeof migrateStatusAndCount !== 'number'
324
+ ? migrateStatusAndCount?.['no change'] || 0
325
+ : migrateStatusAndCount;
326
+ const changedPercentage = (
327
+ (noChangeOrTotalEntriesCount / counts.totalCount) *
328
+ 100
329
+ ).toFixed(0);
330
+ const existingColor =
331
+ existingPercent === '0' || action === 'delete'
332
+ ? log.warningText
333
+ : log.infoText;
334
+
335
+ const changedColor =
336
+ changedPercentage === '100' ? log.successText : log.warningText;
337
+
338
+ console.log(
339
+ ` - ${log.highlightText(`totalCount: ${counts.totalCount}`)}${
340
+ changedPercentage === '100'
341
+ ? ''
342
+ : existingColor(` [existing: ${`${existingPercent}%`}]`)
343
+ }${
344
+ existingPercent === '0'
345
+ ? ''
346
+ : changedColor(
347
+ ` ${
348
+ changedPercentage === '100'
349
+ ? 'up to date'
350
+ : `[needs update: ${100 - Number(changedPercentage)}%]`
351
+ }`
352
+ )
353
+ }`
354
+ );
355
+ }
356
+ if (migrateResult.errors?.length) {
357
+ console.log(
358
+ ` - ${log.errorText(`errors: ${migrateResult.errors.length}`)}\n`
359
+ );
360
+ for (const error of migrateResult.errors)
361
+ log.error(error.message || error, null, '');
362
+ }
363
+ };
257
364
  const highlightDiffText = (str: string) => {
258
365
  const addedRegex = new RegExp(/<<\+>>(.*?)<<\/\+>>/, 'g');
259
366
  const removedRegex = new RegExp(/<<->>(.*?)<<\/->>/, 'g');
@@ -363,3 +470,43 @@ export const printModelMigrationResult = (
363
470
  }
364
471
  }
365
472
  };
473
+
474
+ export const printNodeTreeOutput = (
475
+ { log }: ContensisCli,
476
+ root: Node | undefined
477
+ ) => {
478
+ log.object({ ...root, children: undefined });
479
+ log.raw('');
480
+ log.info(
481
+ `${log.highlightText('e')} = has entry; ${log.highlightText(
482
+ 'c'
483
+ )} = canonical; ${log.highlightText('m')} = include in menu`
484
+ );
485
+ log.line();
486
+
487
+ const outputNode = (node: Node | any, spaces: string) =>
488
+ `${node.entry ? log.highlightText('e') : log.infoText('-')}${
489
+ node.isCanonical ? log.highlightText('c') : log.infoText('-')
490
+ }${
491
+ node.includeInMenu ? log.highlightText('m') : log.infoText('-')
492
+ }${spaces}${
493
+ node.isCanonical ? log.boldText(`/${node.slug}`) : `/${node.slug}`
494
+ }${node.entry ? ` ${log.helpText(node.entry.sys.contentTypeId)}` : ''}${
495
+ node.childCount ? ` +${node.childCount}` : ``
496
+ } ${log.infoText(node.displayName)}`;
497
+
498
+ const outputChildren = (root: Node | undefined, depth = 2) => {
499
+ let str = '';
500
+ for (const node of (root as any)?.children as Node[]) {
501
+ str += `${outputNode(node, Array(depth + 1).join(' '))}\n`;
502
+ if ('children' in node) str += outputChildren(node, depth + 1);
503
+ }
504
+ return str;
505
+ };
506
+
507
+ const children = outputChildren(root);
508
+ log.limits(
509
+ `${outputNode(root, ' ')}${children ? `\n${children}` : ''}`,
510
+ 100
511
+ );
512
+ };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.0.12-beta.1";
1
+ export const LIB_VERSION = "1.0.12-beta.2";