2018-12-17 16:34:32 +00:00
|
|
|
const { readFileSync, writeFileSync } = require('fs')
|
|
|
|
const { resolve } = require('path')
|
2017-02-24 21:45:18 +00:00
|
|
|
const glob = require('glob')
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
const defaultMessages = glob
|
|
|
|
.sync('./lang/.messages/**/*.json')
|
|
|
|
.map(filename => readFileSync(filename, 'utf8'))
|
|
|
|
.map(file => JSON.parse(file))
|
2017-02-24 21:45:18 +00:00
|
|
|
.reduce((messages, descriptors) => {
|
2018-12-17 16:34:32 +00:00
|
|
|
descriptors.forEach(({ id, defaultMessage }) => {
|
2017-02-24 21:45:18 +00:00
|
|
|
if (messages.hasOwnProperty(id)) {
|
|
|
|
throw new Error(`Duplicate message id: ${id}`)
|
|
|
|
}
|
|
|
|
messages[id] = defaultMessage
|
|
|
|
})
|
|
|
|
return messages
|
|
|
|
}, {})
|
|
|
|
|
|
|
|
writeFileSync('./lang/en.json', JSON.stringify(defaultMessages, null, 2))
|
|
|
|
console.log(`> Wrote default messages to: "${resolve('./lang/en.json')}"`)
|