From 57f2dd2cb8f3ae92ba29d17ced2f490109bd8bd3 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 14 Feb 2022 06:12:11 +0300 Subject: [PATCH] Update db/export.js --- .github/workflows/deploy.yml | 2 +- scripts/db/export.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dd58d1b7..70c10da3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -22,7 +22,7 @@ jobs: with: repository-name: iptv-org/api branch: gh-pages - folder: .gh-pages + folder: .api token: ${{ steps.create-app-token.outputs.token }} git-config-name: iptv-bot[bot] git-config-email: 84861620+iptv-bot[bot]@users.noreply.github.com diff --git a/scripts/db/export.js b/scripts/db/export.js index e14f1cac..1c850527 100644 --- a/scripts/db/export.js +++ b/scripts/db/export.js @@ -1,14 +1,18 @@ -const { csv, file } = require('../core') +const { csv, file, logger } = require('../core') +const chalk = require('chalk') const DATA_DIR = process.env.DATA_DIR || './data' -const OUTPUT_DIR = process.env.OUTPUT_DIR || './.gh-pages' +const OUTPUT_DIR = process.env.OUTPUT_DIR || './.api' async function main() { const files = await file.list(`${DATA_DIR}/*.csv`) - for (const inputFile of files) { - const inputFilename = file.getFilename(inputFile) - const json = await csv.load(inputFile) - await file.create(`${OUTPUT_DIR}/${inputFilename}.json`, JSON.stringify(json)) + for (const filepath of files) { + const filename = file.getFilename(filepath) + const json = await csv.load(filepath).catch(err => { + logger.error(chalk.red(`\n${err.message} (${filepath})`)) + process.exit(1) + }) + await file.create(`${OUTPUT_DIR}/${filename}.json`, JSON.stringify(json)) } }