You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1.0 KiB
26 lines
1.0 KiB
const fs = require('fs')
|
|
const path = require('path')
|
|
const promisify = require('pify')
|
|
const getLocaleMessages = require('./get-locale-messages')
|
|
|
|
start().catch(console.error)
|
|
|
|
async function start () {
|
|
const statesPath = path.join(__dirname, 'states')
|
|
const stateFilesNames = await promisify(fs.readdir)(statesPath)
|
|
const states = {}
|
|
await Promise.all(stateFilesNames.map(async (stateFileName) => {
|
|
const stateFilePath = path.join(__dirname, 'states', stateFileName)
|
|
const stateFileContent = await promisify(fs.readFile)(stateFilePath, 'utf8')
|
|
const state = JSON.parse(stateFileContent)
|
|
|
|
const enLocaleMessages = await getLocaleMessages()
|
|
state.localeMessages = { en: enLocaleMessages, current: {} }
|
|
|
|
const stateName = stateFileName.split('.')[0].replace(/-/g, ' ', 'g')
|
|
states[stateName] = state
|
|
}))
|
|
const generatedFileContent = `module.exports = ${JSON.stringify(states)}`
|
|
const generatedFilePath = path.join(__dirname, 'states.js')
|
|
await promisify(fs.writeFile)(generatedFilePath, generatedFileContent)
|
|
}
|
|
|