@messagevisor/catalog 0.6.0 → 0.8.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.
package/lib/node/index.js CHANGED
@@ -89,7 +89,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
89
89
  return to.concat(ar || Array.prototype.slice.call(from));
90
90
  };
91
91
  Object.defineProperty(exports, "__esModule", { value: true });
92
- exports.CATALOG_HISTORY_PAGE_SIZE = exports.CATALOG_SCHEMA_VERSION = void 0;
92
+ exports.__catalogDevInternals = exports.CATALOG_HISTORY_PAGE_SIZE = exports.CATALOG_SCHEMA_VERSION = void 0;
93
93
  exports.exportCatalog = exportCatalog;
94
94
  exports.serveCatalog = serveCatalog;
95
95
  exports.createCatalogApi = createCatalogApi;
@@ -163,6 +163,11 @@ var CatalogProgressReporter = /** @class */ (function () {
163
163
  console.log(" ".concat(colorize("•", 36), " ").concat(label).concat(suffix));
164
164
  return Date.now();
165
165
  };
166
+ CatalogProgressReporter.prototype.substep = function (label, detail) {
167
+ var suffix = detail ? ": ".concat(colorize(detail, 2)) : "";
168
+ console.log(" ".concat(colorize("•", 36), " ").concat(label).concat(suffix));
169
+ return Date.now();
170
+ };
166
171
  CatalogProgressReporter.prototype.done = function (startedAt, detail) {
167
172
  var suffix = detail ? " ".concat(detail) : "";
168
173
  console.log(CLI_FORMAT_DIM, " done in ".concat(prettyDuration(Date.now() - startedAt)).concat(suffix));
@@ -438,15 +443,61 @@ function toLocaleDuplicatesFile(localeKey, duplicatesByLocale) {
438
443
  duplicateValues: duplicateValues,
439
444
  };
440
445
  }
441
- function writeJson(filePath, content) {
446
+ var CatalogJsonWriter = /** @class */ (function () {
447
+ function CatalogJsonWriter() {
448
+ this.directories = new Map();
449
+ }
450
+ CatalogJsonWriter.prototype.ensureDirectory = function (directoryPath) {
451
+ var promise = this.directories.get(directoryPath);
452
+ if (!promise) {
453
+ promise = fs.promises.mkdir(directoryPath, { recursive: true }).then(function () { return undefined; });
454
+ this.directories.set(directoryPath, promise);
455
+ }
456
+ return promise;
457
+ };
458
+ CatalogJsonWriter.prototype.write = function (filePath, content) {
459
+ return __awaiter(this, void 0, void 0, function () {
460
+ return __generator(this, function (_a) {
461
+ switch (_a.label) {
462
+ case 0: return [4 /*yield*/, this.ensureDirectory(path.dirname(filePath))];
463
+ case 1:
464
+ _a.sent();
465
+ return [4 /*yield*/, fs.promises.writeFile(filePath, JSON.stringify(content, null, 2))];
466
+ case 2:
467
+ _a.sent();
468
+ return [2 /*return*/];
469
+ }
470
+ });
471
+ });
472
+ };
473
+ return CatalogJsonWriter;
474
+ }());
475
+ function mapWithConcurrency(items, concurrency, callback) {
442
476
  return __awaiter(this, void 0, void 0, function () {
477
+ var nextIndex, workerCount, workers;
478
+ var _this = this;
443
479
  return __generator(this, function (_a) {
444
480
  switch (_a.label) {
445
- case 0: return [4 /*yield*/, fs.promises.mkdir(path.dirname(filePath), { recursive: true })];
481
+ case 0:
482
+ nextIndex = 0;
483
+ workerCount = Math.min(concurrency, items.length);
484
+ workers = Array.from({ length: workerCount }, function () { return __awaiter(_this, void 0, void 0, function () {
485
+ var index;
486
+ return __generator(this, function (_a) {
487
+ switch (_a.label) {
488
+ case 0:
489
+ if (!(nextIndex < items.length)) return [3 /*break*/, 2];
490
+ index = nextIndex++;
491
+ return [4 /*yield*/, callback(items[index], index)];
492
+ case 1:
493
+ _a.sent();
494
+ return [3 /*break*/, 0];
495
+ case 2: return [2 /*return*/];
496
+ }
497
+ });
498
+ }); });
499
+ return [4 /*yield*/, Promise.all(workers)];
446
500
  case 1:
447
- _a.sent();
448
- return [4 /*yield*/, fs.promises.writeFile(filePath, JSON.stringify(content, null, 2))];
449
- case 2:
450
501
  _a.sent();
451
502
  return [2 /*return*/];
452
503
  }
@@ -537,6 +588,14 @@ function addHistoryIndexEntry(target, key, entry) {
537
588
  }
538
589
  target[key].push(entry);
539
590
  }
591
+ function toEntityHistoryEntry(entry, entity) {
592
+ return {
593
+ commit: entry.commit,
594
+ author: entry.author,
595
+ timestamp: entry.timestamp,
596
+ entities: [entity],
597
+ };
598
+ }
540
599
  function buildCatalogHistoryIndex(entries) {
541
600
  var index = createEmptyHistoryIndex();
542
601
  index.entries = entries;
@@ -549,7 +608,7 @@ function buildCatalogHistoryIndex(entries) {
549
608
  continue;
550
609
  }
551
610
  var entityKey = getHistoryEntityKey(entity.type, entity.key, entity.set);
552
- addHistoryIndexEntry(index.byEntity, entityKey, entry);
611
+ addHistoryIndexEntry(index.byEntity, entityKey, toEntityHistoryEntry(entry, entity));
553
612
  if (!index.lastModifiedByEntity[entityKey]) {
554
613
  index.lastModifiedByEntity[entityKey] = toLastModified(entry);
555
614
  }
@@ -758,6 +817,19 @@ function getRepositoryRootDirectoryPath(rootDirectoryPath) {
758
817
  return getRealPath(rootDirectoryPath);
759
818
  }
760
819
  }
820
+ function getRepositorySourceRootDirectoryPath(rootDirectoryPath) {
821
+ try {
822
+ var gitRootDirectoryPath = runGit(rootDirectoryPath, ["rev-parse", "--show-toplevel"]).trim() || rootDirectoryPath;
823
+ var realRootDirectoryPath = getRealPath(rootDirectoryPath);
824
+ if (realRootDirectoryPath !== rootDirectoryPath) {
825
+ return path.resolve(rootDirectoryPath, path.relative(realRootDirectoryPath, gitRootDirectoryPath));
826
+ }
827
+ return gitRootDirectoryPath;
828
+ }
829
+ catch (_error) {
830
+ return rootDirectoryPath;
831
+ }
832
+ }
761
833
  function getOwnerAndRepoFromGitRemote(origin, host) {
762
834
  var escapedHost = host.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
763
835
  var match = origin.match(new RegExp("".concat(escapedHost, "[:/]([^/]+)/(.+?)(?:\\.git)?$")));
@@ -819,18 +891,22 @@ function chunkHistory(history, pageSize) {
819
891
  }
820
892
  return pages.length > 0 ? pages : [[]];
821
893
  }
822
- function writeHistoryPages(directoryPath, history) {
823
- return __awaiter(this, void 0, void 0, function () {
894
+ function writeHistoryPages(writer_1, directoryPath_1, history_1) {
895
+ return __awaiter(this, arguments, void 0, function (writer, directoryPath, history, options) {
824
896
  var pages, index;
897
+ if (options === void 0) { options = {}; }
825
898
  return __generator(this, function (_a) {
826
899
  switch (_a.label) {
827
900
  case 0:
901
+ if (options.skipEmpty && history.length === 0) {
902
+ return [2 /*return*/, 1];
903
+ }
828
904
  pages = chunkHistory(history);
829
905
  index = 0;
830
906
  _a.label = 1;
831
907
  case 1:
832
908
  if (!(index < pages.length)) return [3 /*break*/, 4];
833
- return [4 /*yield*/, writeJson(path.join(directoryPath, "page-".concat(index + 1, ".json")), {
909
+ return [4 /*yield*/, writer.write(path.join(directoryPath, "page-".concat(index + 1, ".json")), {
834
910
  page: index + 1,
835
911
  pageSize: exports.CATALOG_HISTORY_PAGE_SIZE,
836
912
  totalPages: pages.length,
@@ -842,7 +918,7 @@ function writeHistoryPages(directoryPath, history) {
842
918
  case 3:
843
919
  index++;
844
920
  return [3 /*break*/, 1];
845
- case 4: return [2 /*return*/];
921
+ case 4: return [2 /*return*/, 0];
846
922
  }
847
923
  });
848
924
  });
@@ -850,7 +926,8 @@ function writeHistoryPages(directoryPath, history) {
850
926
  function getHistoryForEntity(historyIndex, type, key, set) {
851
927
  return historyIndex.byEntity[getHistoryEntityKey(type, key, set)] || [];
852
928
  }
853
- function getSourceFileInfo(repositoryRootDirectoryPath, rootDirectoryPath, projectConfig, type, key) {
929
+ function getSourceFileInfo(repositorySourceRootDirectoryPath, rootDirectoryPath, projectConfig, type, key, options) {
930
+ if (options === void 0) { options = {}; }
854
931
  var directoryByType = {
855
932
  locale: projectConfig.localesDirectoryPath,
856
933
  message: projectConfig.messagesDirectoryPath,
@@ -861,9 +938,9 @@ function getSourceFileInfo(repositoryRootDirectoryPath, rootDirectoryPath, proje
861
938
  var extension = ".".concat(projectConfig.parser.extension);
862
939
  var filePath = path.resolve(path.resolve.apply(path, __spreadArray([rootDirectoryPath,
863
940
  directoryByType[type]], key.split(projectConfig.namespaceCharacter), false)) + extension);
864
- var absolutePath = getRealPath(filePath);
941
+ var absolutePath = options.resolveAbsolutePath ? getRealPath(filePath) : filePath;
865
942
  return {
866
- sourcePath: toPosixPath(path.relative(repositoryRootDirectoryPath, absolutePath)),
943
+ sourcePath: toPosixPath(path.relative(repositorySourceRootDirectoryPath, filePath)),
867
944
  absolutePath: absolutePath,
868
945
  };
869
946
  }
@@ -899,10 +976,11 @@ function buildSetCatalog(context, set, projectConfig, datasource, outputRelative
899
976
  translationShards[filename][msgKey].add(lower);
900
977
  }
901
978
  }
902
- var outputDirectoryPath, setStartedAt, entitiesStartedAt, _a, localeKeys, messageKeys, attributeKeys, segmentKeys, targetKeys, _b, locales, messages, attributes, segments, targets, relationshipsStartedAt, messageTargets, targetMessages, localeTargets, attributeTargets, segmentTargets, attributesUsedInSegments, attributesUsedInMessages, segmentsUsedInMessages, _i, targetKeys_1, targetKey, targetLocaleKeys, _c, targetLocaleKeys_1, localeKey, _d, _e, messageKey, _f, segmentKeys_1, segmentKey, usedAttributes, _g, _h, attributeKey, _j, messageKeys_1, messageKey, message, targetsForMessage, _k, _l, override, usedAttributes, usedSegments, _m, _o, attributeKey, _p, targetsForMessage_1, targetKey, _q, _r, segmentKey, _s, targetsForMessage_2, targetKey, _t, _u, attributeKey, _v, _w, segmentKey, _x, _y, targetKey, history, localeDirections, duplicateResult, duplicatesByLocale, index, historyStartedAt, examplesStartedAt, evaluatedMessageExamplesByKey, evaluatedLocaleExamplesByKey, localesStartedAt, _loop_1, _z, localeKeys_1, localeKey, duplicatesStartedAt, _0, localeKeys_2, localeKey, translationShards, messagesStartedAt, _loop_2, _1, messageKeys_2, messageKey, translationSearchStartedAt, _2, messageKeys_3, messageKey, message, _3, localeKeys_3, localeKey, row, _4, _5, override, overrideRow, _6, _7, _8, prefix, messageMap, shardData, _9, _10, _11, msgKey, valueSet, attributesStartedAt, _12, attributeKeys_1, attributeKey, attribute, sourceFileInfo, detail, segmentsStartedAt, _13, segmentKeys_2, segmentKey, segment, usedAttributes, sourceFileInfo, detail, targetsStartedAt, _14, targetKeys_2, targetKey, target, targetLocaleKeys, formatsByLocale, formatRowsByLocale, _15, targetLocaleKeys_2, localeKey, sourceFileInfo, detail, indexStartedAt, _16, _17, type;
903
- var _18, _19;
904
- return __generator(this, function (_20) {
905
- switch (_20.label) {
979
+ var outputDirectoryPath, setStartedAt, entitiesStartedAt, _a, localeKeys, messageKeys, attributeKeys, segmentKeys, targetKeys, _b, locales, messages, attributes, segments, targets, relationshipsStartedAt, messageTargets, targetMessages, localeTargets, attributeTargets, segmentTargets, attributesUsedInSegments, attributesUsedInMessages, segmentsUsedInMessages, _i, targetKeys_1, targetKey, targetLocaleKeys, _c, targetLocaleKeys_1, localeKey, _d, _e, messageKey, _f, segmentKeys_1, segmentKey, usedAttributes, _g, _h, attributeKey, _j, messageKeys_1, messageKey, message, targetsForMessage, _k, _l, override, usedAttributes, usedSegments, _m, _o, attributeKey, _p, targetsForMessage_1, targetKey, _q, _r, segmentKey, _s, targetsForMessage_2, targetKey, _t, _u, attributeKey, _v, _w, segmentKey, _x, _y, targetKey, history, localeDirections, duplicateResult, duplicatesByLocale, index, historyStartedAt, examplesStartedAt, evaluatedMessageExamplesByKey, evaluatedLocaleExamplesByKey, localesStartedAt, skippedEmptyHistoryCount, duplicatesStartedAt, translationShards, messagesStartedAt, messageDetailsStartedAt, skippedEmptyMessageHistoryCount, messageHistoryStartedAt, translationSearchStartedAt, _z, messageKeys_2, messageKey, message, _0, localeKeys_1, localeKey, row, _1, _2, override, overrideRow, _3, _4, _5, prefix, messageMap, shardData, _6, _7, _8, msgKey, valueSet, attributesStartedAt, segmentsStartedAt, targetsStartedAt, indexStartedAt, _9, _10, type;
980
+ var _this = this;
981
+ var _11;
982
+ return __generator(this, function (_12) {
983
+ switch (_12.label) {
906
984
  case 0:
907
985
  outputDirectoryPath = path.join(context.dataDirectoryPath, outputRelativeDirectory);
908
986
  setStartedAt = context.progress.setStart(set);
@@ -915,7 +993,7 @@ function buildSetCatalog(context, set, projectConfig, datasource, outputRelative
915
993
  datasource.listTargets(),
916
994
  ])];
917
995
  case 1:
918
- _a = _20.sent(), localeKeys = _a[0], messageKeys = _a[1], attributeKeys = _a[2], segmentKeys = _a[3], targetKeys = _a[4];
996
+ _a = (_12.sent()), localeKeys = _a[0], messageKeys = _a[1], attributeKeys = _a[2], segmentKeys = _a[3], targetKeys = _a[4];
919
997
  return [4 /*yield*/, Promise.all([
920
998
  readAll(localeKeys, function (key) { return datasource.readLocale(key); }),
921
999
  readAll(messageKeys, function (key) { return datasource.readMessage(key); }),
@@ -924,7 +1002,7 @@ function buildSetCatalog(context, set, projectConfig, datasource, outputRelative
924
1002
  readAll(targetKeys, function (key) { return datasource.readTarget(key); }),
925
1003
  ])];
926
1004
  case 2:
927
- _b = _20.sent(), locales = _b[0], messages = _b[1], attributes = _b[2], segments = _b[3], targets = _b[4];
1005
+ _b = _12.sent(), locales = _b[0], messages = _b[1], attributes = _b[2], segments = _b[3], targets = _b[4];
928
1006
  context.progress.done(entitiesStartedAt, "(".concat([
929
1007
  pluralize(localeKeys.length, "locale"),
930
1008
  pluralize(messageKeys.length, "message"),
@@ -944,7 +1022,7 @@ function buildSetCatalog(context, set, projectConfig, datasource, outputRelative
944
1022
  for (_i = 0, targetKeys_1 = targetKeys; _i < targetKeys_1.length; _i++) {
945
1023
  targetKey = targetKeys_1[_i];
946
1024
  targetMessages[targetKey] = getTargetMessageKeys(targets[targetKey], messageKeys);
947
- targetLocaleKeys = ((_18 = targets[targetKey].locales) === null || _18 === void 0 ? void 0 : _18.length)
1025
+ targetLocaleKeys = ((_11 = targets[targetKey].locales) === null || _11 === void 0 ? void 0 : _11.length)
948
1026
  ? targets[targetKey].locales
949
1027
  : localeKeys;
950
1028
  for (_c = 0, targetLocaleKeys_1 = targetLocaleKeys; _c < targetLocaleKeys_1.length; _c++) {
@@ -1053,16 +1131,16 @@ function buildSetCatalog(context, set, projectConfig, datasource, outputRelative
1053
1131
  },
1054
1132
  };
1055
1133
  historyStartedAt = context.progress.step("Writing history pages");
1056
- return [4 /*yield*/, writeHistoryPages(path.join(outputDirectoryPath, "history"), history)];
1134
+ return [4 /*yield*/, writeHistoryPages(context.writer, path.join(outputDirectoryPath, "history"), history)];
1057
1135
  case 3:
1058
- _20.sent();
1136
+ _12.sent();
1059
1137
  context.progress.done(historyStartedAt, "(".concat(pluralize(history.length, "entry", "entries"), ")"));
1060
1138
  examplesStartedAt = context.progress.step("Evaluating examples");
1061
1139
  return [4 /*yield*/, context.runtime.resolveExamples(projectConfig, datasource, {
1062
1140
  onlyMessages: true,
1063
1141
  })];
1064
1142
  case 4:
1065
- evaluatedMessageExamplesByKey = (_20.sent()).messages.reduce(function (accumulator, example) {
1143
+ evaluatedMessageExamplesByKey = (_12.sent()).messages.reduce(function (accumulator, example) {
1066
1144
  if (!accumulator[example.message]) {
1067
1145
  accumulator[example.message] = [];
1068
1146
  }
@@ -1073,7 +1151,7 @@ function buildSetCatalog(context, set, projectConfig, datasource, outputRelative
1073
1151
  onlyLocales: true,
1074
1152
  })];
1075
1153
  case 5:
1076
- evaluatedLocaleExamplesByKey = (_20.sent()).locales.reduce(function (accumulator, example) {
1154
+ evaluatedLocaleExamplesByKey = (_12.sent()).locales.reduce(function (accumulator, example) {
1077
1155
  var _a;
1078
1156
  var originalTranslation = example.message
1079
1157
  ? resolveTranslationRow((_a = messages[example.message]) === null || _a === void 0 ? void 0 : _a.translations, example.locale, locales)
@@ -1087,159 +1165,155 @@ function buildSetCatalog(context, set, projectConfig, datasource, outputRelative
1087
1165
  }, {});
1088
1166
  context.progress.done(examplesStartedAt, "(".concat(pluralize(Object.values(evaluatedMessageExamplesByKey).reduce(function (total, items) { return total + items.length; }, 0), "message example"), ", ").concat(pluralize(Object.values(evaluatedLocaleExamplesByKey).reduce(function (total, items) { return total + items.length; }, 0), "locale example"), ")"));
1089
1167
  localesStartedAt = context.progress.step("Writing locales");
1090
- _loop_1 = function (localeKey) {
1091
- var locale, sourceFileInfo, detail;
1092
- return __generator(this, function (_21) {
1093
- switch (_21.label) {
1094
- case 0:
1095
- locale = locales[localeKey];
1096
- sourceFileInfo = getSourceFileInfo(context.repositoryRootDirectoryPath, context.rootDirectoryPath, projectConfig, "locale", localeKey);
1097
- detail = {
1098
- type: "locale",
1099
- key: localeKey,
1100
- entity: locale,
1101
- sourcePath: sourceFileInfo.sourcePath,
1102
- editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1103
- baseFormats: locale.formats || {},
1104
- computedFormats: context.runtime.resolveFormats(localeKey, locales),
1105
- formatRows: getFormatRows(context.runtime, localeKey, locales),
1106
- evaluatedExamples: evaluatedLocaleExamplesByKey[localeKey] || [],
1107
- targetFormats: Object.fromEntries(targetKeys.map(function (targetKey) { return [
1108
- targetKey,
1109
- context.runtime.resolveFormats(localeKey, locales, targets[targetKey]),
1110
- ]; })),
1111
- lastModified: getLastModified(context.historyIndex, "locale", localeKey, set || undefined),
1112
- };
1113
- index.entities.locale.push(getEntitySummary(locale, "locale", localeKey, context.historyIndex, set || undefined, {
1114
- targets: sortStrings(Array.from(localeTargets[localeKey] || [])),
1115
- }));
1116
- return [4 /*yield*/, writeJson(path.join(outputDirectoryPath, "entities", "locale", "".concat(encodeKey(localeKey), ".json")), detail)];
1117
- case 1:
1118
- _21.sent();
1119
- return [4 /*yield*/, writeHistoryPages(path.join(outputDirectoryPath, "history", "locale", encodeKey(localeKey)), getHistoryForEntity(context.historyIndex, "locale", localeKey, set || undefined))];
1120
- case 2:
1121
- _21.sent();
1122
- return [2 /*return*/];
1123
- }
1124
- });
1125
- };
1126
- _z = 0, localeKeys_1 = localeKeys;
1127
- _20.label = 6;
1168
+ skippedEmptyHistoryCount = 0;
1169
+ return [4 /*yield*/, mapWithConcurrency(localeKeys, 32, function (localeKey) { return __awaiter(_this, void 0, void 0, function () {
1170
+ var locale, sourceFileInfo, detail, _a;
1171
+ return __generator(this, function (_b) {
1172
+ switch (_b.label) {
1173
+ case 0:
1174
+ locale = locales[localeKey];
1175
+ sourceFileInfo = getSourceFileInfo(context.repositorySourceRootDirectoryPath, context.rootDirectoryPath, projectConfig, "locale", localeKey, { resolveAbsolutePath: context.devEditors.length > 0 });
1176
+ detail = {
1177
+ type: "locale",
1178
+ key: localeKey,
1179
+ entity: locale,
1180
+ sourcePath: sourceFileInfo.sourcePath,
1181
+ editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1182
+ baseFormats: locale.formats || {},
1183
+ computedFormats: context.runtime.resolveFormats(localeKey, locales),
1184
+ formatRows: getFormatRows(context.runtime, localeKey, locales),
1185
+ evaluatedExamples: evaluatedLocaleExamplesByKey[localeKey] || [],
1186
+ targetFormats: Object.fromEntries(targetKeys.map(function (targetKey) { return [
1187
+ targetKey,
1188
+ context.runtime.resolveFormats(localeKey, locales, targets[targetKey]),
1189
+ ]; })),
1190
+ lastModified: getLastModified(context.historyIndex, "locale", localeKey, set || undefined),
1191
+ };
1192
+ index.entities.locale.push(getEntitySummary(locale, "locale", localeKey, context.historyIndex, set || undefined, {
1193
+ targets: sortStrings(Array.from(localeTargets[localeKey] || [])),
1194
+ }));
1195
+ return [4 /*yield*/, context.writer.write(path.join(outputDirectoryPath, "entities", "locale", "".concat(encodeKey(localeKey), ".json")), detail)];
1196
+ case 1:
1197
+ _b.sent();
1198
+ _a = skippedEmptyHistoryCount;
1199
+ return [4 /*yield*/, writeHistoryPages(context.writer, path.join(outputDirectoryPath, "history", "locale", encodeKey(localeKey)), getHistoryForEntity(context.historyIndex, "locale", localeKey, set || undefined), { skipEmpty: true })];
1200
+ case 2:
1201
+ skippedEmptyHistoryCount = _a + _b.sent();
1202
+ return [2 /*return*/];
1203
+ }
1204
+ });
1205
+ }); })];
1128
1206
  case 6:
1129
- if (!(_z < localeKeys_1.length)) return [3 /*break*/, 9];
1130
- localeKey = localeKeys_1[_z];
1131
- return [5 /*yield**/, _loop_1(localeKey)];
1132
- case 7:
1133
- _20.sent();
1134
- _20.label = 8;
1135
- case 8:
1136
- _z++;
1137
- return [3 /*break*/, 6];
1138
- case 9:
1207
+ _12.sent();
1139
1208
  context.progress.done(localesStartedAt, "(".concat(pluralize(localeKeys.length, "locale"), ")"));
1140
- if (!context.withDuplicates) return [3 /*break*/, 14];
1209
+ if (!context.withDuplicates) return [3 /*break*/, 8];
1141
1210
  duplicatesStartedAt = context.progress.step("Writing duplicate reports");
1142
- _0 = 0, localeKeys_2 = localeKeys;
1143
- _20.label = 10;
1144
- case 10:
1145
- if (!(_0 < localeKeys_2.length)) return [3 /*break*/, 13];
1146
- localeKey = localeKeys_2[_0];
1147
- return [4 /*yield*/, writeJson(path.join(outputDirectoryPath, "duplicates", "locales", "".concat(encodeKey(localeKey), ".json")), toLocaleDuplicatesFile(localeKey, duplicatesByLocale))];
1148
- case 11:
1149
- _20.sent();
1150
- _20.label = 12;
1151
- case 12:
1152
- _0++;
1153
- return [3 /*break*/, 10];
1154
- case 13:
1211
+ return [4 /*yield*/, mapWithConcurrency(localeKeys, 32, function (localeKey) { return __awaiter(_this, void 0, void 0, function () {
1212
+ return __generator(this, function (_a) {
1213
+ switch (_a.label) {
1214
+ case 0: return [4 /*yield*/, context.writer.write(path.join(outputDirectoryPath, "duplicates", "locales", "".concat(encodeKey(localeKey), ".json")), toLocaleDuplicatesFile(localeKey, duplicatesByLocale))];
1215
+ case 1:
1216
+ _a.sent();
1217
+ return [2 /*return*/];
1218
+ }
1219
+ });
1220
+ }); })];
1221
+ case 7:
1222
+ _12.sent();
1155
1223
  context.progress.done(duplicatesStartedAt, "(".concat(pluralize(localeKeys.length, "locale"), ")"));
1156
- _20.label = 14;
1157
- case 14:
1224
+ _12.label = 8;
1225
+ case 8:
1158
1226
  translationShards = {};
1159
1227
  messagesStartedAt = context.progress.step("Writing messages");
1160
- _loop_2 = function (messageKey) {
1161
- var message, overrides, sourceFileInfo, detail, directLocales, overrideLocalesSet, _22, overrides_1, override, _23, _24, lk, overrideLocalesList;
1162
- return __generator(this, function (_25) {
1163
- switch (_25.label) {
1164
- case 0:
1165
- message = messages[messageKey];
1166
- overrides = (message.overrides || []).map(function (override) {
1167
- var attributes = new Set();
1168
- var overrideSegments = new Set();
1169
- collectAttributeKeysFromConditions(override.conditions, attributes);
1170
- collectSegmentKeys(override.segments, overrideSegments);
1171
- return __assign(__assign({}, override), { usedAttributes: sortStrings(Array.from(attributes)), usedSegments: sortStrings(Array.from(overrideSegments)) });
1172
- });
1173
- sourceFileInfo = getSourceFileInfo(context.repositoryRootDirectoryPath, context.rootDirectoryPath, projectConfig, "message", messageKey);
1174
- detail = {
1175
- type: "message",
1176
- key: messageKey,
1177
- entity: __assign(__assign({}, message), { overrides: overrides }),
1178
- sourcePath: sourceFileInfo.sourcePath,
1179
- editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1180
- targets: sortStrings(messageTargets[messageKey] || []),
1181
- localeKeys: localeKeys,
1182
- localeDirections: localeDirections,
1183
- translations: localeKeys.map(function (localeKey) {
1184
- return resolveTranslationRow(message.translations, localeKey, locales);
1185
- }),
1186
- evaluatedExamples: evaluatedMessageExamplesByKey[messageKey] || [],
1187
- overrideTranslations: overrides.map(function (override) { return ({
1188
- key: override.key,
1189
- rows: localeKeys.map(function (localeKey) {
1190
- return resolveTranslationRow(override.translations, localeKey, locales);
1228
+ messageDetailsStartedAt = context.progress.substep("Writing message details");
1229
+ skippedEmptyMessageHistoryCount = 0;
1230
+ return [4 /*yield*/, mapWithConcurrency(messageKeys, 32, function (messageKey) { return __awaiter(_this, void 0, void 0, function () {
1231
+ var message, overrides, sourceFileInfo, detail, directLocales, overrideLocalesSet, _i, overrides_1, override, _a, _b, lk, overrideLocalesList;
1232
+ return __generator(this, function (_c) {
1233
+ switch (_c.label) {
1234
+ case 0:
1235
+ message = messages[messageKey];
1236
+ overrides = (message.overrides || []).map(function (override) {
1237
+ var attributes = new Set();
1238
+ var overrideSegments = new Set();
1239
+ collectAttributeKeysFromConditions(override.conditions, attributes);
1240
+ collectSegmentKeys(override.segments, overrideSegments);
1241
+ return __assign(__assign({}, override), { usedAttributes: sortStrings(Array.from(attributes)), usedSegments: sortStrings(Array.from(overrideSegments)) });
1242
+ });
1243
+ sourceFileInfo = getSourceFileInfo(context.repositorySourceRootDirectoryPath, context.rootDirectoryPath, projectConfig, "message", messageKey, { resolveAbsolutePath: context.devEditors.length > 0 });
1244
+ detail = {
1245
+ type: "message",
1246
+ key: messageKey,
1247
+ entity: __assign(__assign({}, message), { overrides: overrides }),
1248
+ sourcePath: sourceFileInfo.sourcePath,
1249
+ editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1250
+ targets: sortStrings(messageTargets[messageKey] || []),
1251
+ localeKeys: localeKeys,
1252
+ localeDirections: localeDirections,
1253
+ translations: localeKeys.map(function (localeKey) {
1254
+ return resolveTranslationRow(message.translations, localeKey, locales);
1191
1255
  }),
1192
- }); }),
1193
- lastModified: getLastModified(context.historyIndex, "message", messageKey, set || undefined),
1194
- };
1195
- directLocales = localeKeys.filter(function (lk) { return message.translations && typeof message.translations[lk] === "string"; });
1196
- overrideLocalesSet = new Set();
1197
- for (_22 = 0, overrides_1 = overrides; _22 < overrides_1.length; _22++) {
1198
- override = overrides_1[_22];
1199
- for (_23 = 0, _24 = Object.keys(override.translations || {}); _23 < _24.length; _23++) {
1200
- lk = _24[_23];
1201
- overrideLocalesSet.add(lk);
1256
+ evaluatedExamples: evaluatedMessageExamplesByKey[messageKey] || [],
1257
+ overrideTranslations: overrides.map(function (override) { return ({
1258
+ key: override.key,
1259
+ rows: localeKeys.map(function (localeKey) {
1260
+ return resolveTranslationRow(override.translations, localeKey, locales);
1261
+ }),
1262
+ }); }),
1263
+ lastModified: getLastModified(context.historyIndex, "message", messageKey, set || undefined),
1264
+ };
1265
+ directLocales = localeKeys.filter(function (lk) { return message.translations && typeof message.translations[lk] === "string"; });
1266
+ overrideLocalesSet = new Set();
1267
+ for (_i = 0, overrides_1 = overrides; _i < overrides_1.length; _i++) {
1268
+ override = overrides_1[_i];
1269
+ for (_a = 0, _b = Object.keys(override.translations || {}); _a < _b.length; _a++) {
1270
+ lk = _b[_a];
1271
+ overrideLocalesSet.add(lk);
1272
+ }
1202
1273
  }
1203
- }
1204
- overrideLocalesList = sortStrings(Array.from(overrideLocalesSet));
1205
- index.entities.message.push(getEntitySummary(message, "message", messageKey, context.historyIndex, set || undefined, __assign(__assign({ targets: sortStrings(messageTargets[messageKey] || []) }, (directLocales.length > 0 ? { locales: sortStrings(directLocales) } : {})), (overrideLocalesList.length > 0 ? { overrideLocales: overrideLocalesList } : {}))));
1206
- return [4 /*yield*/, writeJson(path.join(outputDirectoryPath, "entities", "message", "".concat(encodeKey(messageKey), ".json")), detail)];
1207
- case 1:
1208
- _25.sent();
1209
- return [4 /*yield*/, writeHistoryPages(path.join(outputDirectoryPath, "history", "message", encodeKey(messageKey)), getHistoryForEntity(context.historyIndex, "message", messageKey, set || undefined))];
1210
- case 2:
1211
- _25.sent();
1212
- return [2 /*return*/];
1213
- }
1214
- });
1215
- };
1216
- _1 = 0, messageKeys_2 = messageKeys;
1217
- _20.label = 15;
1218
- case 15:
1219
- if (!(_1 < messageKeys_2.length)) return [3 /*break*/, 18];
1220
- messageKey = messageKeys_2[_1];
1221
- return [5 /*yield**/, _loop_2(messageKey)];
1222
- case 16:
1223
- _20.sent();
1224
- _20.label = 17;
1225
- case 17:
1226
- _1++;
1227
- return [3 /*break*/, 15];
1228
- case 18:
1229
- context.progress.done(messagesStartedAt, "(".concat(pluralize(messageKeys.length, "message"), ")"));
1230
- if (!context.withTranslationSearch) return [3 /*break*/, 23];
1274
+ overrideLocalesList = sortStrings(Array.from(overrideLocalesSet));
1275
+ index.entities.message.push(getEntitySummary(message, "message", messageKey, context.historyIndex, set || undefined, __assign(__assign({ targets: sortStrings(messageTargets[messageKey] || []) }, (directLocales.length > 0 ? { locales: sortStrings(directLocales) } : {})), (overrideLocalesList.length > 0 ? { overrideLocales: overrideLocalesList } : {}))));
1276
+ return [4 /*yield*/, context.writer.write(path.join(outputDirectoryPath, "entities", "message", "".concat(encodeKey(messageKey), ".json")), detail)];
1277
+ case 1:
1278
+ _c.sent();
1279
+ return [2 /*return*/];
1280
+ }
1281
+ });
1282
+ }); })];
1283
+ case 9:
1284
+ _12.sent();
1285
+ context.progress.done(messageDetailsStartedAt, "(".concat(pluralize(messageKeys.length, "message"), ")"));
1286
+ messageHistoryStartedAt = context.progress.substep("Writing message history pages");
1287
+ return [4 /*yield*/, mapWithConcurrency(messageKeys, 32, function (messageKey) { return __awaiter(_this, void 0, void 0, function () {
1288
+ var skippedHistory;
1289
+ return __generator(this, function (_a) {
1290
+ switch (_a.label) {
1291
+ case 0: return [4 /*yield*/, writeHistoryPages(context.writer, path.join(outputDirectoryPath, "history", "message", encodeKey(messageKey)), getHistoryForEntity(context.historyIndex, "message", messageKey, set || undefined), { skipEmpty: true })];
1292
+ case 1:
1293
+ skippedHistory = _a.sent();
1294
+ skippedEmptyMessageHistoryCount += skippedHistory;
1295
+ skippedEmptyHistoryCount += skippedHistory;
1296
+ return [2 /*return*/];
1297
+ }
1298
+ });
1299
+ }); })];
1300
+ case 10:
1301
+ _12.sent();
1302
+ context.progress.done(messageHistoryStartedAt, "(".concat(pluralize(messageKeys.length, "message"), ", ").concat(pluralize(skippedEmptyMessageHistoryCount, "empty history", "empty histories"), " skipped)"));
1303
+ context.progress.done(messagesStartedAt, "(".concat(pluralize(messageKeys.length, "message"), ", ").concat(pluralize(skippedEmptyMessageHistoryCount, "empty history", "empty histories"), " skipped)"));
1304
+ if (!context.withTranslationSearch) return [3 /*break*/, 15];
1231
1305
  translationSearchStartedAt = context.progress.step("Building translation search shards");
1232
- for (_2 = 0, messageKeys_3 = messageKeys; _2 < messageKeys_3.length; _2++) {
1233
- messageKey = messageKeys_3[_2];
1306
+ for (_z = 0, messageKeys_2 = messageKeys; _z < messageKeys_2.length; _z++) {
1307
+ messageKey = messageKeys_2[_z];
1234
1308
  message = messages[messageKey];
1235
- for (_3 = 0, localeKeys_3 = localeKeys; _3 < localeKeys_3.length; _3++) {
1236
- localeKey = localeKeys_3[_3];
1309
+ for (_0 = 0, localeKeys_1 = localeKeys; _0 < localeKeys_1.length; _0++) {
1310
+ localeKey = localeKeys_1[_0];
1237
1311
  row = resolveTranslationRow(message.translations, localeKey, locales);
1238
1312
  if (row.source !== "missing" && row.value) {
1239
1313
  addToTranslationShard(messageKey, row.value);
1240
1314
  }
1241
- for (_4 = 0, _5 = message.overrides || []; _4 < _5.length; _4++) {
1242
- override = _5[_4];
1315
+ for (_1 = 0, _2 = message.overrides || []; _1 < _2.length; _1++) {
1316
+ override = _2[_1];
1243
1317
  overrideRow = resolveTranslationRow(override.translations, localeKey, locales);
1244
1318
  if (overrideRow.source !== "missing" && overrideRow.value) {
1245
1319
  addToTranslationShard(messageKey, overrideRow.value);
@@ -1247,152 +1321,159 @@ function buildSetCatalog(context, set, projectConfig, datasource, outputRelative
1247
1321
  }
1248
1322
  }
1249
1323
  }
1250
- _6 = 0, _7 = Object.entries(translationShards);
1251
- _20.label = 19;
1252
- case 19:
1253
- if (!(_6 < _7.length)) return [3 /*break*/, 22];
1254
- _8 = _7[_6], prefix = _8[0], messageMap = _8[1];
1324
+ _3 = 0, _4 = Object.entries(translationShards);
1325
+ _12.label = 11;
1326
+ case 11:
1327
+ if (!(_3 < _4.length)) return [3 /*break*/, 14];
1328
+ _5 = _4[_3], prefix = _5[0], messageMap = _5[1];
1255
1329
  shardData = {};
1256
- for (_9 = 0, _10 = Object.entries(messageMap); _9 < _10.length; _9++) {
1257
- _11 = _10[_9], msgKey = _11[0], valueSet = _11[1];
1330
+ for (_6 = 0, _7 = Object.entries(messageMap); _6 < _7.length; _6++) {
1331
+ _8 = _7[_6], msgKey = _8[0], valueSet = _8[1];
1258
1332
  shardData[msgKey] = Array.from(valueSet);
1259
1333
  }
1260
- return [4 /*yield*/, writeJson(path.join(outputDirectoryPath, "translations", "".concat(prefix, ".json")), shardData)];
1261
- case 20:
1262
- _20.sent();
1263
- _20.label = 21;
1264
- case 21:
1265
- _6++;
1266
- return [3 /*break*/, 19];
1267
- case 22:
1334
+ return [4 /*yield*/, context.writer.write(path.join(outputDirectoryPath, "translations", "".concat(prefix, ".json")), shardData)];
1335
+ case 12:
1336
+ _12.sent();
1337
+ _12.label = 13;
1338
+ case 13:
1339
+ _3++;
1340
+ return [3 /*break*/, 11];
1341
+ case 14:
1268
1342
  context.progress.done(translationSearchStartedAt, "(".concat(pluralize(Object.keys(translationShards).length, "shard"), ")"));
1269
- _20.label = 23;
1270
- case 23:
1343
+ _12.label = 15;
1344
+ case 15:
1271
1345
  attributesStartedAt = context.progress.step("Writing attributes");
1272
- _12 = 0, attributeKeys_1 = attributeKeys;
1273
- _20.label = 24;
1274
- case 24:
1275
- if (!(_12 < attributeKeys_1.length)) return [3 /*break*/, 28];
1276
- attributeKey = attributeKeys_1[_12];
1277
- attribute = attributes[attributeKey];
1278
- sourceFileInfo = getSourceFileInfo(context.repositoryRootDirectoryPath, context.rootDirectoryPath, projectConfig, "attribute", attributeKey);
1279
- detail = {
1280
- type: "attribute",
1281
- key: attributeKey,
1282
- entity: attribute,
1283
- sourcePath: sourceFileInfo.sourcePath,
1284
- editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1285
- usage: {
1286
- segments: sortStrings(Array.from(attributesUsedInSegments[attributeKey] || [])),
1287
- messages: sortStrings(Array.from(attributesUsedInMessages[attributeKey] || [])),
1288
- },
1289
- lastModified: getLastModified(context.historyIndex, "attribute", attributeKey, set || undefined),
1290
- };
1291
- index.entities.attribute.push(getEntitySummary(attribute, "attribute", attributeKey, context.historyIndex, set || undefined, {
1292
- targets: sortStrings(Array.from(attributeTargets[attributeKey] || [])),
1293
- }));
1294
- return [4 /*yield*/, writeJson(path.join(outputDirectoryPath, "entities", "attribute", "".concat(encodeKey(attributeKey), ".json")), detail)];
1295
- case 25:
1296
- _20.sent();
1297
- return [4 /*yield*/, writeHistoryPages(path.join(outputDirectoryPath, "history", "attribute", encodeKey(attributeKey)), getHistoryForEntity(context.historyIndex, "attribute", attributeKey, set || undefined))];
1298
- case 26:
1299
- _20.sent();
1300
- _20.label = 27;
1301
- case 27:
1302
- _12++;
1303
- return [3 /*break*/, 24];
1304
- case 28:
1346
+ return [4 /*yield*/, mapWithConcurrency(attributeKeys, 32, function (attributeKey) { return __awaiter(_this, void 0, void 0, function () {
1347
+ var attribute, sourceFileInfo, detail, _a;
1348
+ return __generator(this, function (_b) {
1349
+ switch (_b.label) {
1350
+ case 0:
1351
+ attribute = attributes[attributeKey];
1352
+ sourceFileInfo = getSourceFileInfo(context.repositorySourceRootDirectoryPath, context.rootDirectoryPath, projectConfig, "attribute", attributeKey, { resolveAbsolutePath: context.devEditors.length > 0 });
1353
+ detail = {
1354
+ type: "attribute",
1355
+ key: attributeKey,
1356
+ entity: attribute,
1357
+ sourcePath: sourceFileInfo.sourcePath,
1358
+ editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1359
+ usage: {
1360
+ segments: sortStrings(Array.from(attributesUsedInSegments[attributeKey] || [])),
1361
+ messages: sortStrings(Array.from(attributesUsedInMessages[attributeKey] || [])),
1362
+ },
1363
+ lastModified: getLastModified(context.historyIndex, "attribute", attributeKey, set || undefined),
1364
+ };
1365
+ index.entities.attribute.push(getEntitySummary(attribute, "attribute", attributeKey, context.historyIndex, set || undefined, {
1366
+ targets: sortStrings(Array.from(attributeTargets[attributeKey] || [])),
1367
+ }));
1368
+ return [4 /*yield*/, context.writer.write(path.join(outputDirectoryPath, "entities", "attribute", "".concat(encodeKey(attributeKey), ".json")), detail)];
1369
+ case 1:
1370
+ _b.sent();
1371
+ _a = skippedEmptyHistoryCount;
1372
+ return [4 /*yield*/, writeHistoryPages(context.writer, path.join(outputDirectoryPath, "history", "attribute", encodeKey(attributeKey)), getHistoryForEntity(context.historyIndex, "attribute", attributeKey, set || undefined), { skipEmpty: true })];
1373
+ case 2:
1374
+ skippedEmptyHistoryCount = _a + _b.sent();
1375
+ return [2 /*return*/];
1376
+ }
1377
+ });
1378
+ }); })];
1379
+ case 16:
1380
+ _12.sent();
1305
1381
  context.progress.done(attributesStartedAt, "(".concat(pluralize(attributeKeys.length, "attribute"), ")"));
1306
1382
  segmentsStartedAt = context.progress.step("Writing segments");
1307
- _13 = 0, segmentKeys_2 = segmentKeys;
1308
- _20.label = 29;
1309
- case 29:
1310
- if (!(_13 < segmentKeys_2.length)) return [3 /*break*/, 33];
1311
- segmentKey = segmentKeys_2[_13];
1312
- segment = segments[segmentKey];
1313
- usedAttributes = new Set();
1314
- collectAttributeKeysFromConditions(segment.conditions, usedAttributes);
1315
- sourceFileInfo = getSourceFileInfo(context.repositoryRootDirectoryPath, context.rootDirectoryPath, projectConfig, "segment", segmentKey);
1316
- detail = {
1317
- type: "segment",
1318
- key: segmentKey,
1319
- entity: segment,
1320
- sourcePath: sourceFileInfo.sourcePath,
1321
- editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1322
- usage: {
1323
- attributes: sortStrings(Array.from(usedAttributes)),
1324
- messages: sortStrings(Array.from(segmentsUsedInMessages[segmentKey] || [])),
1325
- },
1326
- lastModified: getLastModified(context.historyIndex, "segment", segmentKey, set || undefined),
1327
- };
1328
- index.entities.segment.push(getEntitySummary(segment, "segment", segmentKey, context.historyIndex, set || undefined, {
1329
- targets: sortStrings(Array.from(segmentTargets[segmentKey] || [])),
1330
- }));
1331
- return [4 /*yield*/, writeJson(path.join(outputDirectoryPath, "entities", "segment", "".concat(encodeKey(segmentKey), ".json")), detail)];
1332
- case 30:
1333
- _20.sent();
1334
- return [4 /*yield*/, writeHistoryPages(path.join(outputDirectoryPath, "history", "segment", encodeKey(segmentKey)), getHistoryForEntity(context.historyIndex, "segment", segmentKey, set || undefined))];
1335
- case 31:
1336
- _20.sent();
1337
- _20.label = 32;
1338
- case 32:
1339
- _13++;
1340
- return [3 /*break*/, 29];
1341
- case 33:
1383
+ return [4 /*yield*/, mapWithConcurrency(segmentKeys, 32, function (segmentKey) { return __awaiter(_this, void 0, void 0, function () {
1384
+ var segment, usedAttributes, sourceFileInfo, detail, _a;
1385
+ return __generator(this, function (_b) {
1386
+ switch (_b.label) {
1387
+ case 0:
1388
+ segment = segments[segmentKey];
1389
+ usedAttributes = new Set();
1390
+ collectAttributeKeysFromConditions(segment.conditions, usedAttributes);
1391
+ sourceFileInfo = getSourceFileInfo(context.repositorySourceRootDirectoryPath, context.rootDirectoryPath, projectConfig, "segment", segmentKey, { resolveAbsolutePath: context.devEditors.length > 0 });
1392
+ detail = {
1393
+ type: "segment",
1394
+ key: segmentKey,
1395
+ entity: segment,
1396
+ sourcePath: sourceFileInfo.sourcePath,
1397
+ editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1398
+ usage: {
1399
+ attributes: sortStrings(Array.from(usedAttributes)),
1400
+ messages: sortStrings(Array.from(segmentsUsedInMessages[segmentKey] || [])),
1401
+ },
1402
+ lastModified: getLastModified(context.historyIndex, "segment", segmentKey, set || undefined),
1403
+ };
1404
+ index.entities.segment.push(getEntitySummary(segment, "segment", segmentKey, context.historyIndex, set || undefined, {
1405
+ targets: sortStrings(Array.from(segmentTargets[segmentKey] || [])),
1406
+ }));
1407
+ return [4 /*yield*/, context.writer.write(path.join(outputDirectoryPath, "entities", "segment", "".concat(encodeKey(segmentKey), ".json")), detail)];
1408
+ case 1:
1409
+ _b.sent();
1410
+ _a = skippedEmptyHistoryCount;
1411
+ return [4 /*yield*/, writeHistoryPages(context.writer, path.join(outputDirectoryPath, "history", "segment", encodeKey(segmentKey)), getHistoryForEntity(context.historyIndex, "segment", segmentKey, set || undefined), { skipEmpty: true })];
1412
+ case 2:
1413
+ skippedEmptyHistoryCount = _a + _b.sent();
1414
+ return [2 /*return*/];
1415
+ }
1416
+ });
1417
+ }); })];
1418
+ case 17:
1419
+ _12.sent();
1342
1420
  context.progress.done(segmentsStartedAt, "(".concat(pluralize(segmentKeys.length, "segment"), ")"));
1343
1421
  targetsStartedAt = context.progress.step("Writing targets");
1344
- _14 = 0, targetKeys_2 = targetKeys;
1345
- _20.label = 34;
1346
- case 34:
1347
- if (!(_14 < targetKeys_2.length)) return [3 /*break*/, 38];
1348
- targetKey = targetKeys_2[_14];
1349
- target = targets[targetKey];
1350
- targetLocaleKeys = ((_19 = target.locales) === null || _19 === void 0 ? void 0 : _19.length) ? target.locales : localeKeys;
1351
- formatsByLocale = {};
1352
- formatRowsByLocale = {};
1353
- for (_15 = 0, targetLocaleKeys_2 = targetLocaleKeys; _15 < targetLocaleKeys_2.length; _15++) {
1354
- localeKey = targetLocaleKeys_2[_15];
1355
- formatsByLocale[localeKey] = context.runtime.resolveFormats(localeKey, locales, target);
1356
- formatRowsByLocale[localeKey] = getFormatRows(context.runtime, localeKey, locales, target);
1357
- }
1358
- sourceFileInfo = getSourceFileInfo(context.repositoryRootDirectoryPath, context.rootDirectoryPath, projectConfig, "target", targetKey);
1359
- detail = {
1360
- type: "target",
1361
- key: targetKey,
1362
- entity: target,
1363
- sourcePath: sourceFileInfo.sourcePath,
1364
- editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1365
- locales: targetLocaleKeys,
1366
- formatsByLocale: formatsByLocale,
1367
- formatRowsByLocale: formatRowsByLocale,
1368
- messages: targetMessages[targetKey],
1369
- lastModified: getLastModified(context.historyIndex, "target", targetKey, set || undefined),
1370
- };
1371
- index.entities.target.push(getEntitySummary(target, "target", targetKey, context.historyIndex, set || undefined, {
1372
- messageCount: targetMessages[targetKey].length,
1373
- }));
1374
- return [4 /*yield*/, writeJson(path.join(outputDirectoryPath, "entities", "target", "".concat(encodeKey(targetKey), ".json")), detail)];
1375
- case 35:
1376
- _20.sent();
1377
- return [4 /*yield*/, writeHistoryPages(path.join(outputDirectoryPath, "history", "target", encodeKey(targetKey)), getHistoryForEntity(context.historyIndex, "target", targetKey, set || undefined))];
1378
- case 36:
1379
- _20.sent();
1380
- _20.label = 37;
1381
- case 37:
1382
- _14++;
1383
- return [3 /*break*/, 34];
1384
- case 38:
1422
+ return [4 /*yield*/, mapWithConcurrency(targetKeys, 32, function (targetKey) { return __awaiter(_this, void 0, void 0, function () {
1423
+ var target, targetLocaleKeys, formatsByLocale, formatRowsByLocale, _i, targetLocaleKeys_2, localeKey, sourceFileInfo, detail, _a;
1424
+ var _b;
1425
+ return __generator(this, function (_c) {
1426
+ switch (_c.label) {
1427
+ case 0:
1428
+ target = targets[targetKey];
1429
+ targetLocaleKeys = ((_b = target.locales) === null || _b === void 0 ? void 0 : _b.length) ? target.locales : localeKeys;
1430
+ formatsByLocale = {};
1431
+ formatRowsByLocale = {};
1432
+ for (_i = 0, targetLocaleKeys_2 = targetLocaleKeys; _i < targetLocaleKeys_2.length; _i++) {
1433
+ localeKey = targetLocaleKeys_2[_i];
1434
+ formatsByLocale[localeKey] = context.runtime.resolveFormats(localeKey, locales, target);
1435
+ formatRowsByLocale[localeKey] = getFormatRows(context.runtime, localeKey, locales, target);
1436
+ }
1437
+ sourceFileInfo = getSourceFileInfo(context.repositorySourceRootDirectoryPath, context.rootDirectoryPath, projectConfig, "target", targetKey, { resolveAbsolutePath: context.devEditors.length > 0 });
1438
+ detail = {
1439
+ type: "target",
1440
+ key: targetKey,
1441
+ entity: target,
1442
+ sourcePath: sourceFileInfo.sourcePath,
1443
+ editLinks: getEditorLinks(context.devEditors, sourceFileInfo),
1444
+ locales: targetLocaleKeys,
1445
+ formatsByLocale: formatsByLocale,
1446
+ formatRowsByLocale: formatRowsByLocale,
1447
+ messages: targetMessages[targetKey],
1448
+ lastModified: getLastModified(context.historyIndex, "target", targetKey, set || undefined),
1449
+ };
1450
+ index.entities.target.push(getEntitySummary(target, "target", targetKey, context.historyIndex, set || undefined, {
1451
+ messageCount: targetMessages[targetKey].length,
1452
+ }));
1453
+ return [4 /*yield*/, context.writer.write(path.join(outputDirectoryPath, "entities", "target", "".concat(encodeKey(targetKey), ".json")), detail)];
1454
+ case 1:
1455
+ _c.sent();
1456
+ _a = skippedEmptyHistoryCount;
1457
+ return [4 /*yield*/, writeHistoryPages(context.writer, path.join(outputDirectoryPath, "history", "target", encodeKey(targetKey)), getHistoryForEntity(context.historyIndex, "target", targetKey, set || undefined), { skipEmpty: true })];
1458
+ case 2:
1459
+ skippedEmptyHistoryCount = _a + _c.sent();
1460
+ return [2 /*return*/];
1461
+ }
1462
+ });
1463
+ }); })];
1464
+ case 18:
1465
+ _12.sent();
1385
1466
  context.progress.done(targetsStartedAt, "(".concat(pluralize(targetKeys.length, "target"), ")"));
1386
1467
  indexStartedAt = context.progress.step("Writing catalog index");
1387
- for (_16 = 0, _17 = Object.keys(index.entities); _16 < _17.length; _16++) {
1388
- type = _17[_16];
1468
+ for (_9 = 0, _10 = Object.keys(index.entities); _9 < _10.length; _9++) {
1469
+ type = _10[_9];
1389
1470
  index.entities[type].sort(function (a, b) { return a.key.localeCompare(b.key); });
1390
1471
  }
1391
- return [4 /*yield*/, writeJson(path.join(outputDirectoryPath, "index.json"), index)];
1392
- case 39:
1393
- _20.sent();
1472
+ return [4 /*yield*/, context.writer.write(path.join(outputDirectoryPath, "index.json"), index)];
1473
+ case 19:
1474
+ _12.sent();
1394
1475
  context.progress.done(indexStartedAt);
1395
- context.progress.done(setStartedAt, "total");
1476
+ context.progress.done(setStartedAt, "total (".concat(pluralize(skippedEmptyHistoryCount, "empty history", "empty histories"), " skipped)"));
1396
1477
  return [2 /*return*/, index];
1397
1478
  }
1398
1479
  });
@@ -1422,12 +1503,404 @@ function copyCatalogAssets(outputDirectoryPath) {
1422
1503
  });
1423
1504
  });
1424
1505
  }
1506
+ function createCatalogDevSession(rootDirectoryPath_1, projectConfig_1) {
1507
+ return __awaiter(this, arguments, void 0, function (rootDirectoryPath, projectConfig, options) {
1508
+ var outputDirectoryPath;
1509
+ var _a;
1510
+ if (options === void 0) { options = {}; }
1511
+ return __generator(this, function (_b) {
1512
+ switch (_b.label) {
1513
+ case 0:
1514
+ outputDirectoryPath = options.outDir
1515
+ ? path.resolve(rootDirectoryPath, options.outDir)
1516
+ : projectConfig.catalogDirectoryPath;
1517
+ _a = {
1518
+ outputDirectoryPath: outputDirectoryPath,
1519
+ devEditors: options.devEditors || detectDevEditors()
1520
+ };
1521
+ return [4 /*yield*/, getGitHistoryIndex(rootDirectoryPath, projectConfig)];
1522
+ case 1: return [2 /*return*/, (_a.historyIndex = _b.sent(),
1523
+ _a.links = getRepoLinks(rootDirectoryPath),
1524
+ _a.repositoryRootDirectoryPath = getRepositoryRootDirectoryPath(rootDirectoryPath),
1525
+ _a.repositorySourceRootDirectoryPath = getRepositorySourceRootDirectoryPath(rootDirectoryPath),
1526
+ _a)];
1527
+ }
1528
+ });
1529
+ });
1530
+ }
1531
+ function readJsonFile(filePath) {
1532
+ return __awaiter(this, void 0, void 0, function () {
1533
+ var _a, _b, _error_2;
1534
+ return __generator(this, function (_c) {
1535
+ switch (_c.label) {
1536
+ case 0:
1537
+ _c.trys.push([0, 2, , 3]);
1538
+ _b = (_a = JSON).parse;
1539
+ return [4 /*yield*/, fs.promises.readFile(filePath, "utf8")];
1540
+ case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
1541
+ case 2:
1542
+ _error_2 = _c.sent();
1543
+ return [2 /*return*/, undefined];
1544
+ case 3: return [2 /*return*/];
1545
+ }
1546
+ });
1547
+ });
1548
+ }
1549
+ function getOutputRelativeDirectory(projectConfig, set) {
1550
+ return projectConfig.sets ? path.join("sets", set || "") : "root";
1551
+ }
1552
+ function getDataOutputDirectoryPath(session, projectConfig, set) {
1553
+ return path.join(session.outputDirectoryPath, "data", getOutputRelativeDirectory(projectConfig, set));
1554
+ }
1555
+ function getEntityKeyFromChangedPath(rootDirectoryPath, projectConfig, changedPath) {
1556
+ var relativePath = path.relative(rootDirectoryPath, changedPath);
1557
+ if (!relativePath || relativePath.startsWith("..") || path.isAbsolute(relativePath)) {
1558
+ return undefined;
1559
+ }
1560
+ return getEntityInfoFromRelativePath(rootDirectoryPath, projectConfig, relativePath);
1561
+ }
1562
+ function getChangedPathSummary(rootDirectoryPath, changedPaths) {
1563
+ return changedPaths
1564
+ .slice(0, 3)
1565
+ .map(function (changedPath) { return formatCatalogPath(rootDirectoryPath, changedPath); })
1566
+ .join(", ");
1567
+ }
1568
+ function classifyCatalogDevChanges(rootDirectoryPath, projectConfig, changedPaths, options) {
1569
+ var reason = getChangedPathSummary(rootDirectoryPath, changedPaths) || "project changes";
1570
+ var infos = changedPaths.map(function (changedPath) {
1571
+ return getEntityKeyFromChangedPath(rootDirectoryPath, projectConfig, changedPath);
1572
+ });
1573
+ if (infos.length === 0 || infos.some(function (info) { return !info; })) {
1574
+ return { kind: "full", reason: reason };
1575
+ }
1576
+ var sets = new Set(infos.map(function (info) { return (info === null || info === void 0 ? void 0 : info.set) || ""; }));
1577
+ var types = new Set(infos.map(function (info) { return info === null || info === void 0 ? void 0 : info.type; }));
1578
+ if (sets.size > 1) {
1579
+ return { kind: "full", reason: reason };
1580
+ }
1581
+ var set = Array.from(sets)[0] || undefined;
1582
+ if (types.size === 1 &&
1583
+ types.has("message") &&
1584
+ !options.withTranslationSearch &&
1585
+ !options.withDuplicates) {
1586
+ return {
1587
+ kind: "message",
1588
+ reason: reason,
1589
+ set: set,
1590
+ messageKeys: sortStrings(infos.map(function (info) { return (info === null || info === void 0 ? void 0 : info.key) || ""; }).filter(Boolean)),
1591
+ };
1592
+ }
1593
+ if (projectConfig.sets &&
1594
+ set &&
1595
+ types.size > 0 &&
1596
+ !types.has("test") &&
1597
+ !options.withTranslationSearch &&
1598
+ !options.withDuplicates) {
1599
+ return { kind: "set", reason: reason, set: set };
1600
+ }
1601
+ return { kind: "full", reason: reason };
1602
+ }
1603
+ function writeCatalogManifest(writer, rootDirectoryPath, projectConfig, session, options) {
1604
+ return __awaiter(this, void 0, void 0, function () {
1605
+ var manifest;
1606
+ return __generator(this, function (_a) {
1607
+ switch (_a.label) {
1608
+ case 0:
1609
+ manifest = {
1610
+ schemaVersion: exports.CATALOG_SCHEMA_VERSION,
1611
+ generatedAt: new Date().toISOString(),
1612
+ router: options.browserRouter === false ? "hash" : "browser",
1613
+ sets: projectConfig.sets,
1614
+ setKeys: projectConfig.sets ? options.executions.map(function (execution) { return execution.set; }) : [],
1615
+ dev: { editors: session.devEditors },
1616
+ features: {
1617
+ translationSearch: options.withTranslationSearch,
1618
+ duplicates: options.withDuplicates,
1619
+ },
1620
+ links: session.links,
1621
+ paths: {
1622
+ projectHistory: "data/project/history/page-1.json",
1623
+ root: projectConfig.sets ? undefined : "data/root/index.json",
1624
+ sets: projectConfig.sets
1625
+ ? Object.fromEntries(options.executions.map(function (execution) { return [
1626
+ execution.set,
1627
+ "data/sets/".concat(encodeURIComponent(execution.set), "/index.json"),
1628
+ ]; }))
1629
+ : undefined,
1630
+ },
1631
+ counts: Object.fromEntries(Object.keys(options.setIndexes).map(function (key) { return [key, options.setIndexes[key].counts]; })),
1632
+ };
1633
+ return [4 /*yield*/, writer.write(path.join(session.outputDirectoryPath, "data", "manifest.json"), manifest)];
1634
+ case 1:
1635
+ _a.sent();
1636
+ return [2 /*return*/, manifest];
1637
+ }
1638
+ });
1639
+ });
1640
+ }
1641
+ function getMessageRelationshipFingerprint(message) {
1642
+ var attributes = new Set();
1643
+ var segments = new Set();
1644
+ for (var _i = 0, _a = message.overrides || []; _i < _a.length; _i++) {
1645
+ var override = _a[_i];
1646
+ collectAttributeKeysFromConditions(override.conditions, attributes);
1647
+ collectSegmentKeys(override.segments, segments);
1648
+ }
1649
+ return {
1650
+ attributes: sortStrings(Array.from(attributes)),
1651
+ segments: sortStrings(Array.from(segments)),
1652
+ };
1653
+ }
1654
+ function sameStringList(left, right) {
1655
+ if (left === void 0) { left = []; }
1656
+ if (right === void 0) { right = []; }
1657
+ if (left.length !== right.length) {
1658
+ return false;
1659
+ }
1660
+ return left.every(function (value, index) { return value === right[index]; });
1661
+ }
1662
+ function summarizeMessage(message, messageKey, historyIndex, set, targets) {
1663
+ var directLocales = Object.keys(message.translations || {});
1664
+ var overrideLocalesSet = new Set();
1665
+ for (var _i = 0, _a = message.overrides || []; _i < _a.length; _i++) {
1666
+ var override = _a[_i];
1667
+ for (var _b = 0, _c = Object.keys(override.translations || {}); _b < _c.length; _b++) {
1668
+ var localeKey = _c[_b];
1669
+ overrideLocalesSet.add(localeKey);
1670
+ }
1671
+ }
1672
+ var overrideLocales = sortStrings(Array.from(overrideLocalesSet));
1673
+ return getEntitySummary(message, "message", messageKey, historyIndex, set, __assign(__assign({ targets: targets }, (directLocales.length > 0 ? { locales: sortStrings(directLocales) } : {})), (overrideLocales.length > 0 ? { overrideLocales: overrideLocales } : {})));
1674
+ }
1675
+ function tryRebuildCatalogMessage(runtime, rootDirectoryPath, rootProjectConfig, projectConfig, datasource, session, request) {
1676
+ return __awaiter(this, void 0, void 0, function () {
1677
+ var dataDirectoryPath, indexPath, index, _a, localeKeys, messageKeys, targetKeys, messageKeySet, _b, locales, targets, localeDirections, targetMessages, writer, _loop_1, _i, _c, messageKey, state_1;
1678
+ return __generator(this, function (_d) {
1679
+ switch (_d.label) {
1680
+ case 0:
1681
+ if (request.kind !== "message" || !request.messageKeys || request.messageKeys.length === 0) {
1682
+ return [2 /*return*/, false];
1683
+ }
1684
+ dataDirectoryPath = getDataOutputDirectoryPath(session, rootProjectConfig, request.set);
1685
+ indexPath = path.join(dataDirectoryPath, "index.json");
1686
+ return [4 /*yield*/, readJsonFile(indexPath)];
1687
+ case 1:
1688
+ index = _d.sent();
1689
+ if (!index) {
1690
+ return [2 /*return*/, false];
1691
+ }
1692
+ return [4 /*yield*/, Promise.all([
1693
+ datasource.listLocales(),
1694
+ datasource.listMessages(),
1695
+ datasource.listTargets(),
1696
+ ])];
1697
+ case 2:
1698
+ _a = (_d.sent()), localeKeys = _a[0], messageKeys = _a[1], targetKeys = _a[2];
1699
+ messageKeySet = new Set(messageKeys);
1700
+ if (request.messageKeys.some(function (messageKey) { return !messageKeySet.has(messageKey); })) {
1701
+ return [2 /*return*/, false];
1702
+ }
1703
+ return [4 /*yield*/, Promise.all([
1704
+ readAll(localeKeys, function (key) { return datasource.readLocale(key); }),
1705
+ readAll(targetKeys, function (key) { return datasource.readTarget(key); }),
1706
+ ])];
1707
+ case 3:
1708
+ _b = _d.sent(), locales = _b[0], targets = _b[1];
1709
+ localeDirections = getLocaleDirections(locales);
1710
+ targetMessages = Object.fromEntries(targetKeys.map(function (targetKey) { return [
1711
+ targetKey,
1712
+ getTargetMessageKeys(targets[targetKey], messageKeys),
1713
+ ]; }));
1714
+ writer = new CatalogJsonWriter();
1715
+ _loop_1 = function (messageKey) {
1716
+ var oldDetailPath, oldDetail, message, messageTargets, oldRelationshipFingerprint, nextRelationshipFingerprint, examples, overrides, sourceFileInfo, detail, nextSummary, existingSummaryIndex;
1717
+ return __generator(this, function (_e) {
1718
+ switch (_e.label) {
1719
+ case 0:
1720
+ oldDetailPath = path.join(dataDirectoryPath, "entities", "message", "".concat(encodeKey(messageKey), ".json"));
1721
+ return [4 /*yield*/, readJsonFile(oldDetailPath)];
1722
+ case 1:
1723
+ oldDetail = _e.sent();
1724
+ if (!oldDetail) {
1725
+ return [2 /*return*/, { value: false }];
1726
+ }
1727
+ return [4 /*yield*/, datasource.readMessage(messageKey)];
1728
+ case 2:
1729
+ message = _e.sent();
1730
+ messageTargets = sortStrings(targetKeys.filter(function (targetKey) { return targetMessages[targetKey].includes(messageKey); }));
1731
+ if (!sameStringList(sortStrings(oldDetail.targets || []), messageTargets)) {
1732
+ return [2 /*return*/, { value: false }];
1733
+ }
1734
+ oldRelationshipFingerprint = getMessageRelationshipFingerprint(oldDetail.entity || {});
1735
+ nextRelationshipFingerprint = getMessageRelationshipFingerprint(message);
1736
+ if (!sameStringList(oldRelationshipFingerprint.attributes, nextRelationshipFingerprint.attributes) ||
1737
+ !sameStringList(oldRelationshipFingerprint.segments, nextRelationshipFingerprint.segments)) {
1738
+ return [2 /*return*/, { value: false }];
1739
+ }
1740
+ return [4 /*yield*/, runtime.resolveExamples(projectConfig, datasource, {
1741
+ set: request.set,
1742
+ message: messageKey,
1743
+ onlyMessages: true,
1744
+ })];
1745
+ case 3:
1746
+ examples = _e.sent();
1747
+ overrides = (message.overrides || []).map(function (override) {
1748
+ var attributes = new Set();
1749
+ var overrideSegments = new Set();
1750
+ collectAttributeKeysFromConditions(override.conditions, attributes);
1751
+ collectSegmentKeys(override.segments, overrideSegments);
1752
+ return __assign(__assign({}, override), { usedAttributes: sortStrings(Array.from(attributes)), usedSegments: sortStrings(Array.from(overrideSegments)) });
1753
+ });
1754
+ sourceFileInfo = getSourceFileInfo(session.repositorySourceRootDirectoryPath, rootDirectoryPath, projectConfig, "message", messageKey, { resolveAbsolutePath: session.devEditors.length > 0 });
1755
+ detail = {
1756
+ type: "message",
1757
+ key: messageKey,
1758
+ entity: __assign(__assign({}, message), { overrides: overrides }),
1759
+ sourcePath: sourceFileInfo.sourcePath,
1760
+ editLinks: getEditorLinks(session.devEditors, sourceFileInfo),
1761
+ targets: messageTargets,
1762
+ localeKeys: localeKeys,
1763
+ localeDirections: localeDirections,
1764
+ translations: localeKeys.map(function (localeKey) {
1765
+ return resolveTranslationRow(message.translations, localeKey, locales);
1766
+ }),
1767
+ evaluatedExamples: examples.messages,
1768
+ overrideTranslations: overrides.map(function (override) { return ({
1769
+ key: override.key,
1770
+ rows: localeKeys.map(function (localeKey) {
1771
+ return resolveTranslationRow(override.translations, localeKey, locales);
1772
+ }),
1773
+ }); }),
1774
+ lastModified: getLastModified(session.historyIndex, "message", messageKey, request.set),
1775
+ };
1776
+ return [4 /*yield*/, writer.write(oldDetailPath, detail)];
1777
+ case 4:
1778
+ _e.sent();
1779
+ return [4 /*yield*/, writeHistoryPages(writer, path.join(dataDirectoryPath, "history", "message", encodeKey(messageKey)), getHistoryForEntity(session.historyIndex, "message", messageKey, request.set), { skipEmpty: true })];
1780
+ case 5:
1781
+ _e.sent();
1782
+ nextSummary = summarizeMessage(message, messageKey, session.historyIndex, request.set, messageTargets);
1783
+ existingSummaryIndex = index.entities.message.findIndex(function (entry) { return entry.key === messageKey; });
1784
+ if (existingSummaryIndex === -1) {
1785
+ index.entities.message.push(nextSummary);
1786
+ }
1787
+ else {
1788
+ index.entities.message[existingSummaryIndex] = nextSummary;
1789
+ }
1790
+ return [2 /*return*/];
1791
+ }
1792
+ });
1793
+ };
1794
+ _i = 0, _c = request.messageKeys;
1795
+ _d.label = 4;
1796
+ case 4:
1797
+ if (!(_i < _c.length)) return [3 /*break*/, 7];
1798
+ messageKey = _c[_i];
1799
+ return [5 /*yield**/, _loop_1(messageKey)];
1800
+ case 5:
1801
+ state_1 = _d.sent();
1802
+ if (typeof state_1 === "object")
1803
+ return [2 /*return*/, state_1.value];
1804
+ _d.label = 6;
1805
+ case 6:
1806
+ _i++;
1807
+ return [3 /*break*/, 4];
1808
+ case 7:
1809
+ index.entities.message.sort(function (left, right) { return left.key.localeCompare(right.key); });
1810
+ index.counts.message = messageKeys.length;
1811
+ return [4 /*yield*/, writer.write(indexPath, index)];
1812
+ case 8:
1813
+ _d.sent();
1814
+ return [2 /*return*/, true];
1815
+ }
1816
+ });
1817
+ });
1818
+ }
1819
+ function rebuildCatalogSetForDev(runtime, rootDirectoryPath, projectConfig, datasource, session, options) {
1820
+ return __awaiter(this, void 0, void 0, function () {
1821
+ var writer, progress, executions, setIndexes, existingIndexes, _i, existingIndexes_1, _a, key, index, execution, outputRelativeDirectory, context, _b, _c;
1822
+ var _this = this;
1823
+ return __generator(this, function (_d) {
1824
+ switch (_d.label) {
1825
+ case 0:
1826
+ writer = new CatalogJsonWriter();
1827
+ progress = new CatalogProgressReporter(rootDirectoryPath, session.outputDirectoryPath);
1828
+ return [4 /*yield*/, runtime.getProjectSetExecutions(projectConfig, datasource)];
1829
+ case 1:
1830
+ executions = _d.sent();
1831
+ setIndexes = {};
1832
+ return [4 /*yield*/, Promise.all(executions.map(function (execution) { return __awaiter(_this, void 0, void 0, function () {
1833
+ var indexPath, _a;
1834
+ return __generator(this, function (_b) {
1835
+ switch (_b.label) {
1836
+ case 0:
1837
+ indexPath = path.join(session.outputDirectoryPath, "data", getOutputRelativeDirectory(projectConfig, execution.set), "index.json");
1838
+ _a = [execution.set || "root"];
1839
+ return [4 /*yield*/, readJsonFile(indexPath)];
1840
+ case 1: return [2 /*return*/, _a.concat([_b.sent()])];
1841
+ }
1842
+ });
1843
+ }); }))];
1844
+ case 2:
1845
+ existingIndexes = _d.sent();
1846
+ for (_i = 0, existingIndexes_1 = existingIndexes; _i < existingIndexes_1.length; _i++) {
1847
+ _a = existingIndexes_1[_i], key = _a[0], index = _a[1];
1848
+ if (index) {
1849
+ setIndexes[key] = index;
1850
+ }
1851
+ }
1852
+ execution = executions.find(function (item) { return (item.set || undefined) === options.set; });
1853
+ if (!execution) {
1854
+ return [2 /*return*/, false];
1855
+ }
1856
+ outputRelativeDirectory = getOutputRelativeDirectory(projectConfig, execution.set);
1857
+ return [4 /*yield*/, fs.promises.rm(path.join(session.outputDirectoryPath, "data", outputRelativeDirectory), {
1858
+ recursive: true,
1859
+ force: true,
1860
+ })];
1861
+ case 3:
1862
+ _d.sent();
1863
+ context = {
1864
+ rootDirectoryPath: rootDirectoryPath,
1865
+ repositoryRootDirectoryPath: session.repositoryRootDirectoryPath,
1866
+ repositorySourceRootDirectoryPath: session.repositorySourceRootDirectoryPath,
1867
+ outputDirectoryPath: session.outputDirectoryPath,
1868
+ dataDirectoryPath: path.join(session.outputDirectoryPath, "data"),
1869
+ historyIndex: session.historyIndex,
1870
+ runtime: runtime,
1871
+ devEditors: session.devEditors,
1872
+ duplicateResultsBySet: {},
1873
+ withTranslationSearch: options.withTranslationSearch,
1874
+ withDuplicates: options.withDuplicates,
1875
+ progress: progress,
1876
+ writer: writer,
1877
+ };
1878
+ _b = setIndexes;
1879
+ _c = execution.set || "root";
1880
+ return [4 /*yield*/, buildSetCatalog(context, execution.set, execution.projectConfig, execution.datasource, outputRelativeDirectory)];
1881
+ case 4:
1882
+ _b[_c] = _d.sent();
1883
+ return [4 /*yield*/, writeCatalogManifest(writer, rootDirectoryPath, projectConfig, session, {
1884
+ browserRouter: options.browserRouter,
1885
+ withTranslationSearch: options.withTranslationSearch,
1886
+ withDuplicates: options.withDuplicates,
1887
+ setIndexes: setIndexes,
1888
+ executions: executions,
1889
+ })];
1890
+ case 5:
1891
+ _d.sent();
1892
+ return [2 /*return*/, true];
1893
+ }
1894
+ });
1895
+ });
1896
+ }
1425
1897
  function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasource_1) {
1426
1898
  return __awaiter(this, arguments, void 0, function (runtime, rootDirectoryPath, projectConfig, datasource, options) {
1427
- var outputDirectoryPath, dataDirectoryPath, withTranslationSearch, withDuplicates, progress, stepStartedAt, devEditors, historyIndex, links, duplicateResultsBySet, _a, _b, context, executions, setIndexes, _i, executions_1, execution, outputRelativeDirectory, _c, _d, manifest;
1899
+ var outputDirectoryPath, dataDirectoryPath, withTranslationSearch, withDuplicates, progress, writer, stepStartedAt, devEditors, historyIndex, _a, links, duplicateResultsBySet, _b, _c, context, executions, setIndexes, _i, executions_1, execution, outputRelativeDirectory, _d, _e, manifest;
1900
+ var _f, _g, _h, _j, _k;
1428
1901
  if (options === void 0) { options = {}; }
1429
- return __generator(this, function (_e) {
1430
- switch (_e.label) {
1902
+ return __generator(this, function (_l) {
1903
+ switch (_l.label) {
1431
1904
  case 0:
1432
1905
  outputDirectoryPath = options.outDir
1433
1906
  ? path.resolve(rootDirectoryPath, options.outDir)
@@ -1436,43 +1909,57 @@ function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasour
1436
1909
  withTranslationSearch = options.withTranslationSearch === true;
1437
1910
  withDuplicates = options.withDuplicates === true;
1438
1911
  progress = new CatalogProgressReporter(rootDirectoryPath, outputDirectoryPath);
1912
+ writer = new CatalogJsonWriter();
1439
1913
  progress.start({
1440
1914
  browserRouter: options.browserRouter !== false,
1441
1915
  sets: projectConfig.sets === true,
1442
1916
  features: __spreadArray(__spreadArray([], (withTranslationSearch ? ["translation search"] : []), true), (withDuplicates ? ["duplicates"] : []), true),
1443
1917
  });
1444
1918
  stepStartedAt = progress.step("Preparing output directory");
1445
- return [4 /*yield*/, fs.promises.rm(outputDirectoryPath, { recursive: true, force: true })];
1919
+ if (!options.preserveAssets) return [3 /*break*/, 2];
1920
+ return [4 /*yield*/, fs.promises.rm(dataDirectoryPath, { recursive: true, force: true })];
1446
1921
  case 1:
1447
- _e.sent();
1448
- return [4 /*yield*/, fs.promises.mkdir(dataDirectoryPath, { recursive: true })];
1449
- case 2:
1450
- _e.sent();
1922
+ _l.sent();
1923
+ return [3 /*break*/, 4];
1924
+ case 2: return [4 /*yield*/, fs.promises.rm(outputDirectoryPath, { recursive: true, force: true })];
1925
+ case 3:
1926
+ _l.sent();
1927
+ _l.label = 4;
1928
+ case 4: return [4 /*yield*/, fs.promises.mkdir(dataDirectoryPath, { recursive: true })];
1929
+ case 5:
1930
+ _l.sent();
1451
1931
  progress.done(stepStartedAt);
1452
- if (!(options.copyAssets !== false)) return [3 /*break*/, 4];
1932
+ if (!(options.copyAssets !== false)) return [3 /*break*/, 7];
1453
1933
  stepStartedAt = progress.step("Copying Catalog UI assets");
1454
1934
  return [4 /*yield*/, copyCatalogAssets(outputDirectoryPath)];
1455
- case 3:
1456
- _e.sent();
1935
+ case 6:
1936
+ _l.sent();
1457
1937
  progress.done(stepStartedAt);
1458
- _e.label = 4;
1459
- case 4:
1460
- devEditors = options.dev ? options.devEditors || detectDevEditors() : [];
1938
+ _l.label = 7;
1939
+ case 7:
1940
+ devEditors = options.dev
1941
+ ? ((_f = options.devSession) === null || _f === void 0 ? void 0 : _f.devEditors) || options.devEditors || detectDevEditors()
1942
+ : [];
1461
1943
  stepStartedAt = progress.step("Reading Git history");
1944
+ _a = ((_g = options.devSession) === null || _g === void 0 ? void 0 : _g.historyIndex);
1945
+ if (_a) return [3 /*break*/, 9];
1462
1946
  return [4 /*yield*/, getGitHistoryIndex(rootDirectoryPath, projectConfig)];
1463
- case 5:
1464
- historyIndex = _e.sent();
1947
+ case 8:
1948
+ _a = (_l.sent());
1949
+ _l.label = 9;
1950
+ case 9:
1951
+ historyIndex = _a;
1465
1952
  progress.done(stepStartedAt, "(".concat(pluralize(historyIndex.entries.length, "commit"), ")"));
1466
1953
  stepStartedAt = progress.step("Resolving repository links");
1467
- links = getRepoLinks(rootDirectoryPath);
1954
+ links = ((_h = options.devSession) === null || _h === void 0 ? void 0 : _h.links) || getRepoLinks(rootDirectoryPath);
1468
1955
  progress.done(stepStartedAt);
1469
1956
  duplicateResultsBySet = {};
1470
- if (!withDuplicates) return [3 /*break*/, 7];
1957
+ if (!withDuplicates) return [3 /*break*/, 11];
1471
1958
  stepStartedAt = progress.step("Scanning duplicate translations");
1472
- _b = (_a = Object).fromEntries;
1959
+ _c = (_b = Object).fromEntries;
1473
1960
  return [4 /*yield*/, runtime.findDuplicateTranslations(projectConfig, datasource)];
1474
- case 6:
1475
- duplicateResultsBySet = _b.apply(_a, [(_e.sent()).results.map(function (result) { return [
1961
+ case 10:
1962
+ duplicateResultsBySet = _c.apply(_b, [(_l.sent()).results.map(function (result) { return [
1476
1963
  getDuplicateSetKey(result.set),
1477
1964
  result,
1478
1965
  ]; })]);
@@ -1480,11 +1967,14 @@ function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasour
1480
1967
  return total +
1481
1968
  result.locales.reduce(function (localeTotal, localeResult) { return localeTotal + localeResult.duplicateValues.length; }, 0);
1482
1969
  }, 0), "duplicate value"), ")"));
1483
- _e.label = 7;
1484
- case 7:
1970
+ _l.label = 11;
1971
+ case 11:
1485
1972
  context = {
1486
1973
  rootDirectoryPath: rootDirectoryPath,
1487
- repositoryRootDirectoryPath: getRepositoryRootDirectoryPath(rootDirectoryPath),
1974
+ repositoryRootDirectoryPath: ((_j = options.devSession) === null || _j === void 0 ? void 0 : _j.repositoryRootDirectoryPath) ||
1975
+ getRepositoryRootDirectoryPath(rootDirectoryPath),
1976
+ repositorySourceRootDirectoryPath: ((_k = options.devSession) === null || _k === void 0 ? void 0 : _k.repositorySourceRootDirectoryPath) ||
1977
+ getRepositorySourceRootDirectoryPath(rootDirectoryPath),
1488
1978
  outputDirectoryPath: outputDirectoryPath,
1489
1979
  dataDirectoryPath: dataDirectoryPath,
1490
1980
  historyIndex: historyIndex,
@@ -1494,36 +1984,37 @@ function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasour
1494
1984
  withTranslationSearch: withTranslationSearch,
1495
1985
  withDuplicates: withDuplicates,
1496
1986
  progress: progress,
1987
+ writer: writer,
1497
1988
  };
1498
1989
  stepStartedAt = progress.step("Discovering project sets");
1499
1990
  return [4 /*yield*/, runtime.getProjectSetExecutions(projectConfig, datasource)];
1500
- case 8:
1501
- executions = _e.sent();
1991
+ case 12:
1992
+ executions = _l.sent();
1502
1993
  progress.done(stepStartedAt, projectConfig.sets
1503
1994
  ? "(".concat(executions.map(function (execution) { return execution.set; }).join(", ") || "none", ")")
1504
1995
  : "(root)");
1505
1996
  setIndexes = {};
1506
1997
  stepStartedAt = progress.step("Writing project history");
1507
- return [4 /*yield*/, writeHistoryPages(path.join(dataDirectoryPath, "project", "history"), historyIndex.entries)];
1508
- case 9:
1509
- _e.sent();
1998
+ return [4 /*yield*/, writeHistoryPages(writer, path.join(dataDirectoryPath, "project", "history"), historyIndex.entries)];
1999
+ case 13:
2000
+ _l.sent();
1510
2001
  progress.done(stepStartedAt, "(".concat(pluralize(historyIndex.entries.length, "entry", "entries"), ")"));
1511
2002
  _i = 0, executions_1 = executions;
1512
- _e.label = 10;
1513
- case 10:
1514
- if (!(_i < executions_1.length)) return [3 /*break*/, 13];
2003
+ _l.label = 14;
2004
+ case 14:
2005
+ if (!(_i < executions_1.length)) return [3 /*break*/, 17];
1515
2006
  execution = executions_1[_i];
1516
2007
  outputRelativeDirectory = projectConfig.sets ? path.join("sets", execution.set) : "root";
1517
- _c = setIndexes;
1518
- _d = execution.set || "root";
2008
+ _d = setIndexes;
2009
+ _e = execution.set || "root";
1519
2010
  return [4 /*yield*/, buildSetCatalog(context, execution.set, execution.projectConfig, execution.datasource, outputRelativeDirectory)];
1520
- case 11:
1521
- _c[_d] = _e.sent();
1522
- _e.label = 12;
1523
- case 12:
2011
+ case 15:
2012
+ _d[_e] = _l.sent();
2013
+ _l.label = 16;
2014
+ case 16:
1524
2015
  _i++;
1525
- return [3 /*break*/, 10];
1526
- case 13:
2016
+ return [3 /*break*/, 14];
2017
+ case 17:
1527
2018
  stepStartedAt = progress.step("Writing manifest");
1528
2019
  manifest = {
1529
2020
  schemaVersion: exports.CATALOG_SCHEMA_VERSION,
@@ -1549,9 +2040,9 @@ function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasour
1549
2040
  },
1550
2041
  counts: Object.fromEntries(Object.keys(setIndexes).map(function (key) { return [key, setIndexes[key].counts]; })),
1551
2042
  };
1552
- return [4 /*yield*/, writeJson(path.join(dataDirectoryPath, "manifest.json"), manifest)];
1553
- case 14:
1554
- _e.sent();
2043
+ return [4 /*yield*/, writer.write(path.join(dataDirectoryPath, "manifest.json"), manifest)];
2044
+ case 18:
2045
+ _l.sent();
1555
2046
  progress.done(stepStartedAt);
1556
2047
  progress.complete();
1557
2048
  return [2 /*return*/, {
@@ -1602,7 +2093,17 @@ function injectCatalogLiveReloadClient(html) {
1602
2093
  }
1603
2094
  return "".concat(html).concat(script);
1604
2095
  }
1605
- function createProjectWatcher(rootDirectoryPath, ignoredDirectoryPaths, onChange) {
2096
+ function getCatalogInputWatchPaths(rootDirectoryPath, projectConfig) {
2097
+ var paths = [path.join(rootDirectoryPath, "messagevisor.config.js")];
2098
+ if (projectConfig.sets) {
2099
+ paths.push(projectConfig.setsDirectoryPath);
2100
+ return paths;
2101
+ }
2102
+ paths.push(projectConfig.localesDirectoryPath, projectConfig.messagesDirectoryPath, projectConfig.attributesDirectoryPath, projectConfig.segmentsDirectoryPath, projectConfig.targetsDirectoryPath, projectConfig.testsDirectoryPath);
2103
+ return paths.filter(function (entry) { return typeof entry === "string" && entry.length > 0; });
2104
+ }
2105
+ function createCatalogInputWatcher(rootDirectoryPath, projectConfig, ignoredDirectoryPaths, onChange) {
2106
+ var watchPaths = getCatalogInputWatchPaths(rootDirectoryPath, projectConfig);
1606
2107
  function shouldIgnore(targetPath) {
1607
2108
  var resolvedTargetPath = path.resolve(targetPath);
1608
2109
  return ignoredDirectoryPaths.some(function (ignoredDirectoryPath) {
@@ -1611,6 +2112,17 @@ function createProjectWatcher(rootDirectoryPath, ignoredDirectoryPaths, onChange
1611
2112
  resolvedTargetPath.startsWith("".concat(resolvedIgnoredPath).concat(path.sep)));
1612
2113
  });
1613
2114
  }
2115
+ function shouldWatch(targetPath) {
2116
+ var resolvedTargetPath = path.resolve(targetPath);
2117
+ if (shouldIgnore(resolvedTargetPath)) {
2118
+ return false;
2119
+ }
2120
+ return watchPaths.some(function (watchPath) {
2121
+ var resolvedWatchPath = path.resolve(watchPath);
2122
+ return (resolvedTargetPath === resolvedWatchPath ||
2123
+ resolvedTargetPath.startsWith("".concat(resolvedWatchPath).concat(path.sep)));
2124
+ });
2125
+ }
1614
2126
  function collectSnapshotEntries(directoryPath, snapshotEntries) {
1615
2127
  if (shouldIgnore(directoryPath)) {
1616
2128
  return;
@@ -1637,8 +2149,7 @@ function createProjectWatcher(rootDirectoryPath, ignoredDirectoryPaths, onChange
1637
2149
  }
1638
2150
  try {
1639
2151
  var stat = fs.statSync(entryPath);
1640
- var relativePath = path.relative(rootDirectoryPath, entryPath);
1641
- snapshotEntries.push("".concat(relativePath, ":").concat(stat.size, ":").concat(stat.mtimeMs));
2152
+ snapshotEntries.set(entryPath, "".concat(stat.size, ":").concat(stat.mtimeMs));
1642
2153
  }
1643
2154
  catch (_b) {
1644
2155
  // Ignore transient editor save races.
@@ -1646,22 +2157,94 @@ function createProjectWatcher(rootDirectoryPath, ignoredDirectoryPaths, onChange
1646
2157
  }
1647
2158
  }
1648
2159
  function createSnapshot() {
1649
- var snapshotEntries = [];
1650
- collectSnapshotEntries(rootDirectoryPath, snapshotEntries);
1651
- snapshotEntries.sort();
1652
- return snapshotEntries.join("|");
1653
- }
1654
- var previousSnapshot = createSnapshot();
1655
- var interval = setInterval(function () {
1656
- var nextSnapshot = createSnapshot();
1657
- if (nextSnapshot === previousSnapshot) {
1658
- return;
2160
+ var snapshotEntries = new Map();
2161
+ for (var _i = 0, watchPaths_2 = watchPaths; _i < watchPaths_2.length; _i++) {
2162
+ var watchPath = watchPaths_2[_i];
2163
+ if (!fs.existsSync(watchPath)) {
2164
+ continue;
2165
+ }
2166
+ var stat = fs.statSync(watchPath);
2167
+ if (stat.isFile()) {
2168
+ snapshotEntries.set(watchPath, "".concat(stat.size, ":").concat(stat.mtimeMs));
2169
+ continue;
2170
+ }
2171
+ collectSnapshotEntries(watchPath, snapshotEntries);
2172
+ }
2173
+ return snapshotEntries;
2174
+ }
2175
+ function getSnapshotChanges(previous, next) {
2176
+ var changedPaths = new Set();
2177
+ for (var _i = 0, _a = Array.from(next.entries()); _i < _a.length; _i++) {
2178
+ var _b = _a[_i], filePath = _b[0], signature = _b[1];
2179
+ if (previous.get(filePath) !== signature) {
2180
+ changedPaths.add(filePath);
2181
+ }
2182
+ }
2183
+ for (var _c = 0, _d = Array.from(previous.keys()); _c < _d.length; _c++) {
2184
+ var filePath = _d[_c];
2185
+ if (!next.has(filePath)) {
2186
+ changedPaths.add(filePath);
2187
+ }
2188
+ }
2189
+ return Array.from(changedPaths);
2190
+ }
2191
+ function createPollingWatcher() {
2192
+ var previousSnapshot = createSnapshot();
2193
+ var interval = setInterval(function () {
2194
+ var nextSnapshot = createSnapshot();
2195
+ var changedPaths = getSnapshotChanges(previousSnapshot, nextSnapshot).filter(shouldWatch);
2196
+ previousSnapshot = nextSnapshot;
2197
+ if (changedPaths.length === 0) {
2198
+ return;
2199
+ }
2200
+ onChange(changedPaths);
2201
+ }, 1000);
2202
+ return function () {
2203
+ clearInterval(interval);
2204
+ };
2205
+ }
2206
+ var watchers = [];
2207
+ var nativeWatcherFailed = false;
2208
+ var _loop_2 = function (watchPath) {
2209
+ if (!fs.existsSync(watchPath)) {
2210
+ return "continue";
2211
+ }
2212
+ try {
2213
+ var stat = fs.statSync(watchPath);
2214
+ var directoryPath_1 = stat.isDirectory() ? watchPath : path.dirname(watchPath);
2215
+ var watcher = fs.watch(directoryPath_1, { recursive: stat.isDirectory() }, function (_eventType, filename) {
2216
+ var changedPath = filename
2217
+ ? path.resolve(directoryPath_1, filename.toString())
2218
+ : directoryPath_1;
2219
+ if (shouldWatch(changedPath)) {
2220
+ onChange([changedPath]);
2221
+ }
2222
+ });
2223
+ watchers.push(watcher);
1659
2224
  }
1660
- previousSnapshot = nextSnapshot;
1661
- onChange(rootDirectoryPath);
1662
- }, 250);
2225
+ catch (_error) {
2226
+ nativeWatcherFailed = true;
2227
+ return "break";
2228
+ }
2229
+ };
2230
+ for (var _i = 0, watchPaths_1 = watchPaths; _i < watchPaths_1.length; _i++) {
2231
+ var watchPath = watchPaths_1[_i];
2232
+ var state_2 = _loop_2(watchPath);
2233
+ if (state_2 === "break")
2234
+ break;
2235
+ }
2236
+ if (nativeWatcherFailed || watchers.length === 0) {
2237
+ for (var _a = 0, watchers_1 = watchers; _a < watchers_1.length; _a++) {
2238
+ var watcher = watchers_1[_a];
2239
+ watcher.close();
2240
+ }
2241
+ return createPollingWatcher();
2242
+ }
1663
2243
  return function () {
1664
- clearInterval(interval);
2244
+ for (var _i = 0, watchers_2 = watchers; _i < watchers_2.length; _i++) {
2245
+ var watcher = watchers_2[_i];
2246
+ watcher.close();
2247
+ }
1665
2248
  };
1666
2249
  }
1667
2250
  function serveCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasource_1) {
@@ -1790,13 +2373,17 @@ function isWithTranslationSearchEnabled(parsed) {
1790
2373
  function isWithDuplicatesEnabled(parsed) {
1791
2374
  return parsed.withDuplicates === true || parsed["with-duplicates"] === true;
1792
2375
  }
2376
+ exports.__catalogDevInternals = {
2377
+ classifyCatalogDevChanges: classifyCatalogDevChanges,
2378
+ getCatalogInputWatchPaths: getCatalogInputWatchPaths,
2379
+ };
1793
2380
  function createCatalogPlugin(runtime, api) {
1794
2381
  var _this = this;
1795
2382
  if (api === void 0) { api = createCatalogApi(runtime); }
1796
2383
  return {
1797
2384
  command: "catalog [subcommand]",
1798
2385
  handler: function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
1799
- var allowedSubcommands, browserRouter, withTranslationSearch, withDuplicates, server_1, outputDirectoryPath, ignoredDirectoryPaths, exportInFlight_1, exportQueued_1, queuedReason_1, debounceTimer_1, runExportAndReload_1, stopWatchingProject;
2386
+ var allowedSubcommands, browserRouter, withTranslationSearch, withDuplicates, outputDirectoryPath, devSession_1, server_1, ignoredDirectoryPaths, exportInFlight_1, queuedChanges_1, pendingChanges_1, debounceTimer_1, runRebuildAndReload_1, stopWatchingProject;
1800
2387
  var _this = this;
1801
2388
  var rootDirectoryPath = _b.rootDirectoryPath, projectConfig = _b.projectConfig, datasource = _b.datasource, parsed = _b.parsed;
1802
2389
  return __generator(this, function (_c) {
@@ -1806,16 +2393,25 @@ function createCatalogPlugin(runtime, api) {
1806
2393
  browserRouter = !(parsed.hashRouter || parsed["hash-router"]);
1807
2394
  withTranslationSearch = isWithTranslationSearchEnabled(parsed);
1808
2395
  withDuplicates = isWithDuplicatesEnabled(parsed);
1809
- if (!!parsed.subcommand) return [3 /*break*/, 3];
2396
+ if (!!parsed.subcommand) return [3 /*break*/, 4];
2397
+ outputDirectoryPath = parsed.outDir
2398
+ ? path.resolve(rootDirectoryPath, parsed.outDir)
2399
+ : projectConfig.catalogDirectoryPath;
2400
+ return [4 /*yield*/, createCatalogDevSession(rootDirectoryPath, projectConfig, {
2401
+ outDir: parsed.outDir,
2402
+ })];
2403
+ case 1:
2404
+ devSession_1 = _c.sent();
1810
2405
  return [4 /*yield*/, api.exportCatalog(rootDirectoryPath, projectConfig, datasource, {
1811
2406
  outDir: parsed.outDir,
1812
2407
  copyAssets: !parsed.noAssets,
1813
2408
  browserRouter: browserRouter,
1814
2409
  dev: true,
2410
+ devSession: devSession_1,
1815
2411
  withTranslationSearch: withTranslationSearch,
1816
2412
  withDuplicates: withDuplicates,
1817
2413
  })];
1818
- case 1:
2414
+ case 2:
1819
2415
  _c.sent();
1820
2416
  return [4 /*yield*/, api.serveCatalog(rootDirectoryPath, projectConfig, datasource, {
1821
2417
  outDir: parsed.outDir,
@@ -1823,11 +2419,8 @@ function createCatalogPlugin(runtime, api) {
1823
2419
  browserRouter: browserRouter,
1824
2420
  liveReload: true,
1825
2421
  })];
1826
- case 2:
2422
+ case 3:
1827
2423
  server_1 = _c.sent();
1828
- outputDirectoryPath = parsed.outDir
1829
- ? path.resolve(rootDirectoryPath, parsed.outDir)
1830
- : projectConfig.catalogDirectoryPath;
1831
2424
  ignoredDirectoryPaths = [
1832
2425
  path.join(rootDirectoryPath, ".git"),
1833
2426
  path.join(rootDirectoryPath, "node_modules"),
@@ -1839,72 +2432,102 @@ function createCatalogPlugin(runtime, api) {
1839
2432
  outputDirectoryPath,
1840
2433
  ];
1841
2434
  exportInFlight_1 = false;
1842
- exportQueued_1 = false;
1843
- queuedReason_1 = null;
2435
+ queuedChanges_1 = [];
2436
+ pendingChanges_1 = [];
1844
2437
  debounceTimer_1 = null;
1845
- runExportAndReload_1 = function (reason) { return __awaiter(_this, void 0, void 0, function () {
1846
- var error_1, nextReason;
2438
+ runRebuildAndReload_1 = function (changedPaths) { return __awaiter(_this, void 0, void 0, function () {
2439
+ var request, handled, execution, error_1, nextChanges;
1847
2440
  return __generator(this, function (_a) {
1848
2441
  switch (_a.label) {
1849
2442
  case 0:
1850
2443
  if (exportInFlight_1) {
1851
- exportQueued_1 = true;
1852
- queuedReason_1 = queuedReason_1 || reason;
2444
+ queuedChanges_1.push.apply(queuedChanges_1, changedPaths);
1853
2445
  return [2 /*return*/];
1854
2446
  }
1855
2447
  exportInFlight_1 = true;
1856
- console.log("\n[catalog] Re-exporting because ".concat(reason));
2448
+ request = classifyCatalogDevChanges(rootDirectoryPath, projectConfig, changedPaths, {
2449
+ withTranslationSearch: withTranslationSearch,
2450
+ withDuplicates: withDuplicates,
2451
+ });
2452
+ console.log("\n[catalog] Rebuilding (".concat(request.kind, ") because ").concat(request.reason));
1857
2453
  _a.label = 1;
1858
2454
  case 1:
1859
- _a.trys.push([1, 3, 4, 5]);
2455
+ _a.trys.push([1, 9, 10, 11]);
2456
+ handled = false;
2457
+ if (!(request.kind === "message")) return [3 /*break*/, 4];
2458
+ return [4 /*yield*/, runtime.getProjectSetExecutions(projectConfig, datasource, request.set)];
2459
+ case 2:
2460
+ execution = (_a.sent())[0];
2461
+ return [4 /*yield*/, tryRebuildCatalogMessage(runtime, rootDirectoryPath, projectConfig, execution.projectConfig, execution.datasource, devSession_1, request)];
2462
+ case 3:
2463
+ handled = _a.sent();
2464
+ _a.label = 4;
2465
+ case 4:
2466
+ if (!(!handled && request.kind === "set" && request.set)) return [3 /*break*/, 6];
2467
+ return [4 /*yield*/, rebuildCatalogSetForDev(runtime, rootDirectoryPath, projectConfig, datasource, devSession_1, {
2468
+ set: request.set,
2469
+ browserRouter: browserRouter,
2470
+ withTranslationSearch: withTranslationSearch,
2471
+ withDuplicates: withDuplicates,
2472
+ })];
2473
+ case 5:
2474
+ handled = _a.sent();
2475
+ _a.label = 6;
2476
+ case 6:
2477
+ if (!!handled) return [3 /*break*/, 8];
1860
2478
  return [4 /*yield*/, api.exportCatalog(rootDirectoryPath, projectConfig, datasource, {
1861
2479
  outDir: parsed.outDir,
1862
- copyAssets: !parsed.noAssets,
2480
+ copyAssets: false,
2481
+ preserveAssets: true,
1863
2482
  browserRouter: browserRouter,
1864
2483
  dev: true,
2484
+ devSession: devSession_1,
1865
2485
  withTranslationSearch: withTranslationSearch,
1866
2486
  withDuplicates: withDuplicates,
1867
2487
  })];
1868
- case 2:
2488
+ case 7:
1869
2489
  _a.sent();
2490
+ _a.label = 8;
2491
+ case 8:
1870
2492
  server_1.triggerReload();
1871
- return [3 /*break*/, 5];
1872
- case 3:
2493
+ return [3 /*break*/, 11];
2494
+ case 9:
1873
2495
  error_1 = _a.sent();
1874
2496
  console.error("[catalog] Export failed during watch mode");
1875
2497
  console.error(error_1);
1876
- return [3 /*break*/, 5];
1877
- case 4:
2498
+ return [3 /*break*/, 11];
2499
+ case 10:
1878
2500
  exportInFlight_1 = false;
1879
- if (exportQueued_1) {
1880
- nextReason = queuedReason_1 || "more project changes";
1881
- exportQueued_1 = false;
1882
- queuedReason_1 = null;
1883
- void runExportAndReload_1(nextReason);
2501
+ if (queuedChanges_1.length > 0) {
2502
+ nextChanges = queuedChanges_1;
2503
+ queuedChanges_1 = [];
2504
+ void runRebuildAndReload_1(nextChanges);
1884
2505
  }
1885
2506
  return [7 /*endfinally*/];
1886
- case 5: return [2 /*return*/];
2507
+ case 11: return [2 /*return*/];
1887
2508
  }
1888
2509
  });
1889
2510
  }); };
1890
- stopWatchingProject = createProjectWatcher(rootDirectoryPath, ignoredDirectoryPaths, function (changedPath) {
1891
- var reason = "project change in ".concat(path.relative(rootDirectoryPath, changedPath) || ".");
2511
+ stopWatchingProject = createCatalogInputWatcher(rootDirectoryPath, projectConfig, ignoredDirectoryPaths, function (changedPaths) {
2512
+ pendingChanges_1.push.apply(pendingChanges_1, changedPaths);
1892
2513
  if (debounceTimer_1) {
1893
2514
  clearTimeout(debounceTimer_1);
1894
2515
  }
1895
2516
  debounceTimer_1 = setTimeout(function () {
2517
+ var nextChanges = Array.from(new Set(pendingChanges_1));
2518
+ pendingChanges_1 = [];
1896
2519
  debounceTimer_1 = null;
1897
- void runExportAndReload_1(reason);
1898
- }, 150);
2520
+ void runRebuildAndReload_1(nextChanges);
2521
+ }, 250);
1899
2522
  });
1900
2523
  process.on("exit", stopWatchingProject);
1901
2524
  return [2 /*return*/];
1902
- case 3:
2525
+ case 4:
1903
2526
  if (allowedSubcommands.indexOf(parsed.subcommand) === -1) {
1904
2527
  console.log("Please specify a subcommand: `export` or `serve`");
1905
2528
  return [2 /*return*/, false];
1906
2529
  }
1907
- if (!(parsed.subcommand === "export")) return [3 /*break*/, 5];
2530
+ if (!(parsed.subcommand === "export")) return [3 /*break*/, 6];
1908
2531
  return [4 /*yield*/, api.exportCatalog(rootDirectoryPath, projectConfig, datasource, {
1909
2532
  outDir: parsed.outDir,
1910
2533
  copyAssets: !parsed.noAssets,
@@ -1912,20 +2535,20 @@ function createCatalogPlugin(runtime, api) {
1912
2535
  withTranslationSearch: withTranslationSearch,
1913
2536
  withDuplicates: withDuplicates,
1914
2537
  })];
1915
- case 4:
1916
- _c.sent();
1917
- _c.label = 5;
1918
2538
  case 5:
1919
- if (!(parsed.subcommand === "serve")) return [3 /*break*/, 7];
2539
+ _c.sent();
2540
+ _c.label = 6;
2541
+ case 6:
2542
+ if (!(parsed.subcommand === "serve")) return [3 /*break*/, 8];
1920
2543
  return [4 /*yield*/, api.serveCatalog(rootDirectoryPath, projectConfig, datasource, {
1921
2544
  outDir: parsed.outDir,
1922
2545
  port: parsed.port || parsed.p,
1923
2546
  browserRouter: browserRouter,
1924
2547
  })];
1925
- case 6:
2548
+ case 7:
1926
2549
  _c.sent();
1927
- _c.label = 7;
1928
- case 7: return [2 /*return*/];
2550
+ _c.label = 8;
2551
+ case 8: return [2 /*return*/];
1929
2552
  }
1930
2553
  });
1931
2554
  }); },