contensis-cli 1.0.12-beta.1 → 1.0.12-beta.3

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