Update db/export.js

This commit is contained in:
Aleksandr Statciuk 2022-02-14 06:12:11 +03:00
parent 46c9fcf345
commit 57f2dd2cb8
2 changed files with 11 additions and 7 deletions

View file

@ -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

View file

@ -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))
}
}