Update export.js

This commit is contained in:
Aleksandr Statciuk 2022-02-12 06:29:23 +03:00
parent 3ff44c3fab
commit 722f167fbb

View file

@ -1,23 +1,15 @@
const { csv } = require('../core')
const path = require('path')
const glob = require('glob')
const fs = require('fs')
const { csv, file } = require('../core')
const DATA_DIR = process.env.DATA_DIR || './data'
const OUTPUT_DIR = process.env.OUTPUT_DIR || './.gh-pages'
fs.exists(OUTPUT_DIR, function (exists) {
if (!exists) {
fs.mkdirSync(OUTPUT_DIR)
}
})
glob(`${DATA_DIR}/*.csv`, async function (err, files) {
async function main() {
const files = await file.list(`${DATA_DIR}/*.csv`)
for (const inputFile of files) {
const inputFilename = path.parse(inputFile).name
const outputFile = `${OUTPUT_DIR}/${inputFilename}.json`
const inputFilename = file.getFilename(inputFile)
const json = await csv.load(inputFile)
fs.writeFileSync(path.resolve(outputFile), JSON.stringify(json))
await file.create(`${OUTPUT_DIR}/${inputFilename}.json`, JSON.stringify(json))
}
})
}
main()