-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
69 lines (58 loc) · 1.52 KB
/
build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import originalList from 'iso-639-3'
import nativeNameList from 'iso-639/data/iso_639-1.json'
import { outputFile } from 'fs-extra'
import prettier from 'prettier'
import speakersRaw from 'speakers'
import { join } from 'path'
const rtl = [
'ara',
'arc',
'ave',
'egy',
'heb',
'nqo',
'pal',
'phn',
'sam',
'syc',
'syr',
'per',
'fas',
'kur',
'urd',
]
const speakers = Object.assign(speakersRaw, { zho: speakersRaw.cmn })
import { Language, LanguageDataset } from './src/models'
import { hasKey } from './src/util'
type WoormyLanguage = Exclude<Language, 'isRTL' | 'nativeName' | 'speakers'>
export async function compile(languages: any, path: string): Promise<void> {
const formattedOutput = prettier.format(JSON.stringify(languages), {
parser: 'json-stringify',
})
await outputFile(join('.', path), formattedOutput)
}
async function run(): Promise<void> {
const dataset: LanguageDataset = (originalList as WoormyLanguage[]).map(
(language) => {
const iso6391 = language.iso6391
const iso6393 = language.iso6393
const out: Language = Object.assign({}, language, {
isRTL: rtl.includes(iso6393),
})
if (!iso6391) {
return out
}
if (hasKey(nativeNameList, iso6391)) {
out['nativeName'] = nativeNameList[iso6391].nativeName
.split(',')
.shift()
}
if (hasKey(speakers, iso6393)) {
out['speakers'] = speakers[iso6393]
}
return out
},
)
await compile(dataset, 'src/data.json')
}
run()