User Tools

Site Tools


catobj.js
/*
 * Author, Copyright: Oleg Borodin <onborodin@gmail.com>
 */
let fs = require('fs')
let path = require('path')
let _ = require('lodash')
 
let baseDir = './zuxxxx'
let classes = [
    'axxx',
    'cxxxx',
    'cxxxx',
    'cxxxx',
    'cxxxx',
    'cxxxx',
    'foxxx',
    'inxxx'
]
 
for (let n in classes) {
    let className = classes[n]
    let dir = path.join(baseDir, className)
    let files = fs.readdirSync(dir)
    let mix = {}
    for (let i in files) {
        data = fs.readFileSync(path.join(dir, files[i]), 'utf8')
        obj = JSON.parse(data)
        mix = _.merge(mix, obj)
    }
    let jsonData = JSON.stringify(mix, null, '    ')
    console.log(jsonData)
    fs.writeFileSync(className + '.json', jsonData)
}
// EOF