mirror of
https://github.com/iptv-org/database.git
synced 2024-11-22 02:44:10 -05:00
Update export.js
This commit is contained in:
parent
3ff44c3fab
commit
722f167fbb
1 changed files with 8 additions and 16 deletions
|
@ -1,23 +1,15 @@
|
||||||
const { csv } = require('../core')
|
const { csv, file } = require('../core')
|
||||||
const path = require('path')
|
|
||||||
const glob = require('glob')
|
|
||||||
const fs = require('fs')
|
|
||||||
|
|
||||||
const DATA_DIR = process.env.DATA_DIR || './data'
|
const DATA_DIR = process.env.DATA_DIR || './data'
|
||||||
const OUTPUT_DIR = process.env.OUTPUT_DIR || './.gh-pages'
|
const OUTPUT_DIR = process.env.OUTPUT_DIR || './.gh-pages'
|
||||||
|
|
||||||
fs.exists(OUTPUT_DIR, function (exists) {
|
async function main() {
|
||||||
if (!exists) {
|
const files = await file.list(`${DATA_DIR}/*.csv`)
|
||||||
fs.mkdirSync(OUTPUT_DIR)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
glob(`${DATA_DIR}/*.csv`, async function (err, files) {
|
|
||||||
for (const inputFile of files) {
|
for (const inputFile of files) {
|
||||||
const inputFilename = path.parse(inputFile).name
|
const inputFilename = file.getFilename(inputFile)
|
||||||
const outputFile = `${OUTPUT_DIR}/${inputFilename}.json`
|
|
||||||
|
|
||||||
const json = await csv.load(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()
|
||||||
|
|
Loading…
Reference in a new issue