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