From f387f50003c479f77626abd22b5da702e5e36f8d Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 10 Feb 2022 21:23:02 +0300 Subject: [PATCH] Create update.js --- scripts/api/update.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 scripts/api/update.js diff --git a/scripts/api/update.js b/scripts/api/update.js new file mode 100644 index 0000000..3839bb2 --- /dev/null +++ b/scripts/api/update.js @@ -0,0 +1,23 @@ +const { csv } = require('./core') +const path = require('path') +const glob = require('glob') +const fs = require('fs') + +const DATABASE_DIR = './database' +const OUTPUT_DIR = './.gh-pages' + +fs.exists(OUTPUT_DIR, function (exists) { + if (!exists) { + fs.mkdirSync(OUTPUT_DIR) + } +}) + +glob(`${DATABASE_DIR}/*.csv`, async function (err, files) { + for (const inputFile of files) { + const inputFilename = path.parse(inputFile).name + const outputFile = `${OUTPUT_DIR}/${inputFilename}.json` + + const json = await csv.load(inputFile) + fs.writeFileSync(path.resolve(outputFile), JSON.stringify(json)) + } +})