1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/development/genStates.js

27 lines
1010 B
JavaScript
Raw Normal View History

2016-07-01 03:22:16 +02:00
const fs = require('fs')
const path = require('path')
const promisify = require('pify')
const enLocaleMessages = require('../app/_locales/en/messages.json')
2016-07-01 03:22:16 +02:00
2018-03-11 22:51:54 +01:00
start().catch(console.error)
2016-07-01 03:22:16 +02:00
2018-03-11 22:51:54 +01:00
async function start () {
const statesPath = path.join(__dirname, 'states')
2018-03-12 03:06:14 +01:00
const stateFilesNames = await promisify(fs.readdir)(statesPath)
2018-03-11 22:51:54 +01:00
const states = {}
await Promise.all(stateFilesNames.map(async (stateFileName) => {
const stateFilePath = path.join(__dirname, 'states', stateFileName)
2018-03-12 03:06:14 +01:00
const stateFileContent = await promisify(fs.readFile)(stateFilePath, 'utf8')
2018-03-11 22:51:54 +01:00
const state = JSON.parse(stateFileContent)
2018-03-22 04:39:21 +01:00
state.localeMessages = { en: enLocaleMessages, current: {} }
2018-03-11 22:51:54 +01:00
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)
}