@type {(localesDir: string, code: string) => Promise }
(localesDir, code)
| 39 | |
| 40 | /** @type {(localesDir: string, code: string) => Promise<string>} */ |
| 41 | async function mergeLocale(localesDir, code) { |
| 42 | /** @type {LocaleMessages} */ |
| 43 | let result = {}; |
| 44 | |
| 45 | /** @type {(dir: string) => Promise<void>} */ |
| 46 | const walk = async (dir) => { |
| 47 | const dirFiles = []; |
| 48 | const dirDirs = []; |
| 49 | const paths = await fs.readdir(dir); |
| 50 | for (const path of paths) { |
| 51 | const stat = await fs.stat(`${dir}/${path}`); |
| 52 | if (stat.isDirectory()) { |
| 53 | dirDirs.push(path); |
| 54 | } else { |
| 55 | dirFiles.push(path); |
| 56 | } |
| 57 | } |
| 58 | const localeFiles = dirFiles.filter((f) => f.split('.').at(-2) === code); |
| 59 | for (const localeFile of localeFiles) { |
| 60 | const messages = await localeFileToJson(`${dir}/${localeFile}`); |
| 61 | result = {...result, ...messages}; |
| 62 | } |
| 63 | for (const folder of dirDirs) { |
| 64 | await walk(`${dir}/${folder}`); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | await walk(localesDir); |
| 69 | return JSON.stringify(result, null, 4); |
| 70 | } |
| 71 | |
| 72 | async function bundleLocales(srcLocalesDir, {platforms, debug}) { |
| 73 | const absoluteSrcLocalesDir = absolutePath(srcLocalesDir); |
no test coverage detected
searching dependent graphs…