1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

test - genStates - use async api

This commit is contained in:
kumavis 2018-03-11 14:51:54 -07:00
parent 2c3e6552d2
commit 7e56c6b6fa

View File

@ -1,18 +1,21 @@
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const { promisify } = require('util')
const statesPath = path.join(__dirname, 'states') start().catch(console.error)
const stateNames = fs.readdirSync(statesPath)
const states = stateNames.reduce((result, stateFileName) => { async function start () {
const statePath = path.join(__dirname, 'states', stateFileName) const statesPath = path.join(__dirname, 'states')
const stateFile = fs.readFileSync(statePath).toString() const stateFilesNames = await promisify(fs.readdirSync)(statesPath)
const state = JSON.parse(stateFile) const states = {}
result[stateFileName.split('.')[0].replace(/-/g, ' ', 'g')] = state await Promise.all(stateFilesNames.map(async (stateFileName) => {
return result const stateFilePath = path.join(__dirname, 'states', stateFileName)
}, {}) const stateFileContent = await promisify(fs.readFileSync)(stateFilePath, 'utf8')
const state = JSON.parse(stateFileContent)
const result = `module.exports = ${JSON.stringify(states)}` const stateName = stateFileName.split('.')[0].replace(/-/g, ' ', 'g')
states[stateName] = state
const statesJsonPath = path.join(__dirname, 'states.js') }))
fs.writeFileSync(statesJsonPath, result) const generatedFileContent = `module.exports = ${JSON.stringify(states)}`
const generatedFilePath = path.join(__dirname, 'states.js')
await promisify(fs.writeFile)(generatedFilePath, generatedFileContent)
}