contensis-cli 1.2.2-beta.4 → 1.2.2-beta.6

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.
@@ -5,6 +5,7 @@ import { Logger, addNewLines } from './logger';
5
5
  import {
6
6
  BlockVersion,
7
7
  CopyFieldResult,
8
+ EntriesMigrationResult,
8
9
  EntriesResult,
9
10
  MigrateModelsResult,
10
11
  MigrateNodesTree,
@@ -116,8 +117,8 @@ export const printBlockVersion = (
116
117
  };
117
118
 
118
119
  export const printEntriesMigrateResult = (
119
- { log, messages, currentProject }: ContensisCli,
120
- migrateResult: EntriesResult | CopyFieldResult,
120
+ service: ContensisCli,
121
+ migrateResult: EntriesMigrationResult | EntriesResult | CopyFieldResult,
121
122
  {
122
123
  action = 'import',
123
124
  showDiff = false,
@@ -131,7 +132,7 @@ export const printEntriesMigrateResult = (
131
132
  } = {}
132
133
  ) => {
133
134
  console.log(``);
134
-
135
+ const { log, messages, currentProject } = service;
135
136
  for (const [contentTypeId, entryRes] of Object.entries(
136
137
  migrateResult.entriesToMigrate.entryIds
137
138
  ) as [string, any]) {
@@ -229,6 +230,14 @@ export const printEntriesMigrateResult = (
229
230
  ? log.successText
230
231
  : log.warningText;
231
232
 
233
+ if (isTotalCountRow && 'nodes' in migrateResult) {
234
+ printNodesMigrateResult(service, migrateResult, {
235
+ showAll,
236
+ showDiff,
237
+ showChanged,
238
+ isEntriesMigration: true,
239
+ });
240
+ }
232
241
  console.log(
233
242
  ` - ${
234
243
  isTotalCountRow
@@ -267,22 +276,24 @@ export const printEntriesMigrateResult = (
267
276
 
268
277
  export const printNodesMigrateResult = (
269
278
  { log, currentProject }: ContensisCli,
270
- migrateResult: NodesResult,
279
+ migrateResult: EntriesMigrationResult | NodesResult,
271
280
  {
272
281
  action = 'import',
273
282
  logLimit = 50,
274
283
  showDiff = false,
275
284
  showAll = false,
276
285
  showChanged = false,
286
+ isEntriesMigration = false,
277
287
  }: {
278
288
  action?: 'import' | 'delete';
279
289
  logLimit?: number;
280
290
  showDiff?: boolean;
281
291
  showAll?: boolean;
282
292
  showChanged?: boolean;
293
+ isEntriesMigration?: boolean;
283
294
  } = {}
284
295
  ) => {
285
- log.raw(``);
296
+ if (!isEntriesMigration) log.raw(``);
286
297
  for (const [projectId, counts] of Object.entries(migrateResult.nodes || {})) {
287
298
  const importTitle =
288
299
  action === 'delete'
@@ -292,14 +303,13 @@ export const printNodesMigrateResult = (
292
303
  ? `from project ${log.highlightText(projectId)} `
293
304
  : ''
294
305
  }to ${log.boldText(log.warningText(currentProject))}`;
295
- log.help(importTitle);
306
+ if (!isEntriesMigration) log.help(importTitle);
296
307
 
297
308
  const migrateStatusAndCount = migrateResult.nodesToMigrate[
298
309
  currentProject
299
310
  ] as ProjectNodesToMigrate;
300
311
 
301
- const existingCount =
302
- migrateResult.existing?.[currentProject]?.totalCount || 0;
312
+ const existingCount = migrateResult.nodes?.[projectId]?.totalCount || 0;
303
313
 
304
314
  const totalCount = Object.keys(migrateResult.nodesToMigrate.nodeIds).length;
305
315
  const existingPercent = counts.totalCount
@@ -320,25 +330,28 @@ export const printNodesMigrateResult = (
320
330
  const changedColor =
321
331
  changedPercentage === '100' ? log.successText : log.warningText;
322
332
 
323
- console.log(
324
- ` - ${log.highlightText(
325
- `totalCount: ${migrateStatusAndCount.totalCount}`
326
- )}${
327
- changedPercentage === '100'
328
- ? ''
329
- : existingColor(` [existing: ${`${existingPercent}%`}]`)
330
- }${
331
- existingPercent === '0'
332
- ? ''
333
- : changedColor(
334
- ` ${
335
- changedPercentage === '100'
336
- ? 'up to date'
337
- : `[needs update: ${100 - Number(changedPercentage)}%]`
338
- }`
339
- )
340
- }`
341
- );
333
+ if (!isEntriesMigration || migrateStatusAndCount.totalCount > 0)
334
+ console.log(
335
+ ` - ${log.highlightText(
336
+ `${isEntriesMigration ? ' + nodes' : 'totalCount'}: ${
337
+ migrateStatusAndCount.totalCount
338
+ }`
339
+ )}${
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
+ );
342
355
  }
343
356
  if (migrateResult.errors?.length) {
344
357
  console.log(
@@ -468,7 +481,7 @@ export const printModelMigrationResult = (
468
481
 
469
482
  export const printNodeTreeOutput = (
470
483
  { log, messages }: ContensisCli,
471
- root: Node | MigrateNodesTree | undefined,
484
+ root: Node | Partial<MigrateNodesTree> | undefined,
472
485
  logDetail = 'errors',
473
486
  logLimit = 1000
474
487
  ) => {
@@ -496,7 +509,7 @@ export const printNodeTreeOutput = (
496
509
  log.line();
497
510
 
498
511
  const outputNode = (
499
- node: Node | MigrateNodesTree,
512
+ node: Partial<Node | MigrateNodesTree>,
500
513
  spaces: string,
501
514
  isRoot = false
502
515
  ) => {
@@ -506,6 +519,7 @@ export const printNodeTreeOutput = (
506
519
  const changesOutput =
507
520
  logDetail === 'changes' &&
508
521
  'status' in node &&
522
+ node.status &&
509
523
  ['create', 'update'].includes(node.status);
510
524
 
511
525
  const diffOutput =
@@ -514,7 +528,7 @@ export const printNodeTreeOutput = (
514
528
  node.diff?.replaceAll('\n', '');
515
529
 
516
530
  return `${
517
- 'status' in node
531
+ 'status' in node && node.status
518
532
  ? `${statusColour(node.status)(
519
533
  node.status.substring(0, 1).toUpperCase()
520
534
  )} `
@@ -531,8 +545,10 @@ export const printNodeTreeOutput = (
531
545
  : 'standardText'
532
546
  ](
533
547
  'isCanonical' in node && node.isCanonical
534
- ? log.boldText(fullOutput || isRoot ? node.path : `/${node.slug}`)
535
- : fullOutput || isRoot
548
+ ? log.boldText(
549
+ fullOutput || isRoot || !node.slug ? node.path : `/${node.slug}`
550
+ )
551
+ : fullOutput || isRoot || !node.slug
536
552
  ? node.path
537
553
  : `/${node.slug}`
538
554
  )}${node.entry ? ` ${log.helpText(node.entry.sys.contentTypeId)}` : ''}${
@@ -540,7 +556,7 @@ export const printNodeTreeOutput = (
540
556
  } ${'displayName' in node ? log.infoText(node.displayName) : ''}${
541
557
  fullOutput || (changesOutput && node.id !== node.originalId)
542
558
  ? `~n ${log.infoText(`id:`)} ${
543
- node.id === node.originalId
559
+ !('originalId' in node) || node.id === node.originalId
544
560
  ? node.id
545
561
  : `${node.id} ${log.infoText(`<= ${node.originalId}`)}`
546
562
  }`
@@ -551,6 +567,7 @@ export const printNodeTreeOutput = (
551
567
  node.parentId
552
568
  ? `~n ${log.infoText(
553
569
  `parentId: ${
570
+ !('originalParentId' in node) ||
554
571
  node.parentId === node.originalParentId
555
572
  ? node.parentId
556
573
  : `${node.parentId} <= ${node.originalParentId}`
@@ -575,7 +592,10 @@ export const printNodeTreeOutput = (
575
592
  }`;
576
593
  };
577
594
 
578
- const outputChildren = (node: Node | undefined, depth = 2) => {
595
+ const outputChildren = (
596
+ node: Partial<Node | MigrateNodesTree> | undefined,
597
+ depth = 2
598
+ ) => {
579
599
  let str = '';
580
600
  for (const child of ((node as any)?.children || []) as Node[]) {
581
601
  str += `${outputNode(child, Array(depth + 1).join(' '))}\n`;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.2.2-beta.4";
1
+ export const LIB_VERSION = "1.2.2-beta.6";