forked from Oky-period-tracker/periodtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge-provinces.ts
82 lines (63 loc) · 2.15 KB
/
merge-provinces.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
70
71
72
73
74
75
76
77
78
79
80
81
82
import fs from 'fs'
import { provinces } from './packages/core/src/modules/translations/provinces'
import { logger } from './logger'
// Temporarily add locales to this array then execute this script to merge them into the locales.ts file in your /translations submodule
const localesToMerge = []
// Temporarily add provinces to this array then execute this script to merge them into the provinces.ts file in your /translations submodule
const provincesToMerge = []
const outputFilepath = './packages/core/src/modules/translations/provinces.ts'
// ========================= Merge ========================= //
const mergeProvinces = () => {
const mergedProvinces = provinces.map((province, index) => {
if (
province.code !== provincesToMerge[index].code ||
province.uid !== provincesToMerge[index].uid
) {
throw new Error('Error, mismatch between arrays')
}
const newValues = Object.keys(provincesToMerge[index]).reduce((acc, key) => {
if (localesToMerge.includes(key)) {
acc[key] = provincesToMerge[index][key]
}
return acc
}, {})
return {
...province,
...newValues,
}
})
const outputString = `
import { Locale } from '.'
type Province = {
code: string
uid: number
} & {
[K in Locale]: string
}
export const provinces: Province[] = ${JSON.stringify(mergedProvinces)}`
fs.writeFileSync(outputFilepath, outputString)
}
// ========================= Add Locales ========================= //
const localeToInsert = 'es'
const addLocale = () => {
const updatedProvinces = provinces.map((province, index) => {
return {
...province,
[localeToInsert]: province.en, // TODO: This simply copies the english value
}
})
const outputString = `
import { Locale } from '.'
type Province = {
code: string
uid: number
} & {
[K in Locale]: string
}
export const provinces: Province[] = ${JSON.stringify(updatedProvinces)}`
fs.writeFileSync(outputFilepath, outputString)
}
// ========================= Execute ========================= //
// mergeProvinces()
// addLocale()
logger('===== EDIT THIS FILE BEFORE EXECUTING IT =====')