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

22 lines
873 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')
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)
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)
}