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:
parent
2c3e6552d2
commit
7e56c6b6fa
@ -1,18 +1,21 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const { promisify } = require('util')
|
||||||
|
|
||||||
|
start().catch(console.error)
|
||||||
|
|
||||||
|
async function start () {
|
||||||
const statesPath = path.join(__dirname, 'states')
|
const statesPath = path.join(__dirname, 'states')
|
||||||
const stateNames = fs.readdirSync(statesPath)
|
const stateFilesNames = await promisify(fs.readdirSync)(statesPath)
|
||||||
|
const states = {}
|
||||||
const states = stateNames.reduce((result, stateFileName) => {
|
await Promise.all(stateFilesNames.map(async (stateFileName) => {
|
||||||
const statePath = path.join(__dirname, 'states', stateFileName)
|
const stateFilePath = path.join(__dirname, 'states', stateFileName)
|
||||||
const stateFile = fs.readFileSync(statePath).toString()
|
const stateFileContent = await promisify(fs.readFileSync)(stateFilePath, 'utf8')
|
||||||
const state = JSON.parse(stateFile)
|
const state = JSON.parse(stateFileContent)
|
||||||
result[stateFileName.split('.')[0].replace(/-/g, ' ', 'g')] = state
|
const stateName = stateFileName.split('.')[0].replace(/-/g, ' ', 'g')
|
||||||
return result
|
states[stateName] = state
|
||||||
}, {})
|
}))
|
||||||
|
const generatedFileContent = `module.exports = ${JSON.stringify(states)}`
|
||||||
const result = `module.exports = ${JSON.stringify(states)}`
|
const generatedFilePath = path.join(__dirname, 'states.js')
|
||||||
|
await promisify(fs.writeFile)(generatedFilePath, generatedFileContent)
|
||||||
const statesJsonPath = path.join(__dirname, 'states.js')
|
}
|
||||||
fs.writeFileSync(statesJsonPath, result)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user