contensis-cli 1.6.1-beta.3 → 1.6.1-beta.4

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.
@@ -54,6 +54,7 @@ import {
54
54
  printModelMigrationResult,
55
55
  printNodeTreeOutput,
56
56
  printNodesMigrateResult,
57
+ printWebhooksMigrateResult,
57
58
  } from '~/util/console.printer';
58
59
  import { csvFormatter } from '~/util/csv.formatter';
59
60
  import { htmlFormatter } from '~/util/html.formatter';
@@ -1833,7 +1834,7 @@ class ContensisCli {
1833
1834
  else
1834
1835
  await this.HandleFormattingAndOutput(result, () => {
1835
1836
  // print the results to console
1836
- if (!result.committed) {
1837
+ if (result && !result?.committed) {
1837
1838
  log.raw(log.boldText(`\nContent types:`));
1838
1839
  if (!result.contentTypes) log.info(`- None returned\n`);
1839
1840
  else printModelMigrationAnalysis(this, result.contentTypes);
@@ -1859,7 +1860,7 @@ class ContensisCli {
1859
1860
  log.object(result.errors);
1860
1861
  }
1861
1862
  } else {
1862
- const { modelsResult = {} } = result;
1863
+ const { modelsResult = {} } = result || {};
1863
1864
  log.raw(log.boldText(`\nContent types:`));
1864
1865
  printModelMigrationResult(
1865
1866
  this,
@@ -2267,8 +2268,8 @@ class ContensisCli {
2267
2268
  });
2268
2269
  if (
2269
2270
  !err &&
2270
- ((!commit && result.entriesToMigrate[currentProject].totalCount) ||
2271
- (commit && result.migrateResult?.deleted))
2271
+ ((!commit && result?.entriesToMigrate[currentProject].totalCount) ||
2272
+ (commit && result?.migrateResult?.deleted))
2272
2273
  ) {
2273
2274
  log.success(messages.entries.removed(currentEnv, commit));
2274
2275
  if (!commit) {
@@ -2357,7 +2358,7 @@ class ContensisCli {
2357
2358
  const [err, result] = await contensis.MigrateEntries();
2358
2359
 
2359
2360
  if (err) logError(err);
2360
- else {
2361
+ else if (result) {
2361
2362
  const { entries, nodes, tags } =
2362
2363
  contensis.content.targets[currentProject];
2363
2364
 
@@ -2394,19 +2395,19 @@ class ContensisCli {
2394
2395
  }
2395
2396
  if (
2396
2397
  !err &&
2397
- !result.errors?.length &&
2398
- ((!commit && result.entriesToMigrate[currentProject].totalCount) ||
2398
+ !result?.errors?.length &&
2399
+ ((!commit && result?.entriesToMigrate[currentProject].totalCount) ||
2399
2400
  (commit &&
2400
- (result.migrateResult?.created || result.migrateResult?.updated)))
2401
+ (result?.migrateResult?.created || result?.migrateResult?.updated)))
2401
2402
  ) {
2402
2403
  log.success(
2403
2404
  messages.entries.imported(
2404
2405
  currentEnv,
2405
2406
  commit,
2406
2407
  commit
2407
- ? (result.migrateResult?.created || 0) +
2408
- (result.migrateResult?.updated || 0)
2409
- : result.entriesToMigrate[currentProject].totalCount,
2408
+ ? (result?.migrateResult?.created || 0) +
2409
+ (result?.migrateResult?.updated || 0)
2410
+ : result?.entriesToMigrate[currentProject].totalCount,
2410
2411
  commit
2411
2412
  ? (result.nodesResult?.created || 0) +
2412
2413
  (result.nodesResult?.updated || 0)
@@ -2665,7 +2666,7 @@ class ContensisCli {
2665
2666
  const [err, result] = await contensis.MigrateNodes();
2666
2667
 
2667
2668
  if (err) log.raw(``);
2668
- else
2669
+ else if (result)
2669
2670
  await this.HandleFormattingAndOutput(result, () => {
2670
2671
  // print the migrateResult to console
2671
2672
  const migrateTree =
@@ -2688,9 +2689,9 @@ class ContensisCli {
2688
2689
 
2689
2690
  if (
2690
2691
  !err &&
2691
- (!result.errors?.length || this.contensisOpts.ignoreErrors) &&
2692
+ (!result?.errors?.length || this.contensisOpts.ignoreErrors) &&
2692
2693
  ((!commit && nodesMigrateCount) ||
2693
- (commit && (nodesCreated || nodesUpdated || result.errors?.length)))
2694
+ (commit && (nodesCreated || nodesUpdated || result?.errors?.length)))
2694
2695
  ) {
2695
2696
  let totalCount: number;
2696
2697
  if (commit) {
@@ -2751,8 +2752,8 @@ class ContensisCli {
2751
2752
  }
2752
2753
  if (
2753
2754
  !err &&
2754
- ((!commit && result.nodesToMigrate[currentProject].totalCount) ||
2755
- (commit && result.nodesResult?.deleted))
2755
+ ((!commit && result?.nodesToMigrate[currentProject].totalCount) ||
2756
+ (commit && result?.nodesResult?.deleted))
2756
2757
  ) {
2757
2758
  log.success(
2758
2759
  messages.nodes.removed(currentEnv, commit, contensis.nodes.rootPath)
@@ -2809,7 +2810,7 @@ class ContensisCli {
2809
2810
  } of filteredResults) {
2810
2811
  console.log(
2811
2812
  log.infoText(
2812
- ` ${chalk.bold.white`- ${name}`} ${id} [${(
2813
+ `${chalk.bold.white`${enabled ? '🟢' : '🔴'} ${name}`} ${id} [${(
2813
2814
  version.modified || version.created
2814
2815
  )
2815
2816
  .toString()
@@ -2819,6 +2820,9 @@ class ContensisCli {
2819
2820
  )
2820
2821
  );
2821
2822
  if (description) console.log(log.infoText` ${description}`);
2823
+ console.log(
2824
+ ` ${log.infoText`enabled`}: ${chalk[enabled ? 'green' : 'red'](enabled)}`
2825
+ );
2822
2826
  console.log(` ${log.infoText`[${method}]`} ${url}`);
2823
2827
  if (headers && Object.keys(headers).length) {
2824
2828
  console.log(` ${log.infoText`headers`}:`);
@@ -2849,8 +2853,6 @@ class ContensisCli {
2849
2853
  templates
2850
2854
  ).join(' ')}`
2851
2855
  );
2852
- if (enabled === false)
2853
- console.log(` ${log.infoText`enabled`}: ${enabled}`);
2854
2856
  }
2855
2857
  });
2856
2858
  }
@@ -2863,6 +2865,90 @@ class ContensisCli {
2863
2865
  }
2864
2866
  };
2865
2867
 
2868
+ ImportWebhooks = async ({
2869
+ commit,
2870
+ fromFile,
2871
+ logOutput,
2872
+ enabled = false,
2873
+ disabled = false,
2874
+ }: {
2875
+ commit: boolean;
2876
+ fromFile?: string;
2877
+ logOutput: string;
2878
+ enabled?: boolean;
2879
+ disabled?: boolean;
2880
+ }) => {
2881
+ const { currentEnv, currentProject, log, messages } = this;
2882
+
2883
+ const contensis = await this.ConnectContensisImport({
2884
+ commit,
2885
+ fromFile,
2886
+ });
2887
+
2888
+ if (contensis) {
2889
+ log.line();
2890
+ if (contensis.isPreview) {
2891
+ log.success(messages.migrate.preview());
2892
+ } else {
2893
+ log.warning(messages.migrate.commit());
2894
+ }
2895
+
2896
+ const [err, result] = await to(
2897
+ contensis.webhooks.MigrateWebhooks({
2898
+ // trying to simulate XOR logic, setting enabled arg from
2899
+ // enabled or disabled option only if one of them is set
2900
+ enabled: enabled !== disabled ? enabled || !disabled : undefined,
2901
+ })
2902
+ );
2903
+
2904
+ if (err) logError(err);
2905
+ else if (result) {
2906
+ await this.HandleFormattingAndOutput(result, () => {
2907
+ printWebhooksMigrateResult(this, result, {
2908
+ showAll: logOutput === 'all',
2909
+ showDiff: logOutput === 'all' || logOutput === 'changes',
2910
+ showChanged: logOutput === 'changes',
2911
+ });
2912
+ });
2913
+ }
2914
+ if (
2915
+ !err &&
2916
+ !result.errors?.length &&
2917
+ ((!commit && result.webhooksToMigrate[currentProject].totalCount) ||
2918
+ (commit &&
2919
+ (result.webhooksResult?.created || result.webhooksResult?.updated)))
2920
+ ) {
2921
+ log.success(
2922
+ messages.webhooks.imported(
2923
+ currentEnv,
2924
+ commit,
2925
+ commit
2926
+ ? (result.webhooksResult?.created || 0) +
2927
+ (result.webhooksResult?.updated || 0)
2928
+ : (result.webhooksToMigrate[currentProject].totalCount as number)
2929
+ )
2930
+ );
2931
+ if (!commit) {
2932
+ log.raw(``);
2933
+ log.help(messages.migrate.commitTip());
2934
+ }
2935
+ } else {
2936
+ const noChanges =
2937
+ result?.webhooksToMigrate?.[currentProject]?.['no change'] &&
2938
+ result?.webhooksToMigrate?.[currentProject].totalCount === 0;
2939
+
2940
+ if (noChanges && !err && !result.errors?.length) {
2941
+ log.help(messages.webhooks.noChange(currentEnv));
2942
+ } else {
2943
+ log.error(messages.webhooks.failedCreate(currentEnv), err);
2944
+ }
2945
+ }
2946
+ } else {
2947
+ log.warning(messages.models.noList(currentProject));
2948
+ log.help(messages.connect.tip());
2949
+ }
2950
+ };
2951
+
2866
2952
  PrintBlocks = async () => {
2867
2953
  const { currentEnv, env, log, messages } = this;
2868
2954
  const contensis = await this.ConnectContensis();
package/src/shell.ts CHANGED
@@ -183,6 +183,7 @@ class ContensisShell {
183
183
  'import nodes',
184
184
  'import tags',
185
185
  'import taggroups',
186
+ 'import webhooks',
186
187
  'list blocks',
187
188
  'list contenttypes',
188
189
  'list components',
@@ -12,6 +12,7 @@ import {
12
12
  MigrateStatus,
13
13
  NodesResult,
14
14
  ProjectNodesToMigrate,
15
+ WebhooksResult,
15
16
  } from 'migratortron';
16
17
  import ContensisCli from '~/services/ContensisCliService';
17
18
 
@@ -374,6 +375,57 @@ export const printNodesMigrateResult = (
374
375
  }
375
376
  };
376
377
 
378
+ export const printWebhooksMigrateResult = (
379
+ service: ContensisCli,
380
+ migrateResult: WebhooksResult,
381
+ {
382
+ showDiff = false,
383
+ showAll = false,
384
+ showChanged = false,
385
+ }: {
386
+ showDiff?: boolean;
387
+ showAll?: boolean;
388
+ showChanged?: boolean;
389
+ } = {}
390
+ ) => {
391
+ console.log(``);
392
+ const { log, messages } = service;
393
+
394
+ for (const [originalId, webhookStatus] of Object.entries(
395
+ migrateResult.webhooksToMigrate.webhookIds
396
+ )) {
397
+ if (
398
+ showAll ||
399
+ (showChanged &&
400
+ webhookStatus.status !== 'no change' &&
401
+ webhookStatus.status !== 'ignore')
402
+ ) {
403
+ console.log(
404
+ log.infoText(
405
+ `${messages.migrate.status(webhookStatus.status)(`${webhookStatus.status}`)} ${originalId}${
406
+ webhookStatus.id !== originalId
407
+ ? ` -> ${webhookStatus.id}\n `
408
+ : ' '
409
+ }`
410
+ ) + `${webhookStatus.name}`
411
+ );
412
+
413
+ if (webhookStatus.error) log.error(webhookStatus.error);
414
+ if (webhookStatus.diff && showDiff) {
415
+ console.log(
416
+ ` ${log.infoText(`diff: ${highlightDiffText(webhookStatus.diff)}`)}\n`
417
+ );
418
+ }
419
+ }
420
+ }
421
+
422
+ if (migrateResult.errors?.length) {
423
+ console.log(
424
+ ` - ${log.errorText(`errors: ${migrateResult.errors.length}`)}\n`
425
+ );
426
+ }
427
+ };
428
+
377
429
  const highlightDiffText = (str: string) => {
378
430
  const addedRegex = new RegExp(/<<\+>>(.*?)<<\/\+>>/, 'g');
379
431
  const removedRegex = new RegExp(/<<->>(.*?)<<\/->>/, 'g');
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.6.1-beta.3";
1
+ export const LIB_VERSION = "1.6.1-beta.4";