2016-07-01 03:22:16 +02:00
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
2018-03-14 18:32:55 +01:00
|
|
|
const promisify = require('pify')
|
2016-07-01 03:22:16 +02:00
|
|
|
|
2018-03-11 22:51:54 +01:00
|
|
|
start().catch(console.error)
|
2016-07-01 03:22:16 +02:00
|
|
|
|
2018-03-11 22:51:54 +01:00
|
|
|
async function start () {
|
|
|
|
const statesPath = path.join(__dirname, 'states')
|
2018-03-12 03:06:14 +01:00
|
|
|
const stateFilesNames = await promisify(fs.readdir)(statesPath)
|
2018-03-11 22:51:54 +01:00
|
|
|
const states = {}
|
|
|
|
await Promise.all(stateFilesNames.map(async (stateFileName) => {
|
|
|
|
const stateFilePath = path.join(__dirname, 'states', stateFileName)
|
2018-03-12 03:06:14 +01:00
|
|
|
const stateFileContent = await promisify(fs.readFile)(stateFilePath, 'utf8')
|
2018-03-11 22:51:54 +01:00
|
|
|
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)
|
|
|
|
}
|