diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-03-14 01:46:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-14 01:46:14 +0800 |
commit | 572234e383f944eb2be28c4192f209c3972747b7 (patch) | |
tree | 3d6a214b845790c96e2c98e6c140ed6724d261e4 /development/genStates.js | |
parent | 70f33d47472863e3fce41eff60c1fe078efef7de (diff) | |
parent | 1fa5cec2ec784ace2dd8d1afab6c0d8cc195feb5 (diff) | |
download | tangerine-wallet-browser-572234e383f944eb2be28c4192f209c3972747b7.tar tangerine-wallet-browser-572234e383f944eb2be28c4192f209c3972747b7.tar.gz tangerine-wallet-browser-572234e383f944eb2be28c4192f209c3972747b7.tar.bz2 tangerine-wallet-browser-572234e383f944eb2be28c4192f209c3972747b7.tar.lz tangerine-wallet-browser-572234e383f944eb2be28c4192f209c3972747b7.tar.xz tangerine-wallet-browser-572234e383f944eb2be28c4192f209c3972747b7.tar.zst tangerine-wallet-browser-572234e383f944eb2be28c4192f209c3972747b7.zip |
Merge branch 'master' into i3033-responsive-newui-onboarding
Diffstat (limited to 'development/genStates.js')
-rw-r--r-- | development/genStates.js | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/development/genStates.js b/development/genStates.js index 39a672ee0..d92e2bc2e 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.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) +} |