@verbaly/compiler 0.57.0 → 0.59.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/dist/cli.js +33 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.js +33 -11
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as resolveConfig, i as loadConfigFile, o as targetLocales, r as loadConfig, t as findConfigFile } from "./config-DYlbHrPc.js";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
|
-
import { CATALOG_SCRIPT, LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseTags, safeAttribute } from "verbaly";
|
|
4
|
+
import { CATALOG_SCRIPT, LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseIcu, parseTags, safeAttribute } from "verbaly";
|
|
5
5
|
import { glob } from "tinyglobby";
|
|
6
6
|
import { parse as parse$1 } from "@babel/parser";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
@@ -77,8 +77,31 @@ function sortTree(tree) {
|
|
|
77
77
|
}
|
|
78
78
|
return sorted;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
|
|
80
|
+
function isSorted(keys) {
|
|
81
|
+
for (let i = 1; i < keys.length; i++) if (keys[i - 1] > keys[i]) return false;
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
function orderLike(tree, previous) {
|
|
85
|
+
const had = Object.keys(previous);
|
|
86
|
+
if (isSorted(had)) return sortTree(tree);
|
|
87
|
+
const out = {};
|
|
88
|
+
const take = (key) => {
|
|
89
|
+
const value = tree[key];
|
|
90
|
+
if (typeof value === "string") {
|
|
91
|
+
out[key] = value;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (value === void 0) return;
|
|
95
|
+
const before = previous[key];
|
|
96
|
+
out[key] = typeof before === "object" && before !== null ? orderLike(value, before) : sortTree(value);
|
|
97
|
+
};
|
|
98
|
+
for (const key of had) if (key in tree) take(key);
|
|
99
|
+
for (const key of Object.keys(tree).sort()) if (!(key in previous)) take(key);
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
function serializeCatalog(catalog, nested = false, previous) {
|
|
103
|
+
const tree = nested ? nest(catalog) : catalog;
|
|
104
|
+
return JSON.stringify(previous ? orderLike(tree, previous) : sortTree(tree), null, 2) + "\n";
|
|
82
105
|
}
|
|
83
106
|
function writeCatalog(cfg, locale, catalog) {
|
|
84
107
|
const path = catalogPath(cfg, locale);
|
|
@@ -88,16 +111,14 @@ function writeCatalog(cfg, locale, catalog) {
|
|
|
88
111
|
} catch {
|
|
89
112
|
mkdirSync(cfg.dir, { recursive: true });
|
|
90
113
|
}
|
|
91
|
-
const
|
|
114
|
+
const previous = existing === void 0 ? void 0 : parseTree(existing);
|
|
115
|
+
const serialized = serializeCatalog(catalog, wantsNesting(cfg, locale, existing, previous), previous);
|
|
92
116
|
if (existing === serialized) return serialized;
|
|
93
117
|
writeFileSync(path, serialized);
|
|
94
118
|
return serialized;
|
|
95
119
|
}
|
|
96
|
-
function wantsNesting(cfg, locale, existing) {
|
|
97
|
-
if (existing !== void 0)
|
|
98
|
-
const tree = parseTree(existing);
|
|
99
|
-
return tree !== void 0 && isNested(tree);
|
|
100
|
-
}
|
|
120
|
+
function wantsNesting(cfg, locale, existing, previous) {
|
|
121
|
+
if (existing !== void 0) return previous !== void 0 && isNested(previous);
|
|
101
122
|
if (locale === cfg.sourceLocale) return false;
|
|
102
123
|
return isNested(readTree(cfg, cfg.sourceLocale));
|
|
103
124
|
}
|
|
@@ -740,6 +761,7 @@ function pruneCatalogs(cfg, catalogs, registry) {
|
|
|
740
761
|
}
|
|
741
762
|
//#endregion
|
|
742
763
|
//#region src/validate.ts
|
|
764
|
+
const read = (message) => parse(message, parseIcu);
|
|
743
765
|
const PLURAL_CATEGORIES = /* @__PURE__ */ new Set([
|
|
744
766
|
"zero",
|
|
745
767
|
"one",
|
|
@@ -750,7 +772,7 @@ const PLURAL_CATEGORIES = /* @__PURE__ */ new Set([
|
|
|
750
772
|
const EXACT = /^=\d+$/;
|
|
751
773
|
function shapes(message) {
|
|
752
774
|
const out = /* @__PURE__ */ new Map();
|
|
753
|
-
walk(
|
|
775
|
+
walk(read(message), out);
|
|
754
776
|
return out;
|
|
755
777
|
}
|
|
756
778
|
function walk(nodes, out) {
|
|
@@ -767,7 +789,7 @@ function walk(nodes, out) {
|
|
|
767
789
|
}
|
|
768
790
|
function paramNames(message) {
|
|
769
791
|
const names = /* @__PURE__ */ new Set();
|
|
770
|
-
collect(
|
|
792
|
+
collect(read(message), names);
|
|
771
793
|
return [...names].sort();
|
|
772
794
|
}
|
|
773
795
|
function collect(nodes, out) {
|