From 722f167fbb44bedeff6b0e18c75ce9f5684f49ef Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 12 Feb 2022 06:29:23 +0300 Subject: [PATCH] Update export.js --- scripts/db/export.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/scripts/db/export.js b/scripts/db/export.js index 787a7f68..e14f1cac 100644 --- a/scripts/db/export.js +++ b/scripts/db/export.js @@ -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()