From 83d7d33d868d51cc5249a0dc3eeb550d3ac5d1ce Mon Sep 17 00:00:00 2001 From: ShareVB Date: Sun, 15 Nov 2026 22:37:23 +0100 Subject: [PATCH] fix(extract desc script): handle formatting of long lines --- scripts/extract-tools-desc.mjs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/extract-tools-desc.mjs b/scripts/extract-tools-desc.mjs index c4e6f4a2..74a41e00 100644 --- a/scripts/extract-tools-desc.mjs +++ b/scripts/extract-tools-desc.mjs @@ -12,12 +12,13 @@ if (fs.existsSync(localesFile)) { } // Single-quoted JS string that may contain escaped quotes. `[^'\\]|\\.` cannot overlap, so it cannot backtrack exponentially. -const quotedValue = (key) => new RegExp(`\\b${key}: '((?:[^'\\\\]|\\\\.)*)'`); +const quotedValue = (key) => new RegExp(`\\b${key}:[ \n]+'((?:[^'\\\\]|\\\\.)*)'`); // Decode JS string escapes (\n, \x27, \u00e9, \u{1F600}, \') the way the JS parser would const JS_ESCAPES = { n: '\n', r: '\r', t: '\t', b: '\b', f: '\f', v: '\v', 0: '\0' }; const unescapeValue = (value) => value.replace(/\\(?:u\{([\da-fA-F]+)\}|u([\da-fA-F]{4})|x([\da-fA-F]{2})|(.))/g, (_, codePoint, u4, x2, char) => - char === undefined ? String.fromCodePoint(Number.parseInt(codePoint ?? u4 ?? x2, 16)) : (JS_ESCAPES[char] ?? char)); + char === undefined ? String.fromCodePoint(Number.parseInt(codePoint ?? u4 ?? x2, 16)) : (JS_ESCAPES[char] ?? char), + ); function processFile(filePath) { const parentDir = path.basename(path.dirname(filePath)); // Get parent directory name @@ -29,13 +30,17 @@ function processFile(filePath) { const externAccessDescriptionMatch = originalContent.match(quotedValue('externAccessDescription')); if (!nameMatch || !descriptionMatch) { - console.warn(`Skipping ${filePath}: Unable to extract name or description.`); + console.warn( + `Skipping ${filePath}: Unable to extract name (${nameMatch ? 'found' : 'not found'}) or description (${descriptionMatch ? 'found' : 'not found'}).`, + ); return; } const nameValue = unescapeValue(nameMatch[1]); const descriptionValue = unescapeValue(descriptionMatch[1]); - const externAccessDescriptionValue = externAccessDescriptionMatch ? unescapeValue(externAccessDescriptionMatch[1]) : null; + const externAccessDescriptionValue = externAccessDescriptionMatch + ? unescapeValue(externAccessDescriptionMatch[1]) + : null; // Modify name and description to use the translate function const transformedContent = originalContent @@ -67,8 +72,7 @@ function iterateFolder(folderPath) { if (stat.isDirectory()) { iterateFolder(itemPath); - } - else if (item === 'index.ts') { + } else if (item === 'index.ts') { processFile(itemPath); } });