aboutsummaryrefslogtreecommitdiffstats
path: root/development/genStates.js
diff options
context:
space:
mode:
authorLe Quoc Viet <vietlq85@gmail.com>2018-03-15 16:11:42 +0800
committerGitHub <noreply@github.com>2018-03-15 16:11:42 +0800
commit04079455e36e48433cf8055c8f1f79e1e7e18298 (patch)
treed7de2a6603b67b56abacf09bee4d2bbbfe886b8f /development/genStates.js
parent5bdee96e73f65a0b369277e9c56b0afe5159e65b (diff)
parente2efc91aee64072c408ab509219dcbfb389c7609 (diff)
downloadtangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.tar
tangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.tar.gz
tangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.tar.bz2
tangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.tar.lz
tangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.tar.xz
tangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.tar.zst
tangerine-wallet-browser-04079455e36e48433cf8055c8f1f79e1e7e18298.zip
Merge pull request #1 from MetaMask/master
Merge from the source
Diffstat (limited to 'development/genStates.js')
-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..bc274c757 100644
--- a/development/genStates.js
+++ b/development/genStates.js
@@ -1,18 +1,21 @@
const fs = require('fs')
const path = require('path')
+const promisify = require('pify')
-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.readdir)(statesPath)
+ const states = {}
+ await Promise.all(stateFilesNames.map(async (stateFileName) => {
+ const stateFilePath = path.join(__dirname, 'states', stateFileName)
+ const stateFileContent = await promisify(fs.readFile)(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)
+}