Skip to content

Commit e9a8442

Browse files
committed
chore: fix error for lunaria script
1 parent 5b68303 commit e9a8442

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lunaria/prepare-json-files.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@ export async function prepareJsonFiles() {
3737
await Promise.all(currentLocales.map(l => mergeLocale(l)))
3838
}
3939

40-
export async function mergeLocaleObject(locale: LocaleObject) {
40+
export async function mergeLocaleObject(locale: LocaleObject, copy = false) {
4141
const files = locale.files ?? []
4242
if (locale.file || files.length === 1) {
43-
const json = locale.file ?? (files[0] ? getFileName(files[0]) : undefined)
43+
const json =
44+
(locale.file ? getFileName(locale.file) : undefined) ??
45+
(files[0] ? getFileName(files[0]) : undefined)
4446
if (!json) return
45-
await fs.cp(path.resolve(`${localesFolder}/${json}`), path.resolve(`${destFolder}/${json}`))
46-
return
47+
if (copy) {
48+
await fs.cp(path.resolve(`${localesFolder}/${json}`), path.resolve(`${destFolder}/${json}`))
49+
return
50+
} else {
51+
return await loadJsonFile(json)
52+
}
4753
}
4854

4955
const firstFile = files[0]
@@ -69,9 +75,14 @@ function getFileName(file: string | { path: string }): string {
6975
}
7076

7177
async function mergeLocale(locale: LocaleObject) {
72-
const source = await mergeLocaleObject(locale)
78+
const source = await mergeLocaleObject(locale, true)
79+
if (!source) {
80+
return
81+
}
82+
7383
await fs.writeFile(
7484
path.resolve(`${destFolder}/${locale.code}.json`),
7585
JSON.stringify(source, null, 2),
86+
'utf-8',
7687
)
7788
}

0 commit comments

Comments
 (0)