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 { csv, file } = require('../core')
const path = require('path')
const glob = require('glob')
const fs = require('fs')
const DATA_DIR = process.env.DATA_DIR || './data' const DATA_DIR = process.env.DATA_DIR || './data'
const OUTPUT_DIR = process.env.OUTPUT_DIR || './.gh-pages' const OUTPUT_DIR = process.env.OUTPUT_DIR || './.gh-pages'
fs.exists(OUTPUT_DIR, function (exists) { async function main() {
if (!exists) { const files = await file.list(`${DATA_DIR}/*.csv`)
fs.mkdirSync(OUTPUT_DIR)
}
})
glob(`${DATA_DIR}/*.csv`, async function (err, files) {
for (const inputFile of files) { for (const inputFile of files) {
const inputFilename = path.parse(inputFile).name const inputFilename = file.getFilename(inputFile)
const outputFile = `${OUTPUT_DIR}/${inputFilename}.json`
const json = await csv.load(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()