lingo.dev 0.87.0 → 0.87.1
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 +221 -550
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +133 -462
- package/build/cli.mjs.map +1 -1
- package/package.json +3 -3
package/build/cli.mjs
CHANGED
|
@@ -621,9 +621,9 @@ function makeGitlabInitializer(spinner) {
|
|
|
621
621
|
|
|
622
622
|
// src/cli/cmd/init.ts
|
|
623
623
|
import open2 from "open";
|
|
624
|
-
var openUrl = (
|
|
624
|
+
var openUrl = (path17) => {
|
|
625
625
|
const settings = getSettings(void 0);
|
|
626
|
-
open2(`${settings.auth.webUrl}${
|
|
626
|
+
open2(`${settings.auth.webUrl}${path17}`, { wait: false });
|
|
627
627
|
};
|
|
628
628
|
var throwHelpError = (option, value) => {
|
|
629
629
|
if (value === "help") {
|
|
@@ -970,8 +970,8 @@ var files_default = new Command4().command("files").description("Print out the l
|
|
|
970
970
|
} else if (type.target) {
|
|
971
971
|
result.push(...targetPaths);
|
|
972
972
|
}
|
|
973
|
-
result.forEach((
|
|
974
|
-
console.log(
|
|
973
|
+
result.forEach((path17) => {
|
|
974
|
+
console.log(path17);
|
|
975
975
|
});
|
|
976
976
|
}
|
|
977
977
|
}
|
|
@@ -998,8 +998,8 @@ import {
|
|
|
998
998
|
} from "@lingo.dev/_spec";
|
|
999
999
|
import { Command as Command6 } from "interactive-commander";
|
|
1000
1000
|
import Z3 from "zod";
|
|
1001
|
-
import
|
|
1002
|
-
import * as
|
|
1001
|
+
import _22 from "lodash";
|
|
1002
|
+
import * as path14 from "path";
|
|
1003
1003
|
import Ora5 from "ora";
|
|
1004
1004
|
|
|
1005
1005
|
// src/cli/loaders/_utils.ts
|
|
@@ -1218,7 +1218,7 @@ function createTextFileLoader(pathPattern) {
|
|
|
1218
1218
|
const trimmedResult = result.trim();
|
|
1219
1219
|
return trimmedResult;
|
|
1220
1220
|
},
|
|
1221
|
-
async push(locale, data,
|
|
1221
|
+
async push(locale, data, _25, originalLocale) {
|
|
1222
1222
|
const draftPath = pathPattern.replaceAll("[locale]", locale);
|
|
1223
1223
|
const finalPath = path10.resolve(draftPath);
|
|
1224
1224
|
const dirPath = path10.dirname(finalPath);
|
|
@@ -1554,9 +1554,9 @@ function createHtmlLoader() {
|
|
|
1554
1554
|
const bDepth = b.split("/").length;
|
|
1555
1555
|
return aDepth - bDepth;
|
|
1556
1556
|
});
|
|
1557
|
-
paths.forEach((
|
|
1558
|
-
const value = data[
|
|
1559
|
-
const [nodePath, attribute] =
|
|
1557
|
+
paths.forEach((path17) => {
|
|
1558
|
+
const value = data[path17];
|
|
1559
|
+
const [nodePath, attribute] = path17.split("#");
|
|
1560
1560
|
const [rootTag, ...indices] = nodePath.split("/");
|
|
1561
1561
|
let parent = rootTag === "head" ? document.head : document.body;
|
|
1562
1562
|
let current = parent;
|
|
@@ -1659,7 +1659,7 @@ function createPropertiesLoader() {
|
|
|
1659
1659
|
return result;
|
|
1660
1660
|
},
|
|
1661
1661
|
async push(locale, payload) {
|
|
1662
|
-
const result = Object.entries(payload).filter(([
|
|
1662
|
+
const result = Object.entries(payload).filter(([_25, value]) => value != null).map(([key, value]) => `${key}=${value}`).join("\n");
|
|
1663
1663
|
return result;
|
|
1664
1664
|
}
|
|
1665
1665
|
});
|
|
@@ -1836,8 +1836,12 @@ function createXcodeXcstringsLoader(defaultLocale) {
|
|
|
1836
1836
|
import path11 from "path";
|
|
1837
1837
|
import prettier from "prettier";
|
|
1838
1838
|
function createPrettierLoader(options) {
|
|
1839
|
+
const stage = options.stage || "both";
|
|
1839
1840
|
return createLoader({
|
|
1840
1841
|
async pull(locale, data) {
|
|
1842
|
+
if (!["pull", "both"].includes(stage)) {
|
|
1843
|
+
return data;
|
|
1844
|
+
}
|
|
1841
1845
|
const draftPath = options.bucketPathPattern.replaceAll(
|
|
1842
1846
|
"[locale]",
|
|
1843
1847
|
locale
|
|
@@ -1846,6 +1850,9 @@ function createPrettierLoader(options) {
|
|
|
1846
1850
|
return await formatDataWithPrettier(data, finalPath, options);
|
|
1847
1851
|
},
|
|
1848
1852
|
async push(locale, data) {
|
|
1853
|
+
if (!["push", "both"].includes(stage)) {
|
|
1854
|
+
return data;
|
|
1855
|
+
}
|
|
1849
1856
|
const draftPath = options.bucketPathPattern.replaceAll(
|
|
1850
1857
|
"[locale]",
|
|
1851
1858
|
locale
|
|
@@ -1919,10 +1926,10 @@ function createUnlocalizableLoader(isCacheRestore = false, returnUnlocalizedKeys
|
|
|
1919
1926
|
}
|
|
1920
1927
|
}
|
|
1921
1928
|
return false;
|
|
1922
|
-
}).map(([key,
|
|
1923
|
-
const result = _10.omitBy(input2, (
|
|
1929
|
+
}).map(([key, _25]) => key);
|
|
1930
|
+
const result = _10.omitBy(input2, (_25, key) => passthroughKeys.includes(key));
|
|
1924
1931
|
if (returnUnlocalizedKeys) {
|
|
1925
|
-
result.unlocalizable = _10.omitBy(input2, (
|
|
1932
|
+
result.unlocalizable = _10.omitBy(input2, (_25, key) => !passthroughKeys.includes(key));
|
|
1926
1933
|
}
|
|
1927
1934
|
return result;
|
|
1928
1935
|
},
|
|
@@ -2092,10 +2099,10 @@ function createXmlLoader() {
|
|
|
2092
2099
|
// src/cli/loaders/srt.ts
|
|
2093
2100
|
import srtParser from "srt-parser-2";
|
|
2094
2101
|
function createSrtLoader() {
|
|
2095
|
-
const
|
|
2102
|
+
const parser = new srtParser();
|
|
2096
2103
|
return createLoader({
|
|
2097
2104
|
async pull(locale, input2) {
|
|
2098
|
-
const parsed =
|
|
2105
|
+
const parsed = parser.fromSrt(input2) || [];
|
|
2099
2106
|
const result = {};
|
|
2100
2107
|
parsed.forEach((entry) => {
|
|
2101
2108
|
const key = `${entry.id}#${entry.startTime}-${entry.endTime}`;
|
|
@@ -2116,7 +2123,7 @@ function createSrtLoader() {
|
|
|
2116
2123
|
text
|
|
2117
2124
|
};
|
|
2118
2125
|
});
|
|
2119
|
-
const srtContent =
|
|
2126
|
+
const srtContent = parser.toSrt(output).trim().replace(/\r?\n/g, "\n");
|
|
2120
2127
|
return srtContent;
|
|
2121
2128
|
}
|
|
2122
2129
|
});
|
|
@@ -2626,18 +2633,18 @@ function createRawDatoValue(parsedDatoValue, originalRawDatoValue, isClean = fal
|
|
|
2626
2633
|
}
|
|
2627
2634
|
function serializeStructuredText(rawStructuredText) {
|
|
2628
2635
|
return serializeStructuredTextNode(rawStructuredText);
|
|
2629
|
-
function serializeStructuredTextNode(node,
|
|
2636
|
+
function serializeStructuredTextNode(node, path17 = [], acc = {}) {
|
|
2630
2637
|
if ("document" in node) {
|
|
2631
|
-
return serializeStructuredTextNode(node.document, [...
|
|
2638
|
+
return serializeStructuredTextNode(node.document, [...path17, "document"], acc);
|
|
2632
2639
|
}
|
|
2633
2640
|
if (!_15.isNil(node.value)) {
|
|
2634
|
-
acc[[...
|
|
2641
|
+
acc[[...path17, "value"].join(".")] = node.value;
|
|
2635
2642
|
} else if (_15.get(node, "type") === "block") {
|
|
2636
|
-
acc[[...
|
|
2643
|
+
acc[[...path17, "item"].join(".")] = serializeBlock(node.item);
|
|
2637
2644
|
}
|
|
2638
2645
|
if (node.children) {
|
|
2639
2646
|
for (let i = 0; i < node.children.length; i++) {
|
|
2640
|
-
serializeStructuredTextNode(node.children[i], [...
|
|
2647
|
+
serializeStructuredTextNode(node.children[i], [...path17, i.toString()], acc);
|
|
2641
2648
|
}
|
|
2642
2649
|
}
|
|
2643
2650
|
return acc;
|
|
@@ -2696,8 +2703,8 @@ function deserializeBlockList(parsedBlockList, originalRawBlockList, isClean = f
|
|
|
2696
2703
|
}
|
|
2697
2704
|
function deserializeStructuredText(parsedStructuredText, originalRawStructuredText) {
|
|
2698
2705
|
const result = _15.cloneDeep(originalRawStructuredText);
|
|
2699
|
-
for (const [
|
|
2700
|
-
const realPath = _15.chain(
|
|
2706
|
+
for (const [path17, value] of _15.entries(parsedStructuredText)) {
|
|
2707
|
+
const realPath = _15.chain(path17.split(".")).flatMap((s) => !_15.isNaN(_15.toNumber(s)) ? ["children", s] : s).value();
|
|
2701
2708
|
const deserializedValue = createRawDatoValue(value, _15.get(originalRawStructuredText, realPath), true);
|
|
2702
2709
|
_15.set(result, realPath, deserializedValue);
|
|
2703
2710
|
}
|
|
@@ -3084,16 +3091,6 @@ function createMdxFrontmatterSplitLoader() {
|
|
|
3084
3091
|
});
|
|
3085
3092
|
}
|
|
3086
3093
|
|
|
3087
|
-
// src/cli/loaders/mdx2/_utils.ts
|
|
3088
|
-
function traverseMdast(ast, visitor) {
|
|
3089
|
-
visitor(ast);
|
|
3090
|
-
if ("children" in ast && Array.isArray(ast.children)) {
|
|
3091
|
-
for (const child of ast.children) {
|
|
3092
|
-
traverseMdast(child, visitor);
|
|
3093
|
-
}
|
|
3094
|
-
}
|
|
3095
|
-
}
|
|
3096
|
-
|
|
3097
3094
|
// src/cli/utils/md5.ts
|
|
3098
3095
|
import { MD5 } from "object-hash";
|
|
3099
3096
|
function md5(input2) {
|
|
@@ -3106,36 +3103,18 @@ import remarkParse from "remark-parse";
|
|
|
3106
3103
|
import remarkGfm from "remark-gfm";
|
|
3107
3104
|
import { VFile } from "vfile";
|
|
3108
3105
|
import remarkMdx from "remark-mdx";
|
|
3109
|
-
function parseMdast(content) {
|
|
3110
|
-
const file = new VFile(content);
|
|
3111
|
-
const parser2 = unified().use(remarkParse).use(remarkGfm).use(remarkMdx);
|
|
3112
|
-
const result = parser2.parse(file);
|
|
3113
|
-
return result;
|
|
3114
|
-
}
|
|
3115
3106
|
function extractCodePlaceholders(content) {
|
|
3116
|
-
const ast = parseMdast(content);
|
|
3117
|
-
const placeholderableElements = [
|
|
3118
|
-
"code",
|
|
3119
|
-
"inlineCode"
|
|
3120
|
-
];
|
|
3121
3107
|
let finalContent = content;
|
|
3122
3108
|
const codePlaceholders = {};
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
const
|
|
3128
|
-
const
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
const nodeContentEnd = node.position?.end.offset;
|
|
3133
|
-
if (!nodeContentStart || !nodeContentEnd) {
|
|
3134
|
-
return;
|
|
3135
|
-
}
|
|
3136
|
-
codePlaceholders[placeholderId] = nodeContent;
|
|
3137
|
-
finalContent = finalContent.split(nodeContent).join(placeholderId);
|
|
3138
|
-
});
|
|
3109
|
+
const codeBlockRegex = /^```.*\n([\s\S]*?)^```$/gm;
|
|
3110
|
+
const codeBlockMatches = finalContent.matchAll(codeBlockRegex);
|
|
3111
|
+
for (const match of codeBlockMatches) {
|
|
3112
|
+
const codeBlock = match[0];
|
|
3113
|
+
const codeBlockHash = md5(codeBlock);
|
|
3114
|
+
const placeholderId = `---CODE_PLACEHOLDER_${codeBlockHash}---`;
|
|
3115
|
+
codePlaceholders[placeholderId] = codeBlock;
|
|
3116
|
+
finalContent = finalContent.replace(codeBlock, placeholderId);
|
|
3117
|
+
}
|
|
3139
3118
|
return {
|
|
3140
3119
|
content: finalContent,
|
|
3141
3120
|
codePlaceholders
|
|
@@ -3144,314 +3123,22 @@ function extractCodePlaceholders(content) {
|
|
|
3144
3123
|
function createMdxCodePlaceholderLoader() {
|
|
3145
3124
|
return createLoader({
|
|
3146
3125
|
async pull(locale, input2) {
|
|
3147
|
-
const
|
|
3148
|
-
|
|
3149
|
-
content: ""
|
|
3150
|
-
};
|
|
3151
|
-
const { content: resultContent, codePlaceholders } = extractCodePlaceholders(content);
|
|
3152
|
-
return {
|
|
3153
|
-
frontmatter,
|
|
3154
|
-
content: resultContent,
|
|
3155
|
-
codePlaceholders
|
|
3156
|
-
};
|
|
3126
|
+
const response = extractCodePlaceholders(input2);
|
|
3127
|
+
return response.content;
|
|
3157
3128
|
},
|
|
3158
3129
|
async push(locale, data, originalInput) {
|
|
3159
|
-
const
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3130
|
+
const response = extractCodePlaceholders(originalInput ?? "");
|
|
3131
|
+
let result = data;
|
|
3132
|
+
for (const [placeholder, original] of Object.entries(
|
|
3133
|
+
response.codePlaceholders
|
|
3134
|
+
)) {
|
|
3135
|
+
result = result.replaceAll(placeholder, original);
|
|
3165
3136
|
}
|
|
3166
|
-
const result = {
|
|
3167
|
-
frontmatter: data.frontmatter,
|
|
3168
|
-
content: finalContent
|
|
3169
|
-
};
|
|
3170
3137
|
return result;
|
|
3171
3138
|
}
|
|
3172
3139
|
});
|
|
3173
3140
|
}
|
|
3174
3141
|
|
|
3175
|
-
// src/cli/loaders/mdx2/section-split.ts
|
|
3176
|
-
import { unified as unified2 } from "unified";
|
|
3177
|
-
import remarkParse2 from "remark-parse";
|
|
3178
|
-
import remarkGfm2 from "remark-gfm";
|
|
3179
|
-
import remarkMdx2 from "remark-mdx";
|
|
3180
|
-
import { VFile as VFile2 } from "vfile";
|
|
3181
|
-
var parser = unified2().use(remarkParse2).use(remarkGfm2).use(remarkMdx2);
|
|
3182
|
-
var SPACING_MATRIX = [
|
|
3183
|
-
// HEADING as previous type
|
|
3184
|
-
["\n\n", "\n\n", "\n\n", "\n\n", "\n\n", "\n\n"],
|
|
3185
|
-
// JSX_OPENING_TAG as previous type
|
|
3186
|
-
["\n\n", "\n", "\n", "\n", "\n", "\n\n"],
|
|
3187
|
-
// JSX_CLOSING_TAG as previous type
|
|
3188
|
-
["\n\n", "\n", "\n", "\n", "\n\n", "\n\n"],
|
|
3189
|
-
// JSX_SELF_CLOSING_TAG as previous type
|
|
3190
|
-
["\n\n", "\n", "\n", "\n", "\n", "\n\n"],
|
|
3191
|
-
// CONTENT as previous type
|
|
3192
|
-
["\n\n", "\n\n", "\n", "\n\n", "\n\n", "\n\n"],
|
|
3193
|
-
// UNKNOWN as previous type
|
|
3194
|
-
["\n\n", "\n\n", "\n\n", "\n\n", "\n\n", "\n\n"]
|
|
3195
|
-
];
|
|
3196
|
-
function createMdxSectionSplitLoader() {
|
|
3197
|
-
return createLoader({
|
|
3198
|
-
async pull(_locale, input2) {
|
|
3199
|
-
const {
|
|
3200
|
-
frontmatter = {},
|
|
3201
|
-
content = "",
|
|
3202
|
-
codePlaceholders = {}
|
|
3203
|
-
} = input2 || {
|
|
3204
|
-
frontmatter: {},
|
|
3205
|
-
content: "",
|
|
3206
|
-
codePlaceholders: {}
|
|
3207
|
-
};
|
|
3208
|
-
if (!content.trim()) {
|
|
3209
|
-
return {
|
|
3210
|
-
frontmatter,
|
|
3211
|
-
sections: {}
|
|
3212
|
-
};
|
|
3213
|
-
}
|
|
3214
|
-
const file = new VFile2(content);
|
|
3215
|
-
const ast = parser.parse(file);
|
|
3216
|
-
const boundaries = findSectionBoundaries(ast, content);
|
|
3217
|
-
const sections = createSectionsFromBoundaries(boundaries, content);
|
|
3218
|
-
return {
|
|
3219
|
-
frontmatter,
|
|
3220
|
-
sections
|
|
3221
|
-
};
|
|
3222
|
-
},
|
|
3223
|
-
async push(_locale, data, originalInput, _originalLocale) {
|
|
3224
|
-
const sectionsArray = Object.values(data.sections);
|
|
3225
|
-
if (sectionsArray.length === 0) {
|
|
3226
|
-
return {
|
|
3227
|
-
frontmatter: data.frontmatter,
|
|
3228
|
-
content: "",
|
|
3229
|
-
codePlaceholders: originalInput?.codePlaceholders ?? {}
|
|
3230
|
-
};
|
|
3231
|
-
}
|
|
3232
|
-
const resultParts = new Array(sectionsArray.length * 2 - 1);
|
|
3233
|
-
const sectionTypes = new Array(sectionsArray.length);
|
|
3234
|
-
for (let i = 0; i < sectionsArray.length; i++) {
|
|
3235
|
-
sectionTypes[i] = determineJsxSectionType(sectionsArray[i]);
|
|
3236
|
-
}
|
|
3237
|
-
resultParts[0] = sectionsArray[0];
|
|
3238
|
-
for (let i = 1, j = 1; i < sectionsArray.length; i++, j += 2) {
|
|
3239
|
-
const prevType = sectionTypes[i - 1];
|
|
3240
|
-
const currentType = sectionTypes[i];
|
|
3241
|
-
resultParts[j] = SPACING_MATRIX[prevType][currentType];
|
|
3242
|
-
resultParts[j + 1] = sectionsArray[i];
|
|
3243
|
-
}
|
|
3244
|
-
const content = resultParts.join("");
|
|
3245
|
-
return {
|
|
3246
|
-
frontmatter: data.frontmatter,
|
|
3247
|
-
content,
|
|
3248
|
-
codePlaceholders: originalInput?.codePlaceholders ?? {}
|
|
3249
|
-
};
|
|
3250
|
-
}
|
|
3251
|
-
});
|
|
3252
|
-
}
|
|
3253
|
-
function determineJsxSectionType(section) {
|
|
3254
|
-
section = section.trim();
|
|
3255
|
-
if (!section) return 5 /* UNKNOWN */;
|
|
3256
|
-
const firstChar = section.charAt(0);
|
|
3257
|
-
const lastChar = section.charAt(section.length - 1);
|
|
3258
|
-
if (firstChar === "#") {
|
|
3259
|
-
if (/^#{1,6}\s/.test(section)) {
|
|
3260
|
-
return 0 /* HEADING */;
|
|
3261
|
-
}
|
|
3262
|
-
}
|
|
3263
|
-
if (firstChar === "<") {
|
|
3264
|
-
if (section.endsWith("/>")) {
|
|
3265
|
-
return 3 /* JSX_SELF_CLOSING_TAG */;
|
|
3266
|
-
}
|
|
3267
|
-
if (section.startsWith("</")) {
|
|
3268
|
-
return 2 /* JSX_CLOSING_TAG */;
|
|
3269
|
-
}
|
|
3270
|
-
if (lastChar === ">") {
|
|
3271
|
-
return 1 /* JSX_OPENING_TAG */;
|
|
3272
|
-
}
|
|
3273
|
-
}
|
|
3274
|
-
return 4 /* CONTENT */;
|
|
3275
|
-
}
|
|
3276
|
-
function isJsxOrHtml(node) {
|
|
3277
|
-
return node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement" || node.type === "html";
|
|
3278
|
-
}
|
|
3279
|
-
function findOpeningTagEnd(text) {
|
|
3280
|
-
let depth = 0;
|
|
3281
|
-
let inQuotes = false;
|
|
3282
|
-
let quoteChar = "";
|
|
3283
|
-
for (let i = 0; i < text.length; i++) {
|
|
3284
|
-
const char = text[i];
|
|
3285
|
-
if ((char === '"' || char === "'") && (i === 0 || text[i - 1] !== "\\")) {
|
|
3286
|
-
if (!inQuotes) {
|
|
3287
|
-
inQuotes = true;
|
|
3288
|
-
quoteChar = char;
|
|
3289
|
-
} else if (char === quoteChar) {
|
|
3290
|
-
inQuotes = false;
|
|
3291
|
-
}
|
|
3292
|
-
}
|
|
3293
|
-
if (!inQuotes) {
|
|
3294
|
-
if (char === "<") depth++;
|
|
3295
|
-
if (char === ">") {
|
|
3296
|
-
depth--;
|
|
3297
|
-
if (depth === 0) return i + 1;
|
|
3298
|
-
}
|
|
3299
|
-
}
|
|
3300
|
-
}
|
|
3301
|
-
return -1;
|
|
3302
|
-
}
|
|
3303
|
-
function findClosingTagStart(text) {
|
|
3304
|
-
const openTagMatch = /<([^\s/>]+)/.exec(text);
|
|
3305
|
-
if (!openTagMatch) return -1;
|
|
3306
|
-
const tagName = openTagMatch[1];
|
|
3307
|
-
const closingTagRegex = new RegExp(`</${tagName}\\s*>`, "g");
|
|
3308
|
-
let lastMatch = null;
|
|
3309
|
-
let match;
|
|
3310
|
-
while ((match = closingTagRegex.exec(text)) !== null) {
|
|
3311
|
-
lastMatch = match;
|
|
3312
|
-
}
|
|
3313
|
-
return lastMatch ? lastMatch.index : -1;
|
|
3314
|
-
}
|
|
3315
|
-
function processJsxNode(node, content, boundaries) {
|
|
3316
|
-
if (!node.position || typeof node.position.start.offset !== "number" || typeof node.position.end.offset !== "number") {
|
|
3317
|
-
return;
|
|
3318
|
-
}
|
|
3319
|
-
const nodeStart = node.position.start.offset;
|
|
3320
|
-
const nodeEnd = node.position.end.offset;
|
|
3321
|
-
const nodeContent = content.slice(nodeStart, nodeEnd);
|
|
3322
|
-
if (node.type === "html") {
|
|
3323
|
-
extractHtmlTags(nodeStart, nodeContent, boundaries);
|
|
3324
|
-
return;
|
|
3325
|
-
}
|
|
3326
|
-
if (node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") {
|
|
3327
|
-
const isSelfClosing = node.selfClosing === true;
|
|
3328
|
-
if (isSelfClosing) {
|
|
3329
|
-
boundaries.push({
|
|
3330
|
-
start: nodeStart,
|
|
3331
|
-
end: nodeEnd,
|
|
3332
|
-
isolateSelf: true
|
|
3333
|
-
});
|
|
3334
|
-
} else {
|
|
3335
|
-
extractJsxTags(node, nodeContent, boundaries);
|
|
3336
|
-
if (node.children) {
|
|
3337
|
-
for (const child of node.children) {
|
|
3338
|
-
if (isJsxOrHtml(child)) {
|
|
3339
|
-
processJsxNode(child, content, boundaries);
|
|
3340
|
-
}
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
|
-
}
|
|
3344
|
-
}
|
|
3345
|
-
}
|
|
3346
|
-
function extractHtmlTags(nodeStart, nodeContent, boundaries) {
|
|
3347
|
-
const tagRegex = /<\/?[a-zA-Z][a-zA-Z0-9:._-]*(?:\s+[a-zA-Z:_][a-zA-Z0-9:._-]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^'">\s]+))?)*\s*\/?>/g;
|
|
3348
|
-
let match;
|
|
3349
|
-
while ((match = tagRegex.exec(nodeContent)) !== null) {
|
|
3350
|
-
const tagStart = nodeStart + match.index;
|
|
3351
|
-
const tagEnd = tagStart + match[0].length;
|
|
3352
|
-
boundaries.push({
|
|
3353
|
-
start: tagStart,
|
|
3354
|
-
end: tagEnd,
|
|
3355
|
-
isolateSelf: true
|
|
3356
|
-
});
|
|
3357
|
-
}
|
|
3358
|
-
}
|
|
3359
|
-
function extractJsxTags(node, nodeContent, boundaries) {
|
|
3360
|
-
const nodeStart = node.position.start.offset;
|
|
3361
|
-
const nodeEnd = node.position.end.offset;
|
|
3362
|
-
if (!nodeStart || !nodeEnd) {
|
|
3363
|
-
return;
|
|
3364
|
-
}
|
|
3365
|
-
const openingTagEnd = findOpeningTagEnd(nodeContent);
|
|
3366
|
-
if (openingTagEnd > 0) {
|
|
3367
|
-
boundaries.push({
|
|
3368
|
-
start: nodeStart,
|
|
3369
|
-
end: nodeStart + openingTagEnd,
|
|
3370
|
-
isolateSelf: true
|
|
3371
|
-
});
|
|
3372
|
-
}
|
|
3373
|
-
const closingTagStart = findClosingTagStart(nodeContent);
|
|
3374
|
-
if (closingTagStart > 0 && closingTagStart < nodeContent.length) {
|
|
3375
|
-
boundaries.push({
|
|
3376
|
-
start: nodeStart + closingTagStart,
|
|
3377
|
-
end: nodeEnd,
|
|
3378
|
-
isolateSelf: true
|
|
3379
|
-
});
|
|
3380
|
-
}
|
|
3381
|
-
}
|
|
3382
|
-
function findSectionBoundaries(ast, content) {
|
|
3383
|
-
const boundaries = [];
|
|
3384
|
-
const nodePositions = /* @__PURE__ */ new Map();
|
|
3385
|
-
traverseMdast(ast, (node) => {
|
|
3386
|
-
if (node.position && typeof node.position.start.offset === "number" && typeof node.position.end.offset === "number") {
|
|
3387
|
-
nodePositions.set(node, {
|
|
3388
|
-
start: node.position.start.offset,
|
|
3389
|
-
end: node.position.end.offset
|
|
3390
|
-
});
|
|
3391
|
-
}
|
|
3392
|
-
});
|
|
3393
|
-
for (const child of ast.children) {
|
|
3394
|
-
const position = nodePositions.get(child);
|
|
3395
|
-
if (!position) continue;
|
|
3396
|
-
if (child.type === "heading") {
|
|
3397
|
-
boundaries.push({
|
|
3398
|
-
start: position.start,
|
|
3399
|
-
end: position.end,
|
|
3400
|
-
isolateSelf: false
|
|
3401
|
-
});
|
|
3402
|
-
} else if (isJsxOrHtml(child)) {
|
|
3403
|
-
processJsxNode(child, content, boundaries);
|
|
3404
|
-
}
|
|
3405
|
-
}
|
|
3406
|
-
return boundaries.sort((a, b) => a.start - b.start);
|
|
3407
|
-
}
|
|
3408
|
-
function createSectionsFromBoundaries(boundaries, content) {
|
|
3409
|
-
const sections = {};
|
|
3410
|
-
if (!content.trim() || boundaries.length === 0) {
|
|
3411
|
-
const trimmed = content.trim();
|
|
3412
|
-
if (trimmed) {
|
|
3413
|
-
sections["0"] = trimmed;
|
|
3414
|
-
}
|
|
3415
|
-
return sections;
|
|
3416
|
-
}
|
|
3417
|
-
let idx = 0;
|
|
3418
|
-
let lastEnd = 0;
|
|
3419
|
-
const sectionsArray = [];
|
|
3420
|
-
for (let i = 0; i < boundaries.length; i++) {
|
|
3421
|
-
const { start, end, isolateSelf } = boundaries[i];
|
|
3422
|
-
if (start > lastEnd) {
|
|
3423
|
-
const segment = content.slice(lastEnd, start).trim();
|
|
3424
|
-
if (segment) {
|
|
3425
|
-
sectionsArray.push(segment);
|
|
3426
|
-
}
|
|
3427
|
-
}
|
|
3428
|
-
if (isolateSelf) {
|
|
3429
|
-
const segment = content.slice(start, end).trim();
|
|
3430
|
-
if (segment) {
|
|
3431
|
-
sectionsArray.push(segment);
|
|
3432
|
-
}
|
|
3433
|
-
lastEnd = end;
|
|
3434
|
-
} else {
|
|
3435
|
-
const nextStart = i + 1 < boundaries.length ? boundaries[i + 1].start : content.length;
|
|
3436
|
-
const segment = content.slice(start, nextStart).trim();
|
|
3437
|
-
if (segment) {
|
|
3438
|
-
sectionsArray.push(segment);
|
|
3439
|
-
}
|
|
3440
|
-
lastEnd = nextStart;
|
|
3441
|
-
}
|
|
3442
|
-
}
|
|
3443
|
-
if (lastEnd < content.length) {
|
|
3444
|
-
const segment = content.slice(lastEnd).trim();
|
|
3445
|
-
if (segment) {
|
|
3446
|
-
sectionsArray.push(segment);
|
|
3447
|
-
}
|
|
3448
|
-
}
|
|
3449
|
-
sectionsArray.forEach((section, index) => {
|
|
3450
|
-
sections[index.toString()] = section;
|
|
3451
|
-
});
|
|
3452
|
-
return sections;
|
|
3453
|
-
}
|
|
3454
|
-
|
|
3455
3142
|
// src/cli/loaders/mdx2/localizable-document.ts
|
|
3456
3143
|
function createLocalizableMdxDocumentLoader() {
|
|
3457
3144
|
return createLoader({
|
|
@@ -3471,14 +3158,28 @@ function createLocalizableMdxDocumentLoader() {
|
|
|
3471
3158
|
});
|
|
3472
3159
|
}
|
|
3473
3160
|
|
|
3474
|
-
// src/cli/loaders/mdx2/
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3161
|
+
// src/cli/loaders/mdx2/sections-split-2.ts
|
|
3162
|
+
import _20 from "lodash";
|
|
3163
|
+
function createMdxSectionsSplit2Loader() {
|
|
3164
|
+
return createLoader({
|
|
3165
|
+
async pull(locale, input2) {
|
|
3166
|
+
const sections = _20.chain(input2.content).split("\n\n").filter(Boolean).map((section, index) => [index, section]).fromPairs().value();
|
|
3167
|
+
const result = {
|
|
3168
|
+
frontmatter: input2.frontmatter,
|
|
3169
|
+
sections
|
|
3170
|
+
};
|
|
3171
|
+
return result;
|
|
3172
|
+
},
|
|
3173
|
+
async push(locale, data, originalInput, _originalLocale, pullInput) {
|
|
3174
|
+
const content = _20.chain(data.sections).values().join("\n\n").value();
|
|
3175
|
+
const result = {
|
|
3176
|
+
frontmatter: data.frontmatter,
|
|
3177
|
+
codePlaceholders: pullInput?.codePlaceholders || {},
|
|
3178
|
+
content
|
|
3179
|
+
};
|
|
3180
|
+
return result;
|
|
3181
|
+
}
|
|
3182
|
+
});
|
|
3482
3183
|
}
|
|
3483
3184
|
|
|
3484
3185
|
// src/cli/loaders/index.ts
|
|
@@ -3547,8 +3248,14 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys)
|
|
|
3547
3248
|
case "mdx":
|
|
3548
3249
|
return composeLoaders(
|
|
3549
3250
|
createTextFileLoader(bucketPathPattern),
|
|
3550
|
-
|
|
3551
|
-
|
|
3251
|
+
createMdxCodePlaceholderLoader(),
|
|
3252
|
+
createPrettierLoader({
|
|
3253
|
+
parser: "mdx",
|
|
3254
|
+
bucketPathPattern
|
|
3255
|
+
}),
|
|
3256
|
+
createMdxFrontmatterSplitLoader(),
|
|
3257
|
+
createMdxSectionsSplit2Loader(),
|
|
3258
|
+
createLocalizableMdxDocumentLoader(),
|
|
3552
3259
|
createFlatLoader(),
|
|
3553
3260
|
createSyncLoader(),
|
|
3554
3261
|
createUnlocalizableLoader(
|
|
@@ -3735,37 +3442,6 @@ import { createTwoFilesPatch } from "diff";
|
|
|
3735
3442
|
import inquirer2 from "inquirer";
|
|
3736
3443
|
import externalEditor from "external-editor";
|
|
3737
3444
|
|
|
3738
|
-
// src/cli/utils/cache.ts
|
|
3739
|
-
import path12 from "path";
|
|
3740
|
-
import fs10 from "fs";
|
|
3741
|
-
var cacheChunk = (targetLocale, sourceChunk, processedChunk) => {
|
|
3742
|
-
const rows = Object.entries(sourceChunk).map(([key, source]) => ({
|
|
3743
|
-
targetLocale,
|
|
3744
|
-
key,
|
|
3745
|
-
source,
|
|
3746
|
-
processed: processedChunk[key]
|
|
3747
|
-
}));
|
|
3748
|
-
_appendToCache(rows);
|
|
3749
|
-
};
|
|
3750
|
-
function deleteCache() {
|
|
3751
|
-
const cacheFilePath = _getCacheFilePath();
|
|
3752
|
-
try {
|
|
3753
|
-
fs10.unlinkSync(cacheFilePath);
|
|
3754
|
-
} catch (e) {
|
|
3755
|
-
}
|
|
3756
|
-
}
|
|
3757
|
-
function _appendToCache(rows) {
|
|
3758
|
-
const cacheFilePath = _getCacheFilePath();
|
|
3759
|
-
const lines = _buildJSONLines(rows);
|
|
3760
|
-
fs10.appendFileSync(cacheFilePath, lines);
|
|
3761
|
-
}
|
|
3762
|
-
function _getCacheFilePath() {
|
|
3763
|
-
return path12.join(process.cwd(), "i18n.cache");
|
|
3764
|
-
}
|
|
3765
|
-
function _buildJSONLines(rows) {
|
|
3766
|
-
return rows.map((row) => JSON.stringify(row)).join("\n") + "\n";
|
|
3767
|
-
}
|
|
3768
|
-
|
|
3769
3445
|
// src/cli/processor/lingo.ts
|
|
3770
3446
|
import { LingoDotDevEngine } from "@lingo.dev/_sdk";
|
|
3771
3447
|
function createLingoLocalizer(params) {
|
|
@@ -3931,33 +3607,33 @@ async function trackEvent(distinctId, event, properties) {
|
|
|
3931
3607
|
}
|
|
3932
3608
|
|
|
3933
3609
|
// src/cli/utils/delta.ts
|
|
3934
|
-
import
|
|
3610
|
+
import _21 from "lodash";
|
|
3935
3611
|
import z from "zod";
|
|
3936
3612
|
|
|
3937
3613
|
// src/cli/utils/fs.ts
|
|
3938
|
-
import * as
|
|
3939
|
-
import * as
|
|
3614
|
+
import * as fs10 from "fs";
|
|
3615
|
+
import * as path12 from "path";
|
|
3940
3616
|
function tryReadFile(filePath, defaultValue = null) {
|
|
3941
3617
|
try {
|
|
3942
|
-
const content =
|
|
3618
|
+
const content = fs10.readFileSync(filePath, "utf-8");
|
|
3943
3619
|
return content;
|
|
3944
3620
|
} catch (error) {
|
|
3945
3621
|
return defaultValue;
|
|
3946
3622
|
}
|
|
3947
3623
|
}
|
|
3948
3624
|
function writeFile(filePath, content) {
|
|
3949
|
-
const dir =
|
|
3950
|
-
if (!
|
|
3951
|
-
|
|
3625
|
+
const dir = path12.dirname(filePath);
|
|
3626
|
+
if (!fs10.existsSync(dir)) {
|
|
3627
|
+
fs10.mkdirSync(dir, { recursive: true });
|
|
3952
3628
|
}
|
|
3953
|
-
|
|
3629
|
+
fs10.writeFileSync(filePath, content);
|
|
3954
3630
|
}
|
|
3955
3631
|
function checkIfFileExists(filePath) {
|
|
3956
|
-
return
|
|
3632
|
+
return fs10.existsSync(filePath);
|
|
3957
3633
|
}
|
|
3958
3634
|
|
|
3959
3635
|
// src/cli/utils/delta.ts
|
|
3960
|
-
import * as
|
|
3636
|
+
import * as path13 from "path";
|
|
3961
3637
|
import YAML3 from "yaml";
|
|
3962
3638
|
var LockSchema = z.object({
|
|
3963
3639
|
version: z.literal(1).default(1),
|
|
@@ -3974,15 +3650,15 @@ var LockSchema = z.object({
|
|
|
3974
3650
|
).default({})
|
|
3975
3651
|
});
|
|
3976
3652
|
function createDeltaProcessor(fileKey) {
|
|
3977
|
-
const lockfilePath =
|
|
3653
|
+
const lockfilePath = path13.join(process.cwd(), "i18n.lock");
|
|
3978
3654
|
return {
|
|
3979
3655
|
async checkIfLockExists() {
|
|
3980
3656
|
return checkIfFileExists(lockfilePath);
|
|
3981
3657
|
},
|
|
3982
3658
|
async calculateDelta(params) {
|
|
3983
|
-
let added =
|
|
3984
|
-
let removed =
|
|
3985
|
-
const updated =
|
|
3659
|
+
let added = _21.difference(Object.keys(params.sourceData), Object.keys(params.targetData));
|
|
3660
|
+
let removed = _21.difference(Object.keys(params.targetData), Object.keys(params.sourceData));
|
|
3661
|
+
const updated = _21.filter(Object.keys(params.sourceData), (key) => {
|
|
3986
3662
|
return md5(params.sourceData[key]) !== params.checksums[key] && params.checksums[key];
|
|
3987
3663
|
});
|
|
3988
3664
|
const renamed = [];
|
|
@@ -4031,7 +3707,7 @@ function createDeltaProcessor(fileKey) {
|
|
|
4031
3707
|
await this.saveLock(lockfileData);
|
|
4032
3708
|
},
|
|
4033
3709
|
async createChecksums(sourceData) {
|
|
4034
|
-
const checksums =
|
|
3710
|
+
const checksums = _21.mapValues(sourceData, (value) => md5(value));
|
|
4035
3711
|
return checksums;
|
|
4036
3712
|
}
|
|
4037
3713
|
};
|
|
@@ -4115,7 +3791,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4115
3791
|
if (flags.file?.length) {
|
|
4116
3792
|
buckets = buckets.map((bucket) => {
|
|
4117
3793
|
const paths = bucket.paths.filter(
|
|
4118
|
-
(
|
|
3794
|
+
(path17) => flags.file.find((file) => path17.pathPattern?.includes(file))
|
|
4119
3795
|
);
|
|
4120
3796
|
return { ...bucket, paths };
|
|
4121
3797
|
}).filter((bucket) => bucket.paths.length > 0);
|
|
@@ -4128,8 +3804,8 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4128
3804
|
ora.info(`\x1B[36mProcessing only filtered buckets:\x1B[0m`);
|
|
4129
3805
|
buckets.map((bucket) => {
|
|
4130
3806
|
ora.info(` ${bucket.type}:`);
|
|
4131
|
-
bucket.paths.forEach((
|
|
4132
|
-
ora.info(` - ${
|
|
3807
|
+
bucket.paths.forEach((path17) => {
|
|
3808
|
+
ora.info(` - ${path17.pathPattern}`);
|
|
4133
3809
|
});
|
|
4134
3810
|
});
|
|
4135
3811
|
}
|
|
@@ -4181,7 +3857,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4181
3857
|
bucketPath.delimiter
|
|
4182
3858
|
);
|
|
4183
3859
|
const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
|
|
4184
|
-
const sourcePath =
|
|
3860
|
+
const sourcePath = path14.join(
|
|
4185
3861
|
process.cwd(),
|
|
4186
3862
|
bucketPath.pathPattern.replace("[locale]", sourceLocale)
|
|
4187
3863
|
);
|
|
@@ -4198,7 +3874,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4198
3874
|
_targetLocale,
|
|
4199
3875
|
bucketPath.delimiter
|
|
4200
3876
|
);
|
|
4201
|
-
const targetPath =
|
|
3877
|
+
const targetPath = path14.join(
|
|
4202
3878
|
process.cwd(),
|
|
4203
3879
|
bucketPath.pathPattern.replace("[locale]", targetLocale)
|
|
4204
3880
|
);
|
|
@@ -4263,7 +3939,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4263
3939
|
const deltaProcessor = createDeltaProcessor(bucketPath.pathPattern);
|
|
4264
3940
|
const sourceChecksums = await deltaProcessor.createChecksums(sourceData);
|
|
4265
3941
|
const savedChecksums = await deltaProcessor.loadChecksums();
|
|
4266
|
-
const updatedSourceData =
|
|
3942
|
+
const updatedSourceData = _22.pickBy(
|
|
4267
3943
|
sourceData,
|
|
4268
3944
|
(value, key) => sourceChecksums[key] !== savedChecksums[key]
|
|
4269
3945
|
);
|
|
@@ -4277,15 +3953,15 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4277
3953
|
bucketPath.delimiter
|
|
4278
3954
|
);
|
|
4279
3955
|
const { unlocalizable: targetUnlocalizable, ...targetData } = await bucketLoader.pull(targetLocale);
|
|
4280
|
-
const missingKeys =
|
|
3956
|
+
const missingKeys = _22.difference(
|
|
4281
3957
|
Object.keys(sourceData),
|
|
4282
3958
|
Object.keys(targetData)
|
|
4283
3959
|
);
|
|
4284
|
-
const extraKeys =
|
|
3960
|
+
const extraKeys = _22.difference(
|
|
4285
3961
|
Object.keys(targetData),
|
|
4286
3962
|
Object.keys(sourceData)
|
|
4287
3963
|
);
|
|
4288
|
-
const unlocalizableDataDiff = !
|
|
3964
|
+
const unlocalizableDataDiff = !_22.isEqual(
|
|
4289
3965
|
sourceUnlocalizable,
|
|
4290
3966
|
targetUnlocalizable
|
|
4291
3967
|
);
|
|
@@ -4365,13 +4041,13 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4365
4041
|
targetData,
|
|
4366
4042
|
checksums: checksums2
|
|
4367
4043
|
});
|
|
4368
|
-
let processableData =
|
|
4044
|
+
let processableData = _22.chain(sourceData).entries().filter(
|
|
4369
4045
|
([key, value]) => delta.added.includes(key) || delta.updated.includes(key) || !!flags.force
|
|
4370
4046
|
).fromPairs().value();
|
|
4371
4047
|
if (flags.key) {
|
|
4372
|
-
processableData =
|
|
4048
|
+
processableData = _22.pickBy(
|
|
4373
4049
|
processableData,
|
|
4374
|
-
(
|
|
4050
|
+
(_25, key) => key === flags.key
|
|
4375
4051
|
);
|
|
4376
4052
|
}
|
|
4377
4053
|
if (flags.verbose) {
|
|
@@ -4398,7 +4074,6 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4398
4074
|
targetData
|
|
4399
4075
|
},
|
|
4400
4076
|
(progress, sourceChunk, processedChunk) => {
|
|
4401
|
-
cacheChunk(targetLocale, sourceChunk, processedChunk);
|
|
4402
4077
|
const progressLog = `[${sourceLocale} -> ${targetLocale}] [${Object.keys(processableData).length} entries] (${progress}%) AI localization in progress...`;
|
|
4403
4078
|
if (flags.verbose) {
|
|
4404
4079
|
bucketOra.info(progressLog);
|
|
@@ -4413,7 +4088,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4413
4088
|
if (flags.verbose) {
|
|
4414
4089
|
bucketOra.info(JSON.stringify(processedTargetData, null, 2));
|
|
4415
4090
|
}
|
|
4416
|
-
let finalTargetData =
|
|
4091
|
+
let finalTargetData = _22.merge(
|
|
4417
4092
|
{},
|
|
4418
4093
|
sourceData,
|
|
4419
4094
|
targetData,
|
|
@@ -4434,7 +4109,7 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4434
4109
|
`Applying changes to ${bucketPath} (${targetLocale})`
|
|
4435
4110
|
);
|
|
4436
4111
|
}
|
|
4437
|
-
const finalDiffSize =
|
|
4112
|
+
const finalDiffSize = _22.chain(finalTargetData).omitBy((value, key) => value === targetData[key]).size().value();
|
|
4438
4113
|
await bucketLoader.push(targetLocale, finalTargetData);
|
|
4439
4114
|
if (finalDiffSize > 0 || flags.force) {
|
|
4440
4115
|
bucketOra.succeed(
|
|
@@ -4476,10 +4151,6 @@ var i18n_default = new Command6().command("i18n").description("Run Localization
|
|
|
4476
4151
|
console.log();
|
|
4477
4152
|
if (!hasErrors) {
|
|
4478
4153
|
ora.succeed("Localization completed.");
|
|
4479
|
-
deleteCache();
|
|
4480
|
-
if (flags.verbose) {
|
|
4481
|
-
ora.info("Cache file deleted.");
|
|
4482
|
-
}
|
|
4483
4154
|
trackEvent(auth.id, "cmd.i18n.success", {
|
|
4484
4155
|
i18nConfig,
|
|
4485
4156
|
flags
|
|
@@ -4606,7 +4277,7 @@ Reviewing changes for ${chalk.blue(args.pathPattern)} (${chalk.yellow(args.targe
|
|
|
4606
4277
|
return args.currentData;
|
|
4607
4278
|
}
|
|
4608
4279
|
const customData = { ...args.currentData };
|
|
4609
|
-
const changes =
|
|
4280
|
+
const changes = _22.reduce(
|
|
4610
4281
|
args.proposedData,
|
|
4611
4282
|
(result, value, key) => {
|
|
4612
4283
|
if (args.currentData[key] !== value) {
|
|
@@ -4674,57 +4345,57 @@ import Z5 from "zod";
|
|
|
4674
4345
|
import Ora6 from "ora";
|
|
4675
4346
|
|
|
4676
4347
|
// src/cli/utils/lockfile.ts
|
|
4677
|
-
import
|
|
4678
|
-
import
|
|
4348
|
+
import fs11 from "fs";
|
|
4349
|
+
import path15 from "path";
|
|
4679
4350
|
import Z4 from "zod";
|
|
4680
4351
|
import YAML4 from "yaml";
|
|
4681
4352
|
import { MD5 as MD52 } from "object-hash";
|
|
4682
|
-
import
|
|
4353
|
+
import _23 from "lodash";
|
|
4683
4354
|
function createLockfileHelper() {
|
|
4684
4355
|
return {
|
|
4685
4356
|
isLockfileExists: () => {
|
|
4686
4357
|
const lockfilePath = _getLockfilePath();
|
|
4687
|
-
return
|
|
4358
|
+
return fs11.existsSync(lockfilePath);
|
|
4688
4359
|
},
|
|
4689
4360
|
registerSourceData: (pathPattern, sourceData) => {
|
|
4690
4361
|
const lockfile = _loadLockfile();
|
|
4691
4362
|
const sectionKey = MD52(pathPattern);
|
|
4692
|
-
const sectionChecksums =
|
|
4363
|
+
const sectionChecksums = _23.mapValues(sourceData, (value) => MD52(value));
|
|
4693
4364
|
lockfile.checksums[sectionKey] = sectionChecksums;
|
|
4694
4365
|
_saveLockfile(lockfile);
|
|
4695
4366
|
},
|
|
4696
4367
|
registerPartialSourceData: (pathPattern, partialSourceData) => {
|
|
4697
4368
|
const lockfile = _loadLockfile();
|
|
4698
4369
|
const sectionKey = MD52(pathPattern);
|
|
4699
|
-
const sectionChecksums =
|
|
4700
|
-
lockfile.checksums[sectionKey] =
|
|
4370
|
+
const sectionChecksums = _23.mapValues(partialSourceData, (value) => MD52(value));
|
|
4371
|
+
lockfile.checksums[sectionKey] = _23.merge({}, lockfile.checksums[sectionKey] ?? {}, sectionChecksums);
|
|
4701
4372
|
_saveLockfile(lockfile);
|
|
4702
4373
|
},
|
|
4703
4374
|
extractUpdatedData: (pathPattern, sourceData) => {
|
|
4704
4375
|
const lockfile = _loadLockfile();
|
|
4705
4376
|
const sectionKey = MD52(pathPattern);
|
|
4706
|
-
const currentChecksums =
|
|
4377
|
+
const currentChecksums = _23.mapValues(sourceData, (value) => MD52(value));
|
|
4707
4378
|
const savedChecksums = lockfile.checksums[sectionKey] || {};
|
|
4708
|
-
const updatedData =
|
|
4379
|
+
const updatedData = _23.pickBy(sourceData, (value, key) => savedChecksums[key] !== currentChecksums[key]);
|
|
4709
4380
|
return updatedData;
|
|
4710
4381
|
}
|
|
4711
4382
|
};
|
|
4712
4383
|
function _loadLockfile() {
|
|
4713
4384
|
const lockfilePath = _getLockfilePath();
|
|
4714
|
-
if (!
|
|
4385
|
+
if (!fs11.existsSync(lockfilePath)) {
|
|
4715
4386
|
return LockfileSchema.parse({});
|
|
4716
4387
|
}
|
|
4717
|
-
const content =
|
|
4388
|
+
const content = fs11.readFileSync(lockfilePath, "utf-8");
|
|
4718
4389
|
const result = LockfileSchema.parse(YAML4.parse(content));
|
|
4719
4390
|
return result;
|
|
4720
4391
|
}
|
|
4721
4392
|
function _saveLockfile(lockfile) {
|
|
4722
4393
|
const lockfilePath = _getLockfilePath();
|
|
4723
4394
|
const content = YAML4.stringify(lockfile);
|
|
4724
|
-
|
|
4395
|
+
fs11.writeFileSync(lockfilePath, content);
|
|
4725
4396
|
}
|
|
4726
4397
|
function _getLockfilePath() {
|
|
4727
|
-
return
|
|
4398
|
+
return path15.join(process.cwd(), "i18n.lock");
|
|
4728
4399
|
}
|
|
4729
4400
|
}
|
|
4730
4401
|
var LockfileSchema = Z4.object({
|
|
@@ -4775,7 +4446,7 @@ var flagsSchema = Z5.object({
|
|
|
4775
4446
|
// src/cli/cmd/cleanup.ts
|
|
4776
4447
|
import { resolveOverriddenLocale as resolveOverriddenLocale5 } from "@lingo.dev/_spec";
|
|
4777
4448
|
import { Command as Command8 } from "interactive-commander";
|
|
4778
|
-
import
|
|
4449
|
+
import _24 from "lodash";
|
|
4779
4450
|
import Ora7 from "ora";
|
|
4780
4451
|
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(
|
|
4781
4452
|
"--verbose",
|
|
@@ -4811,7 +4482,7 @@ var cleanup_default = new Command8().command("cleanup").description("Remove keys
|
|
|
4811
4482
|
try {
|
|
4812
4483
|
const targetData = await bucketLoader.pull(targetLocale);
|
|
4813
4484
|
const targetKeys = Object.keys(targetData);
|
|
4814
|
-
const keysToRemove =
|
|
4485
|
+
const keysToRemove = _24.difference(targetKeys, sourceKeys);
|
|
4815
4486
|
if (keysToRemove.length === 0) {
|
|
4816
4487
|
bucketOra.succeed(`[${targetLocale}] No keys to remove`);
|
|
4817
4488
|
continue;
|
|
@@ -4820,7 +4491,7 @@ var cleanup_default = new Command8().command("cleanup").description("Remove keys
|
|
|
4820
4491
|
bucketOra.info(`[${targetLocale}] Keys to remove: ${JSON.stringify(keysToRemove, null, 2)}`);
|
|
4821
4492
|
}
|
|
4822
4493
|
if (!options.dryRun) {
|
|
4823
|
-
const cleanedData =
|
|
4494
|
+
const cleanedData = _24.pick(targetData, sourceKeys);
|
|
4824
4495
|
await bucketLoader.push(targetLocale, cleanedData);
|
|
4825
4496
|
bucketOra.succeed(`[${targetLocale}] Removed ${keysToRemove.length} keys`);
|
|
4826
4497
|
} else {
|
|
@@ -4875,7 +4546,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
4875
4546
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4876
4547
|
import Z6 from "zod";
|
|
4877
4548
|
import { ReplexicaEngine } from "@lingo.dev/_sdk";
|
|
4878
|
-
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 (
|
|
4549
|
+
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) => {
|
|
4879
4550
|
const apiKey = program.args[0];
|
|
4880
4551
|
const settings = getSettings(apiKey);
|
|
4881
4552
|
if (!settings.auth.apiKey) {
|
|
@@ -4933,7 +4604,7 @@ import { execSync as execSync2 } from "child_process";
|
|
|
4933
4604
|
|
|
4934
4605
|
// ../../action/src/flows/in-branch.ts
|
|
4935
4606
|
import { execSync } from "child_process";
|
|
4936
|
-
import
|
|
4607
|
+
import path16 from "path";
|
|
4937
4608
|
|
|
4938
4609
|
// ../../action/src/flows/_base.ts
|
|
4939
4610
|
var IntegrationFlow = class {
|
|
@@ -5011,7 +4682,7 @@ var InBranchFlow = class extends IntegrationFlow {
|
|
|
5011
4682
|
return false;
|
|
5012
4683
|
}
|
|
5013
4684
|
}
|
|
5014
|
-
const workingDir =
|
|
4685
|
+
const workingDir = path16.resolve(process.cwd(), this.platformKit.config.workingDir);
|
|
5015
4686
|
if (workingDir !== process.cwd()) {
|
|
5016
4687
|
this.ora.info(`Changing to working directory: ${this.platformKit.config.workingDir}`);
|
|
5017
4688
|
process.chdir(workingDir);
|
|
@@ -5583,7 +5254,7 @@ var status_default = new Command11().command("status").description("Show the sta
|
|
|
5583
5254
|
ora.succeed("Buckets retrieved");
|
|
5584
5255
|
if (flags.file?.length) {
|
|
5585
5256
|
buckets = buckets.map((bucket) => {
|
|
5586
|
-
const paths = bucket.paths.filter((
|
|
5257
|
+
const paths = bucket.paths.filter((path17) => flags.file.find((file) => path17.pathPattern?.match(file)));
|
|
5587
5258
|
return { ...bucket, paths };
|
|
5588
5259
|
}).filter((bucket) => bucket.paths.length > 0);
|
|
5589
5260
|
if (buckets.length === 0) {
|
|
@@ -5593,8 +5264,8 @@ var status_default = new Command11().command("status").description("Show the sta
|
|
|
5593
5264
|
ora.info(`\x1B[36mProcessing only filtered buckets:\x1B[0m`);
|
|
5594
5265
|
buckets.map((bucket) => {
|
|
5595
5266
|
ora.info(` ${bucket.type}:`);
|
|
5596
|
-
bucket.paths.forEach((
|
|
5597
|
-
ora.info(` - ${
|
|
5267
|
+
bucket.paths.forEach((path17) => {
|
|
5268
|
+
ora.info(` - ${path17.pathPattern}`);
|
|
5598
5269
|
});
|
|
5599
5270
|
});
|
|
5600
5271
|
}
|
|
@@ -5823,10 +5494,10 @@ var status_default = new Command11().command("status").description("Show the sta
|
|
|
5823
5494
|
if (flags.confirm && Object.keys(fileStats).length > 0) {
|
|
5824
5495
|
console.log(chalk2.bold(`
|
|
5825
5496
|
\u{1F4D1} BREAKDOWN BY FILE:`));
|
|
5826
|
-
Object.entries(fileStats).sort((a, b) => b[1].wordCount - a[1].wordCount).forEach(([
|
|
5497
|
+
Object.entries(fileStats).sort((a, b) => b[1].wordCount - a[1].wordCount).forEach(([path17, stats]) => {
|
|
5827
5498
|
if (stats.sourceKeys === 0) return;
|
|
5828
5499
|
console.log(chalk2.bold(`
|
|
5829
|
-
\u2022 ${
|
|
5500
|
+
\u2022 ${path17}:`));
|
|
5830
5501
|
console.log(` ${stats.sourceKeys} source keys, ~${stats.wordCount.toLocaleString()} source words`);
|
|
5831
5502
|
const fileTable = new Table({
|
|
5832
5503
|
head: ["Language", "Status", "Details"],
|
|
@@ -5956,7 +5627,7 @@ function validateParams2(i18nConfig, flags) {
|
|
|
5956
5627
|
// package.json
|
|
5957
5628
|
var package_default = {
|
|
5958
5629
|
name: "lingo.dev",
|
|
5959
|
-
version: "0.87.
|
|
5630
|
+
version: "0.87.1",
|
|
5960
5631
|
description: "Lingo.dev CLI",
|
|
5961
5632
|
private: false,
|
|
5962
5633
|
publishConfig: {
|