contensis-cli 1.2.2-beta.9 → 1.3.0

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.
@@ -34,6 +34,7 @@ var import_fs = __toESM(require("fs"));
34
34
  var import_inquirer = __toESM(require("inquirer"));
35
35
  var import_node_fetch = __toESM(require("node-fetch"));
36
36
  var import_path = __toESM(require("path"));
37
+ var import_rfdc = __toESM(require("rfdc"));
37
38
  var import_migratortron = require("migratortron");
38
39
  var import_ContensisAuthService = __toESM(require("./ContensisAuthService"));
39
40
  var import_en_GB = require("../localisation/en-GB");
@@ -920,7 +921,7 @@ class ContensisCli {
920
921
  }
921
922
  }
922
923
  };
923
- PrintContentModels = async (modelIds = [], printRequiredBy) => {
924
+ PrintContentModels = async (modelIds = [], opts) => {
924
925
  const { currentProject, log, messages } = this;
925
926
  const contensis = await this.ConnectContensis();
926
927
  if (contensis) {
@@ -930,70 +931,81 @@ class ContensisCli {
930
931
  const returnModels = (modelIds == null ? void 0 : modelIds.length) ? models == null ? void 0 : models.filter(
931
932
  (m) => modelIds.some((id) => id.toLowerCase() === m.id.toLowerCase())
932
933
  ) : void 0;
933
- const contentTypeIds = Array.from(
934
- /* @__PURE__ */ new Set([
935
- ...(returnModels || models || []).map((m) => m.id),
936
- ...(returnModels || models || []).map((m) => {
937
- var _a, _b;
938
- return ((_b = (_a = m.dependencies) == null ? void 0 : _a.contentTypes) == null ? void 0 : _b.map((c) => c[0])) || [];
939
- }).flat()
940
- ])
941
- );
942
- const componentIds = Array.from(
943
- new Set(
944
- (returnModels || models || []).map((m) => {
945
- var _a, _b;
946
- return ((_b = (_a = m.dependencies) == null ? void 0 : _a.components) == null ? void 0 : _b.map((c) => c[0])) || [];
947
- }).flat()
948
- )
949
- );
950
- const contentModelBackup = [
951
- ...contentTypes.filter(
952
- (c) => contentTypeIds.map((i) => i.toLowerCase()).includes(c.id.toLowerCase())
953
- ),
954
- ...components.filter(
955
- (c) => componentIds.map((i) => i.toLowerCase()).includes(c.id.toLowerCase())
956
- )
957
- ];
934
+ const exportResources = [];
935
+ if (opts.export) {
936
+ const contentTypeIds = Array.from(
937
+ /* @__PURE__ */ new Set([
938
+ ...(returnModels || models || []).map((m) => m.id),
939
+ ...(returnModels || models || []).map((m) => {
940
+ var _a, _b;
941
+ return ((_b = (_a = m.dependencies) == null ? void 0 : _a.contentTypes) == null ? void 0 : _b.map((c) => c[0])) || [];
942
+ }).flat()
943
+ ])
944
+ );
945
+ const componentIds = Array.from(
946
+ new Set(
947
+ (returnModels || models || []).map((m) => {
948
+ var _a, _b;
949
+ return ((_b = (_a = m.dependencies) == null ? void 0 : _a.components) == null ? void 0 : _b.map((c) => c[0])) || [];
950
+ }).flat()
951
+ )
952
+ );
953
+ exportResources.push(
954
+ ...contentTypes.filter(
955
+ (c) => contentTypeIds.map((i) => i.toLowerCase()).includes(c.id.toLowerCase())
956
+ ),
957
+ ...components.filter(
958
+ (c) => componentIds.map((i) => i.toLowerCase()).includes(c.id.toLowerCase())
959
+ )
960
+ );
961
+ }
958
962
  if (Array.isArray(returnModels)) {
959
963
  log.success(messages.models.list(currentProject));
960
- await this.HandleFormattingAndOutput(contentModelBackup, () => {
961
- var _a, _b;
962
- for (const model of returnModels) {
963
- if (!printRequiredBy) {
964
- delete model.dependencyOf;
965
- if ((_a = model.dependencies) == null ? void 0 : _a.contentTypes)
966
- model.dependencies.contentTypes.forEach((id) => id[1] = []);
967
- if ((_b = model.dependencies) == null ? void 0 : _b.components)
968
- model.dependencies.components.forEach((id) => id[1] = []);
964
+ await this.HandleFormattingAndOutput(
965
+ opts.export ? exportResources : returnModels,
966
+ () => {
967
+ var _a, _b;
968
+ for (const model of returnModels) {
969
+ const draft = (0, import_rfdc.default)()(model);
970
+ if (!opts.requiredBy) {
971
+ delete draft.dependencyOf;
972
+ if ((_a = draft.dependencies) == null ? void 0 : _a.contentTypes)
973
+ draft.dependencies.contentTypes.forEach((id) => id.pop());
974
+ if ((_b = draft.dependencies) == null ? void 0 : _b.components)
975
+ draft.dependencies.components.forEach((id) => id.pop());
976
+ }
977
+ log.raw("");
978
+ log.object(draft);
969
979
  }
970
980
  log.raw("");
971
- log.object(model);
972
981
  }
973
- log.raw("");
974
- });
982
+ );
975
983
  } else {
976
984
  log.success(
977
985
  messages.models.get(currentProject, (models == null ? void 0 : models.length.toString()) || "0")
978
986
  );
979
987
  log.raw("");
980
988
  if (models == null ? void 0 : models.length) {
981
- await this.HandleFormattingAndOutput(contentModelBackup, () => {
982
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
983
- for (const model of models) {
984
- const components2 = ((_a = model.components) == null ? void 0 : _a.length) || 0;
985
- const contentTypes2 = ((_b = model.contentTypes) == null ? void 0 : _b.length) || 0;
986
- const dependencies = (((_d = (_c = model.dependencies) == null ? void 0 : _c.components) == null ? void 0 : _d.length) || 0) + (((_f = (_e = model.dependencies) == null ? void 0 : _e.contentTypes) == null ? void 0 : _f.length) || 0);
987
- const dependencyOf = (((_h = (_g = model.dependencyOf) == null ? void 0 : _g.components) == null ? void 0 : _h.length) || 0) + (((_j = (_i = model.dependencyOf) == null ? void 0 : _i.contentTypes) == null ? void 0 : _j.length) || 0);
988
- const hasAny = components2 + contentTypes2 + dependencies + dependencyOf;
989
- log.raw(
990
- ` - ${log.highlightText(log.boldText(model.id))} ${hasAny ? log.infoText(
991
- `{ ${components2 ? `components: ${components2}, ` : ""}${contentTypes2 ? `contentTypes: ${contentTypes2}, ` : ""}${dependencies ? `references: ${dependencies}, ` : ""}${dependencyOf ? `required by: ${dependencyOf}` : ""} }`
992
- ) : ""}`
993
- );
989
+ await this.HandleFormattingAndOutput(
990
+ opts.export ? exportResources : models,
991
+ () => {
992
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
993
+ for (const model of models) {
994
+ const components2 = ((_a = model.components) == null ? void 0 : _a.length) || 0;
995
+ const contentTypes2 = ((_b = model.contentTypes) == null ? void 0 : _b.length) || 0;
996
+ const defaults = (((_c = model.defaults) == null ? void 0 : _c.length) || 0) + (((_d = model.nodes) == null ? void 0 : _d.length) || 0);
997
+ const dependencies = (((_f = (_e = model.dependencies) == null ? void 0 : _e.components) == null ? void 0 : _f.length) || 0) + (((_h = (_g = model.dependencies) == null ? void 0 : _g.contentTypes) == null ? void 0 : _h.length) || 0);
998
+ const dependencyOf = (((_j = (_i = model.dependencyOf) == null ? void 0 : _i.components) == null ? void 0 : _j.length) || 0) + (((_l = (_k = model.dependencyOf) == null ? void 0 : _k.contentTypes) == null ? void 0 : _l.length) || 0);
999
+ const hasAny = components2 + contentTypes2 + dependencies + dependencyOf;
1000
+ log.raw(
1001
+ ` - ${log.highlightText(log.boldText(model.id))} ${hasAny ? log.infoText(
1002
+ `{ ${components2 ? `components: ${components2}, ` : ""}${contentTypes2 ? `contentTypes: ${contentTypes2}, ` : ""}${defaults ? `defaults: ${defaults}, ` : ""}${dependencies ? `references: ${dependencies}, ` : ""}${dependencyOf ? `required by: ${dependencyOf}` : ""} }`
1003
+ ) : ""}`
1004
+ );
1005
+ }
1006
+ log.raw("");
994
1007
  }
995
- log.raw("");
996
- });
1008
+ );
997
1009
  }
998
1010
  }
999
1011
  }
@@ -1023,7 +1035,7 @@ class ContensisCli {
1023
1035
  (0, import_logger.logError)(migrateErr);
1024
1036
  else
1025
1037
  await this.HandleFormattingAndOutput(result, () => {
1026
- if (!commit) {
1038
+ if (!result.committed) {
1027
1039
  log.raw(log.boldText(`
1028
1040
  Content types:`));
1029
1041
  if (!result.contentTypes)
@@ -1038,20 +1050,59 @@ Components:`));
1038
1050
  `);
1039
1051
  else
1040
1052
  (0, import_console.printModelMigrationAnalysis)(this, result.components);
1053
+ if (Object.keys(result.defaults).length) {
1054
+ log.raw(log.boldText(`
1055
+ Defaults:`));
1056
+ (0, import_console.printModelMigrationAnalysis)(this, result.defaults);
1057
+ }
1058
+ if (Object.keys(result.nodes).length) {
1059
+ log.raw(log.boldText(`
1060
+ Nodes:`));
1061
+ (0, import_console.printModelMigrationAnalysis)(this, result.nodes);
1062
+ }
1063
+ if (result.errors) {
1064
+ log.raw(log.boldText(`
1065
+ Errors:`));
1066
+ log.object(result.errors);
1067
+ }
1041
1068
  } else {
1042
- const migrateResult = result;
1069
+ const { modelsResult = {} } = result;
1043
1070
  log.raw(log.boldText(`
1044
1071
  Content types:`));
1045
1072
  (0, import_console.printModelMigrationResult)(
1046
1073
  this,
1047
- migrateResult[currentProject].contentTypes
1074
+ modelsResult[currentProject].contentTypes
1048
1075
  );
1049
- log.raw(log.boldText(`
1076
+ if (Object.values(modelsResult[currentProject].components).some(
1077
+ (r) => r.length > 0
1078
+ )) {
1079
+ log.raw(log.boldText(`
1050
1080
  Components:`));
1051
- (0, import_console.printModelMigrationResult)(
1052
- this,
1053
- migrateResult[currentProject].components
1054
- );
1081
+ (0, import_console.printModelMigrationResult)(
1082
+ this,
1083
+ modelsResult[currentProject].components
1084
+ );
1085
+ }
1086
+ if (Object.values(modelsResult[currentProject].defaults).some(
1087
+ (r) => r.length > 0
1088
+ )) {
1089
+ log.raw(log.boldText(`
1090
+ Defaults:`));
1091
+ (0, import_console.printModelMigrationResult)(
1092
+ this,
1093
+ modelsResult[currentProject].defaults
1094
+ );
1095
+ }
1096
+ if (Object.values(modelsResult[currentProject].nodes).some(
1097
+ (r) => r.length > 0
1098
+ )) {
1099
+ log.raw(log.boldText(`
1100
+ Nodes:`));
1101
+ (0, import_console.printModelMigrationResult)(
1102
+ this,
1103
+ modelsResult[currentProject].nodes
1104
+ );
1105
+ }
1055
1106
  }
1056
1107
  });
1057
1108
  } else {
@@ -1199,18 +1250,21 @@ Components:`));
1199
1250
  )}
1200
1251
  `
1201
1252
  );
1202
- log.raw(log.boldText(`Content types:`));
1203
- if (!result.contentTypes)
1204
- log.info(`- None returned
1253
+ if (result.committed === false) {
1254
+ log.raw(log.boldText(`Content types:`));
1255
+ if (!result.contentTypes)
1256
+ log.info(`- None returned
1205
1257
  `);
1206
- else
1207
- (0, import_console.printModelMigrationAnalysis)(this, result.contentTypes);
1208
- log.raw(log.boldText(`Components:`));
1209
- if (!result.components)
1210
- log.info(`- None returned
1258
+ else
1259
+ (0, import_console.printModelMigrationAnalysis)(this, result.contentTypes);
1260
+ log.raw(log.boldText(`
1261
+ Components:`));
1262
+ if (!result.components)
1263
+ log.info(`- None returned
1211
1264
  `);
1212
- else
1213
- (0, import_console.printModelMigrationAnalysis)(this, result.components);
1265
+ else
1266
+ (0, import_console.printModelMigrationAnalysis)(this, result.components);
1267
+ }
1214
1268
  });
1215
1269
  }
1216
1270
  };
@@ -1361,7 +1415,7 @@ Components:`));
1361
1415
  };
1362
1416
  GetEntries = async ({
1363
1417
  withDependents = false
1364
- }) => {
1418
+ } = {}) => {
1365
1419
  const { currentProject, log, messages } = this;
1366
1420
  const contensis = await this.ConnectContensis();
1367
1421
  if (contensis) {
@@ -1389,7 +1443,7 @@ Components:`));
1389
1443
  logOutput,
1390
1444
  saveEntries
1391
1445
  }) => {
1392
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1446
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1393
1447
  const { currentEnv, currentProject, log, messages } = this;
1394
1448
  const contensis = await this.ConnectContensisImport({
1395
1449
  commit,
@@ -1407,8 +1461,8 @@ Components:`));
1407
1461
  if (err)
1408
1462
  (0, import_logger.logError)(err);
1409
1463
  else {
1410
- const { migrateEntries, nodes } = contensis.content.targets[currentProject];
1411
- const output = saveEntries ? migrateEntries == null ? void 0 : migrateEntries.map((me) => me.finalEntry) : result;
1464
+ const { entries, nodes } = contensis.content.targets[currentProject];
1465
+ const output = saveEntries ? (_a = entries.migrate) == null ? void 0 : _a.map((me) => me.toJSON()) : result;
1412
1466
  await this.HandleFormattingAndOutput(output, () => {
1413
1467
  (0, import_console.printEntriesMigrateResult)(this, result, {
1414
1468
  showAll: logOutput === "all",
@@ -1427,13 +1481,13 @@ Components:`));
1427
1481
  );
1428
1482
  });
1429
1483
  }
1430
- if (!err && !((_a = result.errors) == null ? void 0 : _a.length) && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && (((_b = result.migrateResult) == null ? void 0 : _b.created) || ((_c = result.migrateResult) == null ? void 0 : _c.updated)))) {
1484
+ if (!err && !((_b = result.errors) == null ? void 0 : _b.length) && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && (((_c = result.migrateResult) == null ? void 0 : _c.created) || ((_d = result.migrateResult) == null ? void 0 : _d.updated)))) {
1431
1485
  log.success(
1432
1486
  messages.entries.imported(
1433
1487
  currentEnv,
1434
1488
  commit,
1435
- commit ? (((_d = result.migrateResult) == null ? void 0 : _d.created) || 0) + (((_e = result.migrateResult) == null ? void 0 : _e.updated) || 0) : result.entriesToMigrate[currentProject].totalCount,
1436
- commit ? (((_f = result.nodesResult) == null ? void 0 : _f.created) || 0) + (((_g = result.nodesResult) == null ? void 0 : _g.updated) || 0) : ((_h = result.nodesToMigrate) == null ? void 0 : _h[currentProject].totalCount) || 0
1489
+ commit ? (((_e = result.migrateResult) == null ? void 0 : _e.created) || 0) + (((_f = result.migrateResult) == null ? void 0 : _f.updated) || 0) : result.entriesToMigrate[currentProject].totalCount,
1490
+ commit ? (((_g = result.nodesResult) == null ? void 0 : _g.created) || 0) + (((_h = result.nodesResult) == null ? void 0 : _h.updated) || 0) : ((_i = result.nodesToMigrate) == null ? void 0 : _i[currentProject].totalCount) || 0
1437
1491
  )
1438
1492
  );
1439
1493
  if (!commit) {
@@ -1442,7 +1496,7 @@ Components:`));
1442
1496
  }
1443
1497
  } else {
1444
1498
  log.error(messages.entries.failedImport(currentEnv), err);
1445
- if (!((_j = (_i = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _i[currentProject]) == null ? void 0 : _j.totalCount))
1499
+ if (!((_k = (_j = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _j[currentProject]) == null ? void 0 : _k.totalCount))
1446
1500
  log.help(messages.entries.notFound(currentEnv));
1447
1501
  }
1448
1502
  } else {
@@ -1476,8 +1530,8 @@ Components:`));
1476
1530
  if (err)
1477
1531
  (0, import_logger.logError)(err);
1478
1532
  if (result) {
1479
- const output = saveEntries ? (_a = contensis.content.copy.targets[currentProject].migrateEntries) == null ? void 0 : _a.map(
1480
- (me) => me.finalEntry
1533
+ const output = saveEntries ? (_a = contensis.content.copy.targets[currentProject].entries.migrate) == null ? void 0 : _a.map(
1534
+ (me) => me.toJSON()
1481
1535
  ) : result;
1482
1536
  await this.HandleFormattingAndOutput(output, () => {
1483
1537
  (0, import_console.printEntriesMigrateResult)(this, result, {