contensis-cli 1.2.2-beta.1 → 1.2.2-beta.10

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,55 +931,62 @@ 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.printRequiredBy) {
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, () => {
989
+ await this.HandleFormattingAndOutput(exportResources, () => {
982
990
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
983
991
  for (const model of models) {
984
992
  const components2 = ((_a = model.components) == null ? void 0 : _a.length) || 0;
@@ -1389,7 +1397,7 @@ Components:`));
1389
1397
  logOutput,
1390
1398
  saveEntries
1391
1399
  }) => {
1392
- var _a, _b, _c, _d, _e, _f, _g, _h;
1400
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1393
1401
  const { currentEnv, currentProject, log, messages } = this;
1394
1402
  const contensis = await this.ConnectContensisImport({
1395
1403
  commit,
@@ -1407,23 +1415,33 @@ Components:`));
1407
1415
  if (err)
1408
1416
  (0, import_logger.logError)(err);
1409
1417
  else {
1410
- const output = saveEntries ? (_a = contensis.content.targets[currentProject].migrateEntries) == null ? void 0 : _a.map(
1411
- (me) => me.finalEntry
1412
- ) : result;
1418
+ const { migrateEntries, nodes } = contensis.content.targets[currentProject];
1419
+ const output = saveEntries ? migrateEntries == null ? void 0 : migrateEntries.map((me) => me.finalEntry) : result;
1413
1420
  await this.HandleFormattingAndOutput(output, () => {
1414
1421
  (0, import_console.printEntriesMigrateResult)(this, result, {
1415
1422
  showAll: logOutput === "all",
1416
1423
  showDiff: logOutput === "all" || logOutput === "changes",
1417
1424
  showChanged: logOutput === "changes"
1418
1425
  });
1426
+ if (["all", "changes"].includes(logOutput))
1427
+ (0, import_console.printNodeTreeOutput)(
1428
+ this,
1429
+ {
1430
+ ...nodes.rootAncestor,
1431
+ status: "no change",
1432
+ children: nodes.migrateNodes
1433
+ },
1434
+ logOutput
1435
+ );
1419
1436
  });
1420
1437
  }
1421
- 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)))) {
1438
+ 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)))) {
1422
1439
  log.success(
1423
1440
  messages.entries.imported(
1424
1441
  currentEnv,
1425
1442
  commit,
1426
- commit ? (((_e = result.migrateResult) == null ? void 0 : _e.created) || 0) + (((_f = result.migrateResult) == null ? void 0 : _f.updated) || 0) : result.entriesToMigrate[currentProject].totalCount
1443
+ commit ? (((_d = result.migrateResult) == null ? void 0 : _d.created) || 0) + (((_e = result.migrateResult) == null ? void 0 : _e.updated) || 0) : result.entriesToMigrate[currentProject].totalCount,
1444
+ 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
1427
1445
  )
1428
1446
  );
1429
1447
  if (!commit) {
@@ -1432,7 +1450,7 @@ Components:`));
1432
1450
  }
1433
1451
  } else {
1434
1452
  log.error(messages.entries.failedImport(currentEnv), err);
1435
- if (!((_h = (_g = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _g[currentProject]) == null ? void 0 : _h.totalCount))
1453
+ if (!((_j = (_i = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _i[currentProject]) == null ? void 0 : _j.totalCount))
1436
1454
  log.help(messages.entries.notFound(currentEnv));
1437
1455
  }
1438
1456
  } else {
@@ -1541,11 +1559,11 @@ Components:`));
1541
1559
  console.log(log.warningText(` *** COMMITTING IMPORT *** `));
1542
1560
  }
1543
1561
  const [err, result] = await contensis.MigrateNodes();
1544
- const migrateTree = contensis.nodes.targetRepos[currentProject].nodes.migrateNodesTreeView;
1545
1562
  if (err)
1546
1563
  log.raw(``);
1547
1564
  else
1548
1565
  await this.HandleFormattingAndOutput(result, () => {
1566
+ const migrateTree = contensis.nodes.targetRepos[currentProject].nodes.migrateNodesTreeView;
1549
1567
  (0, import_console.printNodeTreeOutput)(this, migrateTree, logOutput, logLimit);
1550
1568
  (0, import_console.printNodesMigrateResult)(this, result, {
1551
1569
  showAll: logOutput === "all",