mirror of
https://github.com/iptv-org/database.git
synced 2024-11-29 21:59:35 -05:00
19 lines
593 B
JavaScript
19 lines
593 B
JavaScript
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 || './.api'
|
|
|
|
async function main() {
|
|
const files = await file.list(`${DATA_DIR}/*.csv`)
|
|
for (const filepath of files) {
|
|
const filename = file.getFilename(filepath)
|
|
const json = await csv.fromFile(filepath).catch(err => {
|
|
logger.error(chalk.red(`\n${err.message} (${filepath})`))
|
|
process.exit(1)
|
|
})
|
|
await file.create(`${OUTPUT_DIR}/${filename}.json`, JSON.stringify(json))
|
|
}
|
|
}
|
|
|
|
main()
|