contensis-cli 1.5.1-beta.6 → 1.5.1-beta.8

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.
@@ -42,7 +42,7 @@ var import_rfdc = __toESM(require("rfdc"));
42
42
  var import_migratortron = require("migratortron");
43
43
  var import_ContensisAuthService = __toESM(require("./ContensisAuthService"));
44
44
  var import_en_GB = require("../localisation/en-GB");
45
- var import_file_provider = require("../providers/file-provider");
45
+ var import_MixedFileData = require("../mappers/MixedFileData");
46
46
  var import_SessionCacheProvider = __toESM(require("../providers/SessionCacheProvider"));
47
47
  var import_CredentialProvider = __toESM(require("../providers/CredentialProvider"));
48
48
  var import_util = require("../util");
@@ -262,16 +262,13 @@ class ContensisCli {
262
262
  };
263
263
  ConnectContensisImport = async ({
264
264
  commit = false,
265
+ noSource = false,
265
266
  fromFile,
266
- importDataType,
267
- importData,
268
- mixedData
267
+ importData
269
268
  }) => {
270
269
  var _a, _b, _c, _d, _e, _f;
271
- const source = fromFile || importData || mixedData ? "file" : "contensis";
272
- const fileData = importData || (fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : []);
273
- if (typeof fileData === "string")
274
- throw new Error(`Import file format must be of type JSON`);
270
+ const source = fromFile || importData || noSource ? "user-input" : "contensis";
271
+ const mixedData = fromFile ? await new import_MixedFileData.MixedFileData().readFile(fromFile) : importData;
275
272
  const { contensisOpts, currentEnv, env, log, messages, sourceAlias } = this;
276
273
  const environments = this.cache.environments || {};
277
274
  const sourceEnvironment = environments[sourceAlias || ""] || {};
@@ -297,7 +294,7 @@ class ContensisCli {
297
294
  );
298
295
  const cachedTargetPassword = (_b = targetCredentials == null ? void 0 : targetCredentials.current) == null ? void 0 : _b.password;
299
296
  if (cachedSourcePassword && cachedTargetPassword) {
300
- if (source === "file" || importDataType === "user-input") {
297
+ if (source === "user-input") {
301
298
  this.contensis = new import_migratortron.ContensisMigrationService(
302
299
  {
303
300
  concurrency: 2,
@@ -312,7 +309,6 @@ class ContensisCli {
312
309
  targetProjects: [env.currentProject || ""],
313
310
  assetHostname: (_d = this.urls) == null ? void 0 : _d.previewWeb
314
311
  },
315
- ...importDataType ? { [importDataType]: fileData } : {},
316
312
  ...mixedData || {}
317
313
  },
318
314
  !commit
@@ -891,14 +887,16 @@ class ContensisCli {
891
887
  }) => {
892
888
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
893
889
  const { currentEnv, currentProject, log, messages } = this;
890
+ let importData;
891
+ if (tags) {
892
+ importData = new import_MixedFileData.MixedFileData();
893
+ importData.tags = tags;
894
+ importData.tagGroups = data || [];
895
+ }
894
896
  const contensis = await this.ConnectContensisImport({
895
897
  commit,
896
898
  fromFile,
897
- importDataType: tags ? "user-input" : "tagGroups",
898
- mixedData: {
899
- tagGroups: data,
900
- tags
901
- }
899
+ importData
902
900
  });
903
901
  if (contensis) {
904
902
  log.line();
@@ -994,10 +992,7 @@ class ContensisCli {
994
992
  withDependents
995
993
  });
996
994
  if (Array.isArray(result)) {
997
- let tags = [];
998
- const groups = [];
999
- if (withDependents) (0, import_util.splitTagsAndGroups)(result, tags, groups);
1000
- else tags = result;
995
+ const { tags, tagGroups } = new import_MixedFileData.MixedFileData(result);
1001
996
  log.success(messages.tags.list(currentEnv, tags.length));
1002
997
  if (tags)
1003
998
  await this.HandleFormattingAndOutput(result, () => {
@@ -1005,10 +1000,12 @@ class ContensisCli {
1005
1000
  log.raw("");
1006
1001
  log.object(tag);
1007
1002
  }
1008
- if (groups.length) {
1003
+ if (tagGroups.length) {
1009
1004
  log.raw("");
1010
- log.success(messages.taggroups.list(currentEnv, groups.length));
1011
- for (const group of groups) {
1005
+ log.success(
1006
+ messages.taggroups.list(currentEnv, tagGroups.length)
1007
+ );
1008
+ for (const group of tagGroups) {
1012
1009
  log.raw("");
1013
1010
  log.object(group);
1014
1011
  }
@@ -1027,10 +1024,7 @@ class ContensisCli {
1027
1024
  withDependents
1028
1025
  });
1029
1026
  if (Array.isArray(result)) {
1030
- let tags = [];
1031
- const groups = [];
1032
- if (withDependents) (0, import_util.splitTagsAndGroups)(result, tags, groups);
1033
- else tags = result;
1027
+ const { tags, tagGroups } = new import_MixedFileData.MixedFileData(result);
1034
1028
  log.success(messages.tags.list(currentEnv, tags.length));
1035
1029
  if (!tags.length) log.help(messages.tags.noneExist());
1036
1030
  await this.HandleFormattingAndOutput(result, () => {
@@ -1038,10 +1032,10 @@ class ContensisCli {
1038
1032
  log.raw("");
1039
1033
  log.object(tag);
1040
1034
  }
1041
- if (groups.length) {
1035
+ if (tagGroups.length) {
1042
1036
  log.raw("");
1043
- log.success(messages.taggroups.list(currentEnv, groups.length));
1044
- for (const { version, ...group } of groups) {
1037
+ log.success(messages.taggroups.list(currentEnv, tagGroups.length));
1038
+ for (const { version, ...group } of tagGroups) {
1045
1039
  log.raw("");
1046
1040
  log.object(group);
1047
1041
  }
@@ -1060,23 +1054,20 @@ class ContensisCli {
1060
1054
  }) => {
1061
1055
  var _a, _b, _c, _d, _e, _f, _g, _h;
1062
1056
  const { currentEnv, currentProject, log, messages } = this;
1063
- const mixedData = { tags: [], tagGroups: [] };
1057
+ let importData;
1064
1058
  if (data) {
1065
- mixedData.tags = data;
1066
- mixedData.tagGroups = [...new Set(data.map((t) => t.groupId))].map(
1059
+ importData = new import_MixedFileData.MixedFileData();
1060
+ importData.tags = data;
1061
+ importData.tagGroups = [...new Set(data.map((t) => t.groupId))].map(
1067
1062
  (id) => ({
1068
1063
  id
1069
1064
  })
1070
1065
  );
1071
1066
  }
1072
- if (fromFile) {
1073
- const fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1074
- (0, import_util.splitTagsAndGroups)(fileData, mixedData.tags, mixedData.tagGroups);
1075
- }
1076
1067
  const contensis = await this.ConnectContensisImport({
1077
1068
  commit,
1078
- importDataType: "tags",
1079
- mixedData
1069
+ fromFile,
1070
+ importData
1080
1071
  });
1081
1072
  if (contensis) {
1082
1073
  log.line();
@@ -1136,8 +1127,7 @@ class ContensisCli {
1136
1127
  this.contensisOpts.concurrency = 1;
1137
1128
  const contensis = await this.ConnectContensisImport({
1138
1129
  commit,
1139
- importDataType: "user-input"
1140
- // 'user-input' import type does not require a source cms
1130
+ noSource: true
1141
1131
  });
1142
1132
  if (contensis) {
1143
1133
  log.line();
@@ -1393,14 +1383,9 @@ class ContensisCli {
1393
1383
  fromFile
1394
1384
  }) => {
1395
1385
  const { currentProject, log, messages } = this;
1396
- const mixedData = { models: [], tagGroups: [] };
1397
- if (fromFile) {
1398
- const fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1399
- (0, import_util.splitTagGroupsInModels)(fileData, mixedData.models, mixedData.tagGroups);
1400
- }
1401
1386
  const contensis = await this.ConnectContensisImport({
1402
1387
  commit,
1403
- mixedData
1388
+ fromFile
1404
1389
  });
1405
1390
  if (contensis) {
1406
1391
  log.line();
@@ -1544,8 +1529,7 @@ Nodes:`));
1544
1529
  const { currentProject, log, messages } = this;
1545
1530
  const contensis = await this.ConnectContensisImport({
1546
1531
  commit,
1547
- importDataType: "user-input"
1548
- // 'user-input' import type does not require a source cms
1532
+ noSource: true
1549
1533
  });
1550
1534
  if (contensis) {
1551
1535
  const [err, result] = await contensis.DeleteContentTypes(contentTypeIds);
@@ -1566,6 +1550,7 @@ Nodes:`));
1566
1550
  )
1567
1551
  );
1568
1552
  await this.HandleFormattingAndOutput(result, log.object);
1553
+ if (!commit) log.help(messages.migrate.commitTip());
1569
1554
  }
1570
1555
  }
1571
1556
  };
@@ -1574,17 +1559,15 @@ Nodes:`));
1574
1559
  fromFile
1575
1560
  }, contentTypeIds = []) => {
1576
1561
  const { currentProject, log, messages } = this;
1577
- let fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1578
- if (typeof fileData === "string")
1579
- throw new Error(`Import file format must be of type JSON`);
1580
- if (!Array.isArray(fileData)) fileData = [fileData];
1562
+ let importData;
1563
+ if (fromFile) importData = await new import_MixedFileData.MixedFileData().readFile(fromFile);
1581
1564
  const contensis = await this.ConnectContensisImport({
1582
1565
  commit,
1583
- importDataType: fromFile ? "user-input" : void 0
1566
+ noSource: !!fromFile
1584
1567
  });
1585
1568
  if (contensis) {
1586
1569
  if (fromFile)
1587
- for (const contentType of fileData) {
1570
+ for (const contentType of importData.models) {
1588
1571
  contentType.projectId = currentProject;
1589
1572
  delete contentType.uuid;
1590
1573
  const [err, , createStatus] = await contensis.models.targets[currentProject].repo.UpsertContentType(false, contentType);
@@ -1608,23 +1591,21 @@ Nodes:`));
1608
1591
  );
1609
1592
  await this.HandleFormattingAndOutput(result, log.object);
1610
1593
  }
1594
+ if (!commit) log.help(messages.migrate.commitTip());
1611
1595
  }
1612
1596
  };
1613
1597
  DiffModels = async ({
1614
1598
  fromFile
1615
1599
  }, modelIds = []) => {
1616
1600
  const { log } = this;
1617
- let fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1618
- if (typeof fileData === "string")
1619
- throw new Error(`Import file format must be of type JSON`);
1620
- if (!Array.isArray(fileData)) fileData = [fileData];
1621
- const contensis = await this.ConnectContensisImport({
1622
- fromFile,
1623
- importDataType: "models"
1624
- });
1601
+ let importData;
1602
+ if (fromFile) importData = await new import_MixedFileData.MixedFileData().readFile(fromFile);
1603
+ const contensis = await this.ConnectContensisImport({ fromFile });
1625
1604
  if (contensis) {
1626
1605
  const [err, result] = await (0, import_await_to_js.default)(
1627
- contensis.models.Diff(fileData.length ? fileData : modelIds)
1606
+ contensis.models.Diff(
1607
+ importData.models.length ? importData.models : modelIds
1608
+ )
1628
1609
  );
1629
1610
  if (err) log.error(err.message, err);
1630
1611
  if (result)
@@ -1691,8 +1672,7 @@ Components:`));
1691
1672
  const { currentProject, log, messages } = this;
1692
1673
  const contensis = await this.ConnectContensisImport({
1693
1674
  commit,
1694
- importDataType: "user-input"
1695
- // 'user-input' import type does not require a source cms
1675
+ noSource: true
1696
1676
  });
1697
1677
  if (contensis) {
1698
1678
  const [err, result] = await contensis.DeleteContentTypes(
@@ -1716,6 +1696,7 @@ Components:`));
1716
1696
  )
1717
1697
  );
1718
1698
  await this.HandleFormattingAndOutput(result, log.object);
1699
+ if (!commit) log.help(messages.migrate.commitTip());
1719
1700
  }
1720
1701
  }
1721
1702
  };
@@ -1724,17 +1705,15 @@ Components:`));
1724
1705
  fromFile
1725
1706
  }, componentIds = []) => {
1726
1707
  const { currentProject, log, messages } = this;
1727
- let fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1728
- if (typeof fileData === "string")
1729
- throw new Error(`Import file format must be of type JSON`);
1730
- if (!Array.isArray(fileData)) fileData = [fileData];
1708
+ let importData;
1709
+ if (fromFile) importData = await new import_MixedFileData.MixedFileData().readFile(fromFile);
1731
1710
  const contensis = await this.ConnectContensisImport({
1732
1711
  commit,
1733
- importDataType: fromFile ? "user-input" : void 0
1712
+ noSource: !!fromFile
1734
1713
  });
1735
1714
  if (contensis) {
1736
1715
  if (fromFile)
1737
- for (const component of fileData) {
1716
+ for (const component of importData.models) {
1738
1717
  component.projectId = currentProject;
1739
1718
  delete component.uuid;
1740
1719
  const [err, , createStatus] = await contensis.models.targets[currentProject].repo.UpsertComponent(false, component);
@@ -1758,6 +1737,7 @@ Components:`));
1758
1737
  );
1759
1738
  await this.HandleFormattingAndOutput(result, log.object);
1760
1739
  }
1740
+ if (!commit) log.help(messages.migrate.commitTip());
1761
1741
  }
1762
1742
  };
1763
1743
  RemoveEntries = async (commit = false) => {
@@ -1766,8 +1746,7 @@ Components:`));
1766
1746
  this.contensisOpts.concurrency = 1;
1767
1747
  const contensis = await this.ConnectContensisImport({
1768
1748
  commit,
1769
- importDataType: "user-input"
1770
- // 'user-input' import type does not require a source cms
1749
+ noSource: true
1771
1750
  });
1772
1751
  if (contensis) {
1773
1752
  if (contensis.isPreview) {
@@ -1834,11 +1813,12 @@ Components:`));
1834
1813
  }) => {
1835
1814
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1836
1815
  const { currentEnv, currentProject, log, messages } = this;
1816
+ let importData;
1817
+ if (data) importData = new import_MixedFileData.MixedFileData(data);
1837
1818
  const contensis = await this.ConnectContensisImport({
1838
1819
  commit,
1839
1820
  fromFile,
1840
- importDataType: "entries",
1841
- importData: data
1821
+ importData
1842
1822
  });
1843
1823
  if (contensis) {
1844
1824
  log.line();
@@ -1916,8 +1896,7 @@ Components:`));
1916
1896
  const { currentEnv, currentProject, log, messages } = this;
1917
1897
  const contensis = await this.ConnectContensisImport({
1918
1898
  commit,
1919
- fromFile,
1920
- importDataType: "entries"
1899
+ fromFile
1921
1900
  });
1922
1901
  if (contensis) {
1923
1902
  log.line();
@@ -1974,8 +1953,7 @@ Components:`));
1974
1953
  const { currentEnv, currentProject, log, messages } = this;
1975
1954
  const contensis = await this.ConnectContensisImport({
1976
1955
  commit,
1977
- fromFile,
1978
- importDataType: "entries"
1956
+ fromFile
1979
1957
  });
1980
1958
  if (contensis) {
1981
1959
  log.line();
@@ -2052,8 +2030,7 @@ Components:`));
2052
2030
  const { currentEnv, currentProject, log, messages } = this;
2053
2031
  const contensis = await this.ConnectContensisImport({
2054
2032
  commit,
2055
- fromFile,
2056
- importDataType: "nodes"
2033
+ fromFile
2057
2034
  });
2058
2035
  if (contensis) {
2059
2036
  log.line();
@@ -2110,8 +2087,7 @@ Components:`));
2110
2087
  const { currentEnv, currentProject, log, messages } = this;
2111
2088
  const contensis = await this.ConnectContensisImport({
2112
2089
  commit,
2113
- importDataType: "user-input"
2114
- // 'user-input' import type does not require a source cms
2090
+ noSource: true
2115
2091
  });
2116
2092
  if (contensis) {
2117
2093
  if (contensis.isPreview) {