@messagevisor/catalog 0.7.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;
@@ -1503,12 +1503,404 @@ function copyCatalogAssets(outputDirectoryPath) {
1503
1503
  });
1504
1504
  });
1505
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
+ }
1506
1897
  function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasource_1) {
1507
1898
  return __awaiter(this, arguments, void 0, function (runtime, rootDirectoryPath, projectConfig, datasource, options) {
1508
- var outputDirectoryPath, dataDirectoryPath, withTranslationSearch, withDuplicates, progress, writer, 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;
1509
1901
  if (options === void 0) { options = {}; }
1510
- return __generator(this, function (_e) {
1511
- switch (_e.label) {
1902
+ return __generator(this, function (_l) {
1903
+ switch (_l.label) {
1512
1904
  case 0:
1513
1905
  outputDirectoryPath = options.outDir
1514
1906
  ? path.resolve(rootDirectoryPath, options.outDir)
@@ -1524,37 +1916,50 @@ function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasour
1524
1916
  features: __spreadArray(__spreadArray([], (withTranslationSearch ? ["translation search"] : []), true), (withDuplicates ? ["duplicates"] : []), true),
1525
1917
  });
1526
1918
  stepStartedAt = progress.step("Preparing output directory");
1527
- 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 })];
1528
1921
  case 1:
1529
- _e.sent();
1530
- return [4 /*yield*/, fs.promises.mkdir(dataDirectoryPath, { recursive: true })];
1531
- case 2:
1532
- _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();
1533
1931
  progress.done(stepStartedAt);
1534
- if (!(options.copyAssets !== false)) return [3 /*break*/, 4];
1932
+ if (!(options.copyAssets !== false)) return [3 /*break*/, 7];
1535
1933
  stepStartedAt = progress.step("Copying Catalog UI assets");
1536
1934
  return [4 /*yield*/, copyCatalogAssets(outputDirectoryPath)];
1537
- case 3:
1538
- _e.sent();
1935
+ case 6:
1936
+ _l.sent();
1539
1937
  progress.done(stepStartedAt);
1540
- _e.label = 4;
1541
- case 4:
1542
- 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
+ : [];
1543
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];
1544
1946
  return [4 /*yield*/, getGitHistoryIndex(rootDirectoryPath, projectConfig)];
1545
- case 5:
1546
- historyIndex = _e.sent();
1947
+ case 8:
1948
+ _a = (_l.sent());
1949
+ _l.label = 9;
1950
+ case 9:
1951
+ historyIndex = _a;
1547
1952
  progress.done(stepStartedAt, "(".concat(pluralize(historyIndex.entries.length, "commit"), ")"));
1548
1953
  stepStartedAt = progress.step("Resolving repository links");
1549
- links = getRepoLinks(rootDirectoryPath);
1954
+ links = ((_h = options.devSession) === null || _h === void 0 ? void 0 : _h.links) || getRepoLinks(rootDirectoryPath);
1550
1955
  progress.done(stepStartedAt);
1551
1956
  duplicateResultsBySet = {};
1552
- if (!withDuplicates) return [3 /*break*/, 7];
1957
+ if (!withDuplicates) return [3 /*break*/, 11];
1553
1958
  stepStartedAt = progress.step("Scanning duplicate translations");
1554
- _b = (_a = Object).fromEntries;
1959
+ _c = (_b = Object).fromEntries;
1555
1960
  return [4 /*yield*/, runtime.findDuplicateTranslations(projectConfig, datasource)];
1556
- case 6:
1557
- 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 [
1558
1963
  getDuplicateSetKey(result.set),
1559
1964
  result,
1560
1965
  ]; })]);
@@ -1562,12 +1967,14 @@ function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasour
1562
1967
  return total +
1563
1968
  result.locales.reduce(function (localeTotal, localeResult) { return localeTotal + localeResult.duplicateValues.length; }, 0);
1564
1969
  }, 0), "duplicate value"), ")"));
1565
- _e.label = 7;
1566
- case 7:
1970
+ _l.label = 11;
1971
+ case 11:
1567
1972
  context = {
1568
1973
  rootDirectoryPath: rootDirectoryPath,
1569
- repositoryRootDirectoryPath: getRepositoryRootDirectoryPath(rootDirectoryPath),
1570
- repositorySourceRootDirectoryPath: getRepositorySourceRootDirectoryPath(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),
1571
1978
  outputDirectoryPath: outputDirectoryPath,
1572
1979
  dataDirectoryPath: dataDirectoryPath,
1573
1980
  historyIndex: historyIndex,
@@ -1581,33 +1988,33 @@ function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasour
1581
1988
  };
1582
1989
  stepStartedAt = progress.step("Discovering project sets");
1583
1990
  return [4 /*yield*/, runtime.getProjectSetExecutions(projectConfig, datasource)];
1584
- case 8:
1585
- executions = _e.sent();
1991
+ case 12:
1992
+ executions = _l.sent();
1586
1993
  progress.done(stepStartedAt, projectConfig.sets
1587
1994
  ? "(".concat(executions.map(function (execution) { return execution.set; }).join(", ") || "none", ")")
1588
1995
  : "(root)");
1589
1996
  setIndexes = {};
1590
1997
  stepStartedAt = progress.step("Writing project history");
1591
1998
  return [4 /*yield*/, writeHistoryPages(writer, path.join(dataDirectoryPath, "project", "history"), historyIndex.entries)];
1592
- case 9:
1593
- _e.sent();
1999
+ case 13:
2000
+ _l.sent();
1594
2001
  progress.done(stepStartedAt, "(".concat(pluralize(historyIndex.entries.length, "entry", "entries"), ")"));
1595
2002
  _i = 0, executions_1 = executions;
1596
- _e.label = 10;
1597
- case 10:
1598
- 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];
1599
2006
  execution = executions_1[_i];
1600
2007
  outputRelativeDirectory = projectConfig.sets ? path.join("sets", execution.set) : "root";
1601
- _c = setIndexes;
1602
- _d = execution.set || "root";
2008
+ _d = setIndexes;
2009
+ _e = execution.set || "root";
1603
2010
  return [4 /*yield*/, buildSetCatalog(context, execution.set, execution.projectConfig, execution.datasource, outputRelativeDirectory)];
1604
- case 11:
1605
- _c[_d] = _e.sent();
1606
- _e.label = 12;
1607
- case 12:
2011
+ case 15:
2012
+ _d[_e] = _l.sent();
2013
+ _l.label = 16;
2014
+ case 16:
1608
2015
  _i++;
1609
- return [3 /*break*/, 10];
1610
- case 13:
2016
+ return [3 /*break*/, 14];
2017
+ case 17:
1611
2018
  stepStartedAt = progress.step("Writing manifest");
1612
2019
  manifest = {
1613
2020
  schemaVersion: exports.CATALOG_SCHEMA_VERSION,
@@ -1634,8 +2041,8 @@ function exportCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasour
1634
2041
  counts: Object.fromEntries(Object.keys(setIndexes).map(function (key) { return [key, setIndexes[key].counts]; })),
1635
2042
  };
1636
2043
  return [4 /*yield*/, writer.write(path.join(dataDirectoryPath, "manifest.json"), manifest)];
1637
- case 14:
1638
- _e.sent();
2044
+ case 18:
2045
+ _l.sent();
1639
2046
  progress.done(stepStartedAt);
1640
2047
  progress.complete();
1641
2048
  return [2 /*return*/, {
@@ -1686,7 +2093,17 @@ function injectCatalogLiveReloadClient(html) {
1686
2093
  }
1687
2094
  return "".concat(html).concat(script);
1688
2095
  }
1689
- 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);
1690
2107
  function shouldIgnore(targetPath) {
1691
2108
  var resolvedTargetPath = path.resolve(targetPath);
1692
2109
  return ignoredDirectoryPaths.some(function (ignoredDirectoryPath) {
@@ -1695,6 +2112,17 @@ function createProjectWatcher(rootDirectoryPath, ignoredDirectoryPaths, onChange
1695
2112
  resolvedTargetPath.startsWith("".concat(resolvedIgnoredPath).concat(path.sep)));
1696
2113
  });
1697
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
+ }
1698
2126
  function collectSnapshotEntries(directoryPath, snapshotEntries) {
1699
2127
  if (shouldIgnore(directoryPath)) {
1700
2128
  return;
@@ -1721,8 +2149,7 @@ function createProjectWatcher(rootDirectoryPath, ignoredDirectoryPaths, onChange
1721
2149
  }
1722
2150
  try {
1723
2151
  var stat = fs.statSync(entryPath);
1724
- var relativePath = path.relative(rootDirectoryPath, entryPath);
1725
- snapshotEntries.push("".concat(relativePath, ":").concat(stat.size, ":").concat(stat.mtimeMs));
2152
+ snapshotEntries.set(entryPath, "".concat(stat.size, ":").concat(stat.mtimeMs));
1726
2153
  }
1727
2154
  catch (_b) {
1728
2155
  // Ignore transient editor save races.
@@ -1730,22 +2157,94 @@ function createProjectWatcher(rootDirectoryPath, ignoredDirectoryPaths, onChange
1730
2157
  }
1731
2158
  }
1732
2159
  function createSnapshot() {
1733
- var snapshotEntries = [];
1734
- collectSnapshotEntries(rootDirectoryPath, snapshotEntries);
1735
- snapshotEntries.sort();
1736
- return snapshotEntries.join("|");
1737
- }
1738
- var previousSnapshot = createSnapshot();
1739
- var interval = setInterval(function () {
1740
- var nextSnapshot = createSnapshot();
1741
- if (nextSnapshot === previousSnapshot) {
1742
- 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);
2224
+ }
2225
+ catch (_error) {
2226
+ nativeWatcherFailed = true;
2227
+ return "break";
1743
2228
  }
1744
- previousSnapshot = nextSnapshot;
1745
- onChange(rootDirectoryPath);
1746
- }, 250);
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
+ }
1747
2243
  return function () {
1748
- 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
+ }
1749
2248
  };
1750
2249
  }
1751
2250
  function serveCatalog(runtime_1, rootDirectoryPath_1, projectConfig_1, datasource_1) {
@@ -1874,13 +2373,17 @@ function isWithTranslationSearchEnabled(parsed) {
1874
2373
  function isWithDuplicatesEnabled(parsed) {
1875
2374
  return parsed.withDuplicates === true || parsed["with-duplicates"] === true;
1876
2375
  }
2376
+ exports.__catalogDevInternals = {
2377
+ classifyCatalogDevChanges: classifyCatalogDevChanges,
2378
+ getCatalogInputWatchPaths: getCatalogInputWatchPaths,
2379
+ };
1877
2380
  function createCatalogPlugin(runtime, api) {
1878
2381
  var _this = this;
1879
2382
  if (api === void 0) { api = createCatalogApi(runtime); }
1880
2383
  return {
1881
2384
  command: "catalog [subcommand]",
1882
2385
  handler: function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
1883
- 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;
1884
2387
  var _this = this;
1885
2388
  var rootDirectoryPath = _b.rootDirectoryPath, projectConfig = _b.projectConfig, datasource = _b.datasource, parsed = _b.parsed;
1886
2389
  return __generator(this, function (_c) {
@@ -1890,16 +2393,25 @@ function createCatalogPlugin(runtime, api) {
1890
2393
  browserRouter = !(parsed.hashRouter || parsed["hash-router"]);
1891
2394
  withTranslationSearch = isWithTranslationSearchEnabled(parsed);
1892
2395
  withDuplicates = isWithDuplicatesEnabled(parsed);
1893
- 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();
1894
2405
  return [4 /*yield*/, api.exportCatalog(rootDirectoryPath, projectConfig, datasource, {
1895
2406
  outDir: parsed.outDir,
1896
2407
  copyAssets: !parsed.noAssets,
1897
2408
  browserRouter: browserRouter,
1898
2409
  dev: true,
2410
+ devSession: devSession_1,
1899
2411
  withTranslationSearch: withTranslationSearch,
1900
2412
  withDuplicates: withDuplicates,
1901
2413
  })];
1902
- case 1:
2414
+ case 2:
1903
2415
  _c.sent();
1904
2416
  return [4 /*yield*/, api.serveCatalog(rootDirectoryPath, projectConfig, datasource, {
1905
2417
  outDir: parsed.outDir,
@@ -1907,11 +2419,8 @@ function createCatalogPlugin(runtime, api) {
1907
2419
  browserRouter: browserRouter,
1908
2420
  liveReload: true,
1909
2421
  })];
1910
- case 2:
2422
+ case 3:
1911
2423
  server_1 = _c.sent();
1912
- outputDirectoryPath = parsed.outDir
1913
- ? path.resolve(rootDirectoryPath, parsed.outDir)
1914
- : projectConfig.catalogDirectoryPath;
1915
2424
  ignoredDirectoryPaths = [
1916
2425
  path.join(rootDirectoryPath, ".git"),
1917
2426
  path.join(rootDirectoryPath, "node_modules"),
@@ -1923,72 +2432,102 @@ function createCatalogPlugin(runtime, api) {
1923
2432
  outputDirectoryPath,
1924
2433
  ];
1925
2434
  exportInFlight_1 = false;
1926
- exportQueued_1 = false;
1927
- queuedReason_1 = null;
2435
+ queuedChanges_1 = [];
2436
+ pendingChanges_1 = [];
1928
2437
  debounceTimer_1 = null;
1929
- runExportAndReload_1 = function (reason) { return __awaiter(_this, void 0, void 0, function () {
1930
- 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;
1931
2440
  return __generator(this, function (_a) {
1932
2441
  switch (_a.label) {
1933
2442
  case 0:
1934
2443
  if (exportInFlight_1) {
1935
- exportQueued_1 = true;
1936
- queuedReason_1 = queuedReason_1 || reason;
2444
+ queuedChanges_1.push.apply(queuedChanges_1, changedPaths);
1937
2445
  return [2 /*return*/];
1938
2446
  }
1939
2447
  exportInFlight_1 = true;
1940
- 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));
1941
2453
  _a.label = 1;
1942
2454
  case 1:
1943
- _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];
1944
2478
  return [4 /*yield*/, api.exportCatalog(rootDirectoryPath, projectConfig, datasource, {
1945
2479
  outDir: parsed.outDir,
1946
- copyAssets: !parsed.noAssets,
2480
+ copyAssets: false,
2481
+ preserveAssets: true,
1947
2482
  browserRouter: browserRouter,
1948
2483
  dev: true,
2484
+ devSession: devSession_1,
1949
2485
  withTranslationSearch: withTranslationSearch,
1950
2486
  withDuplicates: withDuplicates,
1951
2487
  })];
1952
- case 2:
2488
+ case 7:
1953
2489
  _a.sent();
2490
+ _a.label = 8;
2491
+ case 8:
1954
2492
  server_1.triggerReload();
1955
- return [3 /*break*/, 5];
1956
- case 3:
2493
+ return [3 /*break*/, 11];
2494
+ case 9:
1957
2495
  error_1 = _a.sent();
1958
2496
  console.error("[catalog] Export failed during watch mode");
1959
2497
  console.error(error_1);
1960
- return [3 /*break*/, 5];
1961
- case 4:
2498
+ return [3 /*break*/, 11];
2499
+ case 10:
1962
2500
  exportInFlight_1 = false;
1963
- if (exportQueued_1) {
1964
- nextReason = queuedReason_1 || "more project changes";
1965
- exportQueued_1 = false;
1966
- queuedReason_1 = null;
1967
- void runExportAndReload_1(nextReason);
2501
+ if (queuedChanges_1.length > 0) {
2502
+ nextChanges = queuedChanges_1;
2503
+ queuedChanges_1 = [];
2504
+ void runRebuildAndReload_1(nextChanges);
1968
2505
  }
1969
2506
  return [7 /*endfinally*/];
1970
- case 5: return [2 /*return*/];
2507
+ case 11: return [2 /*return*/];
1971
2508
  }
1972
2509
  });
1973
2510
  }); };
1974
- stopWatchingProject = createProjectWatcher(rootDirectoryPath, ignoredDirectoryPaths, function (changedPath) {
1975
- 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);
1976
2513
  if (debounceTimer_1) {
1977
2514
  clearTimeout(debounceTimer_1);
1978
2515
  }
1979
2516
  debounceTimer_1 = setTimeout(function () {
2517
+ var nextChanges = Array.from(new Set(pendingChanges_1));
2518
+ pendingChanges_1 = [];
1980
2519
  debounceTimer_1 = null;
1981
- void runExportAndReload_1(reason);
1982
- }, 150);
2520
+ void runRebuildAndReload_1(nextChanges);
2521
+ }, 250);
1983
2522
  });
1984
2523
  process.on("exit", stopWatchingProject);
1985
2524
  return [2 /*return*/];
1986
- case 3:
2525
+ case 4:
1987
2526
  if (allowedSubcommands.indexOf(parsed.subcommand) === -1) {
1988
2527
  console.log("Please specify a subcommand: `export` or `serve`");
1989
2528
  return [2 /*return*/, false];
1990
2529
  }
1991
- if (!(parsed.subcommand === "export")) return [3 /*break*/, 5];
2530
+ if (!(parsed.subcommand === "export")) return [3 /*break*/, 6];
1992
2531
  return [4 /*yield*/, api.exportCatalog(rootDirectoryPath, projectConfig, datasource, {
1993
2532
  outDir: parsed.outDir,
1994
2533
  copyAssets: !parsed.noAssets,
@@ -1996,20 +2535,20 @@ function createCatalogPlugin(runtime, api) {
1996
2535
  withTranslationSearch: withTranslationSearch,
1997
2536
  withDuplicates: withDuplicates,
1998
2537
  })];
1999
- case 4:
2000
- _c.sent();
2001
- _c.label = 5;
2002
2538
  case 5:
2003
- 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];
2004
2543
  return [4 /*yield*/, api.serveCatalog(rootDirectoryPath, projectConfig, datasource, {
2005
2544
  outDir: parsed.outDir,
2006
2545
  port: parsed.port || parsed.p,
2007
2546
  browserRouter: browserRouter,
2008
2547
  })];
2009
- case 6:
2548
+ case 7:
2010
2549
  _c.sent();
2011
- _c.label = 7;
2012
- case 7: return [2 /*return*/];
2550
+ _c.label = 8;
2551
+ case 8: return [2 /*return*/];
2013
2552
  }
2014
2553
  });
2015
2554
  }); },