mirror of https://github.com/iptv-org/iptv
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
598 B
JavaScript
24 lines
598 B
JavaScript
const file = require('./file')
|
|
const generators = require('../generators')
|
|
|
|
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs/generators'
|
|
|
|
const generator = {}
|
|
|
|
generator.generate = async function (name, items = []) {
|
|
if (typeof generators[name] === 'function') {
|
|
try {
|
|
const logs = await generators[name].bind()(items)
|
|
await file.create(`${LOGS_DIR}/${name}.log`, logs.map(toJSON).join('\n'))
|
|
} catch (error) {
|
|
logger.error(`generators/${name}.js: ${error.message}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = generator
|
|
|
|
function toJSON(item) {
|
|
return JSON.stringify(item)
|
|
}
|