aboutsummaryrefslogtreecommitdiffstats
path: root/development
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-03-12 05:51:54 +0800
committerkumavis <aaron@kumavis.me>2018-03-12 05:51:54 +0800
commit7e56c6b6fa92453559f2510e390fce451de2dead (patch)
tree76669d8a41f88b9389f1da0dcb3038736a2bb975 /development
parent2c3e6552d203181bca1c69622a78e5faa633ce76 (diff)
downloadtangerine-wallet-browser-7e56c6b6fa92453559f2510e390fce451de2dead.tar
tangerine-wallet-browser-7e56c6b6fa92453559f2510e390fce451de2dead.tar.gz
tangerine-wallet-browser-7e56c6b6fa92453559f2510e390fce451de2dead.tar.bz2
tangerine-wallet-browser-7e56c6b6fa92453559f2510e390fce451de2dead.tar.lz
tangerine-wallet-browser-7e56c6b6fa92453559f2510e390fce451de2dead.tar.xz
tangerine-wallet-browser-7e56c6b6fa92453559f2510e390fce451de2dead.tar.zst
tangerine-wallet-browser-7e56c6b6fa92453559f2510e390fce451de2dead.zip
test - genStates - use async api
Diffstat (limited to 'development')
-rw-r--r--development/genStates.js31
1 files changed, 17 insertions, 14 deletions
diff --git a/development/genStates.js b/development/genStates.js
index 39a672ee0..325ef71f3 100644
--- a/development/genStates.js
+++ b/development/genStates.js
@@ -1,18 +1,21 @@
const fs = require('fs')
const path = require('path')
+const { promisify } = require('util')
-const statesPath = path.join(__dirname, 'states')
-const stateNames = fs.readdirSync(statesPath)
+start().catch(console.error)
-const states = stateNames.reduce((result, stateFileName) => {
- const statePath = path.join(__dirname, 'states', stateFileName)
- const stateFile = fs.readFileSync(statePath).toString()
- const state = JSON.parse(stateFile)
- result[stateFileName.split('.')[0].replace(/-/g, ' ', 'g')] = state
- return result
-}, {})
-
-const result = `module.exports = ${JSON.stringify(states)}`
-
-const statesJsonPath = path.join(__dirname, 'states.js')
-fs.writeFileSync(statesJsonPath, result)
+async function start () {
+ const statesPath = path.join(__dirname, 'states')
+ const stateFilesNames = await promisify(fs.readdirSync)(statesPath)
+ const states = {}
+ await Promise.all(stateFilesNames.map(async (stateFileName) => {
+ const stateFilePath = path.join(__dirname, 'states', stateFileName)
+ const stateFileContent = await promisify(fs.readFileSync)(stateFilePath, 'utf8')
+ 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)
+}