lingo.dev 0.82.1 → 0.84.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/build/cli.cjs +245 -94
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +302 -151
- package/build/cli.mjs.map +1 -1
- package/package.json +18 -3
package/build/cli.mjs
CHANGED
|
@@ -994,7 +994,7 @@ var show_default = new Command5().command("show").description("Prints out the cu
|
|
|
994
994
|
import { bucketTypeSchema, localeCodeSchema, resolveOverriddenLocale as resolveOverriddenLocale3 } from "@lingo.dev/_spec";
|
|
995
995
|
import { Command as Command6 } from "interactive-commander";
|
|
996
996
|
import Z3 from "zod";
|
|
997
|
-
import
|
|
997
|
+
import _22 from "lodash";
|
|
998
998
|
import * as path15 from "path";
|
|
999
999
|
import Ora5 from "ora";
|
|
1000
1000
|
|
|
@@ -1202,7 +1202,7 @@ function createTextFileLoader(pathPattern) {
|
|
|
1202
1202
|
const trimmedResult = result.trim();
|
|
1203
1203
|
return trimmedResult;
|
|
1204
1204
|
},
|
|
1205
|
-
async push(locale, data,
|
|
1205
|
+
async push(locale, data, _25, originalLocale) {
|
|
1206
1206
|
const draftPath = pathPattern.replaceAll("[locale]", locale);
|
|
1207
1207
|
const finalPath = path10.resolve(draftPath);
|
|
1208
1208
|
const dirPath = path10.dirname(finalPath);
|
|
@@ -1625,6 +1625,58 @@ ${content}`;
|
|
|
1625
1625
|
});
|
|
1626
1626
|
}
|
|
1627
1627
|
|
|
1628
|
+
// src/cli/loaders/mdx.ts
|
|
1629
|
+
import _9 from "lodash";
|
|
1630
|
+
import { unified } from "unified";
|
|
1631
|
+
import remarkParse from "remark-parse";
|
|
1632
|
+
import remarkMdx from "remark-mdx";
|
|
1633
|
+
import remarkFrontmatter from "remark-frontmatter";
|
|
1634
|
+
import remarkGfm from "remark-gfm";
|
|
1635
|
+
import remarkStringify from "remark-stringify";
|
|
1636
|
+
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
|
|
1637
|
+
import { VFile } from "vfile";
|
|
1638
|
+
var parser = unified().use(remarkParse).use(remarkMdx).use(remarkFrontmatter, ["yaml"]).use(remarkMdxFrontmatter).use(remarkGfm);
|
|
1639
|
+
var serializer = unified().use(remarkStringify).use(remarkMdx).use(remarkFrontmatter, ["yaml"]).use(remarkMdxFrontmatter).use(remarkGfm);
|
|
1640
|
+
function createMdxFormatLoader() {
|
|
1641
|
+
return createLoader({
|
|
1642
|
+
async pull(locale, input2) {
|
|
1643
|
+
const file = new VFile(input2);
|
|
1644
|
+
const ast = parser.parse(file);
|
|
1645
|
+
return JSON.parse(JSON.stringify(ast));
|
|
1646
|
+
},
|
|
1647
|
+
async push(locale, data) {
|
|
1648
|
+
const ast = data;
|
|
1649
|
+
const content = String(serializer.stringify(ast));
|
|
1650
|
+
return content;
|
|
1651
|
+
}
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
function createDoubleSerializationLoader() {
|
|
1655
|
+
return createLoader({
|
|
1656
|
+
async pull(locale, input2) {
|
|
1657
|
+
return input2;
|
|
1658
|
+
},
|
|
1659
|
+
async push(locale, data) {
|
|
1660
|
+
const file = new VFile(data);
|
|
1661
|
+
const ast = parser.parse(file);
|
|
1662
|
+
const finalContent = String(serializer.stringify(ast));
|
|
1663
|
+
return finalContent;
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
function createMdxStructureLoader() {
|
|
1668
|
+
return createLoader({
|
|
1669
|
+
async pull(locale, input2) {
|
|
1670
|
+
const result = _9.chain(input2).pickBy((value, key) => key.endsWith("/value")).value();
|
|
1671
|
+
return result;
|
|
1672
|
+
},
|
|
1673
|
+
async push(locale, data, originalInput) {
|
|
1674
|
+
const result = _9.merge({}, originalInput, data);
|
|
1675
|
+
return result;
|
|
1676
|
+
}
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1628
1680
|
// src/cli/loaders/properties.ts
|
|
1629
1681
|
function createPropertiesLoader() {
|
|
1630
1682
|
return createLoader({
|
|
@@ -1644,7 +1696,7 @@ function createPropertiesLoader() {
|
|
|
1644
1696
|
return result;
|
|
1645
1697
|
},
|
|
1646
1698
|
async push(locale, payload) {
|
|
1647
|
-
const result = Object.entries(payload).filter(([
|
|
1699
|
+
const result = Object.entries(payload).filter(([_25, value]) => value != null).map(([key, value]) => `${key}=${value}`).join("\n");
|
|
1648
1700
|
return result;
|
|
1649
1701
|
}
|
|
1650
1702
|
});
|
|
@@ -1730,7 +1782,7 @@ function createXcodeStringsdictLoader() {
|
|
|
1730
1782
|
}
|
|
1731
1783
|
|
|
1732
1784
|
// src/cli/loaders/xcode-xcstrings.ts
|
|
1733
|
-
import
|
|
1785
|
+
import _10 from "lodash";
|
|
1734
1786
|
function createXcodeXcstringsLoader(defaultLocale) {
|
|
1735
1787
|
return createLoader({
|
|
1736
1788
|
async pull(locale, input2, initCtx) {
|
|
@@ -1766,7 +1818,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
1766
1818
|
async push(locale, payload, originalInput) {
|
|
1767
1819
|
const langDataToMerge = {};
|
|
1768
1820
|
langDataToMerge.strings = {};
|
|
1769
|
-
const input2 =
|
|
1821
|
+
const input2 = _10.cloneDeep(originalInput) || { sourceLanguage: locale, strings: {} };
|
|
1770
1822
|
for (const [key, value] of Object.entries(payload)) {
|
|
1771
1823
|
if (value === null || value === void 0) {
|
|
1772
1824
|
continue;
|
|
@@ -1812,7 +1864,7 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
1812
1864
|
}
|
|
1813
1865
|
}
|
|
1814
1866
|
}
|
|
1815
|
-
const result =
|
|
1867
|
+
const result = _10.merge({}, originalInput, langDataToMerge);
|
|
1816
1868
|
return result;
|
|
1817
1869
|
}
|
|
1818
1870
|
});
|
|
@@ -1872,17 +1924,17 @@ async function loadPrettierConfig(filePath) {
|
|
|
1872
1924
|
}
|
|
1873
1925
|
|
|
1874
1926
|
// src/cli/loaders/unlocalizable.ts
|
|
1875
|
-
import
|
|
1927
|
+
import _11 from "lodash";
|
|
1876
1928
|
import _isUrl from "is-url";
|
|
1877
1929
|
import { isValid, parseISO } from "date-fns";
|
|
1878
1930
|
function createUnlocalizableLoader(isCacheRestore = false, returnUnlocalizedKeys = false) {
|
|
1879
1931
|
const rules = {
|
|
1880
|
-
isEmpty: (v) =>
|
|
1932
|
+
isEmpty: (v) => _11.isEmpty(v),
|
|
1881
1933
|
isNumber: (v) => typeof v === "number" || /^[0-9]+$/.test(v),
|
|
1882
|
-
isBoolean: (v) =>
|
|
1883
|
-
isIsoDate: (v) =>
|
|
1884
|
-
isSystemId: (v) =>
|
|
1885
|
-
isUrl: (v) =>
|
|
1934
|
+
isBoolean: (v) => _11.isBoolean(v),
|
|
1935
|
+
isIsoDate: (v) => _11.isString(v) && _isIsoDate(v),
|
|
1936
|
+
isSystemId: (v) => _11.isString(v) && _isSystemId(v),
|
|
1937
|
+
isUrl: (v) => _11.isString(v) && _isUrl(v)
|
|
1886
1938
|
};
|
|
1887
1939
|
return createLoader({
|
|
1888
1940
|
async pull(locale, input2) {
|
|
@@ -1893,18 +1945,18 @@ function createUnlocalizableLoader(isCacheRestore = false, returnUnlocalizedKeys
|
|
|
1893
1945
|
}
|
|
1894
1946
|
}
|
|
1895
1947
|
return false;
|
|
1896
|
-
}).map(([key,
|
|
1897
|
-
const result =
|
|
1948
|
+
}).map(([key, _25]) => key);
|
|
1949
|
+
const result = _11.omitBy(input2, (_25, key) => passthroughKeys.includes(key));
|
|
1898
1950
|
if (returnUnlocalizedKeys) {
|
|
1899
|
-
result.unlocalizable =
|
|
1951
|
+
result.unlocalizable = _11.omitBy(input2, (_25, key) => !passthroughKeys.includes(key));
|
|
1900
1952
|
}
|
|
1901
1953
|
return result;
|
|
1902
1954
|
},
|
|
1903
1955
|
async push(locale, data, originalInput) {
|
|
1904
1956
|
if (isCacheRestore) {
|
|
1905
|
-
return
|
|
1957
|
+
return _11.merge({}, data);
|
|
1906
1958
|
}
|
|
1907
|
-
const result =
|
|
1959
|
+
const result = _11.merge({}, originalInput, data);
|
|
1908
1960
|
return result;
|
|
1909
1961
|
}
|
|
1910
1962
|
});
|
|
@@ -1917,7 +1969,7 @@ function _isIsoDate(v) {
|
|
|
1917
1969
|
}
|
|
1918
1970
|
|
|
1919
1971
|
// src/cli/loaders/po/index.ts
|
|
1920
|
-
import
|
|
1972
|
+
import _12 from "lodash";
|
|
1921
1973
|
import gettextParser from "gettext-parser";
|
|
1922
1974
|
function createPoLoader(params = { multiline: false }) {
|
|
1923
1975
|
return composeLoaders(createPoDataLoader(params), createPoContentLoader());
|
|
@@ -1930,7 +1982,7 @@ function createPoDataLoader(params) {
|
|
|
1930
1982
|
const sections = input2.split("\n\n").filter(Boolean);
|
|
1931
1983
|
for (const section of sections) {
|
|
1932
1984
|
const sectionPo = gettextParser.po.parse(section);
|
|
1933
|
-
const contextKey =
|
|
1985
|
+
const contextKey = _12.keys(sectionPo.translations)[0];
|
|
1934
1986
|
const entries = sectionPo.translations[contextKey];
|
|
1935
1987
|
Object.entries(entries).forEach(([msgid, entry]) => {
|
|
1936
1988
|
if (msgid && entry.msgid) {
|
|
@@ -1948,12 +2000,12 @@ function createPoDataLoader(params) {
|
|
|
1948
2000
|
const sections = originalInput?.split("\n\n").filter(Boolean) || [];
|
|
1949
2001
|
const result = sections.map((section) => {
|
|
1950
2002
|
const sectionPo = gettextParser.po.parse(section);
|
|
1951
|
-
const contextKey =
|
|
2003
|
+
const contextKey = _12.keys(sectionPo.translations)[0];
|
|
1952
2004
|
const entries = sectionPo.translations[contextKey];
|
|
1953
2005
|
const msgid = Object.keys(entries).find((key) => entries[key].msgid);
|
|
1954
2006
|
if (!msgid) return section;
|
|
1955
2007
|
if (data[msgid]) {
|
|
1956
|
-
const updatedPo =
|
|
2008
|
+
const updatedPo = _12.merge({}, sectionPo, {
|
|
1957
2009
|
translations: {
|
|
1958
2010
|
[contextKey]: {
|
|
1959
2011
|
[msgid]: {
|
|
@@ -1973,7 +2025,7 @@ function createPoDataLoader(params) {
|
|
|
1973
2025
|
function createPoContentLoader() {
|
|
1974
2026
|
return createLoader({
|
|
1975
2027
|
async pull(locale, input2) {
|
|
1976
|
-
const result =
|
|
2028
|
+
const result = _12.chain(input2).entries().filter(([, entry]) => !!entry.msgid).map(([, entry]) => [
|
|
1977
2029
|
entry.msgid,
|
|
1978
2030
|
{
|
|
1979
2031
|
singular: entry.msgstr[0] || entry.msgid,
|
|
@@ -1983,7 +2035,7 @@ function createPoContentLoader() {
|
|
|
1983
2035
|
return result;
|
|
1984
2036
|
},
|
|
1985
2037
|
async push(locale, data, originalInput) {
|
|
1986
|
-
const result =
|
|
2038
|
+
const result = _12.chain(originalInput).entries().map(([, entry]) => [
|
|
1987
2039
|
entry.msgid,
|
|
1988
2040
|
{
|
|
1989
2041
|
...entry,
|
|
@@ -2053,10 +2105,10 @@ function createXmlLoader() {
|
|
|
2053
2105
|
// src/cli/loaders/srt.ts
|
|
2054
2106
|
import srtParser from "srt-parser-2";
|
|
2055
2107
|
function createSrtLoader() {
|
|
2056
|
-
const
|
|
2108
|
+
const parser2 = new srtParser();
|
|
2057
2109
|
return createLoader({
|
|
2058
2110
|
async pull(locale, input2) {
|
|
2059
|
-
const parsed =
|
|
2111
|
+
const parsed = parser2.fromSrt(input2) || [];
|
|
2060
2112
|
const result = {};
|
|
2061
2113
|
parsed.forEach((entry) => {
|
|
2062
2114
|
const key = `${entry.id}#${entry.startTime}-${entry.endTime}`;
|
|
@@ -2077,7 +2129,7 @@ function createSrtLoader() {
|
|
|
2077
2129
|
text
|
|
2078
2130
|
};
|
|
2079
2131
|
});
|
|
2080
|
-
const srtContent =
|
|
2132
|
+
const srtContent = parser2.toSrt(output).trim().replace(/\r?\n/g, "\n");
|
|
2081
2133
|
return srtContent;
|
|
2082
2134
|
}
|
|
2083
2135
|
});
|
|
@@ -2106,34 +2158,34 @@ var datoSettingsSchema = Z2.object({
|
|
|
2106
2158
|
});
|
|
2107
2159
|
|
|
2108
2160
|
// src/cli/loaders/dato/filter.ts
|
|
2109
|
-
import
|
|
2161
|
+
import _13 from "lodash";
|
|
2110
2162
|
function createDatoFilterLoader() {
|
|
2111
2163
|
return createLoader({
|
|
2112
2164
|
async pull(locale, input2) {
|
|
2113
2165
|
const result = {};
|
|
2114
|
-
for (const [modelId, modelInfo] of
|
|
2166
|
+
for (const [modelId, modelInfo] of _13.entries(input2)) {
|
|
2115
2167
|
result[modelId] = {};
|
|
2116
2168
|
for (const record of modelInfo.records) {
|
|
2117
|
-
result[modelId][record.id] =
|
|
2169
|
+
result[modelId][record.id] = _13.chain(modelInfo.fields).mapKeys((field) => field.api_key).mapValues((field) => _13.get(record, [field.api_key, locale])).value();
|
|
2118
2170
|
}
|
|
2119
2171
|
}
|
|
2120
2172
|
return result;
|
|
2121
2173
|
},
|
|
2122
2174
|
async push(locale, data, originalInput, originalLocale) {
|
|
2123
|
-
const result =
|
|
2124
|
-
for (const [modelId, modelInfo] of
|
|
2175
|
+
const result = _13.cloneDeep(originalInput || {});
|
|
2176
|
+
for (const [modelId, modelInfo] of _13.entries(result)) {
|
|
2125
2177
|
for (const record of modelInfo.records) {
|
|
2126
|
-
for (const [fieldId, fieldValue] of
|
|
2178
|
+
for (const [fieldId, fieldValue] of _13.entries(record)) {
|
|
2127
2179
|
const fieldInfo = modelInfo.fields.find((field) => field.api_key === fieldId);
|
|
2128
2180
|
if (fieldInfo) {
|
|
2129
|
-
const sourceFieldValue =
|
|
2130
|
-
const targetFieldValue =
|
|
2181
|
+
const sourceFieldValue = _13.get(fieldValue, [originalLocale]);
|
|
2182
|
+
const targetFieldValue = _13.get(data, [modelId, record.id, fieldId]);
|
|
2131
2183
|
if (targetFieldValue) {
|
|
2132
|
-
|
|
2184
|
+
_13.set(record, [fieldId, locale], targetFieldValue);
|
|
2133
2185
|
} else {
|
|
2134
|
-
|
|
2186
|
+
_13.set(record, [fieldId, locale], sourceFieldValue);
|
|
2135
2187
|
}
|
|
2136
|
-
|
|
2188
|
+
_13.chain(fieldValue).keys().reject((loc) => loc === locale || loc === originalLocale).filter((loc) => _13.isEmpty(_13.get(fieldValue, [loc]))).forEach((loc) => _13.set(record, [fieldId, loc], sourceFieldValue)).value();
|
|
2137
2189
|
}
|
|
2138
2190
|
}
|
|
2139
2191
|
}
|
|
@@ -2144,10 +2196,10 @@ function createDatoFilterLoader() {
|
|
|
2144
2196
|
}
|
|
2145
2197
|
|
|
2146
2198
|
// src/cli/loaders/dato/api.ts
|
|
2147
|
-
import
|
|
2199
|
+
import _15 from "lodash";
|
|
2148
2200
|
|
|
2149
2201
|
// src/cli/loaders/dato/_utils.ts
|
|
2150
|
-
import
|
|
2202
|
+
import _14 from "lodash";
|
|
2151
2203
|
import { buildClient } from "@datocms/cma-client-node";
|
|
2152
2204
|
function createDatoClient(params) {
|
|
2153
2205
|
if (!params.apiKey) {
|
|
@@ -2322,7 +2374,7 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
2322
2374
|
const result = {
|
|
2323
2375
|
models: {}
|
|
2324
2376
|
};
|
|
2325
|
-
const updatedConfig =
|
|
2377
|
+
const updatedConfig = _15.cloneDeep(config);
|
|
2326
2378
|
console.log(`Initializing DatoCMS loader...`);
|
|
2327
2379
|
const project = await dato.findProject();
|
|
2328
2380
|
const modelChoices = await getModelChoices(dato, config);
|
|
@@ -2340,7 +2392,7 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
2340
2392
|
delete updatedConfig.models[modelId];
|
|
2341
2393
|
}
|
|
2342
2394
|
}
|
|
2343
|
-
for (const modelId of
|
|
2395
|
+
for (const modelId of _15.keys(updatedConfig.models)) {
|
|
2344
2396
|
const { modelName, fields } = await getModelFields(dato, modelId);
|
|
2345
2397
|
if (fields.length > 0) {
|
|
2346
2398
|
result.models[modelId] = { fields: [], records: [] };
|
|
@@ -2351,7 +2403,7 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
2351
2403
|
const isLocalized = await updateFieldLocalization(dato, fieldInfo, selectedFields.includes(fieldInfo.id));
|
|
2352
2404
|
if (isLocalized) {
|
|
2353
2405
|
result.models[modelId].fields.push(fieldInfo);
|
|
2354
|
-
updatedConfig.models[modelId].fields =
|
|
2406
|
+
updatedConfig.models[modelId].fields = _15.uniq([
|
|
2355
2407
|
...updatedConfig.models[modelId].fields || [],
|
|
2356
2408
|
fieldInfo.api_key
|
|
2357
2409
|
]);
|
|
@@ -2370,7 +2422,7 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
2370
2422
|
},
|
|
2371
2423
|
async pull(locale, input2, initCtx) {
|
|
2372
2424
|
const result = {};
|
|
2373
|
-
for (const modelId of
|
|
2425
|
+
for (const modelId of _15.keys(initCtx?.models || {})) {
|
|
2374
2426
|
let records = initCtx?.models[modelId].records || [];
|
|
2375
2427
|
const recordIds = records.map((record) => record.id);
|
|
2376
2428
|
records = await dato.findRecords(recordIds);
|
|
@@ -2385,7 +2437,7 @@ function createDatoApiLoader(config, onConfigUpdate) {
|
|
|
2385
2437
|
return result;
|
|
2386
2438
|
},
|
|
2387
2439
|
async push(locale, data, originalInput) {
|
|
2388
|
-
for (const modelId of
|
|
2440
|
+
for (const modelId of _15.keys(data)) {
|
|
2389
2441
|
for (let i = 0; i < data[modelId].records.length; i++) {
|
|
2390
2442
|
const record = data[modelId].records[i];
|
|
2391
2443
|
console.log(`Updating record ${i + 1}/${data[modelId].records.length} for model ${modelId}...`);
|
|
@@ -2399,7 +2451,7 @@ async function getModelFields(dato, modelId) {
|
|
|
2399
2451
|
const modelInfo = await dato.findModel(modelId);
|
|
2400
2452
|
return {
|
|
2401
2453
|
modelName: modelInfo.name,
|
|
2402
|
-
fields:
|
|
2454
|
+
fields: _15.filter(modelInfo.fields, (field) => field.type === "field")
|
|
2403
2455
|
};
|
|
2404
2456
|
}
|
|
2405
2457
|
async function getFieldDetails(dato, fields) {
|
|
@@ -2477,17 +2529,17 @@ async function promptModelSelection(choices) {
|
|
|
2477
2529
|
}
|
|
2478
2530
|
|
|
2479
2531
|
// src/cli/loaders/dato/extract.ts
|
|
2480
|
-
import
|
|
2532
|
+
import _16 from "lodash";
|
|
2481
2533
|
function createDatoExtractLoader() {
|
|
2482
2534
|
return createLoader({
|
|
2483
2535
|
async pull(locale, input2) {
|
|
2484
2536
|
const result = {};
|
|
2485
|
-
for (const [modelId, modelInfo] of
|
|
2486
|
-
for (const [recordId, record] of
|
|
2487
|
-
for (const [fieldName, fieldValue] of
|
|
2537
|
+
for (const [modelId, modelInfo] of _16.entries(input2)) {
|
|
2538
|
+
for (const [recordId, record] of _16.entries(modelInfo)) {
|
|
2539
|
+
for (const [fieldName, fieldValue] of _16.entries(record)) {
|
|
2488
2540
|
const parsedValue = createParsedDatoValue(fieldValue);
|
|
2489
2541
|
if (parsedValue) {
|
|
2490
|
-
|
|
2542
|
+
_16.set(result, [modelId, `_${recordId}`, fieldName], parsedValue);
|
|
2491
2543
|
}
|
|
2492
2544
|
}
|
|
2493
2545
|
}
|
|
@@ -2495,14 +2547,14 @@ function createDatoExtractLoader() {
|
|
|
2495
2547
|
return result;
|
|
2496
2548
|
},
|
|
2497
2549
|
async push(locale, data, originalInput) {
|
|
2498
|
-
const result =
|
|
2499
|
-
for (const [modelId, modelInfo] of
|
|
2500
|
-
for (const [virtualRecordId, record] of
|
|
2501
|
-
for (const [fieldName, fieldValue] of
|
|
2550
|
+
const result = _16.cloneDeep(originalInput || {});
|
|
2551
|
+
for (const [modelId, modelInfo] of _16.entries(data)) {
|
|
2552
|
+
for (const [virtualRecordId, record] of _16.entries(modelInfo)) {
|
|
2553
|
+
for (const [fieldName, fieldValue] of _16.entries(record)) {
|
|
2502
2554
|
const [, recordId] = virtualRecordId.split("_");
|
|
2503
|
-
const originalFieldValue =
|
|
2555
|
+
const originalFieldValue = _16.get(originalInput, [modelId, recordId, fieldName]);
|
|
2504
2556
|
const rawValue = createRawDatoValue(fieldValue, originalFieldValue, true);
|
|
2505
|
-
|
|
2557
|
+
_16.set(result, [modelId, recordId, fieldName], rawValue || originalFieldValue);
|
|
2506
2558
|
}
|
|
2507
2559
|
}
|
|
2508
2560
|
}
|
|
@@ -2511,25 +2563,25 @@ function createDatoExtractLoader() {
|
|
|
2511
2563
|
});
|
|
2512
2564
|
}
|
|
2513
2565
|
function detectDatoFieldType(rawDatoValue) {
|
|
2514
|
-
if (
|
|
2566
|
+
if (_16.has(rawDatoValue, "document") && _16.get(rawDatoValue, "schema") === "dast") {
|
|
2515
2567
|
return "structured_text";
|
|
2516
|
-
} else if (
|
|
2568
|
+
} else if (_16.has(rawDatoValue, "no_index") || _16.has(rawDatoValue, "twitter_card")) {
|
|
2517
2569
|
return "seo";
|
|
2518
|
-
} else if (
|
|
2570
|
+
} else if (_16.get(rawDatoValue, "type") === "item") {
|
|
2519
2571
|
return "single_block";
|
|
2520
|
-
} else if (
|
|
2572
|
+
} else if (_16.isArray(rawDatoValue) && _16.every(rawDatoValue, (item) => _16.get(item, "type") === "item")) {
|
|
2521
2573
|
return "rich_text";
|
|
2522
2574
|
} else if (_isFile(rawDatoValue)) {
|
|
2523
2575
|
return "file";
|
|
2524
|
-
} else if (
|
|
2576
|
+
} else if (_16.isArray(rawDatoValue) && _16.every(rawDatoValue, (item) => _isFile(item))) {
|
|
2525
2577
|
return "gallery";
|
|
2526
2578
|
} else if (_isJson(rawDatoValue)) {
|
|
2527
2579
|
return "json";
|
|
2528
|
-
} else if (
|
|
2580
|
+
} else if (_16.isString(rawDatoValue)) {
|
|
2529
2581
|
return "string";
|
|
2530
2582
|
} else if (_isVideo(rawDatoValue)) {
|
|
2531
2583
|
return "video";
|
|
2532
|
-
} else if (
|
|
2584
|
+
} else if (_16.isArray(rawDatoValue) && _16.every(rawDatoValue, (item) => _16.isString(item))) {
|
|
2533
2585
|
return "ref_list";
|
|
2534
2586
|
} else {
|
|
2535
2587
|
return null;
|
|
@@ -2591,9 +2643,9 @@ function serializeStructuredText(rawStructuredText) {
|
|
|
2591
2643
|
if ("document" in node) {
|
|
2592
2644
|
return serializeStructuredTextNode(node.document, [...path18, "document"], acc);
|
|
2593
2645
|
}
|
|
2594
|
-
if (!
|
|
2646
|
+
if (!_16.isNil(node.value)) {
|
|
2595
2647
|
acc[[...path18, "value"].join(".")] = node.value;
|
|
2596
|
-
} else if (
|
|
2648
|
+
} else if (_16.get(node, "type") === "block") {
|
|
2597
2649
|
acc[[...path18, "item"].join(".")] = serializeBlock(node.item);
|
|
2598
2650
|
}
|
|
2599
2651
|
if (node.children) {
|
|
@@ -2605,44 +2657,44 @@ function serializeStructuredText(rawStructuredText) {
|
|
|
2605
2657
|
}
|
|
2606
2658
|
}
|
|
2607
2659
|
function serializeSeo(rawSeo) {
|
|
2608
|
-
return
|
|
2660
|
+
return _16.chain(rawSeo).pick(["title", "description"]).value();
|
|
2609
2661
|
}
|
|
2610
2662
|
function serializeBlock(rawBlock) {
|
|
2611
|
-
if (
|
|
2663
|
+
if (_16.get(rawBlock, "type") === "item" && _16.has(rawBlock, "id")) {
|
|
2612
2664
|
return serializeBlock(rawBlock.attributes);
|
|
2613
2665
|
}
|
|
2614
2666
|
const result = {};
|
|
2615
|
-
for (const [attributeName, attributeValue] of
|
|
2667
|
+
for (const [attributeName, attributeValue] of _16.entries(rawBlock)) {
|
|
2616
2668
|
result[attributeName] = createParsedDatoValue(attributeValue);
|
|
2617
2669
|
}
|
|
2618
2670
|
return result;
|
|
2619
2671
|
}
|
|
2620
2672
|
function serializeBlockList(rawBlockList) {
|
|
2621
|
-
return
|
|
2673
|
+
return _16.chain(rawBlockList).map((block) => serializeBlock(block)).value();
|
|
2622
2674
|
}
|
|
2623
2675
|
function serializeVideo(rawVideo) {
|
|
2624
|
-
return
|
|
2676
|
+
return _16.chain(rawVideo).pick(["title"]).value();
|
|
2625
2677
|
}
|
|
2626
2678
|
function serializeFile(rawFile) {
|
|
2627
|
-
return
|
|
2679
|
+
return _16.chain(rawFile).pick(["alt", "title"]).value();
|
|
2628
2680
|
}
|
|
2629
2681
|
function serializeGallery(rawGallery) {
|
|
2630
|
-
return
|
|
2682
|
+
return _16.chain(rawGallery).map((item) => serializeFile(item)).value();
|
|
2631
2683
|
}
|
|
2632
2684
|
function deserializeFile(parsedFile, originalRawFile) {
|
|
2633
|
-
return
|
|
2685
|
+
return _16.chain(parsedFile).defaults(originalRawFile).value();
|
|
2634
2686
|
}
|
|
2635
2687
|
function deserializeGallery(parsedGallery, originalRawGallery) {
|
|
2636
|
-
return
|
|
2688
|
+
return _16.chain(parsedGallery).map((item, i) => deserializeFile(item, originalRawGallery[i])).value();
|
|
2637
2689
|
}
|
|
2638
2690
|
function deserializeVideo(parsedVideo, originalRawVideo) {
|
|
2639
|
-
return
|
|
2691
|
+
return _16.chain(parsedVideo).defaults(originalRawVideo).value();
|
|
2640
2692
|
}
|
|
2641
2693
|
function deserializeBlock(payload, rawNode, isClean = false) {
|
|
2642
|
-
const result =
|
|
2643
|
-
for (const [attributeName, attributeValue] of
|
|
2694
|
+
const result = _16.cloneDeep(rawNode);
|
|
2695
|
+
for (const [attributeName, attributeValue] of _16.entries(rawNode.attributes)) {
|
|
2644
2696
|
const rawValue = createRawDatoValue(payload[attributeName], attributeValue, isClean);
|
|
2645
|
-
|
|
2697
|
+
_16.set(result, ["attributes", attributeName], rawValue);
|
|
2646
2698
|
}
|
|
2647
2699
|
if (isClean) {
|
|
2648
2700
|
delete result["id"];
|
|
@@ -2650,33 +2702,33 @@ function deserializeBlock(payload, rawNode, isClean = false) {
|
|
|
2650
2702
|
return result;
|
|
2651
2703
|
}
|
|
2652
2704
|
function deserializeSeo(parsedSeo, originalRawSeo) {
|
|
2653
|
-
return
|
|
2705
|
+
return _16.chain(parsedSeo).pick(["title", "description"]).defaults(originalRawSeo).value();
|
|
2654
2706
|
}
|
|
2655
2707
|
function deserializeBlockList(parsedBlockList, originalRawBlockList, isClean = false) {
|
|
2656
|
-
return
|
|
2708
|
+
return _16.chain(parsedBlockList).map((block, i) => deserializeBlock(block, originalRawBlockList[i], isClean)).value();
|
|
2657
2709
|
}
|
|
2658
2710
|
function deserializeStructuredText(parsedStructuredText, originalRawStructuredText) {
|
|
2659
|
-
const result =
|
|
2660
|
-
for (const [path18, value] of
|
|
2661
|
-
const realPath =
|
|
2662
|
-
const deserializedValue = createRawDatoValue(value,
|
|
2663
|
-
|
|
2711
|
+
const result = _16.cloneDeep(originalRawStructuredText);
|
|
2712
|
+
for (const [path18, value] of _16.entries(parsedStructuredText)) {
|
|
2713
|
+
const realPath = _16.chain(path18.split(".")).flatMap((s) => !_16.isNaN(_16.toNumber(s)) ? ["children", s] : s).value();
|
|
2714
|
+
const deserializedValue = createRawDatoValue(value, _16.get(originalRawStructuredText, realPath), true);
|
|
2715
|
+
_16.set(result, realPath, deserializedValue);
|
|
2664
2716
|
}
|
|
2665
2717
|
return result;
|
|
2666
2718
|
}
|
|
2667
2719
|
function _isJson(rawDatoValue) {
|
|
2668
2720
|
try {
|
|
2669
|
-
return
|
|
2721
|
+
return _16.isString(rawDatoValue) && rawDatoValue.startsWith("{") && rawDatoValue.endsWith("}") && !!JSON.parse(rawDatoValue);
|
|
2670
2722
|
} catch (e) {
|
|
2671
2723
|
return false;
|
|
2672
2724
|
}
|
|
2673
2725
|
}
|
|
2674
2726
|
function _isFile(rawDatoValue) {
|
|
2675
|
-
return
|
|
2727
|
+
return _16.isObject(rawDatoValue) && ["alt", "title", "custom_data", "focal_point", "upload_id"].every((key) => _16.has(rawDatoValue, key));
|
|
2676
2728
|
}
|
|
2677
2729
|
function _isVideo(rawDatoValue) {
|
|
2678
|
-
return
|
|
2679
|
-
(key) =>
|
|
2730
|
+
return _16.isObject(rawDatoValue) && ["url", "title", "width", "height", "provider", "provider_uid", "thumbnail_url"].every(
|
|
2731
|
+
(key) => _16.has(rawDatoValue, key)
|
|
2680
2732
|
);
|
|
2681
2733
|
}
|
|
2682
2734
|
|
|
@@ -2737,7 +2789,7 @@ function createVttLoader() {
|
|
|
2737
2789
|
}
|
|
2738
2790
|
|
|
2739
2791
|
// src/cli/loaders/variable/index.ts
|
|
2740
|
-
import
|
|
2792
|
+
import _17 from "lodash";
|
|
2741
2793
|
function createVariableLoader(params) {
|
|
2742
2794
|
return composeLoaders(variableExtractLoader(params), variableContentLoader());
|
|
2743
2795
|
}
|
|
@@ -2746,7 +2798,7 @@ function variableExtractLoader(params) {
|
|
|
2746
2798
|
return createLoader({
|
|
2747
2799
|
pull: async (locale, input2) => {
|
|
2748
2800
|
const result = {};
|
|
2749
|
-
const inputValues =
|
|
2801
|
+
const inputValues = _17.omitBy(input2, _17.isEmpty);
|
|
2750
2802
|
for (const [key, value] of Object.entries(inputValues)) {
|
|
2751
2803
|
const matches = value.match(specifierPattern) || [];
|
|
2752
2804
|
result[key] = result[key] || {
|
|
@@ -2781,11 +2833,11 @@ function variableExtractLoader(params) {
|
|
|
2781
2833
|
function variableContentLoader() {
|
|
2782
2834
|
return createLoader({
|
|
2783
2835
|
pull: async (locale, input2) => {
|
|
2784
|
-
const result =
|
|
2836
|
+
const result = _17.mapValues(input2, (payload) => payload.value);
|
|
2785
2837
|
return result;
|
|
2786
2838
|
},
|
|
2787
2839
|
push: async (locale, data, originalInput) => {
|
|
2788
|
-
const result =
|
|
2840
|
+
const result = _17.cloneDeep(originalInput || {});
|
|
2789
2841
|
for (const [key, originalValueObj] of Object.entries(result)) {
|
|
2790
2842
|
result[key] = {
|
|
2791
2843
|
...originalValueObj,
|
|
@@ -2808,20 +2860,20 @@ function getFormatSpecifierPattern(type) {
|
|
|
2808
2860
|
}
|
|
2809
2861
|
|
|
2810
2862
|
// src/cli/loaders/sync.ts
|
|
2811
|
-
import
|
|
2863
|
+
import _18 from "lodash";
|
|
2812
2864
|
function createSyncLoader() {
|
|
2813
2865
|
return createLoader({
|
|
2814
2866
|
async pull(locale, input2, originalInput) {
|
|
2815
2867
|
if (!originalInput) {
|
|
2816
2868
|
return input2;
|
|
2817
2869
|
}
|
|
2818
|
-
return
|
|
2870
|
+
return _18.chain(originalInput).mapValues((value, key) => input2[key]).value();
|
|
2819
2871
|
},
|
|
2820
2872
|
async push(locale, data, originalInput) {
|
|
2821
2873
|
if (!originalInput) {
|
|
2822
2874
|
return data;
|
|
2823
2875
|
}
|
|
2824
|
-
return
|
|
2876
|
+
return _18.chain(originalInput || {}).mapValues((value, key) => data[key]).value();
|
|
2825
2877
|
}
|
|
2826
2878
|
});
|
|
2827
2879
|
}
|
|
@@ -2981,7 +3033,7 @@ function parseVueFile(input2) {
|
|
|
2981
3033
|
}
|
|
2982
3034
|
|
|
2983
3035
|
// src/cli/loaders/inject-locale.ts
|
|
2984
|
-
import
|
|
3036
|
+
import _19 from "lodash";
|
|
2985
3037
|
function createInjectLocaleLoader(injectLocaleKeys) {
|
|
2986
3038
|
return createLoader({
|
|
2987
3039
|
async pull(locale, data) {
|
|
@@ -2989,19 +3041,19 @@ function createInjectLocaleLoader(injectLocaleKeys) {
|
|
|
2989
3041
|
return data;
|
|
2990
3042
|
}
|
|
2991
3043
|
const omitKeys = injectLocaleKeys.filter((key) => {
|
|
2992
|
-
return
|
|
3044
|
+
return _19.get(data, key) === locale;
|
|
2993
3045
|
});
|
|
2994
|
-
const result =
|
|
3046
|
+
const result = _19.omit(data, omitKeys);
|
|
2995
3047
|
return result;
|
|
2996
3048
|
},
|
|
2997
3049
|
async push(locale, data, originalInput, originalLocale) {
|
|
2998
3050
|
if (!injectLocaleKeys) {
|
|
2999
3051
|
return data;
|
|
3000
3052
|
}
|
|
3001
|
-
const mergedData =
|
|
3053
|
+
const mergedData = _19.merge({}, originalInput, data);
|
|
3002
3054
|
injectLocaleKeys.forEach((key) => {
|
|
3003
|
-
if (
|
|
3004
|
-
|
|
3055
|
+
if (_19.get(mergedData, key) === originalLocale) {
|
|
3056
|
+
_19.set(mergedData, key, locale);
|
|
3005
3057
|
}
|
|
3006
3058
|
});
|
|
3007
3059
|
return mergedData;
|
|
@@ -3010,16 +3062,16 @@ function createInjectLocaleLoader(injectLocaleKeys) {
|
|
|
3010
3062
|
}
|
|
3011
3063
|
|
|
3012
3064
|
// src/cli/loaders/locked-keys.ts
|
|
3013
|
-
import
|
|
3065
|
+
import _20 from "lodash";
|
|
3014
3066
|
function createLockedKeysLoader(lockedKeys, isCacheRestore = false) {
|
|
3015
3067
|
return createLoader({
|
|
3016
|
-
pull: async (locale, data) =>
|
|
3068
|
+
pull: async (locale, data) => _20.chain(data).pickBy((value, key) => !lockedKeys.some((lockedKey) => key.startsWith(lockedKey))).value(),
|
|
3017
3069
|
push: async (locale, data, originalInput) => {
|
|
3018
|
-
const lockedSubObject =
|
|
3070
|
+
const lockedSubObject = _20.chain(originalInput).pickBy((value, key) => lockedKeys.some((lockedKey) => key.startsWith(lockedKey))).value();
|
|
3019
3071
|
if (isCacheRestore) {
|
|
3020
|
-
return
|
|
3072
|
+
return _20.merge({}, data, lockedSubObject);
|
|
3021
3073
|
} else {
|
|
3022
|
-
return
|
|
3074
|
+
return _20.merge({}, originalInput, data, lockedSubObject);
|
|
3023
3075
|
}
|
|
3024
3076
|
}
|
|
3025
3077
|
});
|
|
@@ -3036,7 +3088,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3036
3088
|
createAndroidLoader(),
|
|
3037
3089
|
createFlatLoader(),
|
|
3038
3090
|
createSyncLoader(),
|
|
3039
|
-
createUnlocalizableLoader(
|
|
3091
|
+
createUnlocalizableLoader(
|
|
3092
|
+
options.isCacheRestore,
|
|
3093
|
+
options.returnUnlocalizedKeys
|
|
3094
|
+
)
|
|
3040
3095
|
);
|
|
3041
3096
|
case "csv":
|
|
3042
3097
|
return composeLoaders(
|
|
@@ -3044,7 +3099,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3044
3099
|
createCsvLoader(),
|
|
3045
3100
|
createFlatLoader(),
|
|
3046
3101
|
createSyncLoader(),
|
|
3047
|
-
createUnlocalizableLoader(
|
|
3102
|
+
createUnlocalizableLoader(
|
|
3103
|
+
options.isCacheRestore,
|
|
3104
|
+
options.returnUnlocalizedKeys
|
|
3105
|
+
)
|
|
3048
3106
|
);
|
|
3049
3107
|
case "html":
|
|
3050
3108
|
return composeLoaders(
|
|
@@ -3052,7 +3110,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3052
3110
|
createPrettierLoader({ parser: "html", bucketPathPattern }),
|
|
3053
3111
|
createHtmlLoader(),
|
|
3054
3112
|
createSyncLoader(),
|
|
3055
|
-
createUnlocalizableLoader(
|
|
3113
|
+
createUnlocalizableLoader(
|
|
3114
|
+
options.isCacheRestore,
|
|
3115
|
+
options.returnUnlocalizedKeys
|
|
3116
|
+
)
|
|
3056
3117
|
);
|
|
3057
3118
|
case "json":
|
|
3058
3119
|
return composeLoaders(
|
|
@@ -3063,7 +3124,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3063
3124
|
createFlatLoader(),
|
|
3064
3125
|
createLockedKeysLoader(lockedKeys || [], options.isCacheRestore),
|
|
3065
3126
|
createSyncLoader(),
|
|
3066
|
-
createUnlocalizableLoader(
|
|
3127
|
+
createUnlocalizableLoader(
|
|
3128
|
+
options.isCacheRestore,
|
|
3129
|
+
options.returnUnlocalizedKeys
|
|
3130
|
+
)
|
|
3067
3131
|
);
|
|
3068
3132
|
case "markdown":
|
|
3069
3133
|
return composeLoaders(
|
|
@@ -3071,6 +3135,33 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3071
3135
|
createPrettierLoader({ parser: "markdown", bucketPathPattern }),
|
|
3072
3136
|
createMarkdownLoader(),
|
|
3073
3137
|
createSyncLoader(),
|
|
3138
|
+
createUnlocalizableLoader(
|
|
3139
|
+
options.isCacheRestore,
|
|
3140
|
+
options.returnUnlocalizedKeys
|
|
3141
|
+
)
|
|
3142
|
+
);
|
|
3143
|
+
case "mdx":
|
|
3144
|
+
return composeLoaders(
|
|
3145
|
+
createTextFileLoader(bucketPathPattern),
|
|
3146
|
+
createDoubleSerializationLoader(),
|
|
3147
|
+
createPrettierLoader({ parser: "mdx", bucketPathPattern }),
|
|
3148
|
+
createMdxFormatLoader(),
|
|
3149
|
+
createFlatLoader(),
|
|
3150
|
+
createMdxStructureLoader(),
|
|
3151
|
+
createSyncLoader(),
|
|
3152
|
+
createUnlocalizableLoader(
|
|
3153
|
+
options.isCacheRestore,
|
|
3154
|
+
options.returnUnlocalizedKeys
|
|
3155
|
+
)
|
|
3156
|
+
);
|
|
3157
|
+
case "mdx":
|
|
3158
|
+
return composeLoaders(
|
|
3159
|
+
createTextFileLoader(bucketPathPattern),
|
|
3160
|
+
createPrettierLoader({ parser: "mdx", bucketPathPattern }),
|
|
3161
|
+
createMdxFormatLoader(),
|
|
3162
|
+
createFlatLoader(),
|
|
3163
|
+
createMdxStructureLoader(),
|
|
3164
|
+
createSyncLoader(),
|
|
3074
3165
|
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys)
|
|
3075
3166
|
);
|
|
3076
3167
|
case "po":
|
|
@@ -3080,21 +3171,30 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3080
3171
|
createFlatLoader(),
|
|
3081
3172
|
createSyncLoader(),
|
|
3082
3173
|
createVariableLoader({ type: "python" }),
|
|
3083
|
-
createUnlocalizableLoader(
|
|
3174
|
+
createUnlocalizableLoader(
|
|
3175
|
+
options.isCacheRestore,
|
|
3176
|
+
options.returnUnlocalizedKeys
|
|
3177
|
+
)
|
|
3084
3178
|
);
|
|
3085
3179
|
case "properties":
|
|
3086
3180
|
return composeLoaders(
|
|
3087
3181
|
createTextFileLoader(bucketPathPattern),
|
|
3088
3182
|
createPropertiesLoader(),
|
|
3089
3183
|
createSyncLoader(),
|
|
3090
|
-
createUnlocalizableLoader(
|
|
3184
|
+
createUnlocalizableLoader(
|
|
3185
|
+
options.isCacheRestore,
|
|
3186
|
+
options.returnUnlocalizedKeys
|
|
3187
|
+
)
|
|
3091
3188
|
);
|
|
3092
3189
|
case "xcode-strings":
|
|
3093
3190
|
return composeLoaders(
|
|
3094
3191
|
createTextFileLoader(bucketPathPattern),
|
|
3095
3192
|
createXcodeStringsLoader(),
|
|
3096
3193
|
createSyncLoader(),
|
|
3097
|
-
createUnlocalizableLoader(
|
|
3194
|
+
createUnlocalizableLoader(
|
|
3195
|
+
options.isCacheRestore,
|
|
3196
|
+
options.returnUnlocalizedKeys
|
|
3197
|
+
)
|
|
3098
3198
|
);
|
|
3099
3199
|
case "xcode-stringsdict":
|
|
3100
3200
|
return composeLoaders(
|
|
@@ -3102,7 +3202,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3102
3202
|
createXcodeStringsdictLoader(),
|
|
3103
3203
|
createFlatLoader(),
|
|
3104
3204
|
createSyncLoader(),
|
|
3105
|
-
createUnlocalizableLoader(
|
|
3205
|
+
createUnlocalizableLoader(
|
|
3206
|
+
options.isCacheRestore,
|
|
3207
|
+
options.returnUnlocalizedKeys
|
|
3208
|
+
)
|
|
3106
3209
|
);
|
|
3107
3210
|
case "xcode-xcstrings":
|
|
3108
3211
|
return composeLoaders(
|
|
@@ -3113,7 +3216,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3113
3216
|
createFlatLoader(),
|
|
3114
3217
|
createSyncLoader(),
|
|
3115
3218
|
createVariableLoader({ type: "ieee" }),
|
|
3116
|
-
createUnlocalizableLoader(
|
|
3219
|
+
createUnlocalizableLoader(
|
|
3220
|
+
options.isCacheRestore,
|
|
3221
|
+
options.returnUnlocalizedKeys
|
|
3222
|
+
)
|
|
3117
3223
|
);
|
|
3118
3224
|
case "yaml":
|
|
3119
3225
|
return composeLoaders(
|
|
@@ -3123,7 +3229,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3123
3229
|
createFlatLoader(),
|
|
3124
3230
|
createLockedKeysLoader(lockedKeys || [], options.isCacheRestore),
|
|
3125
3231
|
createSyncLoader(),
|
|
3126
|
-
createUnlocalizableLoader(
|
|
3232
|
+
createUnlocalizableLoader(
|
|
3233
|
+
options.isCacheRestore,
|
|
3234
|
+
options.returnUnlocalizedKeys
|
|
3235
|
+
)
|
|
3127
3236
|
);
|
|
3128
3237
|
case "yaml-root-key":
|
|
3129
3238
|
return composeLoaders(
|
|
@@ -3133,7 +3242,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3133
3242
|
createRootKeyLoader(true),
|
|
3134
3243
|
createFlatLoader(),
|
|
3135
3244
|
createSyncLoader(),
|
|
3136
|
-
createUnlocalizableLoader(
|
|
3245
|
+
createUnlocalizableLoader(
|
|
3246
|
+
options.isCacheRestore,
|
|
3247
|
+
options.returnUnlocalizedKeys
|
|
3248
|
+
)
|
|
3137
3249
|
);
|
|
3138
3250
|
case "flutter":
|
|
3139
3251
|
return composeLoaders(
|
|
@@ -3143,7 +3255,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3143
3255
|
createFlutterLoader(),
|
|
3144
3256
|
createFlatLoader(),
|
|
3145
3257
|
createSyncLoader(),
|
|
3146
|
-
createUnlocalizableLoader(
|
|
3258
|
+
createUnlocalizableLoader(
|
|
3259
|
+
options.isCacheRestore,
|
|
3260
|
+
options.returnUnlocalizedKeys
|
|
3261
|
+
)
|
|
3147
3262
|
);
|
|
3148
3263
|
case "xliff":
|
|
3149
3264
|
return composeLoaders(
|
|
@@ -3151,7 +3266,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3151
3266
|
createXliffLoader(),
|
|
3152
3267
|
createFlatLoader(),
|
|
3153
3268
|
createSyncLoader(),
|
|
3154
|
-
createUnlocalizableLoader(
|
|
3269
|
+
createUnlocalizableLoader(
|
|
3270
|
+
options.isCacheRestore,
|
|
3271
|
+
options.returnUnlocalizedKeys
|
|
3272
|
+
)
|
|
3155
3273
|
);
|
|
3156
3274
|
case "xml":
|
|
3157
3275
|
return composeLoaders(
|
|
@@ -3159,28 +3277,40 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3159
3277
|
createXmlLoader(),
|
|
3160
3278
|
createFlatLoader(),
|
|
3161
3279
|
createSyncLoader(),
|
|
3162
|
-
createUnlocalizableLoader(
|
|
3280
|
+
createUnlocalizableLoader(
|
|
3281
|
+
options.isCacheRestore,
|
|
3282
|
+
options.returnUnlocalizedKeys
|
|
3283
|
+
)
|
|
3163
3284
|
);
|
|
3164
3285
|
case "srt":
|
|
3165
3286
|
return composeLoaders(
|
|
3166
3287
|
createTextFileLoader(bucketPathPattern),
|
|
3167
3288
|
createSrtLoader(),
|
|
3168
3289
|
createSyncLoader(),
|
|
3169
|
-
createUnlocalizableLoader(
|
|
3290
|
+
createUnlocalizableLoader(
|
|
3291
|
+
options.isCacheRestore,
|
|
3292
|
+
options.returnUnlocalizedKeys
|
|
3293
|
+
)
|
|
3170
3294
|
);
|
|
3171
3295
|
case "dato":
|
|
3172
3296
|
return composeLoaders(
|
|
3173
3297
|
createDatoLoader(bucketPathPattern),
|
|
3174
3298
|
createSyncLoader(),
|
|
3175
3299
|
createFlatLoader(),
|
|
3176
|
-
createUnlocalizableLoader(
|
|
3300
|
+
createUnlocalizableLoader(
|
|
3301
|
+
options.isCacheRestore,
|
|
3302
|
+
options.returnUnlocalizedKeys
|
|
3303
|
+
)
|
|
3177
3304
|
);
|
|
3178
3305
|
case "vtt":
|
|
3179
3306
|
return composeLoaders(
|
|
3180
3307
|
createTextFileLoader(bucketPathPattern),
|
|
3181
3308
|
createVttLoader(),
|
|
3182
3309
|
createSyncLoader(),
|
|
3183
|
-
createUnlocalizableLoader(
|
|
3310
|
+
createUnlocalizableLoader(
|
|
3311
|
+
options.isCacheRestore,
|
|
3312
|
+
options.returnUnlocalizedKeys
|
|
3313
|
+
)
|
|
3184
3314
|
);
|
|
3185
3315
|
case "php":
|
|
3186
3316
|
return composeLoaders(
|
|
@@ -3188,7 +3318,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3188
3318
|
createPhpLoader(),
|
|
3189
3319
|
createSyncLoader(),
|
|
3190
3320
|
createFlatLoader(),
|
|
3191
|
-
createUnlocalizableLoader(
|
|
3321
|
+
createUnlocalizableLoader(
|
|
3322
|
+
options.isCacheRestore,
|
|
3323
|
+
options.returnUnlocalizedKeys
|
|
3324
|
+
)
|
|
3192
3325
|
);
|
|
3193
3326
|
case "vue-json":
|
|
3194
3327
|
return composeLoaders(
|
|
@@ -3196,7 +3329,10 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3196
3329
|
createVueJsonLoader(),
|
|
3197
3330
|
createSyncLoader(),
|
|
3198
3331
|
createFlatLoader(),
|
|
3199
|
-
createUnlocalizableLoader(
|
|
3332
|
+
createUnlocalizableLoader(
|
|
3333
|
+
options.isCacheRestore,
|
|
3334
|
+
options.returnUnlocalizedKeys
|
|
3335
|
+
)
|
|
3200
3336
|
);
|
|
3201
3337
|
}
|
|
3202
3338
|
}
|
|
@@ -3439,7 +3575,7 @@ async function trackEvent(distinctId, event, properties) {
|
|
|
3439
3575
|
}
|
|
3440
3576
|
|
|
3441
3577
|
// src/cli/utils/delta.ts
|
|
3442
|
-
import
|
|
3578
|
+
import _21 from "lodash";
|
|
3443
3579
|
import z from "zod";
|
|
3444
3580
|
import { MD5 } from "object-hash";
|
|
3445
3581
|
|
|
@@ -3489,9 +3625,9 @@ function createDeltaProcessor(fileKey) {
|
|
|
3489
3625
|
return checkIfFileExists(lockfilePath);
|
|
3490
3626
|
},
|
|
3491
3627
|
async calculateDelta(params) {
|
|
3492
|
-
let added =
|
|
3493
|
-
let removed =
|
|
3494
|
-
const updated =
|
|
3628
|
+
let added = _21.difference(Object.keys(params.sourceData), Object.keys(params.targetData));
|
|
3629
|
+
let removed = _21.difference(Object.keys(params.targetData), Object.keys(params.sourceData));
|
|
3630
|
+
const updated = _21.filter(Object.keys(params.sourceData), (key) => {
|
|
3495
3631
|
return MD5(params.sourceData[key]) !== params.checksums[key] && params.checksums[key];
|
|
3496
3632
|
});
|
|
3497
3633
|
const renamed = [];
|
|
@@ -3540,7 +3676,7 @@ function createDeltaProcessor(fileKey) {
|
|
|
3540
3676
|
await this.saveLock(lockfileData);
|
|
3541
3677
|
},
|
|
3542
3678
|
async createChecksums(sourceData) {
|
|
3543
|
-
const checksums =
|
|
3679
|
+
const checksums = _21.mapValues(sourceData, (value) => MD5(value));
|
|
3544
3680
|
return checksums;
|
|
3545
3681
|
}
|
|
3546
3682
|
};
|
|
@@ -3770,7 +3906,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
3770
3906
|
const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
|
|
3771
3907
|
const sourceChecksums = await deltaProcessor.createChecksums(sourceData);
|
|
3772
3908
|
const savedChecksums = await deltaProcessor.loadChecksums();
|
|
3773
|
-
const updatedSourceData =
|
|
3909
|
+
const updatedSourceData = _22.pickBy(
|
|
3774
3910
|
sourceData,
|
|
3775
3911
|
(value, key) => sourceChecksums[key] !== savedChecksums[key]
|
|
3776
3912
|
);
|
|
@@ -3781,9 +3917,9 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
3781
3917
|
for (const _targetLocale of targetLocales) {
|
|
3782
3918
|
const targetLocale = resolveOverriddenLocale3(_targetLocale, bucketPath.delimiter);
|
|
3783
3919
|
const { unlocalizable: targetUnlocalizable, ...targetData } = await bucketLoader.pull(targetLocale);
|
|
3784
|
-
const missingKeys =
|
|
3785
|
-
const extraKeys =
|
|
3786
|
-
const unlocalizableDataDiff = !
|
|
3920
|
+
const missingKeys = _22.difference(Object.keys(sourceData), Object.keys(targetData));
|
|
3921
|
+
const extraKeys = _22.difference(Object.keys(targetData), Object.keys(sourceData));
|
|
3922
|
+
const unlocalizableDataDiff = !_22.isEqual(sourceUnlocalizable, targetUnlocalizable);
|
|
3787
3923
|
if (missingKeys.length > 0) {
|
|
3788
3924
|
requiresUpdate = "missing";
|
|
3789
3925
|
break bucketLoop;
|
|
@@ -3846,9 +3982,9 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
3846
3982
|
targetData,
|
|
3847
3983
|
checksums: checksums2
|
|
3848
3984
|
});
|
|
3849
|
-
let processableData =
|
|
3985
|
+
let processableData = _22.chain(sourceData).entries().filter(([key, value]) => delta.added.includes(key) || delta.updated.includes(key) || !!flags.force).fromPairs().value();
|
|
3850
3986
|
if (flags.key) {
|
|
3851
|
-
processableData =
|
|
3987
|
+
processableData = _22.pickBy(processableData, (_25, key) => key === flags.key);
|
|
3852
3988
|
}
|
|
3853
3989
|
if (flags.verbose) {
|
|
3854
3990
|
bucketOra.info(JSON.stringify(processableData, null, 2));
|
|
@@ -3885,7 +4021,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
3885
4021
|
if (flags.verbose) {
|
|
3886
4022
|
bucketOra.info(JSON.stringify(processedTargetData, null, 2));
|
|
3887
4023
|
}
|
|
3888
|
-
let finalTargetData =
|
|
4024
|
+
let finalTargetData = _22.merge({}, sourceData, targetData, processedTargetData);
|
|
3889
4025
|
if (flags.interactive) {
|
|
3890
4026
|
bucketOra.stop();
|
|
3891
4027
|
const reviewedData = await reviewChanges({
|
|
@@ -3899,7 +4035,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
3899
4035
|
finalTargetData = reviewedData;
|
|
3900
4036
|
bucketOra.start(`Applying changes to ${bucketPath} (${targetLocale})`);
|
|
3901
4037
|
}
|
|
3902
|
-
const finalDiffSize =
|
|
4038
|
+
const finalDiffSize = _22.chain(finalTargetData).omitBy((value, key) => value === targetData[key]).size().value();
|
|
3903
4039
|
await bucketLoader.push(targetLocale, finalTargetData);
|
|
3904
4040
|
if (finalDiffSize > 0 || flags.force) {
|
|
3905
4041
|
bucketOra.succeed(`[${sourceLocale} -> ${targetLocale}] Localization completed`);
|
|
@@ -4059,7 +4195,7 @@ Reviewing changes for ${chalk.blue(args.pathPattern)} (${chalk.yellow(args.targe
|
|
|
4059
4195
|
return args.currentData;
|
|
4060
4196
|
}
|
|
4061
4197
|
const customData = { ...args.currentData };
|
|
4062
|
-
const changes =
|
|
4198
|
+
const changes = _22.reduce(
|
|
4063
4199
|
args.proposedData,
|
|
4064
4200
|
(result, value, key) => {
|
|
4065
4201
|
if (args.currentData[key] !== value) {
|
|
@@ -4118,7 +4254,7 @@ import path16 from "path";
|
|
|
4118
4254
|
import Z4 from "zod";
|
|
4119
4255
|
import YAML4 from "yaml";
|
|
4120
4256
|
import { MD5 as MD52 } from "object-hash";
|
|
4121
|
-
import
|
|
4257
|
+
import _23 from "lodash";
|
|
4122
4258
|
function createLockfileHelper() {
|
|
4123
4259
|
return {
|
|
4124
4260
|
isLockfileExists: () => {
|
|
@@ -4128,23 +4264,23 @@ function createLockfileHelper() {
|
|
|
4128
4264
|
registerSourceData: (pathPattern, sourceData) => {
|
|
4129
4265
|
const lockfile = _loadLockfile();
|
|
4130
4266
|
const sectionKey = MD52(pathPattern);
|
|
4131
|
-
const sectionChecksums =
|
|
4267
|
+
const sectionChecksums = _23.mapValues(sourceData, (value) => MD52(value));
|
|
4132
4268
|
lockfile.checksums[sectionKey] = sectionChecksums;
|
|
4133
4269
|
_saveLockfile(lockfile);
|
|
4134
4270
|
},
|
|
4135
4271
|
registerPartialSourceData: (pathPattern, partialSourceData) => {
|
|
4136
4272
|
const lockfile = _loadLockfile();
|
|
4137
4273
|
const sectionKey = MD52(pathPattern);
|
|
4138
|
-
const sectionChecksums =
|
|
4139
|
-
lockfile.checksums[sectionKey] =
|
|
4274
|
+
const sectionChecksums = _23.mapValues(partialSourceData, (value) => MD52(value));
|
|
4275
|
+
lockfile.checksums[sectionKey] = _23.merge({}, lockfile.checksums[sectionKey] ?? {}, sectionChecksums);
|
|
4140
4276
|
_saveLockfile(lockfile);
|
|
4141
4277
|
},
|
|
4142
4278
|
extractUpdatedData: (pathPattern, sourceData) => {
|
|
4143
4279
|
const lockfile = _loadLockfile();
|
|
4144
4280
|
const sectionKey = MD52(pathPattern);
|
|
4145
|
-
const currentChecksums =
|
|
4281
|
+
const currentChecksums = _23.mapValues(sourceData, (value) => MD52(value));
|
|
4146
4282
|
const savedChecksums = lockfile.checksums[sectionKey] || {};
|
|
4147
|
-
const updatedData =
|
|
4283
|
+
const updatedData = _23.pickBy(sourceData, (value, key) => savedChecksums[key] !== currentChecksums[key]);
|
|
4148
4284
|
return updatedData;
|
|
4149
4285
|
}
|
|
4150
4286
|
};
|
|
@@ -4214,7 +4350,7 @@ var flagsSchema = Z5.object({
|
|
|
4214
4350
|
// src/cli/cmd/cleanup.ts
|
|
4215
4351
|
import { resolveOverriddenLocale as resolveOverriddenLocale5 } from "@lingo.dev/_spec";
|
|
4216
4352
|
import { Command as Command8 } from "interactive-commander";
|
|
4217
|
-
import
|
|
4353
|
+
import _24 from "lodash";
|
|
4218
4354
|
import Ora7 from "ora";
|
|
4219
4355
|
var cleanup_default = new Command8().command("cleanup").description("Remove keys from target files that do not exist in the source file").helpOption("-h, --help", "Show help").option("--locale <locale>", "Specific locale to cleanup").option("--bucket <bucket>", "Specific bucket to cleanup").option("--dry-run", "Show what would be removed without making changes").option(
|
|
4220
4356
|
"--verbose",
|
|
@@ -4250,7 +4386,7 @@ var cleanup_default = new Command8().command("cleanup").description("Remove keys
|
|
|
4250
4386
|
try {
|
|
4251
4387
|
const targetData = await bucketLoader.pull(targetLocale);
|
|
4252
4388
|
const targetKeys = Object.keys(targetData);
|
|
4253
|
-
const keysToRemove =
|
|
4389
|
+
const keysToRemove = _24.difference(targetKeys, sourceKeys);
|
|
4254
4390
|
if (keysToRemove.length === 0) {
|
|
4255
4391
|
bucketOra.succeed(`[${targetLocale}] No keys to remove`);
|
|
4256
4392
|
continue;
|
|
@@ -4259,7 +4395,7 @@ var cleanup_default = new Command8().command("cleanup").description("Remove keys
|
|
|
4259
4395
|
bucketOra.info(`[${targetLocale}] Keys to remove: ${JSON.stringify(keysToRemove, null, 2)}`);
|
|
4260
4396
|
}
|
|
4261
4397
|
if (!options.dryRun) {
|
|
4262
|
-
const cleanedData =
|
|
4398
|
+
const cleanedData = _24.pick(targetData, sourceKeys);
|
|
4263
4399
|
await bucketLoader.push(targetLocale, cleanedData);
|
|
4264
4400
|
bucketOra.succeed(`[${targetLocale}] Removed ${keysToRemove.length} keys`);
|
|
4265
4401
|
} else {
|
|
@@ -4314,7 +4450,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
4314
4450
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4315
4451
|
import Z6 from "zod";
|
|
4316
4452
|
import { ReplexicaEngine } from "@lingo.dev/_sdk";
|
|
4317
|
-
var mcp_default = new Command9().command("mcp").description("Use Lingo.dev model context provider with your AI agent").helpOption("-h, --help", "Show help").action(async (
|
|
4453
|
+
var mcp_default = new Command9().command("mcp").description("Use Lingo.dev model context provider with your AI agent").helpOption("-h, --help", "Show help").action(async (_25, program) => {
|
|
4318
4454
|
const apiKey = program.args[0];
|
|
4319
4455
|
const settings = getSettings(apiKey);
|
|
4320
4456
|
if (!settings.auth.apiKey) {
|
|
@@ -4978,7 +5114,7 @@ var ci_default = new Command10().command("ci").description("Run Lingo.dev CI/CD
|
|
|
4978
5114
|
// package.json
|
|
4979
5115
|
var package_default = {
|
|
4980
5116
|
name: "lingo.dev",
|
|
4981
|
-
version: "0.
|
|
5117
|
+
version: "0.84.0",
|
|
4982
5118
|
description: "Lingo.dev CLI",
|
|
4983
5119
|
private: false,
|
|
4984
5120
|
publishConfig: {
|
|
@@ -5044,6 +5180,7 @@ var package_default = {
|
|
|
5044
5180
|
"@lingo.dev/_spec": "workspace:*",
|
|
5045
5181
|
"@modelcontextprotocol/sdk": "^1.5.0",
|
|
5046
5182
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
5183
|
+
"@types/mdast": "^4.0.4",
|
|
5047
5184
|
ai: "^4.3.2",
|
|
5048
5185
|
bitbucket: "^2.12.0",
|
|
5049
5186
|
chalk: "^5.4.1",
|
|
@@ -5073,6 +5210,11 @@ var package_default = {
|
|
|
5073
5210
|
"markdown-it": "^14.1.0",
|
|
5074
5211
|
"markdown-it-front-matter": "^0.2.4",
|
|
5075
5212
|
marked: "^15.0.6",
|
|
5213
|
+
"mdast-util-from-markdown": "^2.0.2",
|
|
5214
|
+
"mdast-util-frontmatter": "^2.0.1",
|
|
5215
|
+
"mdast-util-gfm": "^3.1.0",
|
|
5216
|
+
"mdast-util-mdx": "^3.0.0",
|
|
5217
|
+
"mdast-util-to-markdown": "^2.1.2",
|
|
5076
5218
|
"node-webvtt": "^1.9.4",
|
|
5077
5219
|
"object-hash": "^3.0.0",
|
|
5078
5220
|
octokit: "^4.0.2",
|
|
@@ -5084,9 +5226,18 @@ var package_default = {
|
|
|
5084
5226
|
"posthog-node": "^4.11.2",
|
|
5085
5227
|
prettier: "^3.4.2",
|
|
5086
5228
|
"properties-parser": "^0.6.0",
|
|
5229
|
+
"remark-frontmatter": "^5.0.0",
|
|
5230
|
+
"remark-gfm": "^4.0.1",
|
|
5231
|
+
"remark-mdx": "^3.1.0",
|
|
5232
|
+
"remark-mdx-frontmatter": "^5.1.0",
|
|
5233
|
+
"remark-parse": "^11.0.0",
|
|
5234
|
+
"remark-stringify": "^11.0.0",
|
|
5087
5235
|
slugify: "^1.6.6",
|
|
5088
5236
|
"srt-parser-2": "^1.2.3",
|
|
5089
5237
|
typescript: "^5.7.2",
|
|
5238
|
+
unified: "^11.0.5",
|
|
5239
|
+
"unist-util-visit": "^5.0.0",
|
|
5240
|
+
vfile: "^6.0.3",
|
|
5090
5241
|
vitest: "^2.1.8",
|
|
5091
5242
|
xliff: "^6.2.1",
|
|
5092
5243
|
xml2js: "^0.6.2",
|