iptv/scripts/core/generator.js

24 lines
598 B
JavaScript
Raw Normal View History

2021-12-12 04:10:18 +00:00
const file = require('./file')
2022-02-06 21:04:56 +00:00
const generators = require('../generators')
2021-12-12 04:10:18 +00:00
2022-02-06 21:04:56 +00:00
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs/generators'
2021-12-12 04:10:18 +00:00
2022-02-06 21:04:56 +00:00
const generator = {}
2022-02-05 05:12:17 +00:00
2022-02-06 21:04:56 +00:00
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}`)
2022-02-05 05:12:17 +00:00
}
2021-12-12 04:10:18 +00:00
}
}
2022-02-06 21:04:56 +00:00
module.exports = generator
2021-12-12 04:10:18 +00:00
2022-02-06 21:04:56 +00:00
function toJSON(item) {
return JSON.stringify(item)
2021-12-12 04:10:18 +00:00
}